notion-utils
Advanced tools
Comparing version 6.8.2 to 6.8.3
@@ -1,2 +0,2 @@ | ||
var A=Object.defineProperty;var C=Object.getOwnPropertySymbols;var z=Object.prototype.hasOwnProperty,q=Object.prototype.propertyIsEnumerable;var I=(e,t,o)=>t in e?A(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,g=(e,t)=>{for(var o in t||(t={}))z.call(t,o)&&I(e,o,t[o]);if(C)for(var o of C(t))q.call(t,o)&&I(e,o,t[o]);return e};var T=(e,t,o)=>new Promise((n,s)=>{var r=a=>{try{l(o.next(a))}catch(i){s(i)}},c=a=>{try{l(o.throw(a))}catch(i){s(i)}},l=a=>a.done?n(a.value):Promise.resolve(a.value).then(r,c);l((o=o.apply(e,t)).next())});var h=e=>{var t;return e?Array.isArray(e)?(t=e==null?void 0:e.reduce((o,n)=>o+(n[0]!=="\u204D"&&n[0]!=="\u2023"?n[0]:""),""))!=null?t:"":e:""};function P(e){var t,o;return e.collection_id||((o=(t=e.format)==null?void 0:t.collection_pointer)==null?void 0:o.id)||null}function B(e,t){var o,n;if((o=e.properties)!=null&&o.title)return h(e.properties.title);if(e.type==="collection_view_page"||e.type==="collection_view"){let s=(n=t.collection[P(e)])==null?void 0:n.value;if(s)return h(s.name)}return""}function E(e,t){var o,n,s;if((o=e.format)!=null&&o.page_icon)return(n=e.format)==null?void 0:n.page_icon;if(e.type==="collection_view_page"||e.type==="collection_view"){let r=P(e);if(r){let c=(s=t.collection[r])==null?void 0:s.value;if(c)return c.icon}}return null}function re(e){var o;let t=(o=e.block[Object.keys(e.block)[0]])==null?void 0:o.value;return t?B(t,e):null}function R(e,t,o){var n;try{if(!t.properties||!Object.keys(o.collection))return null;let s=(n=o.collection[t.parent_id])==null?void 0:n.value;if(s){let r=Object.keys(s.schema).find(a=>{var i;return((i=s.schema[a])==null?void 0:i.name)===e});if(!r)return null;let{type:c}=s.schema[r],l=h(t.properties[r]);switch(c){case"created_time":return t.created_time;case"multi_select":return l.split(",");case"date":{let i=t.properties[r][0][1][0][1];if(i.type=="datetime")return new Date(`${i.start_date} ${i.start_time}`).getTime();if(i.type=="date")return new Date(i.start_date).getTime();if(i.type=="datetimerange"){let{start_date:p,start_time:y,end_date:x,end_time:u}=i,b=new Date(`${p} ${y}`).getTime(),m=new Date(`${x} ${u}`).getTime();return[b,m]}else{let p=new Date(i.start_date).getTime(),y=new Date(i.end_date).getTime();return[p,y]}}case"checkbox":return l=="Yes";case"last_edited_time":return t.last_edited_time;default:return l}}}catch(s){}return null}var M=e=>{if(e&&Array.isArray(e)){if(e[0]==="d")return e[1];for(let t of e){let o=M(t);if(o)return o}}return null};var U=(e,t,{inclusive:o=!1}={})=>{var s,r;let n=e;for(;n!=null;){if(o&&(n==null?void 0:n.type)==="page")return n;let c=n.parent_id,l=n.parent_table;if(!c)break;if(l==="collection")n=(s=t.collection[c])==null?void 0:s.value;else if(n=(r=t.block[c])==null?void 0:r.value,(n==null?void 0:n.type)==="page")return n}return null};var F={header:0,sub_header:1,sub_sub_header:2},pe=(e,t)=>{var s;let o=((s=e.content)!=null?s:[]).map(r=>{var l,a;let c=(l=t.block[r])==null?void 0:l.value;if(c){let{type:i}=c;if(i==="header"||i==="sub_header"||i==="sub_sub_header")return{id:r,type:i,text:h((a=c.properties)==null?void 0:a.title),indentLevel:F[i]}}return null}).filter(Boolean),n=[{actual:-1,effective:-1}];for(let r of o){let{indentLevel:c}=r,l=c;do{let a=n[n.length-1],{actual:i,effective:p}=a;if(l>i)r.indentLevel=p+1,n.push({actual:l,effective:r.indentLevel});else if(l===i){r.indentLevel=p;break}else n.pop()}while(!0)}return o};var fe=(e,t)=>{let o=t||Object.keys(e.block)[0],n=new Set;function s(r){var y,x,u,b;if(n.has(r))return;n.add(r);let c=(y=e.block[r])==null?void 0:y.value;if(!c)return;let{content:l,type:a,properties:i,format:p}=c;if(i)for(let m of Object.keys(i)){let f=i[m];f.map(_=>{var v,w;let d=(w=(v=_==null?void 0:_[0])==null?void 0:v[1])==null?void 0:w[0];(d==null?void 0:d[0])==="p"&&d[1]&&s(d[1])});let k=(u=(x=f==null?void 0:f[0])==null?void 0:x[1])==null?void 0:u[0];(k==null?void 0:k[0])==="p"&&k[1]&&s(k[1])}if(p){let m=(b=p.transclusion_reference_pointer)==null?void 0:b.id;m&&s(m)}if(!(!l||!Array.isArray(l))&&!(a==="page"&&r!==o))for(let m of l)s(m)}return s(o),Array.from(n)};var $=(e="")=>`${e.substr(0,8)}-${e.substr(8,4)}-${e.substr(12,4)}-${e.substr(16,4)}-${e.substr(20)}`;var W=/\b([a-f0-9]{32})\b/,S=/\b([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})\b/,D=(e="",{uuid:t=!0}={})=>{if(!e)return null;e=e.split("?")[0];let o=e.match(W);if(o)return t?$(o[1]):o[1];let n=e.match(S);return n?t?n[1]:n[1].replace(/-/g,""):null};var O=e=>e.replace(/-/g,"");import Q from"p-queue";function _e(c,l,a){return T(this,arguments,function*(e,t,o,{concurrency:n=4,traverseCollections:s=!0,targetPageId:r=null}={}){let i={},p=new Set,y=new Q({concurrency:n});function x(u){return T(this,null,function*(){r&&p.has(r)||(u=D(u),u&&!i[u]&&!p.has(u)&&(p.add(u),y.add(()=>T(this,null,function*(){var b,m;try{if(r&&p.has(r)&&u!==r)return;let f=yield o(u);if(!f)return;let k=(m=(b=f.block[u])==null?void 0:b.value)==null?void 0:m.space_id;if(k){if(!t)t=k;else if(t!==k)return}if(Object.keys(f.block).filter(_=>{var v;let d=(v=f.block[_])==null?void 0:v.value;return!(!d||d.type!=="page"&&d.type!=="collection_view_page"||t&&d.space_id&&d.space_id!==t)}).forEach(_=>x(_)),s)for(let _ of Object.values(f.collection_query))for(let d of Object.values(_)){let{blockIds:v}=d;if(v)for(let w of v)x(w)}i[u]=f}catch(f){console.warn("page load error",{pageId:u,spaceId:t},f.statusCode,f.message),i[u]=null}p.delete(u)}))))})}return yield x(e),yield y.onIdle(),i})}var L=e=>(e||"").replace(/ /g,"-").replace(/[^a-zA-Z0-9-\u4e00-\u9fa5]/g,"").replace(/--/g,"-").replace(/-$/,"").replace(/^-/,"").trim().toLowerCase();var Ee=(e,t,{uuid:o=!0}={})=>{var r;if(!e||!t)return null;let n=O(e),s=(r=t.block[e])==null?void 0:r.value;if(s){let c=R("slug",s,t)||R("Slug",s,t)||L(B(s,t));if(c)return o?`${c}-${n}`:c}return n};var $e=(e,t)=>{var r;let o=e.block,n=[],s=t;do{let c=(r=o[s])==null?void 0:r.value;if(!c)break;let l=B(c,e),a=E(c,e);if(!(l||a))break;n.push({block:c,active:s===t,pageId:s,title:l,icon:a});let i=U(c,e),p=i==null?void 0:i.id;if(!p)break;s=p}while(!0);return n.reverse(),n};import j from"is-url-superb";var ze=(e,{mapImageUrl:t})=>{let n=Object.keys(e.block).flatMap(s=>{var l,a,i,p,y,x,u,b;let r=(l=e.block[s])==null?void 0:l.value,c=[];if(r){if(r.type==="image"){let k=((a=e.signed_urls)==null?void 0:a[r.id])||((y=(p=(i=r.properties)==null?void 0:i.source)==null?void 0:p[0])==null?void 0:y[0]);k&&c.push({block:r,url:k})}if((x=r.format)!=null&&x.page_cover){let f=r.format.page_cover;c.push({block:r,url:f})}if((u=r.format)!=null&&u.bookmark_cover){let f=r.format.bookmark_cover;c.push({block:r,url:f})}if((b=r.format)!=null&&b.bookmark_icon){let f=r.format.bookmark_icon;c.push({block:r,url:f})}let m=E(r,e);m&&j(m)&&c.push({block:r,url:m})}return c}).filter(Boolean).map(({block:s,url:r})=>t(r,s)).filter(Boolean);return Array.from(new Set(n))};import V from"normalize-url";import H from"mem";var N=H(e=>{if(!e)return"";try{if(e.startsWith("https://www.notion.so/image/")){let t=new URL(e),o=decodeURIComponent(t.pathname.substr(7)),n=N(o);t.pathname=`/image/${encodeURIComponent(n)}`,e=t.toString()}return V(e,{stripProtocol:!0,stripWWW:!0,stripHash:!0,stripTextFragment:!0,removeQueryParameters:!0})}catch(t){return""}});function Se(e,t){return{block:g(g({},e.block),t.block),collection:g(g({},e.collection),t.collection),collection_view:g(g({},e.collection_view),t.collection_view),notion_user:g(g({},e.notion_user),t.notion_user),collection_query:g(g({},e.collection_query),t.collection_query),signed_urls:g(g({},e.signed_urls),t.signed_urls),preview_images:g(g({},e.preview_images),t.preview_images)}}export{_e as getAllPagesInSpace,P as getBlockCollectionId,E as getBlockIcon,U as getBlockParentPage,B as getBlockTitle,Ee as getCanonicalPageId,M as getDateValue,$e as getPageBreadcrumbs,fe as getPageContentBlockIds,ze as getPageImageUrls,R as getPageProperty,pe as getPageTableOfContents,re as getPageTitle,h as getTextContent,$ as idToUuid,j as isUrl,Se as mergeRecordMaps,L as normalizeTitle,N as normalizeUrl,D as parsePageId,O as uuidToId}; | ||
var A=Object.defineProperty;var C=Object.getOwnPropertySymbols;var z=Object.prototype.hasOwnProperty,q=Object.prototype.propertyIsEnumerable;var I=(e,t,o)=>t in e?A(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,g=(e,t)=>{for(var o in t||(t={}))z.call(t,o)&&I(e,o,t[o]);if(C)for(var o of C(t))q.call(t,o)&&I(e,o,t[o]);return e};var T=(e,t,o)=>new Promise((n,s)=>{var r=a=>{try{l(o.next(a))}catch(i){s(i)}},c=a=>{try{l(o.throw(a))}catch(i){s(i)}},l=a=>a.done?n(a.value):Promise.resolve(a.value).then(r,c);l((o=o.apply(e,t)).next())});var h=e=>{var t;return e?Array.isArray(e)?(t=e==null?void 0:e.reduce((o,n)=>o+(n[0]!=="\u204D"&&n[0]!=="\u2023"?n[0]:""),""))!=null?t:"":e:""};function P(e){var t,o;return e.collection_id||((o=(t=e.format)==null?void 0:t.collection_pointer)==null?void 0:o.id)||null}function B(e,t){var o,n;if((o=e.properties)!=null&&o.title)return h(e.properties.title);if(e.type==="collection_view_page"||e.type==="collection_view"){let s=(n=t.collection[P(e)])==null?void 0:n.value;if(s)return h(s.name)}return""}function E(e,t){var o,n,s;if((o=e.format)!=null&&o.page_icon)return(n=e.format)==null?void 0:n.page_icon;if(e.type==="collection_view_page"||e.type==="collection_view"){let r=P(e);if(r){let c=(s=t.collection[r])==null?void 0:s.value;if(c)return c.icon}}return null}function re(e){var o;let t=(o=e.block[Object.keys(e.block)[0]])==null?void 0:o.value;return t?B(t,e):null}function R(e,t,o){var n;try{if(!t.properties||!Object.keys(o.collection))return null;let s=(n=o.collection[t.parent_id])==null?void 0:n.value;if(s){let r=Object.keys(s.schema).find(a=>{var i;return((i=s.schema[a])==null?void 0:i.name)===e});if(!r)return null;let{type:c}=s.schema[r],l=h(t.properties[r]);switch(c){case"created_time":return t.created_time;case"multi_select":return l.split(",");case"date":{let i=t.properties[r][0][1][0][1];if(i.type=="datetime")return new Date(`${i.start_date} ${i.start_time}`).getTime();if(i.type=="date")return new Date(i.start_date).getTime();if(i.type=="datetimerange"){let{start_date:p,start_time:y,end_date:x,end_time:f}=i,b=new Date(`${p} ${y}`).getTime(),m=new Date(`${x} ${f}`).getTime();return[b,m]}else{let p=new Date(i.start_date).getTime(),y=new Date(i.end_date).getTime();return[p,y]}}case"checkbox":return l=="Yes";case"last_edited_time":return t.last_edited_time;default:return l}}}catch(s){}return null}var M=e=>{if(e&&Array.isArray(e)){if(e[0]==="d")return e[1];for(let t of e){let o=M(t);if(o)return o}}return null};var U=(e,t,{inclusive:o=!1}={})=>{var s,r;let n=e;for(;n!=null;){if(o&&(n==null?void 0:n.type)==="page")return n;let c=n.parent_id,l=n.parent_table;if(!c)break;if(l==="collection")n=(s=t.collection[c])==null?void 0:s.value;else if(n=(r=t.block[c])==null?void 0:r.value,(n==null?void 0:n.type)==="page")return n}return null};var F={header:0,sub_header:1,sub_sub_header:2},pe=(e,t)=>{var s;let o=((s=e.content)!=null?s:[]).map(r=>{var l,a;let c=(l=t.block[r])==null?void 0:l.value;if(c){let{type:i}=c;if(i==="header"||i==="sub_header"||i==="sub_sub_header")return{id:r,type:i,text:h((a=c.properties)==null?void 0:a.title),indentLevel:F[i]}}return null}).filter(Boolean),n=[{actual:-1,effective:-1}];for(let r of o){let{indentLevel:c}=r,l=c;do{let a=n[n.length-1],{actual:i,effective:p}=a;if(l>i)r.indentLevel=p+1,n.push({actual:l,effective:r.indentLevel});else if(l===i){r.indentLevel=p;break}else n.pop()}while(!0)}return o};var ue=(e,t)=>{let o=t||Object.keys(e.block)[0],n=new Set;function s(r){var y,x,f,b;if(n.has(r))return;n.add(r);let c=(y=e.block[r])==null?void 0:y.value;if(!c)return;let{content:l,type:a,properties:i,format:p}=c;if(i)for(let m of Object.keys(i)){let u=i[m];u.map(_=>{var v,w;let d=(w=(v=_==null?void 0:_[0])==null?void 0:v[1])==null?void 0:w[0];(d==null?void 0:d[0])==="p"&&d[1]&&s(d[1])});let k=(f=(x=u==null?void 0:u[0])==null?void 0:x[1])==null?void 0:f[0];(k==null?void 0:k[0])==="p"&&k[1]&&s(k[1])}if(p){let m=(b=p.transclusion_reference_pointer)==null?void 0:b.id;m&&s(m)}if(!(!l||!Array.isArray(l))&&!(r!==o&&(a==="page"||a==="collection_view_page")))for(let m of l)s(m)}return s(o),Array.from(n)};var $=(e="")=>`${e.substr(0,8)}-${e.substr(8,4)}-${e.substr(12,4)}-${e.substr(16,4)}-${e.substr(20)}`;var W=/\b([a-f0-9]{32})\b/,S=/\b([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})\b/,D=(e="",{uuid:t=!0}={})=>{if(!e)return null;e=e.split("?")[0];let o=e.match(W);if(o)return t?$(o[1]):o[1];let n=e.match(S);return n?t?n[1]:n[1].replace(/-/g,""):null};var O=e=>e.replace(/-/g,"");import Q from"p-queue";function _e(c,l,a){return T(this,arguments,function*(e,t,o,{concurrency:n=4,traverseCollections:s=!0,targetPageId:r=null}={}){let i={},p=new Set,y=new Q({concurrency:n});function x(f){return T(this,null,function*(){r&&p.has(r)||(f=D(f),f&&!i[f]&&!p.has(f)&&(p.add(f),y.add(()=>T(this,null,function*(){var b,m;try{if(r&&p.has(r)&&f!==r)return;let u=yield o(f);if(!u)return;let k=(m=(b=u.block[f])==null?void 0:b.value)==null?void 0:m.space_id;if(k){if(!t)t=k;else if(t!==k)return}if(Object.keys(u.block).filter(_=>{var v;let d=(v=u.block[_])==null?void 0:v.value;return!(!d||d.type!=="page"&&d.type!=="collection_view_page"||t&&d.space_id&&d.space_id!==t)}).forEach(_=>x(_)),s)for(let _ of Object.values(u.collection_query))for(let d of Object.values(_)){let{blockIds:v}=d;if(v)for(let w of v)x(w)}i[f]=u}catch(u){console.warn("page load error",{pageId:f,spaceId:t},u.statusCode,u.message),i[f]=null}p.delete(f)}))))})}return yield x(e),yield y.onIdle(),i})}var L=e=>(e||"").replace(/ /g,"-").replace(/[^a-zA-Z0-9-\u4e00-\u9fa5]/g,"").replace(/--/g,"-").replace(/-$/,"").replace(/^-/,"").trim().toLowerCase();var Ee=(e,t,{uuid:o=!0}={})=>{var r;if(!e||!t)return null;let n=O(e),s=(r=t.block[e])==null?void 0:r.value;if(s){let c=R("slug",s,t)||R("Slug",s,t)||L(B(s,t));if(c)return o?`${c}-${n}`:c}return n};var $e=(e,t)=>{var r;let o=e.block,n=[],s=t;do{let c=(r=o[s])==null?void 0:r.value;if(!c)break;let l=B(c,e),a=E(c,e);if(!(l||a))break;n.push({block:c,active:s===t,pageId:s,title:l,icon:a});let i=U(c,e),p=i==null?void 0:i.id;if(!p)break;s=p}while(!0);return n.reverse(),n};import j from"is-url-superb";var ze=(e,{mapImageUrl:t})=>{let n=Object.keys(e.block).flatMap(s=>{var l,a,i,p,y,x,f,b;let r=(l=e.block[s])==null?void 0:l.value,c=[];if(r){if(r.type==="image"){let k=((a=e.signed_urls)==null?void 0:a[r.id])||((y=(p=(i=r.properties)==null?void 0:i.source)==null?void 0:p[0])==null?void 0:y[0]);k&&c.push({block:r,url:k})}if((x=r.format)!=null&&x.page_cover){let u=r.format.page_cover;c.push({block:r,url:u})}if((f=r.format)!=null&&f.bookmark_cover){let u=r.format.bookmark_cover;c.push({block:r,url:u})}if((b=r.format)!=null&&b.bookmark_icon){let u=r.format.bookmark_icon;c.push({block:r,url:u})}let m=E(r,e);m&&j(m)&&c.push({block:r,url:m})}return c}).filter(Boolean).map(({block:s,url:r})=>t(r,s)).filter(Boolean);return Array.from(new Set(n))};import V from"normalize-url";import H from"mem";var N=H(e=>{if(!e)return"";try{if(e.startsWith("https://www.notion.so/image/")){let t=new URL(e),o=decodeURIComponent(t.pathname.substr(7)),n=N(o);t.pathname=`/image/${encodeURIComponent(n)}`,e=t.toString()}return V(e,{stripProtocol:!0,stripWWW:!0,stripHash:!0,stripTextFragment:!0,removeQueryParameters:!0})}catch(t){return""}});function Se(e,t){return{block:g(g({},e.block),t.block),collection:g(g({},e.collection),t.collection),collection_view:g(g({},e.collection_view),t.collection_view),notion_user:g(g({},e.notion_user),t.notion_user),collection_query:g(g({},e.collection_query),t.collection_query),signed_urls:g(g({},e.signed_urls),t.signed_urls),preview_images:g(g({},e.preview_images),t.preview_images)}}export{_e as getAllPagesInSpace,P as getBlockCollectionId,E as getBlockIcon,U as getBlockParentPage,B as getBlockTitle,Ee as getCanonicalPageId,M as getDateValue,$e as getPageBreadcrumbs,ue as getPageContentBlockIds,ze as getPageImageUrls,R as getPageProperty,pe as getPageTableOfContents,re as getPageTitle,h as getTextContent,$ as idToUuid,j as isUrl,Se as mergeRecordMaps,L as normalizeTitle,N as normalizeUrl,D as parsePageId,O as uuidToId}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "notion-utils", | ||
"version": "6.8.2", | ||
"version": "6.8.3", | ||
"type": "module", | ||
@@ -48,3 +48,3 @@ "description": "Useful utilities for working with Notion data. Isomorphic.", | ||
}, | ||
"gitHead": "61bdd3cf4c1d0c4375b349c51a7912aa43bba8b0" | ||
"gitHead": "d8d13c4206bf69c9fd9609da5833555636e4ea42" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
92768