rmapi-js 10.1.0 → 10.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/raw.d.ts +1 -1
- package/dist/raw.js +1 -1
- package/dist/rmapi-js.esm.min.js +1 -1
- package/package.json +1 -1
package/dist/raw.d.ts
CHANGED
|
@@ -216,7 +216,7 @@ export interface CommonDocumentContent {
|
|
|
216
216
|
/** a mapping from page number to page id in pages */
|
|
217
217
|
redirectionPageMap?: number[];
|
|
218
218
|
/** ostensibly the size in bytes of the file, but this differs from other measurements */
|
|
219
|
-
sizeInBytes
|
|
219
|
+
sizeInBytes?: string;
|
|
220
220
|
/** text alignment for this document */
|
|
221
221
|
textAlignment: TextAlignment;
|
|
222
222
|
/**
|
package/dist/raw.js
CHANGED
|
@@ -77,7 +77,6 @@ const documentContentRequired = {
|
|
|
77
77
|
lineHeight: int32(),
|
|
78
78
|
orientation: enumeration("portrait", "landscape"),
|
|
79
79
|
pageCount: uint32(),
|
|
80
|
-
sizeInBytes: string(),
|
|
81
80
|
textAlignment: enumeration("", "justify", "left"),
|
|
82
81
|
textScale: float64(),
|
|
83
82
|
};
|
|
@@ -101,6 +100,7 @@ const documentContentOptional = {
|
|
|
101
100
|
pages: nullable(elements(string())),
|
|
102
101
|
pageTags: elements(pageTag),
|
|
103
102
|
redirectionPageMap: elements(int32()),
|
|
103
|
+
sizeInBytes: string(),
|
|
104
104
|
transform: properties(undefined, {
|
|
105
105
|
m11: float64(),
|
|
106
106
|
m12: float64(),
|
package/dist/rmapi-js.esm.min.js
CHANGED
|
@@ -9,7 +9,7 @@ While trying to validate:
|
|
|
9
9
|
${$}
|
|
10
10
|
|
|
11
11
|
Against schema:
|
|
12
|
-
${X}`)}else return!0}}class NX extends S0{#Q;definitions;nullable=!0;constructor(Q){super();this.#Q=Q,this.definitions=Q.definitions}*pathErrors(Q){if(Q!==null)for(let[q,$]of this.#Q.pathErrors(Q))yield[q,`${$} or ${$2(Q)} is not null`]}fuzz(){return v6(0.1)?null:this.#Q.fuzz()}schema(){return{...this.#Q.schema(),nullable:!0}}}function E6(Q){return new NX(Q)}class yZ extends S0{#Q;#q;definitions;nullable;constructor(Q,q){super();this.#Q=Q,this.#q=q,this.definitions=Q.definitions,this.nullable=Q.nullable}*pathErrors(Q){yield*this.#Q.pathErrors(Q)}fuzz(){return this.#Q.fuzz()}schema(){return{...this.#Q.schema(),metadata:this.#q}}}class DX extends S0{*pathErrors(Q){if(Q===void 0)yield[[],"value is undefined"]}fuzz(){return k8([()=>null,v6,m4,()=>i1(V2()),()=>Array(V2()).fill(null).map(()=>this.fuzz()),()=>Object.fromEntries(Array(V2()).fill(null).map(()=>[i1(V2(3)),this.fuzz()]))])()}schema(){return{}}}function AX(){return new DX}class OX extends S0{*pathErrors(Q){if(typeof Q!=="boolean")yield[[],`${$2(Q)} is not a boolean`]}fuzz(){return v6()}schema(){return{type:"boolean"}}}function w1(){return new OX}class g8 extends S0{#Q;#q;#$;constructor(Q){super();this.#Q=Q,[this.#q,this.#$]=SZ[Q]}*pathErrors(Q){if(typeof Q!=="number")yield[[],`${$2(Q)} is not a number`];else if(Q%1!==0)yield[[],`${Q.toPrecision()} is not an integer`];else if(Q<this.#q)yield[[],`${Q.toFixed()} is less than ${this.#q.toFixed()}`];else if(Q>=this.#$)yield[[],`${Q.toFixed()} is greater than ${(this.#$-1).toFixed()}`]}fuzz(){return CX(this.#q,this.#$)}schema(){return{type:this.#Q}}}function y8(){return new g8("uint8")}function z2(){return new g8("int32")}function o1(){return new g8("uint32")}class RX extends S0{#Q;constructor(Q){super();this.#Q=Q}*pathErrors(Q){if(typeof Q!=="number")yield[[],`${$2(Q)} is not number, expected a float`]}fuzz(){return m4()}schema(){return{type:this.#Q}}}function O0(){return new RX("float64")}class xX extends S0{*pathErrors(Q){if(typeof Q!=="string")yield[[],`${$2(Q)} is not a string`]}fuzz(){return i1(V2(3))}schema(){return{type:"string"}}}function F0(){return new xX}class TX extends S0{*pathErrors(Q){if(typeof Q!=="string")yield[[],`${$2(Q)} is not a string`];else if(!xZ(Q))yield[[],`${Q} is not a valid timestamp`]}fuzz(){return new Date(Math.random()*3153600000000).toISOString()}schema(){return{type:"timestamp"}}}function vX(){return new TX}class EX extends S0{#Q;#q;constructor(Q,q){super();this.#Q=Q,this.#q=q}*pathErrors(Q){if(typeof Q!=="string")yield[[],`${$2(Q)} is not a string`];else if(!this.#q.has(Q))yield[[],`${Q} is not one of ${this.#Q.join(", ")}`]}fuzz(){return k8(this.#Q)}schema(){return{enum:[...this.#Q]}}}function C2(...Q){let q=new Set(Q);if(q.size!==Q.length)throw Error("enum can't contain duplicates");else return new EX(Q,q)}class SX extends S0{#Q;constructor(Q){super();this.#Q=Q}*pathErrors(Q){if(!Array.isArray(Q))yield[[],`${$2(Q)} is not an array`];else for(let[q,$]of Q.entries())for(let[X,Y]of this.#Q.pathErrors($))X.push(`[${q.toFixed()}]`),yield[X,Y]}fuzz(){return Array(V2()).fill(null).map(()=>this.#Q.fuzz())}schema(){return{elements:this.#Q.schema()}}}function h0(Q){if(Q.definitions)throw Error("definitions can only exist on a root schema");else return new SX(Q)}class kX extends S0{#Q;constructor(Q){super();this.#Q=Q}*pathErrors(Q){if(!S8(Q))yield[[],`${$2(Q)} is not a record`];else for(let[q,$]of Object.entries(Q))for(let[X,Y]of this.#Q.pathErrors($))X.push(l1(q)),yield[X,Y]}fuzz(){return Object.fromEntries(Array(V2()).fill(null).map(()=>[i1(V2(3)),this.#Q.fuzz()]))}schema(){return{values:this.#Q.schema()}}}function S6(Q){if(Q.definitions)throw Error("definitions can only exist on a root schema");else return new kX(Q)}class gX extends S0{#Q;#q;#$;keys;constructor(Q,q,$,X){super();this.#Q=Q,this.#q=q,this.#$=$,this.keys=X}*pathErrors(Q){if(!S8(Q))yield[[],`${$2(Q)} is not a record`];else{if(this.#Q)for(let[q,$]of this.#Q){let X=Q[q];if(X===void 0)yield[[],`required key '${q}' is missing`];else for(let[Y,J]of $.pathErrors(X))Y.push(l1(q)),yield[Y,J]}if(this.#q){for(let[q,$]of this.#q)if(Q[q]!==void 0)for(let[X,Y]of $.pathErrors(Q[q]))X.push(l1(q)),yield[X,Y]}if(!this.#$){for(let q of Object.keys(Q))if(!this.keys.has(q))yield[[l1(q)],`'${q}' is not a valid property and additional properties are not allowed`]}}}fuzz(){let Q=E8(this.#Q??[],([X,Y])=>[X,Y.fuzz()]),q=E8(kZ(this.#q??[],()=>v6()),([X,Y])=>[X,Y.fuzz()]),$=this.#$?E8(gZ(V2()),()=>[i1(V2(3)),k8([()=>null,v6,m4,()=>i1(V2()),()=>[],()=>({})])()]):[];return Object.fromEntries(IX(Q,q,$))}schema(){let Q={};if(this.#Q)Q.properties=Object.fromEntries(this.#Q.map(([q,$])=>[q,$.schema()]));if(this.#q)Q.optionalProperties=Object.fromEntries(this.#q.map(([q,$])=>[q,$.schema()]));if(this.#$)Q.additionalProperties=!0;return Q}}function fZ(Q,q,$){let X=new Set(E8(IX(Q??[],q??[]),([Y])=>Y));if(Q?.some(([,Y])=>Y.definitions))throw Error("definitions can only exist on a root schema");else if(q?.some(([,Y])=>Y.definitions))throw Error("definitions can only exist on a root schema");else if(X.size!==(Q?.length??0)+(q?.length??0))throw Error("properties and optionalProperties keys must be unique");else return new gX(Q,q,$??!1,X)}function C0(Q,q,$){return fZ(Q?Object.entries(Q):void 0,q?Object.entries(q):void 0,$)}class hZ extends S0{#Q;#q;#$;constructor(Q,q,$){super();this.#Q=Q,this.#q=q,this.#$=$}guard(Q){if(!S8(Q))return!1;let{[this.#Q]:q,...$}=Q;if(typeof q!=="string")return!1;return this.#q[q]?.guard($)??!1}*pathErrors(Q){if(!S8(Q))yield[[],`${$2(Q)} is not an object`];else{let{[this.#Q]:q,...$}=Q;if(q===void 0)yield[[],`discriminator key '${this.#Q}' is missing`];else if(typeof q!=="string")yield[[l1(this.#Q)],`${$2(q)} is not a string`];else{let X=this.#q[q];if(X===void 0)yield[[l1(this.#Q)],`'${q}' is not a valid discriminator value (${Object.keys(this.#q).join(", ")})`];else yield*X.pathErrors($)}}}fuzz(){let[Q,q]=k8(this.#$);return{...q.fuzz(),[this.#Q]:Q}}schema(){let Q=Object.fromEntries(this.#$.map(([q,$])=>[q,$.schema()]));return{discriminator:this.#Q,mapping:Q}}}class yX extends S0{#Q;#q;definitions=!0;constructor(Q,q){super();this.#Q=Q,this.#q=q}*pathErrors(Q){yield*this.#q.pathErrors(Q)}fuzz(){return this.#q.fuzz()}schema(){let Q=Object.fromEntries(Object.entries(this.#Q).map(([q,$])=>[q,$.schema()]));return{...this.#q.schema(),definitions:Q}}}class fX extends S0{#Q;#q;constructor(Q,q){super();this.#Q=Q,this.#q=q}*pathErrors(Q){yield*this.#q.pathErrors(Q)}fuzz(){return this.#q.fuzz()}schema(){return{ref:this.#Q}}}class hX{#Q;#q;constructor(Q,q){this.#Q=Q,this.#q=q}def(Q,q){let $=q(this.#q);return new hX({...this.#Q,[Q]:$},{...this.#q,[Q]:new fX(Q,$)})}build(Q){return new yX(this.#Q,Q(this.#q))}}class _Z extends S0{#Q;#q;constructor(Q,q){super();this.#q=Q,this.#Q=q}#$(){let Q=this.#q[this.#Q];if(Q===void 0)throw Error(`ref ${this.#Q} was not in definitions after ref builder was finished`);else return Q}*pathErrors(Q){yield*this.#$().pathErrors(Q)}fuzz(){return this.#$().fuzz()}schema(){return{ref:this.#Q}}}var bZ=new Uint8Array(16);function d4(){return crypto.getRandomValues(bZ)}var k0=[];for(let Q=0;Q<256;++Q)k0.push((Q+256).toString(16).slice(1));function _X(Q,q=0){return(k0[Q[q+0]]+k0[Q[q+1]]+k0[Q[q+2]]+k0[Q[q+3]]+"-"+k0[Q[q+4]]+k0[Q[q+5]]+"-"+k0[Q[q+6]]+k0[Q[q+7]]+"-"+k0[Q[q+8]]+k0[Q[q+9]]+"-"+k0[Q[q+10]]+k0[Q[q+11]]+k0[Q[q+12]]+k0[Q[q+13]]+k0[Q[q+14]]+k0[Q[q+15]]).toLowerCase()}function uZ(Q,q,$){if(!q&&!Q&&crypto.randomUUID)return crypto.randomUUID();return cZ(Q,q,$)}function cZ(Q,q,$){Q=Q||{};let X=Q.random??Q.rng?.()??d4();if(X.length<16)throw Error("Random bytes length must be >= 16");if(X[6]=X[6]&15|64,X[8]=X[8]&63|128,q){if($=$||0,$<0||$+16>q.length)throw RangeError(`UUID byte range ${$}:${$+15} is out of buffer bounds`);for(let Y=0;Y<16;++Y)q[$+Y]=X[Y];return q}return _X(X)}var n1=uZ;class I2 extends Error{field;regex;constructor(Q,q,$){super($);this.field=Q,this.regex=q}}class k6 extends Error{hash;constructor(Q){super(`'${Q}' not found in the root hash`);this.hash=Q}}class l4 extends Map{#Q;#q=0;constructor(Q,q=[]){super();this.#Q=Q;for(let[$,X]of q)this.set($,X)}get(Q){let q=super.get(Q);if(q!==void 0)super.delete(Q),super.set(Q,q);return q}set(Q,q){let $=super.get(Q);if($===void 0)this.#q+=Q.length;else if($!==null)this.#q-=$.length;if(q!==null)this.#q+=q.length;super.delete(Q);let X;while(this.#q>this.#Q&&(X=this.entries().next().value)){let[Y,J]=X;if(super.delete(Y),this.#q-=Y.length,J!==null)this.#q-=J.length}return super.set(Q,q),this}delete(Q){let q=super.get(Q);if(q===void 0)return!1;if(super.delete(Q),q!==null)this.#q-=q.length;return this.#q-=Q.length,!0}clear(){super.clear(),this.#q=0}}var eK=V5(uX(),1);function cX(Q){let q=Q.reduce((Y,J)=>Y+J.length,0),$=new Uint8Array(q),X=0;for(let Y of Q)$.set(Y,X),X+=Y.length;return $}var kC=V5(sK(),1),$5=/^[0-9a-f]{64}$/,QU=C0({name:F0(),timestamp:O0()},void 0,!0),xw=C0({name:F0(),pageId:F0(),timestamp:O0()},void 0,!0),Tw=C0(void 0,{authors:h0(F0()),title:F0(),publicationDate:F0(),publisher:F0()},!0),vw=C0({id:F0(),idx:C0({timestamp:F0(),value:F0()},void 0,!0)},{template:C0({timestamp:F0(),value:F0()},void 0,!0),redir:C0({timestamp:F0(),value:z2()},void 0,!0),scrollTime:C0({timestamp:F0(),value:vX()},void 0,!0),verticalScroll:C0({timestamp:F0(),value:O0()},void 0,!0),deleted:C0({timestamp:F0(),value:z2()},void 0,!0)},!0),Ew=C0({lastOpened:C0({timestamp:F0(),value:F0()},void 0,!0),original:C0({timestamp:F0(),value:z2()},void 0,!0),pages:h0(vw),uuids:E6(h0(C0({first:F0(),second:o1()},void 0,!0)))},void 0,!0),Sw=C0(void 0,{tags:h0(QU)}),kw=C0(void 0,{tags:h0(F0())}),qU={coverPageNumber:z2(),documentMetadata:Tw,extraMetadata:S6(F0()),fileType:C2("epub","notebook","pdf"),fontName:F0(),lineHeight:z2(),orientation:C2("portrait","landscape"),pageCount:o1(),sizeInBytes:F0(),textAlignment:C2("","justify","left"),textScale:O0()},$U={cPages:Ew,customZoomCenterX:O0(),customZoomCenterY:O0(),customZoomOrientation:C2("portrait","landscape"),customZoomPageHeight:O0(),customZoomPageWidth:O0(),customZoomScale:O0(),dummyDocument:w1(),formatVersion:y8(),keyboardMetadata:C0({count:o1(),timestamp:O0()},void 0,!0),lastOpenedPage:z2(),margins:o1(),originalPageCount:z2(),pages:E6(h0(F0())),pageTags:h0(xw),redirectionPageMap:h0(z2()),transform:C0(void 0,{m11:O0(),m12:O0(),m13:O0(),m21:O0(),m22:O0(),m23:O0(),m31:O0(),m32:O0(),m33:O0()},!0),viewBackgroundFilter:C2("off","fullpage"),zoomMode:C2("bestFit","customFit","fitToHeight","fitToWidth")},gw=C0(qU,{...$U,tags:h0(QU)},!0),yw=C0(qU,{...$U,tags:h0(F0())},!0),fw=C0({name:F0(),author:F0(),iconData:F0(),categories:h0(F0()),labels:h0(F0()),orientation:C2("portrait","landscape"),templateVersion:F0(),supportedScreens:h0(C2("rm2","rmPP")),constants:h0(S6(z2())),items:h0(AX())},{formatVersion:y8()}),hw=C0({lastModified:F0(),parent:F0(),pinned:w1(),type:C2("DocumentType","CollectionType","TemplateType"),visibleName:F0()},{lastOpened:F0(),lastOpenedPage:z2(),createdTime:F0(),deleted:w1(),metadatamodified:w1(),modified:w1(),synced:w1(),version:o1()},!0),_w=C0({hash:F0(),generation:O0()},void 0,!0),bw=C0({hash:F0(),generation:O0(),schemaVersion:y8()},void 0,!0),uw=C0({docID:F0(),hash:F0()},void 0,!0);async function dQ(Q){let q=await crypto.subtle.digest("SHA-256",Q);return new Uint8Array(q).toHex()}function tK(Q){let[q,$,X,Y,J]=Q.split(":");if(q===void 0||$===void 0||X===void 0||Y===void 0||J===void 0)throw Error(`line '${Q}' was not formatted correctly`);else if($==="80000000"||$==="0")return{hash:q,type:$==="0"?0:80000000,id:X,subfiles:parseInt(Y,10),size:parseInt(J,10)};else throw Error(`line '${Q}' was not formatted correctly`)}class lQ{#Q;#q;#$;#X;constructor(Q,q,$,X){this.#Q=Q,this.#X=q,this.#q=$,this.#$=X}async getRootHash(){let q=await(await this.#Q("GET",`${this.#q}/sync/v4/root`)).text(),$=JSON.parse(q);if(!bw.guardAssert($))throw Error("invalid root hash");let{hash:X,generation:Y,schemaVersion:J}=$;if(J!==3&&J!==4)throw Error(`schema version ${J} not supported`);else if(!Number.isSafeInteger(Y))throw Error(`generation ${Y} was not a safe integer; please file a bug report`);else return[X,Y,J]}async#Y(Q,q){if(!$5.test(q))throw new I2(q,$5,"hash was not a valid hash");let X=await(await this.#Q("GET",`${this.#q}/sync/v3/files/${q}`,{headers:{"rm-filename":Q}})).arrayBuffer();return new Uint8Array(X)}async getHash(Q,q){let $=this.#X.get(q);if($!=null)return new TextEncoder().encode($);else{let X=await this.#Y(Q,q);if(this.#X.get(q)===void 0)this.#X.set(q,null);return X}}async getText(Q,q){let $=this.#X.get(q);if($!=null)return $;else{let X=await this.#Y(Q,q),J=new TextDecoder().decode(X);return this.#X.set(q,J),J}}async getEntries(Q,q){let $=await this.getText(Q,q),[X,...Y]=$.slice(0,-1).split(`
|
|
12
|
+
${X}`)}else return!0}}class NX extends S0{#Q;definitions;nullable=!0;constructor(Q){super();this.#Q=Q,this.definitions=Q.definitions}*pathErrors(Q){if(Q!==null)for(let[q,$]of this.#Q.pathErrors(Q))yield[q,`${$} or ${$2(Q)} is not null`]}fuzz(){return v6(0.1)?null:this.#Q.fuzz()}schema(){return{...this.#Q.schema(),nullable:!0}}}function E6(Q){return new NX(Q)}class yZ extends S0{#Q;#q;definitions;nullable;constructor(Q,q){super();this.#Q=Q,this.#q=q,this.definitions=Q.definitions,this.nullable=Q.nullable}*pathErrors(Q){yield*this.#Q.pathErrors(Q)}fuzz(){return this.#Q.fuzz()}schema(){return{...this.#Q.schema(),metadata:this.#q}}}class DX extends S0{*pathErrors(Q){if(Q===void 0)yield[[],"value is undefined"]}fuzz(){return k8([()=>null,v6,m4,()=>i1(V2()),()=>Array(V2()).fill(null).map(()=>this.fuzz()),()=>Object.fromEntries(Array(V2()).fill(null).map(()=>[i1(V2(3)),this.fuzz()]))])()}schema(){return{}}}function AX(){return new DX}class OX extends S0{*pathErrors(Q){if(typeof Q!=="boolean")yield[[],`${$2(Q)} is not a boolean`]}fuzz(){return v6()}schema(){return{type:"boolean"}}}function w1(){return new OX}class g8 extends S0{#Q;#q;#$;constructor(Q){super();this.#Q=Q,[this.#q,this.#$]=SZ[Q]}*pathErrors(Q){if(typeof Q!=="number")yield[[],`${$2(Q)} is not a number`];else if(Q%1!==0)yield[[],`${Q.toPrecision()} is not an integer`];else if(Q<this.#q)yield[[],`${Q.toFixed()} is less than ${this.#q.toFixed()}`];else if(Q>=this.#$)yield[[],`${Q.toFixed()} is greater than ${(this.#$-1).toFixed()}`]}fuzz(){return CX(this.#q,this.#$)}schema(){return{type:this.#Q}}}function y8(){return new g8("uint8")}function z2(){return new g8("int32")}function o1(){return new g8("uint32")}class RX extends S0{#Q;constructor(Q){super();this.#Q=Q}*pathErrors(Q){if(typeof Q!=="number")yield[[],`${$2(Q)} is not number, expected a float`]}fuzz(){return m4()}schema(){return{type:this.#Q}}}function O0(){return new RX("float64")}class xX extends S0{*pathErrors(Q){if(typeof Q!=="string")yield[[],`${$2(Q)} is not a string`]}fuzz(){return i1(V2(3))}schema(){return{type:"string"}}}function F0(){return new xX}class TX extends S0{*pathErrors(Q){if(typeof Q!=="string")yield[[],`${$2(Q)} is not a string`];else if(!xZ(Q))yield[[],`${Q} is not a valid timestamp`]}fuzz(){return new Date(Math.random()*3153600000000).toISOString()}schema(){return{type:"timestamp"}}}function vX(){return new TX}class EX extends S0{#Q;#q;constructor(Q,q){super();this.#Q=Q,this.#q=q}*pathErrors(Q){if(typeof Q!=="string")yield[[],`${$2(Q)} is not a string`];else if(!this.#q.has(Q))yield[[],`${Q} is not one of ${this.#Q.join(", ")}`]}fuzz(){return k8(this.#Q)}schema(){return{enum:[...this.#Q]}}}function C2(...Q){let q=new Set(Q);if(q.size!==Q.length)throw Error("enum can't contain duplicates");else return new EX(Q,q)}class SX extends S0{#Q;constructor(Q){super();this.#Q=Q}*pathErrors(Q){if(!Array.isArray(Q))yield[[],`${$2(Q)} is not an array`];else for(let[q,$]of Q.entries())for(let[X,Y]of this.#Q.pathErrors($))X.push(`[${q.toFixed()}]`),yield[X,Y]}fuzz(){return Array(V2()).fill(null).map(()=>this.#Q.fuzz())}schema(){return{elements:this.#Q.schema()}}}function h0(Q){if(Q.definitions)throw Error("definitions can only exist on a root schema");else return new SX(Q)}class kX extends S0{#Q;constructor(Q){super();this.#Q=Q}*pathErrors(Q){if(!S8(Q))yield[[],`${$2(Q)} is not a record`];else for(let[q,$]of Object.entries(Q))for(let[X,Y]of this.#Q.pathErrors($))X.push(l1(q)),yield[X,Y]}fuzz(){return Object.fromEntries(Array(V2()).fill(null).map(()=>[i1(V2(3)),this.#Q.fuzz()]))}schema(){return{values:this.#Q.schema()}}}function S6(Q){if(Q.definitions)throw Error("definitions can only exist on a root schema");else return new kX(Q)}class gX extends S0{#Q;#q;#$;keys;constructor(Q,q,$,X){super();this.#Q=Q,this.#q=q,this.#$=$,this.keys=X}*pathErrors(Q){if(!S8(Q))yield[[],`${$2(Q)} is not a record`];else{if(this.#Q)for(let[q,$]of this.#Q){let X=Q[q];if(X===void 0)yield[[],`required key '${q}' is missing`];else for(let[Y,J]of $.pathErrors(X))Y.push(l1(q)),yield[Y,J]}if(this.#q){for(let[q,$]of this.#q)if(Q[q]!==void 0)for(let[X,Y]of $.pathErrors(Q[q]))X.push(l1(q)),yield[X,Y]}if(!this.#$){for(let q of Object.keys(Q))if(!this.keys.has(q))yield[[l1(q)],`'${q}' is not a valid property and additional properties are not allowed`]}}}fuzz(){let Q=E8(this.#Q??[],([X,Y])=>[X,Y.fuzz()]),q=E8(kZ(this.#q??[],()=>v6()),([X,Y])=>[X,Y.fuzz()]),$=this.#$?E8(gZ(V2()),()=>[i1(V2(3)),k8([()=>null,v6,m4,()=>i1(V2()),()=>[],()=>({})])()]):[];return Object.fromEntries(IX(Q,q,$))}schema(){let Q={};if(this.#Q)Q.properties=Object.fromEntries(this.#Q.map(([q,$])=>[q,$.schema()]));if(this.#q)Q.optionalProperties=Object.fromEntries(this.#q.map(([q,$])=>[q,$.schema()]));if(this.#$)Q.additionalProperties=!0;return Q}}function fZ(Q,q,$){let X=new Set(E8(IX(Q??[],q??[]),([Y])=>Y));if(Q?.some(([,Y])=>Y.definitions))throw Error("definitions can only exist on a root schema");else if(q?.some(([,Y])=>Y.definitions))throw Error("definitions can only exist on a root schema");else if(X.size!==(Q?.length??0)+(q?.length??0))throw Error("properties and optionalProperties keys must be unique");else return new gX(Q,q,$??!1,X)}function C0(Q,q,$){return fZ(Q?Object.entries(Q):void 0,q?Object.entries(q):void 0,$)}class hZ extends S0{#Q;#q;#$;constructor(Q,q,$){super();this.#Q=Q,this.#q=q,this.#$=$}guard(Q){if(!S8(Q))return!1;let{[this.#Q]:q,...$}=Q;if(typeof q!=="string")return!1;return this.#q[q]?.guard($)??!1}*pathErrors(Q){if(!S8(Q))yield[[],`${$2(Q)} is not an object`];else{let{[this.#Q]:q,...$}=Q;if(q===void 0)yield[[],`discriminator key '${this.#Q}' is missing`];else if(typeof q!=="string")yield[[l1(this.#Q)],`${$2(q)} is not a string`];else{let X=this.#q[q];if(X===void 0)yield[[l1(this.#Q)],`'${q}' is not a valid discriminator value (${Object.keys(this.#q).join(", ")})`];else yield*X.pathErrors($)}}}fuzz(){let[Q,q]=k8(this.#$);return{...q.fuzz(),[this.#Q]:Q}}schema(){let Q=Object.fromEntries(this.#$.map(([q,$])=>[q,$.schema()]));return{discriminator:this.#Q,mapping:Q}}}class yX extends S0{#Q;#q;definitions=!0;constructor(Q,q){super();this.#Q=Q,this.#q=q}*pathErrors(Q){yield*this.#q.pathErrors(Q)}fuzz(){return this.#q.fuzz()}schema(){let Q=Object.fromEntries(Object.entries(this.#Q).map(([q,$])=>[q,$.schema()]));return{...this.#q.schema(),definitions:Q}}}class fX extends S0{#Q;#q;constructor(Q,q){super();this.#Q=Q,this.#q=q}*pathErrors(Q){yield*this.#q.pathErrors(Q)}fuzz(){return this.#q.fuzz()}schema(){return{ref:this.#Q}}}class hX{#Q;#q;constructor(Q,q){this.#Q=Q,this.#q=q}def(Q,q){let $=q(this.#q);return new hX({...this.#Q,[Q]:$},{...this.#q,[Q]:new fX(Q,$)})}build(Q){return new yX(this.#Q,Q(this.#q))}}class _Z extends S0{#Q;#q;constructor(Q,q){super();this.#q=Q,this.#Q=q}#$(){let Q=this.#q[this.#Q];if(Q===void 0)throw Error(`ref ${this.#Q} was not in definitions after ref builder was finished`);else return Q}*pathErrors(Q){yield*this.#$().pathErrors(Q)}fuzz(){return this.#$().fuzz()}schema(){return{ref:this.#Q}}}var bZ=new Uint8Array(16);function d4(){return crypto.getRandomValues(bZ)}var k0=[];for(let Q=0;Q<256;++Q)k0.push((Q+256).toString(16).slice(1));function _X(Q,q=0){return(k0[Q[q+0]]+k0[Q[q+1]]+k0[Q[q+2]]+k0[Q[q+3]]+"-"+k0[Q[q+4]]+k0[Q[q+5]]+"-"+k0[Q[q+6]]+k0[Q[q+7]]+"-"+k0[Q[q+8]]+k0[Q[q+9]]+"-"+k0[Q[q+10]]+k0[Q[q+11]]+k0[Q[q+12]]+k0[Q[q+13]]+k0[Q[q+14]]+k0[Q[q+15]]).toLowerCase()}function uZ(Q,q,$){if(!q&&!Q&&crypto.randomUUID)return crypto.randomUUID();return cZ(Q,q,$)}function cZ(Q,q,$){Q=Q||{};let X=Q.random??Q.rng?.()??d4();if(X.length<16)throw Error("Random bytes length must be >= 16");if(X[6]=X[6]&15|64,X[8]=X[8]&63|128,q){if($=$||0,$<0||$+16>q.length)throw RangeError(`UUID byte range ${$}:${$+15} is out of buffer bounds`);for(let Y=0;Y<16;++Y)q[$+Y]=X[Y];return q}return _X(X)}var n1=uZ;class I2 extends Error{field;regex;constructor(Q,q,$){super($);this.field=Q,this.regex=q}}class k6 extends Error{hash;constructor(Q){super(`'${Q}' not found in the root hash`);this.hash=Q}}class l4 extends Map{#Q;#q=0;constructor(Q,q=[]){super();this.#Q=Q;for(let[$,X]of q)this.set($,X)}get(Q){let q=super.get(Q);if(q!==void 0)super.delete(Q),super.set(Q,q);return q}set(Q,q){let $=super.get(Q);if($===void 0)this.#q+=Q.length;else if($!==null)this.#q-=$.length;if(q!==null)this.#q+=q.length;super.delete(Q);let X;while(this.#q>this.#Q&&(X=this.entries().next().value)){let[Y,J]=X;if(super.delete(Y),this.#q-=Y.length,J!==null)this.#q-=J.length}return super.set(Q,q),this}delete(Q){let q=super.get(Q);if(q===void 0)return!1;if(super.delete(Q),q!==null)this.#q-=q.length;return this.#q-=Q.length,!0}clear(){super.clear(),this.#q=0}}var eK=V5(uX(),1);function cX(Q){let q=Q.reduce((Y,J)=>Y+J.length,0),$=new Uint8Array(q),X=0;for(let Y of Q)$.set(Y,X),X+=Y.length;return $}var kC=V5(sK(),1),$5=/^[0-9a-f]{64}$/,QU=C0({name:F0(),timestamp:O0()},void 0,!0),xw=C0({name:F0(),pageId:F0(),timestamp:O0()},void 0,!0),Tw=C0(void 0,{authors:h0(F0()),title:F0(),publicationDate:F0(),publisher:F0()},!0),vw=C0({id:F0(),idx:C0({timestamp:F0(),value:F0()},void 0,!0)},{template:C0({timestamp:F0(),value:F0()},void 0,!0),redir:C0({timestamp:F0(),value:z2()},void 0,!0),scrollTime:C0({timestamp:F0(),value:vX()},void 0,!0),verticalScroll:C0({timestamp:F0(),value:O0()},void 0,!0),deleted:C0({timestamp:F0(),value:z2()},void 0,!0)},!0),Ew=C0({lastOpened:C0({timestamp:F0(),value:F0()},void 0,!0),original:C0({timestamp:F0(),value:z2()},void 0,!0),pages:h0(vw),uuids:E6(h0(C0({first:F0(),second:o1()},void 0,!0)))},void 0,!0),Sw=C0(void 0,{tags:h0(QU)}),kw=C0(void 0,{tags:h0(F0())}),qU={coverPageNumber:z2(),documentMetadata:Tw,extraMetadata:S6(F0()),fileType:C2("epub","notebook","pdf"),fontName:F0(),lineHeight:z2(),orientation:C2("portrait","landscape"),pageCount:o1(),textAlignment:C2("","justify","left"),textScale:O0()},$U={cPages:Ew,customZoomCenterX:O0(),customZoomCenterY:O0(),customZoomOrientation:C2("portrait","landscape"),customZoomPageHeight:O0(),customZoomPageWidth:O0(),customZoomScale:O0(),dummyDocument:w1(),formatVersion:y8(),keyboardMetadata:C0({count:o1(),timestamp:O0()},void 0,!0),lastOpenedPage:z2(),margins:o1(),originalPageCount:z2(),pages:E6(h0(F0())),pageTags:h0(xw),redirectionPageMap:h0(z2()),sizeInBytes:F0(),transform:C0(void 0,{m11:O0(),m12:O0(),m13:O0(),m21:O0(),m22:O0(),m23:O0(),m31:O0(),m32:O0(),m33:O0()},!0),viewBackgroundFilter:C2("off","fullpage"),zoomMode:C2("bestFit","customFit","fitToHeight","fitToWidth")},gw=C0(qU,{...$U,tags:h0(QU)},!0),yw=C0(qU,{...$U,tags:h0(F0())},!0),fw=C0({name:F0(),author:F0(),iconData:F0(),categories:h0(F0()),labels:h0(F0()),orientation:C2("portrait","landscape"),templateVersion:F0(),supportedScreens:h0(C2("rm2","rmPP")),constants:h0(S6(z2())),items:h0(AX())},{formatVersion:y8()}),hw=C0({lastModified:F0(),parent:F0(),pinned:w1(),type:C2("DocumentType","CollectionType","TemplateType"),visibleName:F0()},{lastOpened:F0(),lastOpenedPage:z2(),createdTime:F0(),deleted:w1(),metadatamodified:w1(),modified:w1(),synced:w1(),version:o1()},!0),_w=C0({hash:F0(),generation:O0()},void 0,!0),bw=C0({hash:F0(),generation:O0(),schemaVersion:y8()},void 0,!0),uw=C0({docID:F0(),hash:F0()},void 0,!0);async function dQ(Q){let q=await crypto.subtle.digest("SHA-256",Q);return new Uint8Array(q).toHex()}function tK(Q){let[q,$,X,Y,J]=Q.split(":");if(q===void 0||$===void 0||X===void 0||Y===void 0||J===void 0)throw Error(`line '${Q}' was not formatted correctly`);else if($==="80000000"||$==="0")return{hash:q,type:$==="0"?0:80000000,id:X,subfiles:parseInt(Y,10),size:parseInt(J,10)};else throw Error(`line '${Q}' was not formatted correctly`)}class lQ{#Q;#q;#$;#X;constructor(Q,q,$,X){this.#Q=Q,this.#X=q,this.#q=$,this.#$=X}async getRootHash(){let q=await(await this.#Q("GET",`${this.#q}/sync/v4/root`)).text(),$=JSON.parse(q);if(!bw.guardAssert($))throw Error("invalid root hash");let{hash:X,generation:Y,schemaVersion:J}=$;if(J!==3&&J!==4)throw Error(`schema version ${J} not supported`);else if(!Number.isSafeInteger(Y))throw Error(`generation ${Y} was not a safe integer; please file a bug report`);else return[X,Y,J]}async#Y(Q,q){if(!$5.test(q))throw new I2(q,$5,"hash was not a valid hash");let X=await(await this.#Q("GET",`${this.#q}/sync/v3/files/${q}`,{headers:{"rm-filename":Q}})).arrayBuffer();return new Uint8Array(X)}async getHash(Q,q){let $=this.#X.get(q);if($!=null)return new TextEncoder().encode($);else{let X=await this.#Y(Q,q);if(this.#X.get(q)===void 0)this.#X.set(q,null);return X}}async getText(Q,q){let $=this.#X.get(q);if($!=null)return $;else{let X=await this.#Y(Q,q),J=new TextDecoder().decode(X);return this.#X.set(q,J),J}}async getEntries(Q,q){let $=await this.getText(Q,q),[X,...Y]=$.slice(0,-1).split(`
|
|
13
13
|
`);if(X==="3")return{entries:Y.map(tK)};else if(X==="4"){let[J,...K]=Y;if(!J)throw Error("missing info line for schema version 4");let[U,G,V,z]=J.split(":");if(U!=="0"||G===void 0||V===void 0||z===void 0)throw Error(`schema 4 info line '${J}' was not formatted correctly`);let H=K.map(tK);if(parseInt(V,10)!==H.length)throw Error(`schema 4 expected ${V} entries, but found ${H.length}`);else return{entries:H,id:G,size:parseInt(z,10)}}else throw Error(`schema version ${X} not supported`)}async getContent(Q,q){let $=await this.getText(Q,q),X=JSON.parse($),Y=[];for(let[K,U]of[["collection",Sw],["legacy collection",kw],["template",fw],["document",gw],["legacy document",yw]])try{if(U.guardAssert(X))return X}catch(G){let V=G instanceof Error?G.message:"unknown error type";Y.push(`Couldn't validate as ${K} because:
|
|
14
14
|
${V}`)}let J=Y.join(`
|
|
15
15
|
|