notion-client
Advanced tools
Comparing version 4.12.0 to 4.13.0
@@ -31,6 +31,4 @@ import { OptionsOfJSONResponseBody } from 'got'; | ||
getPageRaw(pageId: string, gotOptions?: OptionsOfJSONResponseBody): Promise<notion.PageChunk>; | ||
getCollectionData(collectionId: string, collectionViewId: string, { type, query, groups, limit, searchQuery, userTimeZone, loadContentCover, gotOptions }?: { | ||
getCollectionData(collectionId: string, collectionViewId: string, collectionView: any, { limit, searchQuery, userTimeZone, loadContentCover, gotOptions }?: { | ||
type?: notion.CollectionViewType; | ||
query?: any; | ||
groups?: any; | ||
limit?: number; | ||
@@ -43,3 +41,2 @@ searchQuery?: string; | ||
}): Promise<notion.CollectionInstance>; | ||
private getQuery; | ||
getUsers(userIds: string[], gotOptions?: OptionsOfJSONResponseBody): Promise<notion.RecordValues<notion.User>>; | ||
@@ -46,0 +43,0 @@ getBlocks(blockIds: string[], gotOptions?: OptionsOfJSONResponseBody): Promise<notion.PageChunk>; |
@@ -124,19 +124,12 @@ "use strict"; | ||
var _a; | ||
var _b, _c, _d, _e, _f, _g, _h, _j; | ||
return __generator(this, function (_k) { | ||
switch (_k.label) { | ||
var _b, _c; | ||
return __generator(this, function (_d) { | ||
switch (_d.label) { | ||
case 0: | ||
collectionId = collectionInstance.collectionId, collectionViewId = collectionInstance.collectionViewId; | ||
collectionView = (_b = recordMap.collection_view[collectionViewId]) === null || _b === void 0 ? void 0 : _b.value; | ||
_k.label = 1; | ||
_d.label = 1; | ||
case 1: | ||
_k.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, this.getCollectionData(collectionId, collectionViewId, { | ||
type: collectionView === null || collectionView === void 0 ? void 0 : collectionView.type, | ||
query: this.getQuery(collectionView), | ||
groups: (collectionView === null || collectionView === void 0 ? void 0 : collectionView.type) === 'board' | ||
? ((_c = collectionView === null || collectionView === void 0 ? void 0 : collectionView.format) === null || _c === void 0 ? void 0 : _c.board_groups2) || | ||
((_d = collectionView === null || collectionView === void 0 ? void 0 : collectionView.format) === null || _d === void 0 ? void 0 : _d.board_groups) || | ||
((_e = collectionView === null || collectionView === void 0 ? void 0 : collectionView.format) === null || _e === void 0 ? void 0 : _e.board_columns) | ||
: [], | ||
_d.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, this.getCollectionData(collectionId, collectionViewId, collectionView, { | ||
gotOptions: gotOptions | ||
@@ -150,3 +143,3 @@ }) | ||
case 2: | ||
collectionData = _k.sent(); | ||
collectionData = _d.sent(); | ||
// await fs.writeFile( | ||
@@ -160,6 +153,6 @@ // `${collectionId}-${collectionViewId}.json`, | ||
recordMap.notion_user = __assign(__assign({}, recordMap.notion_user), collectionData.recordMap.notion_user); | ||
recordMap.collection_query[collectionId] = __assign(__assign({}, recordMap.collection_query[collectionId]), (_a = {}, _a[collectionViewId] = (_h = (_g = (_f = collectionData.result) === null || _f === void 0 ? void 0 : _f.reducerResults) === null || _g === void 0 ? void 0 : _g.collection_group_results) !== null && _h !== void 0 ? _h : (_j = collectionData.result) === null || _j === void 0 ? void 0 : _j.reducerResults, _a)); | ||
recordMap.collection_query[collectionId] = __assign(__assign({}, recordMap.collection_query[collectionId]), (_a = {}, _a[collectionViewId] = (_c = collectionData.result) === null || _c === void 0 ? void 0 : _c.reducerResults, _a)); | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
err_1 = _k.sent(); | ||
err_1 = _d.sent(); | ||
// It's possible for public pages to link to private collections, in which case | ||
@@ -275,14 +268,13 @@ // Notion returns a 400 error | ||
}; | ||
NotionAPI.prototype.getCollectionData = function (collectionId, collectionViewId, _a) { | ||
var _b = _a === void 0 ? {} : _a, _c = _b.type, type = _c === void 0 ? 'table' : _c, query = _b.query, _d = _b.groups, groups = _d === void 0 ? undefined : _d, _e = _b.limit, limit = _e === void 0 ? 999999 : _e, _f = _b.searchQuery, searchQuery = _f === void 0 ? '' : _f, _g = _b.userTimeZone, userTimeZone = _g === void 0 ? this._userTimeZone : _g, _h = _b.loadContentCover, loadContentCover = _h === void 0 ? true : _h, gotOptions = _b.gotOptions; | ||
NotionAPI.prototype.getCollectionData = function (collectionId, collectionViewId, collectionView, _a) { | ||
var _b, _c, _d, _e, _f, _g; | ||
var _h = _a === void 0 ? {} : _a, _j = _h.limit, limit = _j === void 0 ? 9999 : _j, _k = _h.searchQuery, searchQuery = _k === void 0 ? '' : _k, _l = _h.userTimeZone, userTimeZone = _l === void 0 ? this._userTimeZone : _l, _m = _h.loadContentCover, loadContentCover = _m === void 0 ? true : _m, gotOptions = _h.gotOptions; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var loader, boardReducers, _i, groups_1, group; | ||
return __generator(this, function (_j) { | ||
// TODO: All other collection types queries fail with 400 errors. | ||
// My guess is that they require slightly different query params, but since | ||
// their results are the same AFAICT, there's not much point in supporting | ||
// them. | ||
if (type !== 'table' && type !== 'board') { | ||
type = 'table'; | ||
} | ||
var type, isBoardType, groupBy, loader, groups, iterators, operators, reducersQuery, _i, groups_1, group, property, _o, value, type_1, _p, iterators_1, iterator, iteratorProps, isUncategorizedValue, isDateValue, queryLabel, queryValue, reducerLabel; | ||
var _q, _r; | ||
return __generator(this, function (_s) { | ||
type = collectionView === null || collectionView === void 0 ? void 0 : collectionView.type; | ||
isBoardType = type === 'board'; | ||
groupBy = ((_b = collectionView === null || collectionView === void 0 ? void 0 : collectionView.format) === null || _b === void 0 ? void 0 : _b.board_columns_by) || | ||
((_c = collectionView === null || collectionView === void 0 ? void 0 : collectionView.format) === null || _c === void 0 ? void 0 : _c.collection_group_by); | ||
loader = __assign(__assign({ type: 'reducer', reducers: { | ||
@@ -293,121 +285,72 @@ collection_group_results: { | ||
loadContentCover: loadContentCover | ||
}, | ||
'table:uncategorized:title:count': { | ||
type: 'aggregation', | ||
aggregation: { | ||
property: 'title', | ||
aggregator: 'count' | ||
} | ||
} | ||
} }, query), { //add the filters | ||
searchQuery: searchQuery, | ||
} }, collectionView === null || collectionView === void 0 ? void 0 : collectionView.query2), { searchQuery: searchQuery, | ||
userTimeZone: userTimeZone }); | ||
if (groups && groups.length > 0) { | ||
boardReducers = { | ||
board_columns: { | ||
type: 'groups', | ||
groupBy: { | ||
sort: { | ||
type: 'manual' | ||
}, | ||
type: 'select', | ||
property: groups[0].property | ||
}, | ||
groupSortPreference: groups.map(function (group) { | ||
if (group.value) { | ||
return { | ||
type: 'select', | ||
value: group.value | ||
}; | ||
} | ||
return { | ||
type: 'select' | ||
}; | ||
}), | ||
limit: 10 | ||
} | ||
}; | ||
if (groupBy) { | ||
groups = ((_d = collectionView === null || collectionView === void 0 ? void 0 : collectionView.format) === null || _d === void 0 ? void 0 : _d.board_columns) || | ||
((_e = collectionView === null || collectionView === void 0 ? void 0 : collectionView.format) === null || _e === void 0 ? void 0 : _e.collection_groups) || | ||
[]; | ||
iterators = [isBoardType ? 'board' : 'group_aggregation', 'results']; | ||
operators = (_q = { | ||
checkbox: 'checkbox_is', | ||
url: 'string_starts_with', | ||
text: 'string_starts_with', | ||
select: 'enum_is', | ||
multi_select: 'enum_contains', | ||
created_time: 'date_is_within' | ||
}, | ||
_q['undefined'] = 'is_empty', | ||
_q); | ||
reducersQuery = {}; | ||
for (_i = 0, groups_1 = groups; _i < groups_1.length; _i++) { | ||
group = groups_1[_i]; | ||
if (!group.value.value) { | ||
boardReducers['board:uncategorized'] = { | ||
type: 'aggregation', | ||
filter: { | ||
operator: 'and', | ||
filters: [ | ||
{ | ||
property: group.property, | ||
filter: { | ||
operator: 'is_empty' | ||
} | ||
} | ||
] | ||
}, | ||
aggregation: { | ||
aggregator: 'count' | ||
property = group.property, _o = group.value, value = _o.value, type_1 = _o.type; | ||
for (_p = 0, iterators_1 = iterators; _p < iterators_1.length; _p++) { | ||
iterator = iterators_1[_p]; | ||
iteratorProps = iterator === 'results' | ||
? { | ||
type: iterator, | ||
limit: limit | ||
} | ||
}; | ||
boardReducers['results:uncategorized'] = { | ||
type: 'results', | ||
filter: { | ||
: { | ||
type: 'aggregation', | ||
aggregation: { | ||
aggregator: 'count' | ||
} | ||
}; | ||
isUncategorizedValue = typeof value === 'undefined'; | ||
isDateValue = value === null || value === void 0 ? void 0 : value.range; | ||
queryLabel = isUncategorizedValue | ||
? 'uncategorized' | ||
: isDateValue | ||
? ((_f = value.range) === null || _f === void 0 ? void 0 : _f.start_date) || ((_g = value.range) === null || _g === void 0 ? void 0 : _g.end_date) | ||
: (value === null || value === void 0 ? void 0 : value.value) || value; | ||
queryValue = !isUncategorizedValue && (isDateValue || (value === null || value === void 0 ? void 0 : value.value) || value); | ||
reducersQuery[iterator + ":" + type_1 + ":" + queryLabel] = __assign(__assign({}, iteratorProps), { filter: { | ||
operator: 'and', | ||
filters: [ | ||
{ | ||
property: group.property, | ||
filter: { | ||
operator: 'is_empty' | ||
} | ||
} | ||
] | ||
}, | ||
limit: limit | ||
}; | ||
} | ||
else { | ||
boardReducers["board:" + group.value.value] = { | ||
type: 'aggregation', | ||
filter: { | ||
operator: 'and', | ||
filters: [ | ||
{ | ||
property: group.property, | ||
filter: { | ||
operator: 'enum_is', | ||
property: property, | ||
filter: __assign({ operator: !isUncategorizedValue | ||
? operators[type_1] | ||
: 'is_empty' }, (!isUncategorizedValue && { | ||
value: { | ||
type: 'exact', | ||
value: group.value.value | ||
value: queryValue | ||
} | ||
} | ||
})) | ||
} | ||
] | ||
}, | ||
aggregation: { | ||
aggregator: 'count' | ||
} | ||
}; | ||
boardReducers["board:" + group.value.value] = { | ||
type: 'results', | ||
filter: { | ||
operator: 'and', | ||
filters: [ | ||
{ | ||
property: group.property, | ||
filter: { | ||
operator: 'enum_is', | ||
value: { | ||
type: 'exact', | ||
value: group.value.value | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
limit: limit | ||
}; | ||
} }); | ||
} | ||
} | ||
loader.reducers = boardReducers; | ||
reducerLabel = isBoardType ? 'board_columns' : type + "_groups"; | ||
loader = __assign(__assign({ type: 'reducer', reducers: __assign((_r = {}, _r[reducerLabel] = { | ||
type: 'groups', | ||
groupBy: groupBy, | ||
groupSortPreference: groups.map(function (group) { return group === null || group === void 0 ? void 0 : group.value; }), | ||
limit: limit | ||
}, _r), reducersQuery) }, collectionView === null || collectionView === void 0 ? void 0 : collectionView.query2), { searchQuery: searchQuery, | ||
userTimeZone: userTimeZone }); | ||
} | ||
//useful for debugging collection queries | ||
//console.log('queryCollection', JSON.stringify( { collectionId, collectionViewId, query, loader}, null, 2)) | ||
return [2 /*return*/, this.fetch({ | ||
@@ -429,16 +372,2 @@ endpoint: 'queryCollection', | ||
}; | ||
//handle setting group_by for the query if it isn't already | ||
NotionAPI.prototype.getQuery = function (collectionView) { | ||
var _a, _b, _c; | ||
var query = (collectionView === null || collectionView === void 0 ? void 0 : collectionView.query2) || (collectionView === null || collectionView === void 0 ? void 0 : collectionView.query); | ||
if (!query) | ||
return undefined; | ||
var groupBy = ((_a = collectionView === null || collectionView === void 0 ? void 0 : collectionView.format) === null || _a === void 0 ? void 0 : _a.board_columns_by) | ||
? (_c = (_b = collectionView === null || collectionView === void 0 ? void 0 : collectionView.format) === null || _b === void 0 ? void 0 : _b.board_columns_by) === null || _c === void 0 ? void 0 : _c.property | ||
: undefined; | ||
if (groupBy) { | ||
query.group_by = groupBy; | ||
} | ||
return query; | ||
}; | ||
NotionAPI.prototype.getUsers = function (userIds, gotOptions) { | ||
@@ -445,0 +374,0 @@ return __awaiter(this, void 0, void 0, function () { |
@@ -31,6 +31,4 @@ import { OptionsOfJSONResponseBody } from 'got'; | ||
getPageRaw(pageId: string, gotOptions?: OptionsOfJSONResponseBody): Promise<notion.PageChunk>; | ||
getCollectionData(collectionId: string, collectionViewId: string, { type, query, groups, limit, searchQuery, userTimeZone, loadContentCover, gotOptions }?: { | ||
getCollectionData(collectionId: string, collectionViewId: string, collectionView: any, { limit, searchQuery, userTimeZone, loadContentCover, gotOptions }?: { | ||
type?: notion.CollectionViewType; | ||
query?: any; | ||
groups?: any; | ||
limit?: number; | ||
@@ -43,3 +41,2 @@ searchQuery?: string; | ||
}): Promise<notion.CollectionInstance>; | ||
private getQuery; | ||
getUsers(userIds: string[], gotOptions?: OptionsOfJSONResponseBody): Promise<notion.RecordValues<notion.User>>; | ||
@@ -46,0 +43,0 @@ getBlocks(blockIds: string[], gotOptions?: OptionsOfJSONResponseBody): Promise<notion.PageChunk>; |
@@ -118,19 +118,12 @@ var __assign = (this && this.__assign) || function () { | ||
var _a; | ||
var _b, _c, _d, _e, _f, _g, _h, _j; | ||
return __generator(this, function (_k) { | ||
switch (_k.label) { | ||
var _b, _c; | ||
return __generator(this, function (_d) { | ||
switch (_d.label) { | ||
case 0: | ||
collectionId = collectionInstance.collectionId, collectionViewId = collectionInstance.collectionViewId; | ||
collectionView = (_b = recordMap.collection_view[collectionViewId]) === null || _b === void 0 ? void 0 : _b.value; | ||
_k.label = 1; | ||
_d.label = 1; | ||
case 1: | ||
_k.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, this.getCollectionData(collectionId, collectionViewId, { | ||
type: collectionView === null || collectionView === void 0 ? void 0 : collectionView.type, | ||
query: this.getQuery(collectionView), | ||
groups: (collectionView === null || collectionView === void 0 ? void 0 : collectionView.type) === 'board' | ||
? ((_c = collectionView === null || collectionView === void 0 ? void 0 : collectionView.format) === null || _c === void 0 ? void 0 : _c.board_groups2) || | ||
((_d = collectionView === null || collectionView === void 0 ? void 0 : collectionView.format) === null || _d === void 0 ? void 0 : _d.board_groups) || | ||
((_e = collectionView === null || collectionView === void 0 ? void 0 : collectionView.format) === null || _e === void 0 ? void 0 : _e.board_columns) | ||
: [], | ||
_d.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, this.getCollectionData(collectionId, collectionViewId, collectionView, { | ||
gotOptions: gotOptions | ||
@@ -144,3 +137,3 @@ }) | ||
case 2: | ||
collectionData = _k.sent(); | ||
collectionData = _d.sent(); | ||
// await fs.writeFile( | ||
@@ -154,6 +147,6 @@ // `${collectionId}-${collectionViewId}.json`, | ||
recordMap.notion_user = __assign(__assign({}, recordMap.notion_user), collectionData.recordMap.notion_user); | ||
recordMap.collection_query[collectionId] = __assign(__assign({}, recordMap.collection_query[collectionId]), (_a = {}, _a[collectionViewId] = (_h = (_g = (_f = collectionData.result) === null || _f === void 0 ? void 0 : _f.reducerResults) === null || _g === void 0 ? void 0 : _g.collection_group_results) !== null && _h !== void 0 ? _h : (_j = collectionData.result) === null || _j === void 0 ? void 0 : _j.reducerResults, _a)); | ||
recordMap.collection_query[collectionId] = __assign(__assign({}, recordMap.collection_query[collectionId]), (_a = {}, _a[collectionViewId] = (_c = collectionData.result) === null || _c === void 0 ? void 0 : _c.reducerResults, _a)); | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
err_1 = _k.sent(); | ||
err_1 = _d.sent(); | ||
// It's possible for public pages to link to private collections, in which case | ||
@@ -269,14 +262,13 @@ // Notion returns a 400 error | ||
}; | ||
NotionAPI.prototype.getCollectionData = function (collectionId, collectionViewId, _a) { | ||
var _b = _a === void 0 ? {} : _a, _c = _b.type, type = _c === void 0 ? 'table' : _c, query = _b.query, _d = _b.groups, groups = _d === void 0 ? undefined : _d, _e = _b.limit, limit = _e === void 0 ? 999999 : _e, _f = _b.searchQuery, searchQuery = _f === void 0 ? '' : _f, _g = _b.userTimeZone, userTimeZone = _g === void 0 ? this._userTimeZone : _g, _h = _b.loadContentCover, loadContentCover = _h === void 0 ? true : _h, gotOptions = _b.gotOptions; | ||
NotionAPI.prototype.getCollectionData = function (collectionId, collectionViewId, collectionView, _a) { | ||
var _b, _c, _d, _e, _f, _g; | ||
var _h = _a === void 0 ? {} : _a, _j = _h.limit, limit = _j === void 0 ? 9999 : _j, _k = _h.searchQuery, searchQuery = _k === void 0 ? '' : _k, _l = _h.userTimeZone, userTimeZone = _l === void 0 ? this._userTimeZone : _l, _m = _h.loadContentCover, loadContentCover = _m === void 0 ? true : _m, gotOptions = _h.gotOptions; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var loader, boardReducers, _i, groups_1, group; | ||
return __generator(this, function (_j) { | ||
// TODO: All other collection types queries fail with 400 errors. | ||
// My guess is that they require slightly different query params, but since | ||
// their results are the same AFAICT, there's not much point in supporting | ||
// them. | ||
if (type !== 'table' && type !== 'board') { | ||
type = 'table'; | ||
} | ||
var type, isBoardType, groupBy, loader, groups, iterators, operators, reducersQuery, _i, groups_1, group, property, _o, value, type_1, _p, iterators_1, iterator, iteratorProps, isUncategorizedValue, isDateValue, queryLabel, queryValue, reducerLabel; | ||
var _q, _r; | ||
return __generator(this, function (_s) { | ||
type = collectionView === null || collectionView === void 0 ? void 0 : collectionView.type; | ||
isBoardType = type === 'board'; | ||
groupBy = ((_b = collectionView === null || collectionView === void 0 ? void 0 : collectionView.format) === null || _b === void 0 ? void 0 : _b.board_columns_by) || | ||
((_c = collectionView === null || collectionView === void 0 ? void 0 : collectionView.format) === null || _c === void 0 ? void 0 : _c.collection_group_by); | ||
loader = __assign(__assign({ type: 'reducer', reducers: { | ||
@@ -287,121 +279,72 @@ collection_group_results: { | ||
loadContentCover: loadContentCover | ||
}, | ||
'table:uncategorized:title:count': { | ||
type: 'aggregation', | ||
aggregation: { | ||
property: 'title', | ||
aggregator: 'count' | ||
} | ||
} | ||
} }, query), { //add the filters | ||
searchQuery: searchQuery, | ||
} }, collectionView === null || collectionView === void 0 ? void 0 : collectionView.query2), { searchQuery: searchQuery, | ||
userTimeZone: userTimeZone }); | ||
if (groups && groups.length > 0) { | ||
boardReducers = { | ||
board_columns: { | ||
type: 'groups', | ||
groupBy: { | ||
sort: { | ||
type: 'manual' | ||
}, | ||
type: 'select', | ||
property: groups[0].property | ||
}, | ||
groupSortPreference: groups.map(function (group) { | ||
if (group.value) { | ||
return { | ||
type: 'select', | ||
value: group.value | ||
}; | ||
} | ||
return { | ||
type: 'select' | ||
}; | ||
}), | ||
limit: 10 | ||
} | ||
}; | ||
if (groupBy) { | ||
groups = ((_d = collectionView === null || collectionView === void 0 ? void 0 : collectionView.format) === null || _d === void 0 ? void 0 : _d.board_columns) || | ||
((_e = collectionView === null || collectionView === void 0 ? void 0 : collectionView.format) === null || _e === void 0 ? void 0 : _e.collection_groups) || | ||
[]; | ||
iterators = [isBoardType ? 'board' : 'group_aggregation', 'results']; | ||
operators = (_q = { | ||
checkbox: 'checkbox_is', | ||
url: 'string_starts_with', | ||
text: 'string_starts_with', | ||
select: 'enum_is', | ||
multi_select: 'enum_contains', | ||
created_time: 'date_is_within' | ||
}, | ||
_q['undefined'] = 'is_empty', | ||
_q); | ||
reducersQuery = {}; | ||
for (_i = 0, groups_1 = groups; _i < groups_1.length; _i++) { | ||
group = groups_1[_i]; | ||
if (!group.value.value) { | ||
boardReducers['board:uncategorized'] = { | ||
type: 'aggregation', | ||
filter: { | ||
operator: 'and', | ||
filters: [ | ||
{ | ||
property: group.property, | ||
filter: { | ||
operator: 'is_empty' | ||
} | ||
} | ||
] | ||
}, | ||
aggregation: { | ||
aggregator: 'count' | ||
property = group.property, _o = group.value, value = _o.value, type_1 = _o.type; | ||
for (_p = 0, iterators_1 = iterators; _p < iterators_1.length; _p++) { | ||
iterator = iterators_1[_p]; | ||
iteratorProps = iterator === 'results' | ||
? { | ||
type: iterator, | ||
limit: limit | ||
} | ||
}; | ||
boardReducers['results:uncategorized'] = { | ||
type: 'results', | ||
filter: { | ||
: { | ||
type: 'aggregation', | ||
aggregation: { | ||
aggregator: 'count' | ||
} | ||
}; | ||
isUncategorizedValue = typeof value === 'undefined'; | ||
isDateValue = value === null || value === void 0 ? void 0 : value.range; | ||
queryLabel = isUncategorizedValue | ||
? 'uncategorized' | ||
: isDateValue | ||
? ((_f = value.range) === null || _f === void 0 ? void 0 : _f.start_date) || ((_g = value.range) === null || _g === void 0 ? void 0 : _g.end_date) | ||
: (value === null || value === void 0 ? void 0 : value.value) || value; | ||
queryValue = !isUncategorizedValue && (isDateValue || (value === null || value === void 0 ? void 0 : value.value) || value); | ||
reducersQuery[iterator + ":" + type_1 + ":" + queryLabel] = __assign(__assign({}, iteratorProps), { filter: { | ||
operator: 'and', | ||
filters: [ | ||
{ | ||
property: group.property, | ||
filter: { | ||
operator: 'is_empty' | ||
} | ||
} | ||
] | ||
}, | ||
limit: limit | ||
}; | ||
} | ||
else { | ||
boardReducers["board:" + group.value.value] = { | ||
type: 'aggregation', | ||
filter: { | ||
operator: 'and', | ||
filters: [ | ||
{ | ||
property: group.property, | ||
filter: { | ||
operator: 'enum_is', | ||
property: property, | ||
filter: __assign({ operator: !isUncategorizedValue | ||
? operators[type_1] | ||
: 'is_empty' }, (!isUncategorizedValue && { | ||
value: { | ||
type: 'exact', | ||
value: group.value.value | ||
value: queryValue | ||
} | ||
} | ||
})) | ||
} | ||
] | ||
}, | ||
aggregation: { | ||
aggregator: 'count' | ||
} | ||
}; | ||
boardReducers["board:" + group.value.value] = { | ||
type: 'results', | ||
filter: { | ||
operator: 'and', | ||
filters: [ | ||
{ | ||
property: group.property, | ||
filter: { | ||
operator: 'enum_is', | ||
value: { | ||
type: 'exact', | ||
value: group.value.value | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
limit: limit | ||
}; | ||
} }); | ||
} | ||
} | ||
loader.reducers = boardReducers; | ||
reducerLabel = isBoardType ? 'board_columns' : type + "_groups"; | ||
loader = __assign(__assign({ type: 'reducer', reducers: __assign((_r = {}, _r[reducerLabel] = { | ||
type: 'groups', | ||
groupBy: groupBy, | ||
groupSortPreference: groups.map(function (group) { return group === null || group === void 0 ? void 0 : group.value; }), | ||
limit: limit | ||
}, _r), reducersQuery) }, collectionView === null || collectionView === void 0 ? void 0 : collectionView.query2), { searchQuery: searchQuery, | ||
userTimeZone: userTimeZone }); | ||
} | ||
//useful for debugging collection queries | ||
//console.log('queryCollection', JSON.stringify( { collectionId, collectionViewId, query, loader}, null, 2)) | ||
return [2 /*return*/, this.fetch({ | ||
@@ -423,16 +366,2 @@ endpoint: 'queryCollection', | ||
}; | ||
//handle setting group_by for the query if it isn't already | ||
NotionAPI.prototype.getQuery = function (collectionView) { | ||
var _a, _b, _c; | ||
var query = (collectionView === null || collectionView === void 0 ? void 0 : collectionView.query2) || (collectionView === null || collectionView === void 0 ? void 0 : collectionView.query); | ||
if (!query) | ||
return undefined; | ||
var groupBy = ((_a = collectionView === null || collectionView === void 0 ? void 0 : collectionView.format) === null || _a === void 0 ? void 0 : _a.board_columns_by) | ||
? (_c = (_b = collectionView === null || collectionView === void 0 ? void 0 : collectionView.format) === null || _b === void 0 ? void 0 : _b.board_columns_by) === null || _c === void 0 ? void 0 : _c.property | ||
: undefined; | ||
if (groupBy) { | ||
query.group_by = groupBy; | ||
} | ||
return query; | ||
}; | ||
NotionAPI.prototype.getUsers = function (userIds, gotOptions) { | ||
@@ -439,0 +368,0 @@ return __awaiter(this, void 0, void 0, function () { |
{ | ||
"name": "notion-client", | ||
"version": "4.12.0", | ||
"version": "4.13.0", | ||
"description": "Robust TypeScript client for the unofficial Notion API.", | ||
@@ -27,3 +27,3 @@ "repository": "NotionX/react-notion-x", | ||
}, | ||
"gitHead": "8a0bf1f7dbfa48cf629e88c5d7a47aa1787f6700" | ||
"gitHead": "cd521edba2290a5632607ca71684347114697b12" | ||
} |
@@ -121,11 +121,4 @@ import got, { OptionsOfJSONResponseBody } from 'got' | ||
collectionViewId, | ||
collectionView, | ||
{ | ||
type: collectionView?.type, | ||
query: this.getQuery(collectionView), | ||
groups: | ||
collectionView?.type === 'board' | ||
? collectionView?.format?.board_groups2 || | ||
(collectionView?.format as any)?.board_groups || | ||
collectionView?.format?.board_columns | ||
: [], | ||
gotOptions | ||
@@ -159,8 +152,6 @@ } | ||
} | ||
recordMap.collection_query![collectionId] = { | ||
...recordMap.collection_query![collectionId], | ||
[collectionViewId]: | ||
(collectionData.result as any)?.reducerResults | ||
?.collection_group_results ?? | ||
(collectionData.result as any)?.reducerResults | ||
[collectionViewId]: (collectionData.result as any)?.reducerResults | ||
} | ||
@@ -287,7 +278,5 @@ } catch (err) { | ||
collectionViewId: string, | ||
collectionView: any, | ||
{ | ||
type = 'table', | ||
query, | ||
groups = undefined, | ||
limit = 999999, | ||
limit = 9999, | ||
searchQuery = '', | ||
@@ -299,4 +288,2 @@ userTimeZone = this._userTimeZone, | ||
type?: notion.CollectionViewType | ||
query?: any | ||
groups?: any | ||
limit?: number | ||
@@ -310,11 +297,9 @@ searchQuery?: string | ||
) { | ||
// TODO: All other collection types queries fail with 400 errors. | ||
// My guess is that they require slightly different query params, but since | ||
// their results are the same AFAICT, there's not much point in supporting | ||
// them. | ||
if (type !== 'table' && type !== 'board') { | ||
type = 'table' | ||
} | ||
const type = collectionView?.type | ||
const isBoardType = type === 'board' | ||
const groupBy = | ||
collectionView?.format?.board_columns_by || | ||
collectionView?.format?.collection_group_by | ||
const loader: any = { | ||
let loader: any = { | ||
type: 'reducer', | ||
@@ -326,12 +311,5 @@ reducers: { | ||
loadContentCover | ||
}, | ||
'table:uncategorized:title:count': { | ||
type: 'aggregation', | ||
aggregation: { | ||
property: 'title', | ||
aggregator: 'count' | ||
} | ||
} | ||
}, | ||
...query, //add the filters | ||
...collectionView?.query2, | ||
searchQuery, | ||
@@ -341,66 +319,52 @@ userTimeZone | ||
if (groups && groups.length > 0) { | ||
// used for 'board' collection view queries | ||
const boardReducers = { | ||
board_columns: { | ||
type: 'groups', | ||
groupBy: { | ||
sort: { | ||
type: 'manual' | ||
}, | ||
type: 'select', | ||
property: groups[0].property | ||
}, | ||
groupSortPreference: groups.map((group) => { | ||
if (group.value) { | ||
return { | ||
type: 'select', | ||
value: group.value | ||
} | ||
} | ||
return { | ||
type: 'select' | ||
} | ||
}), | ||
limit: 10 | ||
} | ||
if (groupBy) { | ||
const groups = | ||
collectionView?.format?.board_columns || | ||
collectionView?.format?.collection_groups || | ||
[] | ||
const iterators = [isBoardType ? 'board' : 'group_aggregation', 'results'] | ||
const operators = { | ||
checkbox: 'checkbox_is', | ||
url: 'string_starts_with', | ||
text: 'string_starts_with', | ||
select: 'enum_is', | ||
multi_select: 'enum_contains', | ||
created_time: 'date_is_within', | ||
['undefined']: 'is_empty' | ||
} | ||
const reducersQuery = {} | ||
for (const group of groups) { | ||
if (!group.value.value) { | ||
boardReducers['board:uncategorized'] = { | ||
type: 'aggregation', | ||
filter: { | ||
operator: 'and', | ||
filters: [ | ||
{ | ||
property: group.property, | ||
filter: { | ||
operator: 'is_empty' | ||
} | ||
const { | ||
property, | ||
value: { value, type } | ||
} = group | ||
for (const iterator of iterators) { | ||
const iteratorProps = | ||
iterator === 'results' | ||
? { | ||
type: iterator, | ||
limit | ||
} | ||
] | ||
}, | ||
aggregation: { | ||
aggregator: 'count' | ||
} | ||
} | ||
boardReducers['results:uncategorized'] = { | ||
type: 'results', | ||
filter: { | ||
operator: 'and', | ||
filters: [ | ||
{ | ||
property: group.property, | ||
filter: { | ||
operator: 'is_empty' | ||
: { | ||
type: 'aggregation', | ||
aggregation: { | ||
aggregator: 'count' | ||
} | ||
} | ||
] | ||
}, | ||
limit | ||
} | ||
} else { | ||
boardReducers[`board:${group.value.value}`] = { | ||
type: 'aggregation', | ||
const isUncategorizedValue = typeof value === 'undefined' | ||
const isDateValue = value?.range | ||
// TODO: review dates reducers | ||
const queryLabel = isUncategorizedValue | ||
? 'uncategorized' | ||
: isDateValue | ||
? value.range?.start_date || value.range?.end_date | ||
: value?.value || value | ||
const queryValue = | ||
!isUncategorizedValue && (isDateValue || value?.value || value) | ||
reducersQuery[`${iterator}:${type}:${queryLabel}`] = { | ||
...iteratorProps, | ||
filter: { | ||
@@ -410,45 +374,39 @@ operator: 'and', | ||
{ | ||
property: group.property, | ||
property, | ||
filter: { | ||
operator: 'enum_is', | ||
value: { | ||
type: 'exact', | ||
value: group.value.value | ||
} | ||
operator: !isUncategorizedValue | ||
? operators[type] | ||
: 'is_empty', | ||
...(!isUncategorizedValue && { | ||
value: { | ||
type: 'exact', | ||
value: queryValue | ||
} | ||
}) | ||
} | ||
} | ||
] | ||
}, | ||
aggregation: { | ||
aggregator: 'count' | ||
} | ||
} | ||
} | ||
} | ||
boardReducers[`board:${group.value.value}`] = { | ||
type: 'results', | ||
filter: { | ||
operator: 'and', | ||
filters: [ | ||
{ | ||
property: group.property, | ||
filter: { | ||
operator: 'enum_is', | ||
value: { | ||
type: 'exact', | ||
value: group.value.value | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
const reducerLabel = isBoardType ? 'board_columns' : `${type}_groups` | ||
loader = { | ||
type: 'reducer', | ||
reducers: { | ||
[reducerLabel]: { | ||
type: 'groups', | ||
groupBy, | ||
groupSortPreference: groups.map((group) => group?.value), | ||
limit | ||
} | ||
} | ||
}, | ||
...reducersQuery | ||
}, | ||
...collectionView?.query2, | ||
searchQuery, | ||
userTimeZone | ||
} | ||
loader.reducers = boardReducers | ||
} | ||
//useful for debugging collection queries | ||
//console.log('queryCollection', JSON.stringify( { collectionId, collectionViewId, query, loader}, null, 2)) | ||
return this.fetch<notion.CollectionInstance>({ | ||
@@ -469,16 +427,2 @@ endpoint: 'queryCollection', | ||
//handle setting group_by for the query if it isn't already | ||
private getQuery(collectionView: notion.CollectionView | undefined) { | ||
let query = collectionView?.query2 || collectionView?.query | ||
if (!query) return undefined | ||
const groupBy = collectionView?.format?.board_columns_by | ||
? collectionView?.format?.board_columns_by?.property | ||
: undefined | ||
if (groupBy) { | ||
query.group_by = groupBy | ||
} | ||
return query | ||
} | ||
public async getUsers( | ||
@@ -485,0 +429,0 @@ userIds: string[], |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
986439
12020