From 18141b07517803347d9adc5758ead49ba4f7294e Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sun, 28 Aug 2022 16:34:46 +0300 Subject: [PATCH] notes, cleanup and tweaks... Signed-off-by: Alex A. Naanou --- browser.js | 7 +++-- pwiki/page.js | 24 ++++++++++++---- pwiki/store/base.js | 4 ++- pwiki2.js | 67 ++++++++++++++++++++++----------------------- 4 files changed, 58 insertions(+), 44 deletions(-) diff --git a/browser.js b/browser.js index 82cc6bf..6662ec6 100755 --- a/browser.js +++ b/browser.js @@ -41,8 +41,8 @@ module.setup = Promise.all([ // static stores... // - //store.next.update('System', - store.update('System', + store.next.update('System', + //store.update('System', Object.create(basestore.BaseStore).load(page.System)), store.update('Settings', Object.create(basestore.BaseStore).load(page.Settings)), @@ -63,7 +63,7 @@ Promise.all([ __proto__: pouchdbstore.PouchDBStore, }), - // next testing... + /*/ XXX next testing... store.next.update('NextPage', { text: 'next page...', }), @@ -79,6 +79,7 @@ Promise.all([ store.next.update('System/NextTest', { text: 'next test..' }), + //*/ ]) // XXX //typeof(Bootstrap) != 'undefined' diff --git a/pwiki/page.js b/pwiki/page.js index 6b3d8a3..2229ccf 100755 --- a/pwiki/page.js +++ b/pwiki/page.js @@ -1138,14 +1138,19 @@ object.Constructor('Page', BasePage, { // // NOTE: writing to .raw is the same as writing to .text... // NOTE: when matching multiple pages this will return a list... + // + // XXX revise how we handle .strict mode... get raw(){ return (async function(){ var data = await this.data // no data... // NOTE: if we hit this it means that nothing was resolved, // not even the System/NotFound page, i.e. something // went really wrong... + // NOTE: in .strict mode this will explicitly fail and not try + // to recover... if(data == null){ - if(this.NOT_FOUND_ERROR){ + if(!this.strict + && this.NOT_FOUND_ERROR){ var msg = this.get(this.NOT_FOUND_ERROR) if(await msg.match()){ return msg.raw } } @@ -1221,10 +1226,16 @@ object.Constructor('Page', BasePage, { // NOTE: this uses .PAGE_TEMPLATE to render the page. // NOTE: writing to .raw is the same as writing to .text... // + // XXX revise how we handle strict mode... + // // NOTE: .__debug_last_render_state is mainly exposed for introspection // and debugging, set comment it out to disable... //__debug_last_render_state: undefined, get text(){ return (async function(){ + // strict mode -- break on non-existing pages... + if(this.strict + && !await this.resolve(true)){ + throw new Error('NOT FOUND ERROR: '+ this.path) } var path = pwpath.split(this.path) path.at(-1)[0] == '_' || path.push(this.PAGE_TEMPLATE) @@ -1509,12 +1520,13 @@ module.System = { // XXX all of these should support pattern pages... _text: { text: '@include(. isolated join="@source(file-separator)")' }, + // XXX /rootpath here is not relative -- makes reuse harder... _view: { text: object.doc` - @source(./path) - (edit) + @source(/rootpath) + (edit)
@@ -1690,10 +1702,12 @@ module.System = { return (this.render_root || {}).path }, referrer: function(){ return this.referrer || this.path }, + location: function(){ + return this.get('..').location }, path: function(){ return this.get('..').path }, - location: function(){ - return this.get('..').path }, + rootpath: function(){ + return this.root.path }, resolved: async function(){ return this.get('..').resolve() }, dir: function(){ diff --git a/pwiki/store/base.js b/pwiki/store/base.js index 06c259b..e6617f7 100755 --- a/pwiki/store/base.js +++ b/pwiki/store/base.js @@ -649,7 +649,9 @@ module.MetaStore = { pwpath.join(s, res) : res }), get: async function(path, strict=false){ - path = await this.resolve(path) + path = await this.resolve(path, strict) + if(path == undefined){ + return } var res var p = this.substore(path) if(p){ diff --git a/pwiki2.js b/pwiki2.js index 48c9dcd..b4530b7 100755 --- a/pwiki2.js +++ b/pwiki2.js @@ -9,9 +9,9 @@ * .get(..) -- DONE * .metadata(..) -- * .delete(..) +* XXX deleting something in .next will break stuff... * ... -* XXX this broke "strict"... -* XXX page search: make things invariant via .names +* XXX OPTIMIZE page search: make things invariant via .names * - if a page is in a system path and there are no alternatives * just return it and do not search. * - if there are alternatives rank them @@ -19,21 +19,20 @@ * - return the first system * XXX sort paths in .names * XXX remove/mark shadowed paths??? -* XXX NORMCACHE .normalize(..) cache normalized strings... -* ...seems to have little impact... -* XXX MATCH limit candidates to actual page name matches -- this will +* XXX OPTIMIZE MATCH limit candidates to actual page name matches -- this will * limit the number of requests to actual number of pages with that * name... * e.g. when searching for xxx/tree the only "tree" available is * System/tree, and if it is overloaded it's now a question of * picking one out of two and not out of tens generated by .paths() -* XXX CACHE match pattern paths -- to catch page creation... +* XXX OPTIMIZE CACHE match pattern paths -- to catch page creation... * 1) explicit subpath matching -- same as .match(..) * 2) identify recursive patterns -- same as ** -* XXX CACHE track store changes... -* XXX CACHE/DEPENDS might be a good idea to add a dependencyUpdated event... +* XXX OPTIMIZE CACHE track store changes... +* XXX OPTIMIZE CACHE/DEPENDS might be a good idea to add a dependencyUpdated event... * ...and use it for cache invalidation... -* XXX CACHE creating a new page does not invalidate /tree cache... +* XXX OPTIMIZE NORMCACHE .normalize(..) cache normalized strings... +* ...seems to have little impact... * XXX OPTIMIZE: the actions that depend on lots of tiny requests (/tree) * can get really slow... * ...it feels like one reason is the async/await ping-pong... @@ -45,7 +44,10 @@ * mark the normalized string and return it as-is on * renormalization... * ...initial experiment made things slower... -* XXX FEATURE eed a uniform way to track some state in links in pwiki +* XXX FEATURE self-doc: +* - some thing lile Action(, , |) +* - System/doc -- show for action... +* XXX FEATURE add a uniform way to track some state in links in pwiki * for things like paging and the like with simple user/macro * access (???)... * ...the simplest that comes to mind is to store in in path @@ -134,6 +136,7 @@ * XXX CHECK: @macro(..) and @slot(..) must overload in the same way... * XXX DEPENDS/CACHE @macro(..) introduces a dependency on count (pattern) * ...not sure how we track these... +* XXX revise how we handle .strict mode in page's .raw and .text... * * * @@ -155,7 +158,7 @@ * - copy/move -- DONE * - resolved (async) -- * - migrate/rewrite bootstrap -- -* - store topology -- +* - store topology -- DONE * - sync and sync conf -- * - images * - get -- @@ -342,11 +345,7 @@ module.path = var page = require('./pwiki/page') var basestore = require('./pwiki/store/base') - -//var localstoragestore = require('./store/localstorage') -// XXX for some reason this does not run quietly in browser -//var pouchdbstore = require('./store/pouchdb') -//var filestore = require('./store/file') +var pouchdbstore = require('./pwiki/store/pouchdb') @@ -355,24 +354,19 @@ var basestore = require('./pwiki/store/base') // // // Store topology: -// -// root (BaseStore) ---next--- main (MetaStore) -// | -// +-- System/... (BaseStore) -// -// Alternative store topology: -// -// root (BaseStore) ---next--- main (MetaStore) -// System/... (static) -// +// XXX // var store = -module.store = - //BaseStore.nest() - // XXX clone... - { __proto__: basestore.BaseStore } - .nest({ __proto__: basestore.MetaStore }) +module.store = { + // XXX base localstorage... + __proto__: pouchdbstore.PouchDBStore, + /*/ + __proto__: basestore.MetaStore, + //*/ + + next: { __proto__: basestore.MetaStore }, +} // XXX these are async... @@ -382,10 +376,13 @@ module.store = // - a root ram store with all the static stuff and nest the rest // - a nested store (as is the case here) // XXX nested system store... -store.update('System', - Object.create(basestore.BaseStore).load(page.System)) -store.update('Settings', - Object.create(basestore.BaseStore).load(page.Settings)) +module.setup = +Promise.all([ + store.next.update('System', + Object.create(basestore.BaseStore).load(page.System)), + store.update('Settings', + Object.create(basestore.BaseStore).load(page.Settings)), +])