notu 0.15.14 → 0.16.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/notu.mjs CHANGED
@@ -803,48 +803,99 @@ class NotuHttpCacheFetcher {
803
803
  )).json();
804
804
  }
805
805
  }
806
- class NoteComponentInfo {
807
- constructor(text, start, processor) {
806
+ class NoteXmlElement {
807
+ constructor() {
808
+ __publicField(this, "tag");
809
+ __publicField(this, "children", []);
810
+ __publicField(this, "attributes");
808
811
  __publicField(this, "text");
809
- __publicField(this, "start");
810
- __publicField(this, "processor");
811
- this.text = text, this.start = start, this.processor = processor;
812
812
  }
813
- get end() {
814
- return this.start + this.text.length;
813
+ get length() {
814
+ return this.text.length;
815
815
  }
816
816
  }
817
- function splitNoteTextIntoComponents(note, notu, componentProcessors, defaultProcessor, groupIntoParagraph) {
818
- const componentInfos = recursiveSplitNoteText(note.text, note, componentProcessors, defaultProcessor), components = [];
817
+ function parseNoteXml(text) {
818
+ const output = [];
819
+ let i = 0;
820
+ for (; i < text.length; ) {
821
+ const child = parseXmlText(text, i);
822
+ output.push(child), i += child.length;
823
+ }
824
+ return output;
825
+ }
826
+ function parseXmlChildren(text, startIndex) {
827
+ const output = [];
828
+ let i = startIndex;
829
+ for (; !(i >= text.length || i + 2 < text.length && text[i] == "<" && text[i + 1] == "|" && text[i + 2] == "/"); ) {
830
+ const child = parseXmlText(text, i);
831
+ output.push(child), i += child.length;
832
+ }
833
+ return output;
834
+ }
835
+ function parseXmlText(text, startIndex) {
836
+ let openStart = text.indexOf("<|", startIndex);
837
+ return openStart == startIndex ? parseXmlElement(text, startIndex) : openStart == -1 ? text.substring(startIndex) : text.substring(startIndex, openStart);
838
+ }
839
+ function parseXmlElement(text, startIndex) {
840
+ const openEnd = text.indexOf("|>", startIndex + 2);
841
+ if (openEnd == -1)
842
+ return text.substring(startIndex);
843
+ const isSelfClosing = text[openEnd - 1] == "/", output = parseXmlOpeningTag(text, startIndex + 2, openEnd - Number(isSelfClosing));
844
+ if (isSelfClosing)
845
+ return output.text = text.substring(startIndex, openEnd + 2), output;
846
+ const children = parseXmlChildren(text, openEnd + 2), childrenLength = children.map((x) => x.length).reduce((acc, cur) => acc + cur, 0), closeStart = text.indexOf("<|/", openEnd + 2 + childrenLength);
847
+ if (closeStart != openEnd + 2 + childrenLength)
848
+ return text.substring(startIndex);
849
+ const closeEnd = text.indexOf("|>", closeStart + 3), closeTagName = text.substring(closeStart + 3, closeEnd).trim();
850
+ return output.tag != closeTagName ? text.substring(startIndex) : (output.children = children, output.text = text.substring(startIndex, closeEnd + 2), output);
851
+ }
852
+ function parseXmlOpeningTag(text, startIndex, endIndex) {
853
+ let substr = text.substring(startIndex, endIndex).trim();
854
+ const output = new NoteXmlElement(), spaceIndex = substr.indexOf(" ");
855
+ if (spaceIndex == -1)
856
+ return output.tag = substr.trim(), output;
857
+ output.tag = substr.substring(0, spaceIndex).trim(), substr = substr.substring(spaceIndex + 1).trim(), output.attributes = {};
858
+ const quotesSplit = substr.split('"');
859
+ for (let i = 0; i < quotesSplit.length; i += 2) {
860
+ let attrName = quotesSplit[i].replace("=", "").trim(), attrVal = quotesSplit[i + 1];
861
+ output.attributes[attrName] = attrVal;
862
+ }
863
+ return output;
864
+ }
865
+ function splitNoteTextIntoComponents(note, notu, componentProcessors, textComponentFactory, paragraphComponentFactory) {
866
+ const xmlData = parseNoteXml(note.text), components = [];
819
867
  async function save() {
820
868
  note.text = components.map((x) => x.getText()).join(""), await notu.saveNotes([note]);
821
869
  }
822
- for (let groupStart = 0; groupStart < componentInfos.length; groupStart++) {
823
- const startInfo = componentInfos[groupStart];
824
- if (!startInfo.processor.componentShowsInlineInParagraph) {
825
- components.push(startInfo.processor.create(startInfo, note, save));
870
+ const ungroupedComponents = [];
871
+ for (const item of xmlData)
872
+ ungroupedComponents.push(
873
+ getComponentFromXmlElement(item, componentProcessors, textComponentFactory, note, save)
874
+ );
875
+ for (let groupStart = 0; groupStart < ungroupedComponents.length; groupStart++) {
876
+ const startComp = ungroupedComponents[groupStart];
877
+ if (!startComp.displaysInline) {
878
+ components.push(startComp);
826
879
  continue;
827
880
  }
828
- for (let groupEnd = groupStart; groupEnd <= componentInfos.length; groupEnd++) {
829
- const endInfo = componentInfos[groupEnd];
830
- if (!endInfo || !endInfo.processor.componentShowsInlineInParagraph) {
831
- const groupedComponents = componentInfos.slice(groupStart, groupEnd).map((x) => x.processor.create(x, note, save));
832
- components.push(groupIntoParagraph(groupedComponents)), groupStart = groupEnd - 1;
881
+ for (let groupEnd = groupStart; groupEnd <= ungroupedComponents.length; groupEnd++) {
882
+ const endComp = ungroupedComponents[groupEnd];
883
+ if (!endComp || !endComp.displaysInline) {
884
+ const groupedComps = ungroupedComponents.slice(groupStart, groupEnd);
885
+ components.push(paragraphComponentFactory(groupedComps)), groupStart = groupEnd - 1;
833
886
  break;
834
887
  }
835
888
  }
836
889
  }
837
890
  return components;
838
891
  }
839
- function recursiveSplitNoteText(text, note, componentProcessors, defaultProcessor) {
840
- let componentInfo = null;
892
+ function getComponentFromXmlElement(element, componentProcessors, textComponentFactory, note, save) {
893
+ if (typeof element == "string")
894
+ return textComponentFactory(element);
841
895
  for (const processor of componentProcessors)
842
- if (componentInfo = processor.identify(text), componentInfo)
843
- break;
844
- if (!componentInfo)
845
- return [new NoteComponentInfo(text, 0, defaultProcessor)];
846
- const output = [];
847
- return componentInfo.start > 0 && output.push(...recursiveSplitNoteText(text.substring(0, componentInfo.start), note, componentProcessors, defaultProcessor)), output.push(componentInfo), componentInfo.end < text.length && output.push(...recursiveSplitNoteText(text.substring(componentInfo.end), note, componentProcessors, defaultProcessor)), output;
896
+ if (processor.tagName == element.tag)
897
+ return processor.create(element, note, save);
898
+ return textComponentFactory(element.text);
848
899
  }
849
900
  class ParsedQuery {
850
901
  constructor() {
@@ -947,8 +998,8 @@ function processTagDataFilter(parsedTag, filterText) {
947
998
  }
948
999
  export {
949
1000
  Note,
950
- NoteComponentInfo,
951
1001
  NoteTag,
1002
+ NoteXmlElement,
952
1003
  Notu,
953
1004
  NotuCache,
954
1005
  NotuHttpCacheFetcher,
@@ -960,6 +1011,7 @@ export {
960
1011
  Space,
961
1012
  SpaceLink,
962
1013
  Tag,
1014
+ parseNoteXml,
963
1015
  parseQuery,
964
1016
  splitNoteTextIntoComponents
965
1017
  };
package/dist/notu.umd.js CHANGED
@@ -1 +1 @@
1
- (function(global,factory){typeof exports=="object"&&typeof module<"u"?factory(exports):typeof define=="function"&&define.amd?define(["exports"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.notu={}))})(this,function(exports2){"use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __publicField=(obj,key,value)=>(__defNormalProp(obj,typeof key!="symbol"?key+"":key,value),value);class Notu{constructor(client,cache){__publicField(this,"_client");__publicField(this,"_cache");this._client=client,this._cache=cache}get client(){return this._client}get cache(){return this._cache}async login(username,password){return await this.client.login(username,password)}async setup(){return await this.client.setup()}getSpaces(){return this.cache.getSpaces()}getSpace(id){return this.cache.getSpace(id)}getSpaceByName(name){return this.cache.getSpaceByName(name)}async saveSpace(space){const spaceData=await this.client.saveSpace(space);return this.cache.spaceSaved(spaceData)}getTags(space=null,includeOtherSpacePublics=!1,includeOtherSpaceCommons=!1){return this.cache.getTags(space,includeOtherSpacePublics,includeOtherSpaceCommons)}getTag(id){return this.cache.getTag(id)}getTagByName(name,space){return this.cache.getTagByName(name,space)}async getNotes(query,spaceId){return(await this.client.getNotes(query,spaceId)).map(n=>this.cache.noteFromJSON(n))}async getNoteCount(query,spaceId){return await this.client.getNoteCount(query,spaceId)}async saveNotes(notes){const tagsBeingDeletedData=notes.filter(x=>!!x.ownTag).filter(x=>x.isDeleted||x.ownTag.isDeleted).map(x=>x.ownTag.toJSON()),notesData=await this.client.saveNotes(notes);for(const noteData of notesData.filter(x=>!!x.ownTag&&!x.ownTag.isDeleted))noteData.ownTag.links=noteData.tags.map(x=>x.tagId),this.cache.tagSaved(noteData.ownTag);for(const tagData of tagsBeingDeletedData)tagData.state="DELETED",this.cache.tagSaved(tagData);return notes=notesData.map(n=>this.cache.noteFromJSON(n)),notes}async customJob(name,data){return await this.client.customJob(name,data)}}class ModelWithState{constructor(){__publicField(this,"state","NEW")}new(){return this.state="NEW",this}clean(){return this.state="CLEAN",this}dirty(){return this.state="DIRTY",this}delete(){return this.state="DELETED",this}get isNew(){return this.state=="NEW"}get isClean(){return this.state=="CLEAN"}get isDirty(){return this.state=="DIRTY"}get isDeleted(){return this.state=="DELETED"}validate(throwError=!1){return!0}}class Space extends ModelWithState{constructor(name=""){super();__publicField(this,"_id",0);__publicField(this,"_name","");__publicField(this,"_internalName","");__publicField(this,"_version","0.0.1");__publicField(this,"_useCommonSpace",!1);__publicField(this,"_settings");__publicField(this,"_links",[]);this._name=name}get id(){return this._id}set id(value){if(!this.isNew)throw Error("Cannot change the id of a Space once it has already been created.");this._id=value}get name(){return this._name}set name(value){value!==this._name&&(this._name=value,this.isClean&&this.dirty())}get internalName(){return this._internalName}set internalName(value){if(!this.isNew&&value!=this.internalName)throw Error("Cannot change the internal name of a space after it has already been saved.");value!=this._internalName&&(this._internalName=value,this.isClean&&this.dirty())}get version(){return this._version}set version(value){value!==this._version&&(this._version=value,this.isClean&&this.dirty())}v(version){return this.version=version,this}get useCommonSpace(){return this._useCommonSpace}set useCommonSpace(value){value!==this._useCommonSpace&&(this._useCommonSpace=value,this.isClean&&this.dirty())}get settings(){return this._settings}set settings(value){this._settings=value,this.isClean&&this.dirty()}withSettings(settings){return this.settings=settings,this}get links(){return this._links.filter(x=>!x.isDeleted)}get linksPendingDeletion(){return this._links.filter(x=>x.isDeleted)}addLink(link){if(link.isDeleted)throw Error("Cannot add a link marked as deleted to a space");if(link.isNew)throw Error("Cannot add a link that hasn't yet been saved to a space");let existing=this._links.find(x=>x.name==link.name);if(existing){if(existing.isDeleted)return existing.dirty(),this;throw Error("The space already contains a link with this name")}return this._links.push(link),this}removeLink(name){const link=this._links.find(x=>x.name==name);return link?(link.isNew?this._links=this._links.filter(x=>x!==link):link.delete(),this):this}duplicate(){const output=new Space;return output.id=this.id,output.name=this.name,output.internalName=this.internalName,output.version=this.version,output.useCommonSpace=this.useCommonSpace,this.settings&&(output._settings=JSON.parse(JSON.stringify(this.settings))),output._links=this.links.map(x=>x.duplicate()),output.state=this.state,output}duplicateAsNew(){const output=new Space;return output.name=this.name,output.internalName=this.internalName,output.version=this.version,output.useCommonSpace=this.useCommonSpace,this.settings&&(output._settings=JSON.parse(JSON.stringify(this.settings))),output._links=this.links.map(x=>x.duplicateAsNew()),output}validate(throwError=!1){let output=null;if(!this.isNew&&this.id<=0&&(output="Space id must be greater than zero if in non-new state."),throwError&&output!=null)throw Error(output);return output==null}toJSON(){return{state:this.state,id:this.id,name:this.name,internalName:this.internalName,version:this.version,useCommonSpace:this.useCommonSpace,settings:this.settings,links:this._links.map(x=>x.toJSON())}}}class NotuHttpClient{constructor(url,fetchMethod=null){__publicField(this,"_url",null);__publicField(this,"_token",null);__publicField(this,"_fetch");__publicField(this,"errorHandler",null);if(!url)throw Error("Endpoint URL must be passed in to NotuClient constructor");url.endsWith("/")&&(url=url.substring(0,url.length-1)),this._url=url,this._fetch=fetchMethod??window.fetch.bind(window)}get url(){return this._url}get token(){return this._token}set token(value){this._token=value}_validateResponseStatus(response){if(response.status>=400&&response.status<600){if(this.errorHandler&&this.errorHandler(response))return;throw Error(response.statusText)}}async login(username,password){const response=await this._fetch(this.url+"/login",{method:"POST",body:JSON.stringify({username,password})});if(this._validateResponseStatus(response),response.body!=null){const result=await response.json();return result&&(this._token=result),result}throw Error("Unknown error occurred on the server")}async setup(){const response=await this._fetch(this.url+"/setup",{method:"POST",headers:{Authorization:"Bearer "+this.token}});this._validateResponseStatus(response),await response.json()}async saveSpace(space){const response=await this._fetch(this.url+"/spaces",{method:"POST",body:JSON.stringify(space),headers:{Authorization:"Bearer "+this.token}});return this._validateResponseStatus(response),await response.json()}async getNotes(query,space){space&&space instanceof Space&&(space=space.id);const response=await this._fetch(this.url+`/notes?${space?`space=${space}&`:""}query=${encodeURIComponent(query)}`,{method:"GET",headers:{Authorization:"Bearer "+this.token}});return this._validateResponseStatus(response),await response.json()}async getNoteCount(query,space){space instanceof Space&&(space=space.id);const response=await this._fetch(this.url+`/notes?count=true&space=${space}&query=${encodeURIComponent(query)}`,{method:"GET",headers:{Authorization:"Bearer "+this.token}});return this._validateResponseStatus(response),(await response.json()).count}async saveNotes(notes){const response=await this._fetch(this.url+"/notes",{method:"POST",body:JSON.stringify(notes),headers:{Authorization:"Bearer "+this.token}});return this._validateResponseStatus(response),await response.json()}async customJob(name,data){const response=await this._fetch(this.url+"/customJob",{method:"POST",body:JSON.stringify({name,data,clientTimezone:Intl.DateTimeFormat().resolvedOptions().timeZone}),headers:{Authorization:"Bearer "+this.token}});return this._validateResponseStatus(response),await response.json()}}class NoteTag extends ModelWithState{constructor(tag){super();__publicField(this,"_tag");__publicField(this,"_data");if(!tag)throw Error("Cannot instanciate new NoteTag without a passed in tag.");if(tag.isNew)throw Error("Cannot create a NoteTag object for a tag that hasn't been saved yet.");if(tag.isDeleted)throw Error("Cannot create a NoteTag object for a tag marked as deleted.");this._tag=tag}get tag(){return this._tag}get data(){return this._data}set data(value){this._data=value,this.isClean&&this.dirty()}withData(data){return this.data=data,this}duplicate(){const output=this.duplicateAsNew();return output.state=this.state,output}duplicateAsNew(){const output=new NoteTag(this.tag);return this.data&&(output._data=JSON.parse(JSON.stringify(this.data))),output}validate(throwError=!1){function exit(message){if(throwError&&message!=null)throw Error(message);return message==null}return this.tag?!0:exit("NoteTag must have a tag set.")}toJSON(){return{state:this.state,tagId:this.tag.id,data:this.data}}}class Tag extends ModelWithState{constructor(name=""){super();__publicField(this,"_id",0);__publicField(this,"_space",null);__publicField(this,"_name","");__publicField(this,"_color",null);__publicField(this,"_availability",0);__publicField(this,"_isInternal",!1);__publicField(this,"links",[]);this._name=name}get id(){return this._id}set id(value){if(!this.isNew)throw Error("Cannot change the id of a Tag once it has already been created.");this._id=value}get space(){return this._space}set space(value){var _a;if(value!==this._space){const idChanged=(value==null?void 0:value.id)!=((_a=this._space)==null?void 0:_a.id);this._space=value,this.isClean&&idChanged&&this.dirty()}}in(space){return this.space=space,this}get name(){return this._name}set name(value){value!==this._name&&(this._name=value,this.isClean&&this.dirty())}getFullName(){return`${this.space.name}.${this.name}`}getQualifiedName(contextSpaceId){var _a;return contextSpaceId==((_a=this.space)==null?void 0:_a.id)?this.name:this.getFullName()}getUniqueName(cache){return cache.getTagsByName(this.name).length==1?this.name:this.getFullName()}get color(){return this._color}set color(value){value!==this._color&&(this._color=value,this.isClean&&this.dirty())}get availability(){return this._availability}set availability(value){if(!this.isNew&&value<this.availability)throw Error("Cannot change a tag to private once its already been saved.");value!=this._availability&&(this._availability=value,this.isClean&&this.dirty())}get isPrivate(){return this._availability==0}get isCommon(){return this._availability==1}get isPublic(){return this.availability==2}asPrivate(){return this.availability=0,this}asCommon(){return this.availability=1,this}asPublic(){return this.availability=2,this}get isInternal(){return this._isInternal}set isInternal(value){if(!this.isNew&&value!=this.isInternal)throw Error("Cannot change whether a tag is internal or not once it has already been saved.");value!=this._isInternal&&(this._isInternal=value,this.isClean&&this.dirty())}asInternal(){return this.isInternal=!0,this}linksTo(tag){return!!this.links.find(x=>x==tag)}duplicate(){const output=this.duplicateAsNew();return output.id=this.id,output.state=this.state,output}duplicateAsNew(){const output=new Tag(this.name);return output.color=this.color,output.space=this.space,output.availability=this.availability,output.isInternal=this.isInternal,output.links=this.links.slice(),output}validate(throwError=!1){let output=null;if(!this.isNew&&this.id<=0?output="Tag id must be greater than zero if in non-new state.":!this.name||!/^[a-zA-Z][a-zA-Z0-9 ]*[a-zA-Z0-9]?$/.test(this.name)?output="Tag name is invalid, must only contain letters, numbers, and spaces, starting with a letter":this.color&&!/^#?[A-z0-9]{6}$/.test(this.color)&&(output="Tag color is invalid, must be a 6 character hexadecimal."),throwError&&output!=null)throw Error(output);return output==null}toJSON(){var _a;return{state:this.state,id:this.id,name:this.name,spaceId:(_a=this.space)==null?void 0:_a.id,color:this.color,availability:this.availability,isInternal:this.isInternal,links:this.links.map(x=>x.id)}}}class Note extends ModelWithState{constructor(text,ownTag){super();__publicField(this,"_id",0);__publicField(this,"_date",new Date);__publicField(this,"_text","");__publicField(this,"_space",null);__publicField(this,"_ownTag",null);__publicField(this,"_group");__publicField(this,"_tags",[]);text&&(this.text=text),this._ownTag=ownTag}get id(){return this._id}set id(value){if(!this.isNew)throw Error("Cannot change the id of a Note once it has already been created.");this._id=value,this.ownTag&&this.ownTag.id!=value&&(this.ownTag.id=value)}get date(){return this._date}set date(value){value!==this._date&&(this._date=value,this.isClean&&this.dirty())}at(value){return this.date=value,this}get text(){return this._text}set text(value){value!==this._text&&(this._text=value,this.isClean&&this.dirty())}get space(){return this._space}set space(value){var _a;if(value!==this._space){const idChanged=(value==null?void 0:value.id)!=((_a=this._space)==null?void 0:_a.id);this._space=value,this.isClean&&idChanged&&this.dirty(),this._setOwnTagSpace()}}in(space){return this.space=space,this}get ownTag(){return this._ownTag}setOwnTag(tagName){return this.ownTag==null?(this._ownTag=new Tag(tagName),this.ownTag.id=this.id):this.ownTag.isDeleted&&this.ownTag.dirty(),this.ownTag.name=tagName,this._setOwnTagSpace(),this}removeOwnTag(){return this.ownTag?(this.ownTag.isNew?this._ownTag=null:this.ownTag.delete(),this):this}_setOwnTagSpace(){this.ownTag&&this.space&&(this.ownTag.space=this.space)}get group(){return this._group}set group(value){this._group=value}get tags(){return this._tags.filter(x=>!x.isDeleted)}get tagsPendingDeletion(){return this._tags.filter(x=>x.isDeleted)}addTag(tag){if(tag.isDeleted)throw Error("Cannot add a tag marked as deleted to a note");if(tag.isNew)throw Error("Cannot add a tag that hasn't yet been saved to a note");if(tag.id==this.id)throw Error("Note cannot add its own tag as a linked tag");if(tag.isPrivate&&tag.space.id!=this.space.id)throw Error("Cannot add a private tag from another space");let nt=this._tags.find(x=>x.tag.id==tag.id);return nt?(nt.isDeleted&&nt.dirty(),nt):(nt=new NoteTag(tag),this._tags.push(nt),nt)}removeTag(tag){const nt=this._tags.find(x=>x.tag.id==tag.id);return nt?(nt.isNew?this._tags=this._tags.filter(x=>x!==nt):nt.delete(),this):this}getTag(tag,space=null){return tag instanceof Tag?this.tags.find(x=>x.tag===tag):(space&&space instanceof Space&&(space=space.id),space!=null?this.tags.find(x=>x.tag.name==tag&&x.tag.space.id==space):this.tags.find(x=>x.tag.name==tag&&x.tag.space.id==this.space.id))}getTagData(tag,type){const nt=this.getTag(tag);return nt?new type(nt):null}duplicate(){var _a;const output=new Note(this.text,(_a=this.ownTag)==null?void 0:_a.duplicate()).at(this.date).in(this.space);return output._tags=this.tags.map(x=>x.duplicate()),output.id=this.id,output.state=this.state,output}duplicateAsNew(){const output=new Note(this.text).at(this.date).in(this.space);return output._tags=this.tags.map(x=>x.duplicateAsNew()),output}toJSON(){var _a;return{state:this.state,id:this.id,date:this.date,text:this.text,spaceId:this.space.id,ownTag:(_a=this.ownTag)==null?void 0:_a.toJSON(),tags:this._tags.map(x=>x.toJSON())}}validate(throwError=!1){function exit(message){if(throwError&&message!=null)throw Error(message);return message==null}if(this.space){if(!this.isNew&&this.id<=0)return exit("Note id must be greater than zero if in non-new state.");if(this.ownTag&&this.ownTag.space.id!=this.space.id)return exit("Note cannot belong to a different space than its own tag")}else return exit("Note must belong to a space.");if(this.ownTag&&!this.ownTag.validate(throwError))return!1;for(const nt of this._tags)if(!nt.validate(throwError))return!1;return!0}}class SpaceLink extends ModelWithState{constructor(){super(...arguments);__publicField(this,"_name");__publicField(this,"_toSpace")}get name(){return this._name}set name(value){value!==this._name&&(this._name=value,this.isClean&&this.dirty())}get toSpace(){return this._toSpace}set toSpace(value){var _a;if((value==null?void 0:value.id)!==((_a=this._toSpace)==null?void 0:_a.id)){if(value.isNew)throw Error("Cannot create a link to a space that hasn't been saved yet");if(value.isDeleted)throw Error("Cannot create a link to a space marked as deleted");this._toSpace=value,this.isClean&&this.dirty()}else this._toSpace=value}duplicate(){const output=this.duplicateAsNew();return output.state=this.state,output}duplicateAsNew(){const output=new SpaceLink;return output.name=this.name,output.toSpace=this.toSpace,output}toJSON(){var _a;return{state:this.state,name:this.name,toSpaceId:(_a=this.toSpace)==null?void 0:_a.id}}}class NotuCache{constructor(fetcher){__publicField(this,"_fetcher");__publicField(this,"_spaces",null);__publicField(this,"_tags",null);__publicField(this,"_tagNames",null);if(!fetcher)throw Error("NotuCache constructor must have a fetcher argument supplied.");this._fetcher=fetcher}async populate(){await this._populateSpaces(),await this._populateTags(),this._populateTagNames()}async _populateSpaces(){const spacesData=await this._fetcher.getSpacesData(),allSpaces=new Map;for(const spaceData of spacesData){const space=this.spaceFromJSON(spaceData);allSpaces.set(space.id,space),spaceData.space=space}this._spaces=allSpaces;for(const spaceData of spacesData)this._populateSpaceLinks(spaceData.space,spaceData)}spaceFromJSON(spaceData){const space=new Space(spaceData.name);return space.internalName=spaceData.internalName,space.id=spaceData.id,space.version=spaceData.version,space.useCommonSpace=spaceData.useCommonSpace,space.settings=spaceData.settings,space.state=spaceData.state,this._spaces&&this._populateSpaceLinks(space,spaceData),space}_populateSpaceLinks(space,spaceData){for(const linkData of spaceData.links){const link=new SpaceLink;link.name=linkData.name,link.toSpace=this._spaces.get(linkData.toSpaceId),link.clean(),space.addLink(link)}}async _populateTags(){const tagsData=await this._fetcher.getTagsData(),allTags=new Map;for(const tagData of tagsData){const tag=this.tagFromJSON(tagData);allTags.set(tag.id,tag),tagData.tag=tag}this._tags=allTags;for(const tagData of tagsData)this._populateTagLinks(tagData.tag,tagData)}_populateTagNames(){const result=new Map;for(const tag of this._tags.values())result.has(tag.name)?result.get(tag.name).push(tag):result.set(tag.name,[tag]);this._tagNames=result}tagFromJSON(tagData){const tag=new Tag(tagData.name);return tag.id=tagData.id,tag.space=this._spaces.get(tagData.spaceId),tag.color=tagData.color,tag.availability=tagData.availability,tag.isInternal=tagData.isInternal,tag.state=tagData.state,this._tags&&this._populateTagLinks(tag,tagData),tag}_populateTagLinks(tag,tagData){tag.links=tagData.links.map(x=>this._tags.get(x))}noteFromJSON(noteData){const ownTag=!noteData.ownTag||noteData.ownTag.state=="CLEAN"?this.getTag(noteData.id):this.tagFromJSON(noteData.ownTag),note=new Note(noteData.text,ownTag).at(new Date(noteData.date)).in(this.getSpace(noteData.spaceId));note.id=noteData.id,note.state=noteData.state;for(const ntData of noteData.tags){const nt=note.addTag(this.getTag(ntData.tagId));nt.data=ntData.data,nt.state=ntData.state}return note}getSpaces(){return Array.from(this._spaces.values())}getSpace(id){return this._spaces.get(id)}getSpaceByName(name){for(const space of this._spaces.values())if(space.name==name)return space}spaceSaved(spaceData){const space=this.spaceFromJSON(spaceData);return space.state=="DELETED"?this._spaces.delete(space.id):this._spaces.set(space.id,space),space}getTags(space=null,includeOtherSpacePublics=!1,includeOtherSpaceCommons=!1){if(space==null)return Array.from(this._tags.values());let spaceObj;return typeof space=="number"?spaceObj=this.getSpace(space):spaceObj=space,Array.from(this._tags.values()).filter(x=>{if(x.space.id==spaceObj.id||x.isPublic&&includeOtherSpacePublics||x.isCommon&&includeOtherSpaceCommons)return!0})}getTag(id){return this._tags.get(id)}getTagByName(name,space){space instanceof Space&&(space=space.id);for(const tag of this._tagNames.get(name)??[])if(tag.name==name&&tag.space.id==space)return tag}getTagsByName(name){return this._tagNames.get(name)??[]}tagSaved(tagData){const tag=this.tagFromJSON(tagData);return tag.state=="DELETED"?this._tags.delete(tag.id):this._tags.set(tag.id,tag),this._populateTagNames(),tag}}class NotuHttpCacheFetcher{constructor(url,token,fetchMethod=null){__publicField(this,"_url",null);__publicField(this,"_token",null);__publicField(this,"_fetch");if(!url)throw Error("Endpoint URL must be passed into NotuHttpCacheFetcher constructor");if(!token)throw Error("Security token must be passed into NotuHttpCacheFetcher constructor");url.endsWith("/")&&(url=url.substring(0,url.length-1)),this._url=url,this._token=token,this._fetch=fetchMethod??window.fetch.bind(window)}get url(){return this._url}get token(){return this._token}async getSpacesData(){return await this._getX("/spaces")}async getTagsData(){return await this._getX("/tags")}async _getX(endpoint){return await(await this._fetch(this.url+endpoint,{method:"GET",headers:{Authorization:"Bearer "+this.token}})).json()}}class NoteComponentInfo{constructor(text,start,processor){__publicField(this,"text");__publicField(this,"start");__publicField(this,"processor");this.text=text,this.start=start,this.processor=processor}get end(){return this.start+this.text.length}}function splitNoteTextIntoComponents(note,notu,componentProcessors,defaultProcessor,groupIntoParagraph){const componentInfos=recursiveSplitNoteText(note.text,note,componentProcessors,defaultProcessor),components=[];async function save(){note.text=components.map(x=>x.getText()).join(""),await notu.saveNotes([note])}for(let groupStart=0;groupStart<componentInfos.length;groupStart++){const startInfo=componentInfos[groupStart];if(!startInfo.processor.componentShowsInlineInParagraph){components.push(startInfo.processor.create(startInfo,note,save));continue}for(let groupEnd=groupStart;groupEnd<=componentInfos.length;groupEnd++){const endInfo=componentInfos[groupEnd];if(!endInfo||!endInfo.processor.componentShowsInlineInParagraph){const groupedComponents=componentInfos.slice(groupStart,groupEnd).map(x=>x.processor.create(x,note,save));components.push(groupIntoParagraph(groupedComponents)),groupStart=groupEnd-1;break}}}return components}function recursiveSplitNoteText(text,note,componentProcessors,defaultProcessor){let componentInfo=null;for(const processor of componentProcessors)if(componentInfo=processor.identify(text),componentInfo)break;if(!componentInfo)return[new NoteComponentInfo(text,0,defaultProcessor)];const output=[];return componentInfo.start>0&&output.push(...recursiveSplitNoteText(text.substring(0,componentInfo.start),note,componentProcessors,defaultProcessor)),output.push(componentInfo),componentInfo.end<text.length&&output.push(...recursiveSplitNoteText(text.substring(componentInfo.end),note,componentProcessors,defaultProcessor)),output}class ParsedQuery{constructor(){__publicField(this,"where",null);__publicField(this,"order",null);__publicField(this,"groupings",[]);__publicField(this,"tags",[])}}class ParsedTag{constructor(){__publicField(this,"space",null);__publicField(this,"name",null);__publicField(this,"searchDepths",[]);__publicField(this,"filter",null)}}class ParsedTagFilter{constructor(){__publicField(this,"pattern",null);__publicField(this,"exps",[])}}class ParsedGrouping{constructor(){__publicField(this,"criteria");__publicField(this,"name")}}function parseQuery(query){const output=splitQuery(query);output.where=identifyTags(output.where,output),output.order=identifyTags(output.order,output);for(const grouping of output.groupings)grouping.criteria=identifyTags(grouping.criteria,output);return output}function splitQuery(query){query=" "+query+" ";const output=new ParsedQuery,groupByIndex=query.toUpperCase().indexOf(" GROUP BY ");if(groupByIndex>=0){const groupings=query.substring(groupByIndex+10).trim().split(",");for(const g of groupings){const asIndex=g.toUpperCase().indexOf(" AS "),grouping=new ParsedGrouping;grouping.criteria=g.substring(0,asIndex).trim(),grouping.name=g.substring(asIndex+4).replace(/'/g,"").trim(),output.groupings.push(grouping)}query=query.substring(0,groupByIndex+1)}const orderByIndex=query.toUpperCase().indexOf(" ORDER BY ");return orderByIndex>=0&&(output.order=query.substring(orderByIndex+10).trim(),query=query.substring(0,orderByIndex+1)),output.where=query.trim(),output.where==""&&(output.where=null),output}function identifyTags(query,parsedQuery){const regexes=[/([#@_]+)([\w\d]+\.)?([\w\d]+)/,/([#@_]+)\[([\w\d\s]+\.)?([\w\d\s]+)\]/];for(const regex of regexes)for(;;){const match=regex.exec(query);if(!match)break;let hashPrefix=match[1];const parsedTag=new ParsedTag;parsedTag.space=match[2]?match[2].substring(0,match[2].length-1):null,parsedTag.name=match[3],hashPrefix.startsWith("@")&&(parsedTag.searchDepths.push(0),hashPrefix=hashPrefix.substring(1));for(let i=0;i<hashPrefix.length;i++)hashPrefix[i]=="#"&&parsedTag.searchDepths.push(i+1);const fullMatch=match[0],matchStart=query.indexOf(fullMatch),matchEnd=matchStart+fullMatch.length,tagDataFilter=getTagDataFilterText(query,matchEnd);tagDataFilter&&(query=query.substring(0,matchEnd)+query.substring(matchEnd+tagDataFilter.length+2),processTagDataFilter(parsedTag,tagDataFilter)),query=query.substring(0,matchStart)+`{tag${parsedQuery.tags.length}}`+query.substring(matchEnd),parsedQuery.tags.push(parsedTag)}return query}function getTagDataFilterText(query,tagEndIndex){if(query.charAt(tagEndIndex)!="{")return null;let i=tagEndIndex+1,braceDepth=1;for(;;){if(i>=query.length)throw Error("Invalid query syntax, expected closing '}' symbol.");const char=query.charAt(i);if(char=="{")braceDepth++;else if(char=="}"&&(braceDepth--,braceDepth==0))break;i++}return query.substring(tagEndIndex+1,i)}function processTagDataFilter(parsedTag,filterText){filterText=` ${filterText}`,parsedTag.filter=new ParsedTagFilter,parsedTag.filter.pattern=filterText;const expressionRegex=/[\s\(]\.([\w\d\[\]\.]+)/;for(;;){const match=expressionRegex.exec(parsedTag.filter.pattern);if(!match)break;const expression=match[1];parsedTag.filter.pattern=parsedTag.filter.pattern.replace(`.${expression}`,`{exp${parsedTag.filter.exps.length}}`),parsedTag.filter.exps.push(expression)}parsedTag.filter.pattern=parsedTag.filter.pattern.trim()}exports2.Note=Note,exports2.NoteComponentInfo=NoteComponentInfo,exports2.NoteTag=NoteTag,exports2.Notu=Notu,exports2.NotuCache=NotuCache,exports2.NotuHttpCacheFetcher=NotuHttpCacheFetcher,exports2.NotuHttpClient=NotuHttpClient,exports2.ParsedGrouping=ParsedGrouping,exports2.ParsedQuery=ParsedQuery,exports2.ParsedTag=ParsedTag,exports2.ParsedTagFilter=ParsedTagFilter,exports2.Space=Space,exports2.SpaceLink=SpaceLink,exports2.Tag=Tag,exports2.parseQuery=parseQuery,exports2.splitNoteTextIntoComponents=splitNoteTextIntoComponents,Object.defineProperty(exports2,Symbol.toStringTag,{value:"Module"})});
1
+ (function(global,factory){typeof exports=="object"&&typeof module<"u"?factory(exports):typeof define=="function"&&define.amd?define(["exports"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.notu={}))})(this,function(exports2){"use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __publicField=(obj,key,value)=>(__defNormalProp(obj,typeof key!="symbol"?key+"":key,value),value);class Notu{constructor(client,cache){__publicField(this,"_client");__publicField(this,"_cache");this._client=client,this._cache=cache}get client(){return this._client}get cache(){return this._cache}async login(username,password){return await this.client.login(username,password)}async setup(){return await this.client.setup()}getSpaces(){return this.cache.getSpaces()}getSpace(id){return this.cache.getSpace(id)}getSpaceByName(name){return this.cache.getSpaceByName(name)}async saveSpace(space){const spaceData=await this.client.saveSpace(space);return this.cache.spaceSaved(spaceData)}getTags(space=null,includeOtherSpacePublics=!1,includeOtherSpaceCommons=!1){return this.cache.getTags(space,includeOtherSpacePublics,includeOtherSpaceCommons)}getTag(id){return this.cache.getTag(id)}getTagByName(name,space){return this.cache.getTagByName(name,space)}async getNotes(query,spaceId){return(await this.client.getNotes(query,spaceId)).map(n=>this.cache.noteFromJSON(n))}async getNoteCount(query,spaceId){return await this.client.getNoteCount(query,spaceId)}async saveNotes(notes){const tagsBeingDeletedData=notes.filter(x=>!!x.ownTag).filter(x=>x.isDeleted||x.ownTag.isDeleted).map(x=>x.ownTag.toJSON()),notesData=await this.client.saveNotes(notes);for(const noteData of notesData.filter(x=>!!x.ownTag&&!x.ownTag.isDeleted))noteData.ownTag.links=noteData.tags.map(x=>x.tagId),this.cache.tagSaved(noteData.ownTag);for(const tagData of tagsBeingDeletedData)tagData.state="DELETED",this.cache.tagSaved(tagData);return notes=notesData.map(n=>this.cache.noteFromJSON(n)),notes}async customJob(name,data){return await this.client.customJob(name,data)}}class ModelWithState{constructor(){__publicField(this,"state","NEW")}new(){return this.state="NEW",this}clean(){return this.state="CLEAN",this}dirty(){return this.state="DIRTY",this}delete(){return this.state="DELETED",this}get isNew(){return this.state=="NEW"}get isClean(){return this.state=="CLEAN"}get isDirty(){return this.state=="DIRTY"}get isDeleted(){return this.state=="DELETED"}validate(throwError=!1){return!0}}class Space extends ModelWithState{constructor(name=""){super();__publicField(this,"_id",0);__publicField(this,"_name","");__publicField(this,"_internalName","");__publicField(this,"_version","0.0.1");__publicField(this,"_useCommonSpace",!1);__publicField(this,"_settings");__publicField(this,"_links",[]);this._name=name}get id(){return this._id}set id(value){if(!this.isNew)throw Error("Cannot change the id of a Space once it has already been created.");this._id=value}get name(){return this._name}set name(value){value!==this._name&&(this._name=value,this.isClean&&this.dirty())}get internalName(){return this._internalName}set internalName(value){if(!this.isNew&&value!=this.internalName)throw Error("Cannot change the internal name of a space after it has already been saved.");value!=this._internalName&&(this._internalName=value,this.isClean&&this.dirty())}get version(){return this._version}set version(value){value!==this._version&&(this._version=value,this.isClean&&this.dirty())}v(version){return this.version=version,this}get useCommonSpace(){return this._useCommonSpace}set useCommonSpace(value){value!==this._useCommonSpace&&(this._useCommonSpace=value,this.isClean&&this.dirty())}get settings(){return this._settings}set settings(value){this._settings=value,this.isClean&&this.dirty()}withSettings(settings){return this.settings=settings,this}get links(){return this._links.filter(x=>!x.isDeleted)}get linksPendingDeletion(){return this._links.filter(x=>x.isDeleted)}addLink(link){if(link.isDeleted)throw Error("Cannot add a link marked as deleted to a space");if(link.isNew)throw Error("Cannot add a link that hasn't yet been saved to a space");let existing=this._links.find(x=>x.name==link.name);if(existing){if(existing.isDeleted)return existing.dirty(),this;throw Error("The space already contains a link with this name")}return this._links.push(link),this}removeLink(name){const link=this._links.find(x=>x.name==name);return link?(link.isNew?this._links=this._links.filter(x=>x!==link):link.delete(),this):this}duplicate(){const output=new Space;return output.id=this.id,output.name=this.name,output.internalName=this.internalName,output.version=this.version,output.useCommonSpace=this.useCommonSpace,this.settings&&(output._settings=JSON.parse(JSON.stringify(this.settings))),output._links=this.links.map(x=>x.duplicate()),output.state=this.state,output}duplicateAsNew(){const output=new Space;return output.name=this.name,output.internalName=this.internalName,output.version=this.version,output.useCommonSpace=this.useCommonSpace,this.settings&&(output._settings=JSON.parse(JSON.stringify(this.settings))),output._links=this.links.map(x=>x.duplicateAsNew()),output}validate(throwError=!1){let output=null;if(!this.isNew&&this.id<=0&&(output="Space id must be greater than zero if in non-new state."),throwError&&output!=null)throw Error(output);return output==null}toJSON(){return{state:this.state,id:this.id,name:this.name,internalName:this.internalName,version:this.version,useCommonSpace:this.useCommonSpace,settings:this.settings,links:this._links.map(x=>x.toJSON())}}}class NotuHttpClient{constructor(url,fetchMethod=null){__publicField(this,"_url",null);__publicField(this,"_token",null);__publicField(this,"_fetch");__publicField(this,"errorHandler",null);if(!url)throw Error("Endpoint URL must be passed in to NotuClient constructor");url.endsWith("/")&&(url=url.substring(0,url.length-1)),this._url=url,this._fetch=fetchMethod??window.fetch.bind(window)}get url(){return this._url}get token(){return this._token}set token(value){this._token=value}_validateResponseStatus(response){if(response.status>=400&&response.status<600){if(this.errorHandler&&this.errorHandler(response))return;throw Error(response.statusText)}}async login(username,password){const response=await this._fetch(this.url+"/login",{method:"POST",body:JSON.stringify({username,password})});if(this._validateResponseStatus(response),response.body!=null){const result=await response.json();return result&&(this._token=result),result}throw Error("Unknown error occurred on the server")}async setup(){const response=await this._fetch(this.url+"/setup",{method:"POST",headers:{Authorization:"Bearer "+this.token}});this._validateResponseStatus(response),await response.json()}async saveSpace(space){const response=await this._fetch(this.url+"/spaces",{method:"POST",body:JSON.stringify(space),headers:{Authorization:"Bearer "+this.token}});return this._validateResponseStatus(response),await response.json()}async getNotes(query,space){space&&space instanceof Space&&(space=space.id);const response=await this._fetch(this.url+`/notes?${space?`space=${space}&`:""}query=${encodeURIComponent(query)}`,{method:"GET",headers:{Authorization:"Bearer "+this.token}});return this._validateResponseStatus(response),await response.json()}async getNoteCount(query,space){space instanceof Space&&(space=space.id);const response=await this._fetch(this.url+`/notes?count=true&space=${space}&query=${encodeURIComponent(query)}`,{method:"GET",headers:{Authorization:"Bearer "+this.token}});return this._validateResponseStatus(response),(await response.json()).count}async saveNotes(notes){const response=await this._fetch(this.url+"/notes",{method:"POST",body:JSON.stringify(notes),headers:{Authorization:"Bearer "+this.token}});return this._validateResponseStatus(response),await response.json()}async customJob(name,data){const response=await this._fetch(this.url+"/customJob",{method:"POST",body:JSON.stringify({name,data,clientTimezone:Intl.DateTimeFormat().resolvedOptions().timeZone}),headers:{Authorization:"Bearer "+this.token}});return this._validateResponseStatus(response),await response.json()}}class NoteTag extends ModelWithState{constructor(tag){super();__publicField(this,"_tag");__publicField(this,"_data");if(!tag)throw Error("Cannot instanciate new NoteTag without a passed in tag.");if(tag.isNew)throw Error("Cannot create a NoteTag object for a tag that hasn't been saved yet.");if(tag.isDeleted)throw Error("Cannot create a NoteTag object for a tag marked as deleted.");this._tag=tag}get tag(){return this._tag}get data(){return this._data}set data(value){this._data=value,this.isClean&&this.dirty()}withData(data){return this.data=data,this}duplicate(){const output=this.duplicateAsNew();return output.state=this.state,output}duplicateAsNew(){const output=new NoteTag(this.tag);return this.data&&(output._data=JSON.parse(JSON.stringify(this.data))),output}validate(throwError=!1){function exit(message){if(throwError&&message!=null)throw Error(message);return message==null}return this.tag?!0:exit("NoteTag must have a tag set.")}toJSON(){return{state:this.state,tagId:this.tag.id,data:this.data}}}class Tag extends ModelWithState{constructor(name=""){super();__publicField(this,"_id",0);__publicField(this,"_space",null);__publicField(this,"_name","");__publicField(this,"_color",null);__publicField(this,"_availability",0);__publicField(this,"_isInternal",!1);__publicField(this,"links",[]);this._name=name}get id(){return this._id}set id(value){if(!this.isNew)throw Error("Cannot change the id of a Tag once it has already been created.");this._id=value}get space(){return this._space}set space(value){var _a;if(value!==this._space){const idChanged=(value==null?void 0:value.id)!=((_a=this._space)==null?void 0:_a.id);this._space=value,this.isClean&&idChanged&&this.dirty()}}in(space){return this.space=space,this}get name(){return this._name}set name(value){value!==this._name&&(this._name=value,this.isClean&&this.dirty())}getFullName(){return`${this.space.name}.${this.name}`}getQualifiedName(contextSpaceId){var _a;return contextSpaceId==((_a=this.space)==null?void 0:_a.id)?this.name:this.getFullName()}getUniqueName(cache){return cache.getTagsByName(this.name).length==1?this.name:this.getFullName()}get color(){return this._color}set color(value){value!==this._color&&(this._color=value,this.isClean&&this.dirty())}get availability(){return this._availability}set availability(value){if(!this.isNew&&value<this.availability)throw Error("Cannot change a tag to private once its already been saved.");value!=this._availability&&(this._availability=value,this.isClean&&this.dirty())}get isPrivate(){return this._availability==0}get isCommon(){return this._availability==1}get isPublic(){return this.availability==2}asPrivate(){return this.availability=0,this}asCommon(){return this.availability=1,this}asPublic(){return this.availability=2,this}get isInternal(){return this._isInternal}set isInternal(value){if(!this.isNew&&value!=this.isInternal)throw Error("Cannot change whether a tag is internal or not once it has already been saved.");value!=this._isInternal&&(this._isInternal=value,this.isClean&&this.dirty())}asInternal(){return this.isInternal=!0,this}linksTo(tag){return!!this.links.find(x=>x==tag)}duplicate(){const output=this.duplicateAsNew();return output.id=this.id,output.state=this.state,output}duplicateAsNew(){const output=new Tag(this.name);return output.color=this.color,output.space=this.space,output.availability=this.availability,output.isInternal=this.isInternal,output.links=this.links.slice(),output}validate(throwError=!1){let output=null;if(!this.isNew&&this.id<=0?output="Tag id must be greater than zero if in non-new state.":!this.name||!/^[a-zA-Z][a-zA-Z0-9 ]*[a-zA-Z0-9]?$/.test(this.name)?output="Tag name is invalid, must only contain letters, numbers, and spaces, starting with a letter":this.color&&!/^#?[A-z0-9]{6}$/.test(this.color)&&(output="Tag color is invalid, must be a 6 character hexadecimal."),throwError&&output!=null)throw Error(output);return output==null}toJSON(){var _a;return{state:this.state,id:this.id,name:this.name,spaceId:(_a=this.space)==null?void 0:_a.id,color:this.color,availability:this.availability,isInternal:this.isInternal,links:this.links.map(x=>x.id)}}}class Note extends ModelWithState{constructor(text,ownTag){super();__publicField(this,"_id",0);__publicField(this,"_date",new Date);__publicField(this,"_text","");__publicField(this,"_space",null);__publicField(this,"_ownTag",null);__publicField(this,"_group");__publicField(this,"_tags",[]);text&&(this.text=text),this._ownTag=ownTag}get id(){return this._id}set id(value){if(!this.isNew)throw Error("Cannot change the id of a Note once it has already been created.");this._id=value,this.ownTag&&this.ownTag.id!=value&&(this.ownTag.id=value)}get date(){return this._date}set date(value){value!==this._date&&(this._date=value,this.isClean&&this.dirty())}at(value){return this.date=value,this}get text(){return this._text}set text(value){value!==this._text&&(this._text=value,this.isClean&&this.dirty())}get space(){return this._space}set space(value){var _a;if(value!==this._space){const idChanged=(value==null?void 0:value.id)!=((_a=this._space)==null?void 0:_a.id);this._space=value,this.isClean&&idChanged&&this.dirty(),this._setOwnTagSpace()}}in(space){return this.space=space,this}get ownTag(){return this._ownTag}setOwnTag(tagName){return this.ownTag==null?(this._ownTag=new Tag(tagName),this.ownTag.id=this.id):this.ownTag.isDeleted&&this.ownTag.dirty(),this.ownTag.name=tagName,this._setOwnTagSpace(),this}removeOwnTag(){return this.ownTag?(this.ownTag.isNew?this._ownTag=null:this.ownTag.delete(),this):this}_setOwnTagSpace(){this.ownTag&&this.space&&(this.ownTag.space=this.space)}get group(){return this._group}set group(value){this._group=value}get tags(){return this._tags.filter(x=>!x.isDeleted)}get tagsPendingDeletion(){return this._tags.filter(x=>x.isDeleted)}addTag(tag){if(tag.isDeleted)throw Error("Cannot add a tag marked as deleted to a note");if(tag.isNew)throw Error("Cannot add a tag that hasn't yet been saved to a note");if(tag.id==this.id)throw Error("Note cannot add its own tag as a linked tag");if(tag.isPrivate&&tag.space.id!=this.space.id)throw Error("Cannot add a private tag from another space");let nt=this._tags.find(x=>x.tag.id==tag.id);return nt?(nt.isDeleted&&nt.dirty(),nt):(nt=new NoteTag(tag),this._tags.push(nt),nt)}removeTag(tag){const nt=this._tags.find(x=>x.tag.id==tag.id);return nt?(nt.isNew?this._tags=this._tags.filter(x=>x!==nt):nt.delete(),this):this}getTag(tag,space=null){return tag instanceof Tag?this.tags.find(x=>x.tag===tag):(space&&space instanceof Space&&(space=space.id),space!=null?this.tags.find(x=>x.tag.name==tag&&x.tag.space.id==space):this.tags.find(x=>x.tag.name==tag&&x.tag.space.id==this.space.id))}getTagData(tag,type){const nt=this.getTag(tag);return nt?new type(nt):null}duplicate(){var _a;const output=new Note(this.text,(_a=this.ownTag)==null?void 0:_a.duplicate()).at(this.date).in(this.space);return output._tags=this.tags.map(x=>x.duplicate()),output.id=this.id,output.state=this.state,output}duplicateAsNew(){const output=new Note(this.text).at(this.date).in(this.space);return output._tags=this.tags.map(x=>x.duplicateAsNew()),output}toJSON(){var _a;return{state:this.state,id:this.id,date:this.date,text:this.text,spaceId:this.space.id,ownTag:(_a=this.ownTag)==null?void 0:_a.toJSON(),tags:this._tags.map(x=>x.toJSON())}}validate(throwError=!1){function exit(message){if(throwError&&message!=null)throw Error(message);return message==null}if(this.space){if(!this.isNew&&this.id<=0)return exit("Note id must be greater than zero if in non-new state.");if(this.ownTag&&this.ownTag.space.id!=this.space.id)return exit("Note cannot belong to a different space than its own tag")}else return exit("Note must belong to a space.");if(this.ownTag&&!this.ownTag.validate(throwError))return!1;for(const nt of this._tags)if(!nt.validate(throwError))return!1;return!0}}class SpaceLink extends ModelWithState{constructor(){super(...arguments);__publicField(this,"_name");__publicField(this,"_toSpace")}get name(){return this._name}set name(value){value!==this._name&&(this._name=value,this.isClean&&this.dirty())}get toSpace(){return this._toSpace}set toSpace(value){var _a;if((value==null?void 0:value.id)!==((_a=this._toSpace)==null?void 0:_a.id)){if(value.isNew)throw Error("Cannot create a link to a space that hasn't been saved yet");if(value.isDeleted)throw Error("Cannot create a link to a space marked as deleted");this._toSpace=value,this.isClean&&this.dirty()}else this._toSpace=value}duplicate(){const output=this.duplicateAsNew();return output.state=this.state,output}duplicateAsNew(){const output=new SpaceLink;return output.name=this.name,output.toSpace=this.toSpace,output}toJSON(){var _a;return{state:this.state,name:this.name,toSpaceId:(_a=this.toSpace)==null?void 0:_a.id}}}class NotuCache{constructor(fetcher){__publicField(this,"_fetcher");__publicField(this,"_spaces",null);__publicField(this,"_tags",null);__publicField(this,"_tagNames",null);if(!fetcher)throw Error("NotuCache constructor must have a fetcher argument supplied.");this._fetcher=fetcher}async populate(){await this._populateSpaces(),await this._populateTags(),this._populateTagNames()}async _populateSpaces(){const spacesData=await this._fetcher.getSpacesData(),allSpaces=new Map;for(const spaceData of spacesData){const space=this.spaceFromJSON(spaceData);allSpaces.set(space.id,space),spaceData.space=space}this._spaces=allSpaces;for(const spaceData of spacesData)this._populateSpaceLinks(spaceData.space,spaceData)}spaceFromJSON(spaceData){const space=new Space(spaceData.name);return space.internalName=spaceData.internalName,space.id=spaceData.id,space.version=spaceData.version,space.useCommonSpace=spaceData.useCommonSpace,space.settings=spaceData.settings,space.state=spaceData.state,this._spaces&&this._populateSpaceLinks(space,spaceData),space}_populateSpaceLinks(space,spaceData){for(const linkData of spaceData.links){const link=new SpaceLink;link.name=linkData.name,link.toSpace=this._spaces.get(linkData.toSpaceId),link.clean(),space.addLink(link)}}async _populateTags(){const tagsData=await this._fetcher.getTagsData(),allTags=new Map;for(const tagData of tagsData){const tag=this.tagFromJSON(tagData);allTags.set(tag.id,tag),tagData.tag=tag}this._tags=allTags;for(const tagData of tagsData)this._populateTagLinks(tagData.tag,tagData)}_populateTagNames(){const result=new Map;for(const tag of this._tags.values())result.has(tag.name)?result.get(tag.name).push(tag):result.set(tag.name,[tag]);this._tagNames=result}tagFromJSON(tagData){const tag=new Tag(tagData.name);return tag.id=tagData.id,tag.space=this._spaces.get(tagData.spaceId),tag.color=tagData.color,tag.availability=tagData.availability,tag.isInternal=tagData.isInternal,tag.state=tagData.state,this._tags&&this._populateTagLinks(tag,tagData),tag}_populateTagLinks(tag,tagData){tag.links=tagData.links.map(x=>this._tags.get(x))}noteFromJSON(noteData){const ownTag=!noteData.ownTag||noteData.ownTag.state=="CLEAN"?this.getTag(noteData.id):this.tagFromJSON(noteData.ownTag),note=new Note(noteData.text,ownTag).at(new Date(noteData.date)).in(this.getSpace(noteData.spaceId));note.id=noteData.id,note.state=noteData.state;for(const ntData of noteData.tags){const nt=note.addTag(this.getTag(ntData.tagId));nt.data=ntData.data,nt.state=ntData.state}return note}getSpaces(){return Array.from(this._spaces.values())}getSpace(id){return this._spaces.get(id)}getSpaceByName(name){for(const space of this._spaces.values())if(space.name==name)return space}spaceSaved(spaceData){const space=this.spaceFromJSON(spaceData);return space.state=="DELETED"?this._spaces.delete(space.id):this._spaces.set(space.id,space),space}getTags(space=null,includeOtherSpacePublics=!1,includeOtherSpaceCommons=!1){if(space==null)return Array.from(this._tags.values());let spaceObj;return typeof space=="number"?spaceObj=this.getSpace(space):spaceObj=space,Array.from(this._tags.values()).filter(x=>{if(x.space.id==spaceObj.id||x.isPublic&&includeOtherSpacePublics||x.isCommon&&includeOtherSpaceCommons)return!0})}getTag(id){return this._tags.get(id)}getTagByName(name,space){space instanceof Space&&(space=space.id);for(const tag of this._tagNames.get(name)??[])if(tag.name==name&&tag.space.id==space)return tag}getTagsByName(name){return this._tagNames.get(name)??[]}tagSaved(tagData){const tag=this.tagFromJSON(tagData);return tag.state=="DELETED"?this._tags.delete(tag.id):this._tags.set(tag.id,tag),this._populateTagNames(),tag}}class NotuHttpCacheFetcher{constructor(url,token,fetchMethod=null){__publicField(this,"_url",null);__publicField(this,"_token",null);__publicField(this,"_fetch");if(!url)throw Error("Endpoint URL must be passed into NotuHttpCacheFetcher constructor");if(!token)throw Error("Security token must be passed into NotuHttpCacheFetcher constructor");url.endsWith("/")&&(url=url.substring(0,url.length-1)),this._url=url,this._token=token,this._fetch=fetchMethod??window.fetch.bind(window)}get url(){return this._url}get token(){return this._token}async getSpacesData(){return await this._getX("/spaces")}async getTagsData(){return await this._getX("/tags")}async _getX(endpoint){return await(await this._fetch(this.url+endpoint,{method:"GET",headers:{Authorization:"Bearer "+this.token}})).json()}}class NoteXmlElement{constructor(){__publicField(this,"tag");__publicField(this,"children",[]);__publicField(this,"attributes");__publicField(this,"text")}get length(){return this.text.length}}function parseNoteXml(text){const output=[];let i=0;for(;i<text.length;){const child=parseXmlText(text,i);output.push(child),i+=child.length}return output}function parseXmlChildren(text,startIndex){const output=[];let i=startIndex;for(;!(i>=text.length||i+2<text.length&&text[i]=="<"&&text[i+1]=="|"&&text[i+2]=="/");){const child=parseXmlText(text,i);output.push(child),i+=child.length}return output}function parseXmlText(text,startIndex){let openStart=text.indexOf("<|",startIndex);return openStart==startIndex?parseXmlElement(text,startIndex):openStart==-1?text.substring(startIndex):text.substring(startIndex,openStart)}function parseXmlElement(text,startIndex){const openEnd=text.indexOf("|>",startIndex+2);if(openEnd==-1)return text.substring(startIndex);const isSelfClosing=text[openEnd-1]=="/",output=parseXmlOpeningTag(text,startIndex+2,openEnd-Number(isSelfClosing));if(isSelfClosing)return output.text=text.substring(startIndex,openEnd+2),output;const children=parseXmlChildren(text,openEnd+2),childrenLength=children.map(x=>x.length).reduce((acc,cur)=>acc+cur,0),closeStart=text.indexOf("<|/",openEnd+2+childrenLength);if(closeStart!=openEnd+2+childrenLength)return text.substring(startIndex);const closeEnd=text.indexOf("|>",closeStart+3),closeTagName=text.substring(closeStart+3,closeEnd).trim();return output.tag!=closeTagName?text.substring(startIndex):(output.children=children,output.text=text.substring(startIndex,closeEnd+2),output)}function parseXmlOpeningTag(text,startIndex,endIndex){let substr=text.substring(startIndex,endIndex).trim();const output=new NoteXmlElement,spaceIndex=substr.indexOf(" ");if(spaceIndex==-1)return output.tag=substr.trim(),output;output.tag=substr.substring(0,spaceIndex).trim(),substr=substr.substring(spaceIndex+1).trim(),output.attributes={};const quotesSplit=substr.split('"');for(let i=0;i<quotesSplit.length;i+=2){let attrName=quotesSplit[i].replace("=","").trim(),attrVal=quotesSplit[i+1];output.attributes[attrName]=attrVal}return output}function splitNoteTextIntoComponents(note,notu,componentProcessors,textComponentFactory,paragraphComponentFactory){const xmlData=parseNoteXml(note.text),components=[];async function save(){note.text=components.map(x=>x.getText()).join(""),await notu.saveNotes([note])}const ungroupedComponents=[];for(const item of xmlData)ungroupedComponents.push(getComponentFromXmlElement(item,componentProcessors,textComponentFactory,note,save));for(let groupStart=0;groupStart<ungroupedComponents.length;groupStart++){const startComp=ungroupedComponents[groupStart];if(!startComp.displaysInline){components.push(startComp);continue}for(let groupEnd=groupStart;groupEnd<=ungroupedComponents.length;groupEnd++){const endComp=ungroupedComponents[groupEnd];if(!endComp||!endComp.displaysInline){const groupedComps=ungroupedComponents.slice(groupStart,groupEnd);components.push(paragraphComponentFactory(groupedComps)),groupStart=groupEnd-1;break}}}return components}function getComponentFromXmlElement(element,componentProcessors,textComponentFactory,note,save){if(typeof element=="string")return textComponentFactory(element);for(const processor of componentProcessors)if(processor.tagName==element.tag)return processor.create(element,note,save);return textComponentFactory(element.text)}class ParsedQuery{constructor(){__publicField(this,"where",null);__publicField(this,"order",null);__publicField(this,"groupings",[]);__publicField(this,"tags",[])}}class ParsedTag{constructor(){__publicField(this,"space",null);__publicField(this,"name",null);__publicField(this,"searchDepths",[]);__publicField(this,"filter",null)}}class ParsedTagFilter{constructor(){__publicField(this,"pattern",null);__publicField(this,"exps",[])}}class ParsedGrouping{constructor(){__publicField(this,"criteria");__publicField(this,"name")}}function parseQuery(query){const output=splitQuery(query);output.where=identifyTags(output.where,output),output.order=identifyTags(output.order,output);for(const grouping of output.groupings)grouping.criteria=identifyTags(grouping.criteria,output);return output}function splitQuery(query){query=" "+query+" ";const output=new ParsedQuery,groupByIndex=query.toUpperCase().indexOf(" GROUP BY ");if(groupByIndex>=0){const groupings=query.substring(groupByIndex+10).trim().split(",");for(const g of groupings){const asIndex=g.toUpperCase().indexOf(" AS "),grouping=new ParsedGrouping;grouping.criteria=g.substring(0,asIndex).trim(),grouping.name=g.substring(asIndex+4).replace(/'/g,"").trim(),output.groupings.push(grouping)}query=query.substring(0,groupByIndex+1)}const orderByIndex=query.toUpperCase().indexOf(" ORDER BY ");return orderByIndex>=0&&(output.order=query.substring(orderByIndex+10).trim(),query=query.substring(0,orderByIndex+1)),output.where=query.trim(),output.where==""&&(output.where=null),output}function identifyTags(query,parsedQuery){const regexes=[/([#@_]+)([\w\d]+\.)?([\w\d]+)/,/([#@_]+)\[([\w\d\s]+\.)?([\w\d\s]+)\]/];for(const regex of regexes)for(;;){const match=regex.exec(query);if(!match)break;let hashPrefix=match[1];const parsedTag=new ParsedTag;parsedTag.space=match[2]?match[2].substring(0,match[2].length-1):null,parsedTag.name=match[3],hashPrefix.startsWith("@")&&(parsedTag.searchDepths.push(0),hashPrefix=hashPrefix.substring(1));for(let i=0;i<hashPrefix.length;i++)hashPrefix[i]=="#"&&parsedTag.searchDepths.push(i+1);const fullMatch=match[0],matchStart=query.indexOf(fullMatch),matchEnd=matchStart+fullMatch.length,tagDataFilter=getTagDataFilterText(query,matchEnd);tagDataFilter&&(query=query.substring(0,matchEnd)+query.substring(matchEnd+tagDataFilter.length+2),processTagDataFilter(parsedTag,tagDataFilter)),query=query.substring(0,matchStart)+`{tag${parsedQuery.tags.length}}`+query.substring(matchEnd),parsedQuery.tags.push(parsedTag)}return query}function getTagDataFilterText(query,tagEndIndex){if(query.charAt(tagEndIndex)!="{")return null;let i=tagEndIndex+1,braceDepth=1;for(;;){if(i>=query.length)throw Error("Invalid query syntax, expected closing '}' symbol.");const char=query.charAt(i);if(char=="{")braceDepth++;else if(char=="}"&&(braceDepth--,braceDepth==0))break;i++}return query.substring(tagEndIndex+1,i)}function processTagDataFilter(parsedTag,filterText){filterText=` ${filterText}`,parsedTag.filter=new ParsedTagFilter,parsedTag.filter.pattern=filterText;const expressionRegex=/[\s\(]\.([\w\d\[\]\.]+)/;for(;;){const match=expressionRegex.exec(parsedTag.filter.pattern);if(!match)break;const expression=match[1];parsedTag.filter.pattern=parsedTag.filter.pattern.replace(`.${expression}`,`{exp${parsedTag.filter.exps.length}}`),parsedTag.filter.exps.push(expression)}parsedTag.filter.pattern=parsedTag.filter.pattern.trim()}exports2.Note=Note,exports2.NoteTag=NoteTag,exports2.NoteXmlElement=NoteXmlElement,exports2.Notu=Notu,exports2.NotuCache=NotuCache,exports2.NotuHttpCacheFetcher=NotuHttpCacheFetcher,exports2.NotuHttpClient=NotuHttpClient,exports2.ParsedGrouping=ParsedGrouping,exports2.ParsedQuery=ParsedQuery,exports2.ParsedTag=ParsedTag,exports2.ParsedTagFilter=ParsedTagFilter,exports2.Space=Space,exports2.SpaceLink=SpaceLink,exports2.Tag=Tag,exports2.parseNoteXml=parseNoteXml,exports2.parseQuery=parseQuery,exports2.splitNoteTextIntoComponents=splitNoteTextIntoComponents,Object.defineProperty(exports2,Symbol.toStringTag,{value:"Module"})});
@@ -1,5 +1,6 @@
1
- import { Note, Space, Tag } from ".";
2
- import { NotuCacheFetcher } from "./services/HttpCacheFetcher";
1
+ import { Note, Space, Tag } from '.';
2
+ import { NotuCacheFetcher } from './services/HttpCacheFetcher';
3
+
3
4
  export declare function newNote(text?: string, id?: number): Note;
4
5
  export declare function newSpace(name?: string, id?: number): Space;
5
6
  export declare function newTag(name?: string, id?: number): Tag;
@@ -1,12 +1,14 @@
1
1
  import { Notu } from './services/Notu';
2
- import NotuHttpClient from './services/HttpClient';
2
+ import { default as NotuHttpClient } from './services/HttpClient';
3
3
  import { NotuCache } from './services/NotuCache';
4
4
  import { NotuHttpCacheFetcher } from './services/HttpCacheFetcher';
5
- import Note from './models/Note';
6
- import { NoteComponentInfo, splitNoteTextIntoComponents } from './notecomponents/NoteComponent';
7
- import NoteTag from './models/NoteTag';
8
- import parseQuery, { ParsedQuery, ParsedTag, ParsedTagFilter, ParsedGrouping } from './services/QueryParser';
9
- import Space from './models/Space';
10
- import SpaceLink from './models/SpaceLink';
11
- import Tag from './models/Tag';
12
- export { Notu, NotuHttpClient, NotuCache, NotuHttpCacheFetcher, Note, NoteComponentInfo, splitNoteTextIntoComponents, NoteTag, parseQuery, ParsedQuery, ParsedTag, ParsedTagFilter, ParsedGrouping, Space, SpaceLink, Tag };
5
+ import { default as Note } from './models/Note';
6
+ import { splitNoteTextIntoComponents } from './notecomponents/NoteComponent';
7
+ import { parseNoteXml, NoteXmlElement } from './notecomponents/XmlParser';
8
+ import { default as NoteTag } from './models/NoteTag';
9
+ import { default as parseQuery, ParsedQuery, ParsedTag, ParsedTagFilter, ParsedGrouping } from './services/QueryParser';
10
+ import { default as Space } from './models/Space';
11
+ import { default as SpaceLink } from './models/SpaceLink';
12
+ import { default as Tag } from './models/Tag';
13
+
14
+ export { Notu, NotuHttpClient, NotuCache, NotuHttpCacheFetcher, Note, splitNoteTextIntoComponents, parseNoteXml, NoteXmlElement, NoteTag, parseQuery, ParsedQuery, ParsedTag, ParsedTagFilter, ParsedGrouping, Space, SpaceLink, Tag };
@@ -1,7 +1,8 @@
1
- import ModelWithState from './ModelWithState';
2
- import NoteTag from './NoteTag';
3
- import Space from './Space';
4
- import Tag from './Tag';
1
+ import { default as ModelWithState } from './ModelWithState';
2
+ import { default as NoteTag } from './NoteTag';
3
+ import { default as Space } from './Space';
4
+ import { default as Tag } from './Tag';
5
+
5
6
  export default class Note extends ModelWithState<Note> {
6
7
  constructor(text?: string, ownTag?: Tag);
7
8
  private _id;
@@ -1,5 +1,6 @@
1
- import ModelWithState from './ModelWithState';
2
- import Tag from './Tag';
1
+ import { default as ModelWithState } from './ModelWithState';
2
+ import { default as Tag } from './Tag';
3
+
3
4
  export default class NoteTag extends ModelWithState<NoteTag> {
4
5
  constructor(tag: Tag);
5
6
  private _tag;
@@ -1,5 +1,6 @@
1
- import ModelWithState from './ModelWithState';
2
- import SpaceLink from './SpaceLink';
1
+ import { default as ModelWithState } from './ModelWithState';
2
+ import { default as SpaceLink } from './SpaceLink';
3
+
3
4
  export default class Space extends ModelWithState<Space> {
4
5
  private _id;
5
6
  get id(): number;
@@ -1,5 +1,6 @@
1
- import ModelWithState from "./ModelWithState";
2
- import Space from "./Space";
1
+ import { default as ModelWithState } from './ModelWithState';
2
+ import { default as Space } from './Space';
3
+
3
4
  export default class SpaceLink extends ModelWithState<SpaceLink> {
4
5
  private _name;
5
6
  get name(): string;
@@ -1,5 +1,6 @@
1
1
  import { NotuCache, Space } from '..';
2
- import ModelWithState from './ModelWithState';
2
+ import { default as ModelWithState } from './ModelWithState';
3
+
3
4
  export default class Tag extends ModelWithState<Tag> {
4
5
  private _id;
5
6
  get id(): number;
@@ -1,28 +1,22 @@
1
- import Note from '../models/Note';
1
+ import { default as Note } from '../models/Note';
2
2
  import { Notu } from '../services/Notu';
3
+ import { NoteXmlElement } from './XmlParser';
4
+
3
5
  /** The base interface that all note components must implement */
4
6
  export interface NoteComponent {
5
7
  /** Gets the text which would be used for saving the current state of the note component's contents */
6
8
  getText(): string;
7
9
  /** Returns some text data about what type of text component this is */
8
- getTypeInfo(): string;
9
- }
10
- /** Stores info about a found NoteComponenet in a note's text until it is ready to be generated */
11
- export declare class NoteComponentInfo {
12
- text: string;
13
- start: number;
14
- get end(): number;
15
- processor: NoteComponentProcessor;
16
- constructor(text: string, start: number, processor: NoteComponentProcessor);
10
+ get typeInfo(): string;
11
+ get displaysInline(): boolean;
17
12
  }
18
13
  /** Defines the interface for an object which can identify and then create instances of a particular type of note component */
19
14
  export interface NoteComponentProcessor {
20
15
  get displayName(): string;
16
+ get tagName(): string;
21
17
  newComponentText(contentText: string): string;
22
- identify(text: string): NoteComponentInfo;
23
18
  /** Accepts a function which converts a NoteComponentInfo object into an actual NoteComponent that can be rendered */
24
- create(info: NoteComponentInfo, note: Note, save: () => Promise<void>): NoteComponent;
25
- get componentShowsInlineInParagraph(): boolean;
19
+ create(data: NoteXmlElement, note: Note, save: () => Promise<void>): NoteComponent;
26
20
  }
27
21
  /** Takes a note and a set of processors, returns an array of all the note components which make up that note's text */
28
- export declare function splitNoteTextIntoComponents(note: Note, notu: Notu, componentProcessors: Array<NoteComponentProcessor>, defaultProcessor: NoteComponentProcessor, groupIntoParagraph: (components: Array<NoteComponent>) => NoteComponent): Array<NoteComponent>;
22
+ export declare function splitNoteTextIntoComponents(note: Note, notu: Notu, componentProcessors: Array<NoteComponentProcessor>, textComponentFactory: (text: string) => NoteComponent, paragraphComponentFactory: (components: Array<NoteComponent>) => NoteComponent): Array<NoteComponent>;
@@ -0,0 +1,11 @@
1
+ export declare class NoteXmlElement {
2
+ tag: string;
3
+ children: Array<any>;
4
+ attributes: any;
5
+ text: string;
6
+ get length(): number;
7
+ }
8
+ /**
9
+ * This function will take in some text from a note and return a mixed array of string portions and xml data.
10
+ * This is beneficial over using an existing xml parser library because the proper xml protocol doesn't keep track of whitespace. */
11
+ export declare function parseNoteXml(text: string): Array<NoteXmlElement | string>;
@@ -1,5 +1,6 @@
1
- import Note from '../models/Note';
2
- import Space from '../models/Space';
1
+ import { default as Note } from '../models/Note';
2
+ import { default as Space } from '../models/Space';
3
+
3
4
  export interface NotuClient {
4
5
  login(username: string, password: string): Promise<string>;
5
6
  setup(): Promise<void>;
@@ -1,6 +1,7 @@
1
1
  import { Note, Space, Tag } from '..';
2
2
  import { NotuClient } from './HttpClient';
3
3
  import { NotuCache } from './NotuCache';
4
+
4
5
  export declare class Notu {
5
6
  private _client;
6
7
  get client(): NotuClient;
@@ -1,7 +1,8 @@
1
- import Note from '../models/Note';
2
- import Space from '../models/Space';
3
- import Tag from '../models/Tag';
1
+ import { default as Note } from '../models/Note';
2
+ import { default as Space } from '../models/Space';
3
+ import { default as Tag } from '../models/Tag';
4
4
  import { NotuCacheFetcher } from './HttpCacheFetcher';
5
+
5
6
  export declare class NotuCache {
6
7
  private _fetcher;
7
8
  constructor(fetcher: NotuCacheFetcher);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notu",
3
- "version": "0.15.14",
3
+ "version": "0.16.1",
4
4
  "main": "dist/notu.mjs",
5
5
  "unpkg": "dist/notu.mjs",
6
6
  "types": "dist/types/index.d.ts",