@bitblit/ratchet-misc 4.0.307-alpha → 4.0.308-alpha
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/lib/index.mjs +1 -1
- package/package.json +3 -3
package/lib/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{NumberRatchet as e,StringRatchet as t,ErrorRatchet as a,Logger as r,MapRatchet as s,TimeoutToken as l}from"@bitblit/ratchet-common";import n from"handlebars";import i from"cross-fetch";import o from"handlebars-layouts";import c from"swagger-model-validator";import u from"js-yaml";import{race as m,Observable as h}from"rxjs";class d{constructor(){}static buildInformation(){return{version:"
|
|
1
|
+
import{NumberRatchet as e,StringRatchet as t,ErrorRatchet as a,Logger as r,MapRatchet as s,TimeoutToken as l}from"@bitblit/ratchet-common";import n from"handlebars";import i from"cross-fetch";import o from"handlebars-layouts";import c from"swagger-model-validator";import u from"js-yaml";import{race as m,Observable as h}from"rxjs";class d{constructor(){}static buildInformation(){return{version:"308",hash:"c919764aec4d8dfbc9f7b8aaccc6725fb63d1367",branch:"alpha-2024-01-26-1",tag:"alpha-2024-01-26-1",timeBuiltISO:"2024-01-26T00:57:21-0800",notes:"No notes"}}}class f{constructor(){}static functionMap(){return{eq:f.equal,ne:f.notEqual,lt:f.lessThan,gt:f.greaterThan,lte:f.lessThanEqual,gte:f.greaterThanEqual,and:f.and,or:f.or,formatBytes:f.formatBytes,rpn:f.reversePolishNotation,add:f.add,sub:f.sub,mul:f.mul,div:f.div,mod:f.mod,maxNum:f.maxNum,minNum:f.minNum}}static registerAll(e){e.registerHelper(f.functionMap())}static add(t,a){return e.safeNumber(t)+e.safeNumber(a)}static sub(t,a){return e.safeNumber(t)-e.safeNumber(a)}static mul(t,a){return e.safeNumber(t)*e.safeNumber(a)}static div(t,a){return e.safeNumber(t)/e.safeNumber(a)}static mod(t,a){return e.safeNumber(t)%e.safeNumber(a)}static equal(e,t){return e===t}static notEqual(e,t){return e!==t}static lessThan(e,t){return e<t}static lessThanEqual(e,t){return e<=t}static greaterThan(e,t){return e>t}static greaterThanEqual(e,t){return e>=t}static maxNum(...e){return Math.max(...e.slice(0,-1))}static minNum(...e){return Math.min(...e.slice(0,-1))}static and(...e){return Array.prototype.every.call(e,Boolean)}static or(...e){return Array.prototype.slice.call(e,0,-1).some(Boolean)}static formatBytes(e){return t.formatBytes(e)}static reversePolishNotation(...e){let t=null;try{const r=Object.assign({},f.functionMap());delete r.formatBytes;const s=[];for(let t=0;t<e.length-1;t++){const l=e[t];if(r[l])if(s.length>1){const e=s.pop(),t=s.pop(),a=r[l](t,e,{});s.push(a)}else a.throwFormattedErr("Cannot execute operation %s - not enough args",l);else s.push(l)}t=s.pop()}catch(e){r.error("Failed to execute RPN: %s",e,e),t=a.asErr(e)?.message||"Failure"}return t}}class p{prefix;suffix;maxCacheTemplates;cache;constructor(e="",t="",a=10){this.prefix=e,this.suffix=t,this.maxCacheTemplates=a,this.maxCacheTemplates>0&&(this.cache=new Map)}async renderTemplate(e,t,a=null){return this.renderRemoteTemplate(e,t,a)}async renderRemoteTemplate(e,t,a=null){const r=await this.fetchTemplate(e),s=a?await this.fetchTemplateText(a):null;s&&(await o.register(n),n.registerPartial(a,s));return r?r(t||{}):null}async renderTemplateDirect(e,t,a=null){return n.compile(e)(t)}async fetchTemplate(e){let t=null;try{if(this.cache&&this.cache.has(e))r.silly("Cache hit for template : %s",e),t=this.cache.get(e);else{r.debug("Cache miss for template : %s",e);const a=await this.fetchTemplateText(e);a&&(t=n.compile(a),this.cache&&t&&(this.cache.set(e,t),this.cache.size>this.maxCacheTemplates&&this.cache.delete(Array.from(this.cache.keys())[0])))}}catch(a){r.warn("Could not fetch and compile template : %s : %s",e,a,a),t=null}return t}async fetchTemplateText(e){let a=null;const s=t.trimToEmpty(this.prefix)+e+t.trimToEmpty(this.suffix);try{const e=await i(s);a=await e.text()}catch(e){r.warn("Could not fetch url : %s : %s",s,e,e),a=null}return a}}class b{allModels;constructor(e){this.allModels=e,e&&0!=Object.keys(e).length||a.throwFormattedErr("Cannot create model validator, passed models was null/empty : %j",e)}static createFromYamlString(e,t){const a=u.load(e),r=t&&t.length>0?s.findValue(a,t):a;return b.createFromParsedObject(r)}static createFromParsedObject(e){return new b(e)}get modelNames(){return Object.keys(this.allModels)}addModel(e,t){this.allModels[e]=t}fetchModel(e){return this.allModels[e]}validate(e,t,a=!1,s=!0){let l=[];r.silly("Validating model %s all definitions are : %j",e,this.allModels);if(!t||0===Object.keys(t).length)a||l.push("Empty / null object sent, but empty not allowed here");else if(this.allModels&&e&&this.allModels[e]){const r=(new c).validate(t,this.allModels[e],this.allModels,a,s);r.errorCount>0&&(l=r.errors.map((e=>e.message)))}else l=['Model named "'+e+'" not present in schema'];return l}}class T{static timeout(e,t,a){return m(e,this.createTimeoutObservable(t,a))}static createTimeoutObservable(e,t){return h.create((a=>{const r=setTimeout((()=>{clearTimeout(r),a.next(new l(e,t))}),t)}))}}class y{static safeUnsubscribe(e){return s.safeCallFunction(e,"unsubscribe")}static async waitForNonNullOnSubject(e){return e.value?e.value:new Promise(((t,a)=>{const r=e.subscribe((e=>{e&&(y.safeUnsubscribe(r),t(e))}))}))}static async waitForTargetValueOnSubject(e,t){return e.value===t?e.value:new Promise(((a,r)=>{const s=e.subscribe((e=>{e===t&&(y.safeUnsubscribe(s),a(e))}))}))}}export{f as HandlebarsRatchet,b as ModelValidator,T as ObservableRatchet,d as RatchetMiscInfo,p as RemoteHandlebarsTemplateRenderer,y as RxjsRatchet};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bitblit/ratchet-misc",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.308-alpha",
|
|
4
4
|
"description": "Ratchet miscellaneous tooling that requires smallish dependant libraries",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
},
|
|
53
53
|
"license": "Apache-2.0",
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@bitblit/ratchet-common": "4.0.
|
|
55
|
+
"@bitblit/ratchet-common": "4.0.308-alpha",
|
|
56
56
|
"handlebars": "4.7.8",
|
|
57
57
|
"handlebars-layouts": "3.1.4",
|
|
58
58
|
"js-yaml": "4.1.0",
|
|
@@ -60,6 +60,6 @@
|
|
|
60
60
|
"swagger-model-validator": "3.0.21"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
|
-
"@bitblit/ratchet-common": "4.0.
|
|
63
|
+
"@bitblit/ratchet-common": "4.0.308-alpha"
|
|
64
64
|
}
|
|
65
65
|
}
|