@ezpaarse-project/ezreeport-sdk-js 2.0.0 → 2.1.0-beta.2
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/{body-BqAn9vHJ.d.ts → body-ADynkNh0.d.ts} +4 -2
- package/dist/helpers/jobs.d.ts +2 -2
- package/dist/helpers/jobs.js +1 -1
- package/dist/helpers/jobs.mjs +2 -2
- package/dist/helpers/layouts.d.ts +9 -4
- package/dist/helpers/task-presets.d.ts +2 -2
- package/dist/helpers/task-presets.js +1 -1
- package/dist/helpers/task-presets.mjs +1 -1
- package/dist/helpers/tasks.d.ts +19 -7
- package/dist/helpers/tasks.js +1 -1
- package/dist/helpers/tasks.js.map +1 -1
- package/dist/helpers/tasks.mjs +91 -64
- package/dist/helpers/tasks.mjs.map +1 -1
- package/dist/helpers/templates.d.ts +2 -2
- package/dist/helpers/templates.js +1 -1
- package/dist/helpers/templates.js.map +1 -1
- package/dist/helpers/templates.mjs +3 -1
- package/dist/helpers/templates.mjs.map +1 -1
- package/dist/{index-6ma-WCUD.d.ts → index-DfRKlMeG.d.ts} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/methods-8bLJk-Sx.mjs +161 -0
- package/dist/{methods-DUqC5qzU.mjs.map → methods-8bLJk-Sx.mjs.map} +1 -1
- package/dist/methods-BOf9WLn2.js +2 -0
- package/dist/methods-BOf9WLn2.js.map +1 -0
- package/dist/methods-C3rgYZb1.mjs +122 -0
- package/dist/methods-C3rgYZb1.mjs.map +1 -0
- package/dist/methods-CMrpqFJZ.js +2 -0
- package/dist/{methods-CGdoP4Hi.js.map → methods-CMrpqFJZ.js.map} +1 -1
- package/dist/methods-ChKQbOFl.js +2 -0
- package/dist/methods-ChKQbOFl.js.map +1 -0
- package/dist/methods-DC2Gjy1i.js +2 -0
- package/dist/{methods-cUjyNkoK.js.map → methods-DC2Gjy1i.js.map} +1 -1
- package/dist/methods-jKz01wri.mjs +151 -0
- package/dist/methods-jKz01wri.mjs.map +1 -0
- package/dist/methods-sTFYWEAr.mjs +156 -0
- package/dist/methods-sTFYWEAr.mjs.map +1 -0
- package/dist/queues.d.ts +2 -2
- package/dist/reports.d.ts +1 -1
- package/dist/reports.js +1 -1
- package/dist/reports.mjs +1 -1
- package/dist/task-activity.d.ts +1 -1
- package/dist/task-activity.js +1 -1
- package/dist/task-activity.mjs +1 -1
- package/dist/task-presets.d.ts +2 -2
- package/dist/task-presets.js +1 -1
- package/dist/task-presets.mjs +1 -1
- package/dist/tasks.d.ts +2 -2
- package/dist/tasks.js +1 -1
- package/dist/tasks.mjs +1 -1
- package/dist/templates.js +1 -1
- package/dist/templates.mjs +1 -1
- package/dist/{types-C4AhJDkW.d.ts → types-DP1QhOKe.d.ts} +1 -1
- package/dist/{types-BGlpjxH9.d.ts → types-DtBHOMlQ.d.ts} +1 -1
- package/package.json +1 -1
- package/dist/methods-BBsb3M5p.mjs +0 -142
- package/dist/methods-BBsb3M5p.mjs.map +0 -1
- package/dist/methods-CGdoP4Hi.js +0 -2
- package/dist/methods-CO0p8irP.js +0 -2
- package/dist/methods-CO0p8irP.js.map +0 -1
- package/dist/methods-DOB4Ry8E.mjs +0 -147
- package/dist/methods-DOB4Ry8E.mjs.map +0 -1
- package/dist/methods-DUqC5qzU.mjs +0 -146
- package/dist/methods-DY2VLwGd.mjs +0 -116
- package/dist/methods-DY2VLwGd.mjs.map +0 -1
- package/dist/methods-cUjyNkoK.js +0 -2
- package/dist/methods-uWDk6_pk.js +0 -2
- package/dist/methods-uWDk6_pk.js.map +0 -1
- package/dist/tasks-BDFAJ6Oi.d.ts +0 -12
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as TemplateFilter, g as TemplateBodyGrid } from './types-DcoMmjs3.js';
|
|
1
|
+
import { c as TemplateFilter, g as TemplateBodyGrid, h as TemplateBody } from './types-DcoMmjs3.js';
|
|
2
2
|
import { L as LayoutHelper } from './templates-BgRTZc5c.js';
|
|
3
3
|
|
|
4
4
|
interface TemplateBodyHelper {
|
|
@@ -9,8 +9,10 @@ interface TemplateBodyHelper {
|
|
|
9
9
|
layouts: LayoutHelper[];
|
|
10
10
|
grid?: TemplateBodyGrid;
|
|
11
11
|
}
|
|
12
|
+
declare function createTemplateBodyHelper(index?: string, dateField?: string, layouts?: LayoutHelper[], filters?: TemplateFilter[], grid?: TemplateBodyGrid): TemplateBodyHelper;
|
|
13
|
+
declare function createTemplateBodyHelperFrom(body: TemplateBody): TemplateBodyHelper;
|
|
12
14
|
declare function addLayoutOfHelper(body: TemplateBodyHelper, layout: LayoutHelper, index?: number): TemplateBodyHelper;
|
|
13
15
|
declare function removeLayoutOfHelper(body: TemplateBodyHelper, layout: LayoutHelper): TemplateBodyHelper;
|
|
14
16
|
declare function updateLayoutOfHelper(body: TemplateBodyHelper, oldLayout: LayoutHelper, newLayout: LayoutHelper): TemplateBodyHelper;
|
|
15
17
|
|
|
16
|
-
export { type TemplateBodyHelper as T,
|
|
18
|
+
export { type TemplateBodyHelper as T, createTemplateBodyHelperFrom as a, addLayoutOfHelper as b, createTemplateBodyHelper as c, removeLayoutOfHelper as r, updateLayoutOfHelper as u };
|
package/dist/helpers/jobs.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { A as ApiRequestOptions } from '../api-C_g0ldUn.js';
|
|
2
2
|
import { R as ReportResult, f as RawReportResult } from '../types-jXqGnCKQ.js';
|
|
3
|
-
import { T as Task } from '../types-
|
|
4
|
-
import { J as Job, G as GenerationData, M as MailData, a as MailError, P as PaginatedJobs, b as JobStatus } from '../index-
|
|
3
|
+
import { T as Task } from '../types-DP1QhOKe.js';
|
|
4
|
+
import { J as Job, G as GenerationData, M as MailData, a as MailError, P as PaginatedJobs, b as JobStatus } from '../index-DfRKlMeG.js';
|
|
5
5
|
import '../namespaces.js';
|
|
6
6
|
import '../types-DcoMmjs3.js';
|
|
7
7
|
|
package/dist/helpers/jobs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var Z=Object.defineProperty,ee=Object.defineProperties;var te=Object.getOwnPropertyDescriptors;var b=Object.getOwnPropertySymbols;var A=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable;var P=(e,t,n)=>t in e?Z(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,l=(e,t)=>{for(var n in t||(t={}))A.call(t,n)&&P(e,n,t[n]);if(b)for(var n of b(t))N.call(t,n)&&P(e,n,t[n]);return e},m=(e,t)=>ee(e,te(t));var J=(e,t)=>{var n={};for(var r in e)A.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&b)for(var r of b(e))t.indexOf(r)<0&&N.call(e,r)&&(n[r]=e[r]);return n};var v=(e,t,n)=>new Promise((r,s)=>{var o=f=>{try{a(n.next(f))}catch(d){s(d)}},i=f=>{try{a(n.throw(f))}catch(d){s(d)}},a=f=>f.done?r(f.value):Promise.resolve(f.value).then(o,i);a((n=n.apply(e,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ne=require("date-fns"),h=require("../decorator-C2gcn2rK.js"),w=require("../methods-
|
|
1
|
+
"use strict";var Z=Object.defineProperty,ee=Object.defineProperties;var te=Object.getOwnPropertyDescriptors;var b=Object.getOwnPropertySymbols;var A=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable;var P=(e,t,n)=>t in e?Z(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,l=(e,t)=>{for(var n in t||(t={}))A.call(t,n)&&P(e,n,t[n]);if(b)for(var n of b(t))N.call(t,n)&&P(e,n,t[n]);return e},m=(e,t)=>ee(e,te(t));var J=(e,t)=>{var n={};for(var r in e)A.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&b)for(var r of b(e))t.indexOf(r)<0&&N.call(e,r)&&(n[r]=e[r]);return n};var v=(e,t,n)=>new Promise((r,s)=>{var o=f=>{try{a(n.next(f))}catch(d){s(d)}},i=f=>{try{a(n.throw(f))}catch(d){s(d)}},a=f=>f.done?r(f.value):Promise.resolve(f.value).then(o,i);a((n=n.apply(e,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ne=require("date-fns"),h=require("../decorator-C2gcn2rK.js"),w=require("../methods-CMrpqFJZ.js"),re=require("../methods-DC2Gjy1i.js"),c=require("../methods-DU5cbtLn.js");function se(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var M={exports:{}},y=typeof Reflect=="object"?Reflect:null,S=y&&typeof y.apply=="function"?y.apply:function(t,n,r){return Function.prototype.apply.call(t,n,r)},L;y&&typeof y.ownKeys=="function"?L=y.ownKeys:Object.getOwnPropertySymbols?L=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:L=function(t){return Object.getOwnPropertyNames(t)};function ie(e){console&&console.warn&&console.warn(e)}var k=Number.isNaN||function(t){return t!==t};function u(){u.init.call(this)}M.exports=u;M.exports.once=fe;u.EventEmitter=u;u.prototype._events=void 0;u.prototype._eventsCount=0;u.prototype._maxListeners=void 0;var j=10;function _(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(u,"defaultMaxListeners",{enumerable:!0,get:function(){return j},set:function(e){if(typeof e!="number"||e<0||k(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");j=e}});u.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};u.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||k(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this};function G(e){return e._maxListeners===void 0?u.defaultMaxListeners:e._maxListeners}u.prototype.getMaxListeners=function(){return G(this)};u.prototype.emit=function(t){for(var n=[],r=1;r<arguments.length;r++)n.push(arguments[r]);var s=t==="error",o=this._events;if(o!==void 0)s=s&&o.error===void 0;else if(!s)return!1;if(s){var i;if(n.length>0&&(i=n[0]),i instanceof Error)throw i;var a=new Error("Unhandled error."+(i?" ("+i.message+")":""));throw a.context=i,a}var f=o[t];if(f===void 0)return!1;if(typeof f=="function")S(f,this,n);else for(var d=f.length,g=W(f,d),r=0;r<d;++r)S(g[r],this,n);return!0};function F(e,t,n,r){var s,o,i;if(_(n),o=e._events,o===void 0?(o=e._events=Object.create(null),e._eventsCount=0):(o.newListener!==void 0&&(e.emit("newListener",t,n.listener?n.listener:n),o=e._events),i=o[t]),i===void 0)i=o[t]=n,++e._eventsCount;else if(typeof i=="function"?i=o[t]=r?[n,i]:[i,n]:r?i.unshift(n):i.push(n),s=G(e),s>0&&i.length>s&&!i.warned){i.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+i.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=i.length,ie(a)}return e}u.prototype.addListener=function(t,n){return F(this,t,n,!1)};u.prototype.on=u.prototype.addListener;u.prototype.prependListener=function(t,n){return F(this,t,n,!0)};function oe(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function q(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},s=oe.bind(r);return s.listener=n,r.wrapFn=s,s}u.prototype.once=function(t,n){return _(n),this.on(t,q(this,t,n)),this};u.prototype.prependOnceListener=function(t,n){return _(n),this.prependListener(t,q(this,t,n)),this};u.prototype.removeListener=function(t,n){var r,s,o,i,a;if(_(n),s=this._events,s===void 0)return this;if(r=s[t],r===void 0)return this;if(r===n||r.listener===n)--this._eventsCount===0?this._events=Object.create(null):(delete s[t],s.removeListener&&this.emit("removeListener",t,r.listener||n));else if(typeof r!="function"){for(o=-1,i=r.length-1;i>=0;i--)if(r[i]===n||r[i].listener===n){a=r[i].listener,o=i;break}if(o<0)return this;o===0?r.shift():ue(r,o),r.length===1&&(s[t]=r[0]),s.removeListener!==void 0&&this.emit("removeListener",t,a||n)}return this};u.prototype.off=u.prototype.removeListener;u.prototype.removeAllListeners=function(t){var n,r,s;if(r=this._events,r===void 0)return this;if(r.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):r[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete r[t]),this;if(arguments.length===0){var o=Object.keys(r),i;for(s=0;s<o.length;++s)i=o[s],i!=="removeListener"&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(n=r[t],typeof n=="function")this.removeListener(t,n);else if(n!==void 0)for(s=n.length-1;s>=0;s--)this.removeListener(t,n[s]);return this};function K(e,t,n){var r=e._events;if(r===void 0)return[];var s=r[t];return s===void 0?[]:typeof s=="function"?n?[s.listener||s]:[s]:n?ae(s):W(s,s.length)}u.prototype.listeners=function(t){return K(this,t,!0)};u.prototype.rawListeners=function(t){return K(this,t,!1)};u.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):Q.call(e,t)};u.prototype.listenerCount=Q;function Q(e){var t=this._events;if(t!==void 0){var n=t[e];if(typeof n=="function")return 1;if(n!==void 0)return n.length}return 0}u.prototype.eventNames=function(){return this._eventsCount>0?L(this._events):[]};function W(e,t){for(var n=new Array(t),r=0;r<t;++r)n[r]=e[r];return n}function ue(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function ae(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}function fe(e,t){return new Promise(function(n,r){function s(i){e.removeListener(t,o),r(i)}function o(){typeof e.removeListener=="function"&&e.removeListener("error",s),n([].slice.call(arguments))}$(e,t,o,{once:!0}),t!=="error"&&ce(e,s,{once:!0})})}function ce(e,t,n){typeof e.on=="function"&&$(e,"error",t,n)}function $(e,t,n,r){if(typeof e.on=="function")r.once?e.once(t,n):e.on(t,n);else if(typeof e.addEventListener=="function")e.addEventListener(t,function s(o){r.once&&e.removeEventListener(t,s),n(o)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e)}var pe=M.exports;const de=se(pe),le=(e,t=new de)=>{const n={emit:(o,...i)=>(t.emit(o.toString(),...i),n)},r=e(n),s=Object.assign(r,{on:(o,i)=>(t.on(o.toString(),(...a)=>i(...a)),s),once:(o,i)=>(t.once(o.toString(),(...a)=>i(...a)),s),off:(o,i)=>(t.off(o.toString(),(...a)=>i(...a)),s)});return s},ve=e=>new Promise(t=>{setTimeout(t,e)}),he=e=>m(l({},e),{task:re.transformTask(e.task),period:e.period?w.transformPeriod(e.period):void 0}),me=e=>m(l({},e),{date:ne.parseISO(e.date)}),O=e=>m(l({},e),{data:he(e.data)}),R=e=>m(l({},e),{data:me(e.data)}),U=e=>"error"in e.data,ye=e=>!U(e);function H(e){return v(this,null,function*(){const r=yield c.getQueueJobs("generation",e),{items:t}=r,n=J(r,["items"]);return l({items:t.map(O)},n)})}h.assignDependencies(H,[c.getQueueJobs]);function I(e){return v(this,null,function*(){const r=yield c.getQueueJobs("mail",e),{items:t}=r,n=J(r,["items"]);return l({items:t.map(R)},n)})}h.assignDependencies(I,[c.getQueueJobs]);function E(e){return v(this,null,function*(){const t=typeof e=="string"?e:e.id,n=yield c.getJob("generation",t);return m(l({},O(n)),{result:n.result&&w.transformReportResult(n.result)})})}h.assignDependencies(E,[c.getJob]);function z(e){return v(this,null,function*(){const t=typeof e=="string"?e:e.id,n=yield c.getJob("mail",t);return R(n)})}h.assignDependencies(z,[c.getJob]);function B(e){return v(this,null,function*(){const t=typeof e=="string"||typeof e=="number"?e:e.id,n=yield c.retryJob("generation",t);return O(n)})}h.assignDependencies(B,[c.retryJob]);function V(e){return v(this,null,function*(){const t=typeof e=="string"||typeof e=="number"?e:e.id,n=yield c.retryJob("mail",t);return R(n)})}h.assignDependencies(V,[c.retryJob]);function X(e,t,n,r){var i,a;const s=new Set(["completed","failed","stuck"]),o={pending:typeof r=="number"?r:(i=r==null?void 0:r.pending)!=null?i:1e3,active:typeof r=="number"?r:(a=r==null?void 0:r.active)!=null?a:1e3};return le(f=>v(this,null,function*(){var x;const{queue:d,jobId:g}=yield w.generateReportOfTask(e,t,n);f.emit("started",{queue:d,jobId:g});let p;for(;!s.has((x=p==null?void 0:p.status)!=null?x:"");){const{progress:C,status:T,result:Y}=yield E(g);p={progress:C,status:T,result:Y},f.emit("progress",{progress:C,status:T});let D=o.pending;(p==null?void 0:p.status)==="active"&&(D=o.active),yield ve(D)}if(!(p!=null&&p.result))throw new Error("Job failed");return p.result}))}h.assignDependencies(X,[w.generateReportOfTask,E]);exports.generateAndListenReportOfTask=X;exports.getGenerationJob=E;exports.getGenerationJobs=H;exports.getMailJob=z;exports.getMailJobs=I;exports.isDataMailJob=ye;exports.isErrorMailJob=U;exports.retryGenerationJob=B;exports.retryMailJob=V;
|
|
2
2
|
//# sourceMappingURL=jobs.js.map
|
package/dist/helpers/jobs.mjs
CHANGED
|
@@ -37,8 +37,8 @@ var d = (e, t, n) => new Promise((r, i) => {
|
|
|
37
37
|
});
|
|
38
38
|
import { parseISO as X } from "date-fns";
|
|
39
39
|
import { b as l } from "../decorator-DBkj--6g.mjs";
|
|
40
|
-
import { t as Y, b as F, i as Z } from "../methods-
|
|
41
|
-
import { t as ee } from "../methods-
|
|
40
|
+
import { t as Y, b as F, i as Z } from "../methods-8bLJk-Sx.mjs";
|
|
41
|
+
import { t as ee } from "../methods-sTFYWEAr.mjs";
|
|
42
42
|
import { c as w, b, r as _ } from "../methods-BJfwYB1p.mjs";
|
|
43
43
|
function te(e) {
|
|
44
44
|
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { L as LayoutHelper } from '../templates-BgRTZc5c.js';
|
|
2
2
|
export { c as createLayoutHelper, a as createLayoutHelperFrom, h as hashLayout, l as layoutHelperToJSON } from '../templates-BgRTZc5c.js';
|
|
3
|
-
import {
|
|
4
|
-
export { c as createTaskLayoutHelper, a as createTaskLayoutHelperFrom, t as taskLayoutHelperToJSON } from '../tasks-BDFAJ6Oi.js';
|
|
3
|
+
import { b as TaskBodyLayout } from '../types-DP1QhOKe.js';
|
|
5
4
|
import { AnyFigureHelper } from './figures.js';
|
|
6
5
|
import '../types-DcoMmjs3.js';
|
|
7
|
-
import '../types-C4AhJDkW.js';
|
|
8
6
|
import '../namespaces.js';
|
|
9
7
|
import './aggregations.js';
|
|
10
8
|
|
|
9
|
+
interface TaskLayoutHelper extends LayoutHelper {
|
|
10
|
+
at: number;
|
|
11
|
+
}
|
|
12
|
+
declare function createTaskLayoutHelper(figures: AnyFigureHelper[], at: number): TaskLayoutHelper;
|
|
13
|
+
declare function createTaskLayoutHelperFrom(layout: TaskBodyLayout): TaskLayoutHelper;
|
|
14
|
+
declare function taskLayoutHelperToJSON(layout: TaskLayoutHelper): TaskBodyLayout;
|
|
15
|
+
|
|
11
16
|
type AnyLayoutHelper = LayoutHelper | TaskLayoutHelper;
|
|
12
17
|
declare function isTaskLayoutHelper(layout: AnyLayoutHelper): layout is TaskLayoutHelper;
|
|
13
18
|
declare function isTemplateLayoutHelper(layout: AnyLayoutHelper): layout is LayoutHelper;
|
|
@@ -16,4 +21,4 @@ declare function addFigureOfHelper(layout: AnyLayoutHelper, figure: AnyFigureHel
|
|
|
16
21
|
declare function removeFigureOfHelper(layout: AnyLayoutHelper, figure: AnyFigureHelper): AnyLayoutHelper;
|
|
17
22
|
declare function updateFigureOfHelper(layout: AnyLayoutHelper, oldFigure: AnyFigureHelper, newFigure: AnyFigureHelper): AnyLayoutHelper;
|
|
18
23
|
|
|
19
|
-
export { type AnyLayoutHelper, LayoutHelper, TaskLayoutHelper, addFigureOfHelper, hasLayoutHelperChanged, isTaskLayoutHelper, isTemplateLayoutHelper, removeFigureOfHelper, updateFigureOfHelper };
|
|
24
|
+
export { type AnyLayoutHelper, LayoutHelper, type TaskLayoutHelper, addFigureOfHelper, createTaskLayoutHelper, createTaskLayoutHelperFrom, hasLayoutHelperChanged, isTaskLayoutHelper, isTemplateLayoutHelper, removeFigureOfHelper, taskLayoutHelperToJSON, updateFigureOfHelper };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var u=(s,i,e)=>new Promise((c,o)=>{var d=t=>{try{a(e.next(t))}catch(n){o(n)}},g=t=>{try{a(e.throw(t))}catch(n){o(n)}},a=t=>t.done?c(t.value):Promise.resolve(t.value).then(d,g);a((e=e.apply(s,i)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../methods-
|
|
1
|
+
"use strict";var u=(s,i,e)=>new Promise((c,o)=>{var d=t=>{try{a(e.next(t))}catch(n){o(n)}},g=t=>{try{a(e.throw(t))}catch(n){o(n)}},a=t=>t.done?c(t.value):Promise.resolve(t.value).then(d,g);a((e=e.apply(s,i)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../methods-ChKQbOFl.js"),l=require("../decorator-C2gcn2rK.js");function p(s,i){return u(this,null,function*(){let e=s;return typeof e=="string"&&(e=yield r.getTaskPreset(s)),yield r.upsertTaskPreset({id:e.id,name:e.name,templateId:e.templateId,recurrence:e.recurrence,fetchOptions:e.fetchOptions,hidden:i})})}l.assignDependencies(p,[r.getTaskPreset,r.upsertTaskPreset]);exports.changeTaskPresetVisibility=p;
|
|
2
2
|
//# sourceMappingURL=task-presets.js.map
|
|
@@ -14,7 +14,7 @@ var p = (s, a, e) => new Promise((n, c) => {
|
|
|
14
14
|
}, r = (t) => t.done ? n(t.value) : Promise.resolve(t.value).then(f, u);
|
|
15
15
|
r((e = e.apply(s, a)).next());
|
|
16
16
|
});
|
|
17
|
-
import { a as o, u as m } from "../methods-
|
|
17
|
+
import { a as o, u as m } from "../methods-jKz01wri.mjs";
|
|
18
18
|
import { b as d } from "../decorator-DBkj--6g.mjs";
|
|
19
19
|
function g(s, a) {
|
|
20
20
|
return p(this, null, function* () {
|
package/dist/helpers/tasks.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { a as TaskRecurrence, L as LastExtended,
|
|
2
|
-
import { T as TemplateBodyHelper } from '../body-
|
|
3
|
-
import {
|
|
1
|
+
import { T as Task, a as TaskRecurrence, L as LastExtended, I as InputTask } from '../types-DP1QhOKe.js';
|
|
2
|
+
import { T as TemplateBodyHelper } from '../body-ADynkNh0.js';
|
|
3
|
+
import { TaskLayoutHelper, AnyLayoutHelper } from './layouts.js';
|
|
4
4
|
import { c as TemplateFilter } from '../types-DcoMmjs3.js';
|
|
5
|
-
import { T as TaskLayoutHelper } from '../tasks-BDFAJ6Oi.js';
|
|
6
5
|
import '../namespaces.js';
|
|
6
|
+
import '../templates-BgRTZc5c.js';
|
|
7
7
|
import './figures.js';
|
|
8
8
|
import './aggregations.js';
|
|
9
9
|
|
|
@@ -14,6 +14,8 @@ interface TaskBodyHelper {
|
|
|
14
14
|
dateField?: string;
|
|
15
15
|
inserts: TaskLayoutHelper[];
|
|
16
16
|
}
|
|
17
|
+
declare function createTaskBodyHelper(index?: string, dateField?: string, inserts?: TaskLayoutHelper[], filters?: TemplateFilter[]): TaskBodyHelper;
|
|
18
|
+
declare function createTaskBodyHelperFrom(template: Task['template']): TaskBodyHelper;
|
|
17
19
|
declare function addLayoutOfHelper(body: TaskBodyHelper, layout: TaskLayoutHelper): TaskBodyHelper;
|
|
18
20
|
declare function removeLayoutOfHelper(body: TaskBodyHelper, layout: TaskLayoutHelper): TaskBodyHelper;
|
|
19
21
|
declare function updateLayoutOfHelper(body: TaskBodyHelper, oldLayout: TaskLayoutHelper, newLayout: TaskLayoutHelper): TaskBodyHelper;
|
|
@@ -37,12 +39,22 @@ interface TaskHelper {
|
|
|
37
39
|
}
|
|
38
40
|
declare function createTaskHelper(name?: string, description?: string, namespaceId?: string, extendedId?: string, template?: TaskBodyHelper, targets?: string[], recurrence?: TaskRecurrence, nextRun?: Date, enabled?: boolean, lastExtended?: LastExtended, lastRun?: Date, id?: string, createdAt?: Date, updatedAt?: Date): TaskHelper;
|
|
39
41
|
declare function createTaskHelperFrom(task: Task): TaskHelper;
|
|
40
|
-
declare function taskHelperToJSON(task: TaskHelper):
|
|
42
|
+
declare function taskHelperToJSON(task: TaskHelper): InputTask;
|
|
41
43
|
declare function hasTaskChanged(task: TaskHelper): boolean;
|
|
42
|
-
declare function getLayoutsOfHelpers(taskBody: TaskBodyHelper, templateBody: TemplateBodyHelper): (
|
|
44
|
+
declare function getLayoutsOfHelpers(taskBody: TaskBodyHelper, templateBody: TemplateBodyHelper): (AnyLayoutHelper & {
|
|
43
45
|
readonly: boolean;
|
|
44
46
|
})[];
|
|
45
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Calculate next run date for the task
|
|
50
|
+
*
|
|
51
|
+
* @param initial Initial date of the task
|
|
52
|
+
* @param recurrence The task recurrence
|
|
53
|
+
*
|
|
54
|
+
* @returns The new date of the task
|
|
55
|
+
*/
|
|
56
|
+
declare function calcNextDateFromRecurrence(initial: Date, recurrence: TaskRecurrence): Date;
|
|
57
|
+
|
|
46
58
|
/**
|
|
47
59
|
* Change enable state of a task
|
|
48
60
|
*
|
|
@@ -53,4 +65,4 @@ declare function getLayoutsOfHelpers(taskBody: TaskBodyHelper, templateBody: Tem
|
|
|
53
65
|
*/
|
|
54
66
|
declare function changeTaskEnableState(taskOrId: Omit<Task, 'template'> | string, enabled: boolean): Promise<Task>;
|
|
55
67
|
|
|
56
|
-
export { type TaskBodyHelper, type TaskHelper, addLayoutOfHelper, changeTaskEnableState, createTaskHelper, createTaskHelperFrom, getLayoutsOfHelpers, hasTaskChanged, removeLayoutOfHelper, taskHelperToJSON, updateLayoutOfHelper };
|
|
68
|
+
export { type TaskBodyHelper, type TaskHelper, addLayoutOfHelper, calcNextDateFromRecurrence, changeTaskEnableState, createTaskBodyHelper, createTaskBodyHelperFrom, createTaskHelper, createTaskHelperFrom, getLayoutsOfHelpers, hasTaskChanged, removeLayoutOfHelper, taskHelperToJSON, updateLayoutOfHelper };
|
package/dist/helpers/tasks.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var A=Object.defineProperty,S=Object.defineProperties;var D=Object.getOwnPropertyDescriptors;var u=Object.getOwnPropertySymbols;var h=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var x=(e,n,r)=>n in e?A(e,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[n]=r,f=(e,n)=>{for(var r in n||(n={}))h.call(n,r)&&x(e,r,n[r]);if(u)for(var r of u(n))H.call(n,r)&&x(e,r,n[r]);return e},m=(e,n)=>S(e,D(n));var y=(e,n)=>{var r={};for(var t in e)h.call(e,t)&&n.indexOf(t)<0&&(r[t]=e[t]);if(e!=null&&u)for(var t of u(e))n.indexOf(t)<0&&H.call(e,t)&&(r[t]=e[t]);return r};var g=(e,n,r)=>new Promise((t,a)=>{var s=d=>{try{c(r.next(d))}catch(i){a(i)}},o=d=>{try{c(r.throw(d))}catch(i){a(i)}},c=d=>d.done?t(d.value):Promise.resolve(d.value).then(s,o);c((r=r.apply(e,n)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Y=require("../decorator-C2gcn2rK.js"),l=require("../methods-DC2Gjy1i.js"),B=require("object-hash"),q=require("date-fns"),L=require("../tasks-hn70eL7B.js");function I(e,n){const r={};switch(n){case"DAILY":r.days=1;break;case"WEEKLY":r.weeks=1;break;case"MONTHLY":r.months=1;break;case"QUARTERLY":r.months=3;break;case"BIENNIAL":r.months=6;break;case"YEARLY":r.years=1;break;default:throw new Error("Recurrence not found")}return q.add(e,r)}function T(e="",n="",r=[],t=[]){var a;return{version:2,dateField:n,inserts:r,filters:new Map((a=t==null?void 0:t.map(s=>[s.name,s]))!=null?a:[]),index:e}}function E(e){var n,r;return T(e.index,e.dateField,(r=(n=e.inserts)==null?void 0:n.map(t=>L.createTaskLayoutHelperFrom(t)))!=null?r:[],e.filters)}function J(e){return{version:e.version,index:e.index,inserts:e.inserts.map(n=>L.taskLayoutHelperToJSON(n)),dateField:e.dateField,filters:Array.from(e.filters.values())}}function k(e,n){if(e.inserts.some(r=>r.id===n.id))throw new Error(`Layout "${n.id}" already exists`);return e.inserts.splice(n.at,0,n),e}function M(e,n){const r=e;return r.inserts=e.inserts.filter(t=>t.id!==n.id),e}function j(e,n,r){const t=e.inserts.findIndex(s=>s.id===n.id);if(t<0)throw new Error(`Layout "${n.id}" not found`);const a=e;return a.inserts[t]=r,e}function O(e){return B({name:e.name,description:e.description,extendedId:e.extendedId,template:e.template,targets:e.targets,recurrence:e.recurrence,nextRun:e.nextRun,enabled:e.enabled})}function w(e="",n="",r="",t="",a,s=[],o="DAILY",c,d=!0,i,F,R="",N=new Date,v){const p={id:R,name:e,description:n,namespaceId:r,extendedId:t,template:a!=null?a:T(),targets:s,recurrence:o,nextRun:c!=null?c:I(new Date,o),enabled:d,lastExtended:i,lastRun:F,createdAt:N,updatedAt:v,hash:""};return p.hash=O(p),p}function C(e){var n;return w(e.name,e.description,e.namespaceId,e.extendedId,E(e.template),e.targets,e.recurrence,e.nextRun,e.enabled,(n=e.lastExtended)!=null?n:void 0,e.lastRun,e.id,e.createdAt,e.updatedAt)}function $(e){return{name:e.name,description:e.description,namespaceId:e.namespaceId,extendedId:e.extendedId,template:J(e.template),targets:e.targets,recurrence:e.recurrence,nextRun:e.nextRun,enabled:e.enabled,lastExtended:e.lastExtended}}function K(e){return e.hash!==O(e)}function P(e,n){const r=n.layouts.map(s=>m(f({},s),{readonly:!0}));for(const t of e.inserts){const a=t,{at:s}=a,o=y(a,["at"]);r.splice(s,0,m(f({},o),{readonly:!1}))}return r}function b(e,n){return g(this,null,function*(){const r=yield l.getTask(e);return yield l.upsertTask({id:r.id,name:r.name,description:r.description,extendedId:r.extendedId,namespaceId:r.namespaceId,nextRun:r.nextRun,recurrence:r.recurrence,targets:r.targets,template:r.template,lastExtended:r.lastExtended,enabled:n})})}Y.assignDependencies(b,[l.getTask,l.upsertTask]);exports.addLayoutOfHelper=k;exports.calcNextDateFromRecurrence=I;exports.changeTaskEnableState=b;exports.createTaskBodyHelper=T;exports.createTaskBodyHelperFrom=E;exports.createTaskHelper=w;exports.createTaskHelperFrom=C;exports.getLayoutsOfHelpers=P;exports.hasTaskChanged=K;exports.removeLayoutOfHelper=M;exports.taskHelperToJSON=$;exports.updateLayoutOfHelper=j;
|
|
2
2
|
//# sourceMappingURL=tasks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tasks.js","sources":["../../src/helpers/tasks/editor/body.ts","../../src/helpers/tasks/editor/index.ts","../../src/helpers/tasks/index.ts"],"sourcesContent":["import type { TemplateFilter } from '~/modules/templates';\nimport type { Task } from '~/modules/tasks';\n\nimport {\n createTaskLayoutHelperFrom,\n taskLayoutHelperToJSON,\n type TaskLayoutHelper,\n} from '../../templates/editor/layouts';\n\nexport interface TaskBodyHelper {\n readonly version: number;\n filters: Map<string, TemplateFilter>;\n index: string;\n dateField?: string;\n inserts: TaskLayoutHelper[];\n}\n\nexport function createTaskBodyHelper(\n index: string = '',\n dateField: string = '',\n inserts: TaskLayoutHelper[] = [],\n filters: TemplateFilter[] = [],\n): TaskBodyHelper {\n return {\n version: 2,\n dateField,\n inserts,\n filters: new Map(filters?.map((filter) => [filter.name, filter]) ?? []),\n index,\n };\n}\n\nexport function createTaskBodyHelperFrom(template: Task['template']): TaskBodyHelper {\n return createTaskBodyHelper(\n template.index,\n template.dateField,\n template.inserts.map((l) => createTaskLayoutHelperFrom(l)),\n template.filters,\n );\n}\n\nexport function taskBodyHelperToJSON(template: TaskBodyHelper): Task['template'] {\n return {\n version: template.version,\n index: template.index,\n inserts: template.inserts.map((l) => taskLayoutHelperToJSON(l)),\n dateField: template.dateField,\n filters: Array.from(template.filters.values()),\n };\n}\n\nexport function addLayoutOfHelper(\n body: TaskBodyHelper,\n layout: TaskLayoutHelper,\n): TaskBodyHelper {\n if (body.inserts.some((l) => l.id === layout.id)) {\n throw new Error(`Layout \"${layout.id}\" already exists`);\n }\n body.inserts.splice(layout.at, 0, layout);\n return body;\n}\n\nexport function removeLayoutOfHelper(\n body: TaskBodyHelper,\n layout: TaskLayoutHelper,\n): TaskBodyHelper {\n const template = body;\n template.inserts = body.inserts.filter((l) => l.id !== layout.id);\n return body;\n}\n\nexport function updateLayoutOfHelper(\n body: TaskBodyHelper,\n oldLayout: TaskLayoutHelper,\n newLayout: TaskLayoutHelper,\n): TaskBodyHelper {\n const index = body.inserts.findIndex((l) => l.id === oldLayout.id);\n if (index < 0) {\n throw new Error(`Layout \"${oldLayout.id}\" not found`);\n }\n const template = body;\n template.inserts[index] = newLayout;\n return body;\n}\n","import objectHash from 'object-hash';\n\nimport type { Task } from '~/modules/tasks';\nimport type { LastExtended, TaskRecurrence } from '~/modules/tasks/types';\n\nimport type { TemplateBodyHelper } from '../../templates/editor/body';\nimport type { LayoutHelper } from '../../templates/editor/layouts';\nimport {\n createTaskBodyHelper,\n createTaskBodyHelperFrom,\n taskBodyHelperToJSON,\n type TaskBodyHelper,\n} from './body';\n\nexport interface TaskHelper {\n readonly id: string;\n name: string;\n description: string;\n namespaceId: string;\n extendedId: string;\n template: TaskBodyHelper;\n targets: string[];\n recurrence: TaskRecurrence;\n nextRun: Date;\n enabled: boolean;\n readonly lastExtended?: LastExtended | null;\n readonly lastRun?: Date;\n readonly createdAt: Date;\n readonly updatedAt?: Date;\n readonly hash: string;\n}\n\nfunction hashTask(task: TaskHelper | Task): string {\n return objectHash({\n name: task.name,\n extendedId: task.extendedId,\n template: task.template,\n targets: task.targets,\n recurrence: task.recurrence,\n nextRun: task.nextRun,\n enabled: task.enabled,\n });\n}\n\nexport function createTaskHelper(\n name: string = '',\n description: string = '',\n namespaceId: string = '',\n extendedId: string = '',\n template?: TaskBodyHelper,\n targets: string[] = [],\n recurrence: TaskRecurrence = 'DAILY',\n nextRun?: Date,\n enabled: boolean = true,\n lastExtended?: LastExtended,\n lastRun?: Date,\n id: string = '',\n createdAt: Date = new Date(),\n updatedAt?: Date,\n): TaskHelper {\n const task = {\n id,\n name,\n description,\n namespaceId,\n extendedId,\n template: template ?? createTaskBodyHelper(),\n targets,\n recurrence,\n nextRun: nextRun ?? new Date(), // TODO: recurrence\n enabled,\n lastExtended,\n lastRun,\n createdAt,\n updatedAt,\n hash: '',\n };\n\n task.hash = hashTask(task);\n\n return task;\n}\n\nexport function createTaskHelperFrom(task: Task): TaskHelper {\n return createTaskHelper(\n task.name,\n task.description,\n task.namespaceId,\n task.extendedId,\n createTaskBodyHelperFrom(task.template),\n task.targets,\n task.recurrence,\n task.nextRun,\n task.enabled,\n task.lastExtended ?? undefined,\n task.lastRun,\n task.id,\n task.createdAt,\n task.updatedAt,\n );\n}\n\nexport function taskHelperToJSON(task: TaskHelper): Task {\n return {\n id: task.id,\n name: task.name,\n description: task.description,\n namespaceId: task.namespaceId,\n extendedId: task.extendedId,\n template: taskBodyHelperToJSON(task.template),\n targets: task.targets,\n recurrence: task.recurrence,\n nextRun: task.nextRun,\n enabled: task.enabled,\n lastExtended: task.lastExtended,\n lastRun: task.lastRun,\n createdAt: task.createdAt,\n updatedAt: task.updatedAt,\n };\n}\n\nexport function hasTaskChanged(task: TaskHelper): boolean {\n return task.hash !== hashTask(task);\n}\n\nexport function getLayoutsOfHelpers(\n taskBody: TaskBodyHelper,\n templateBody: TemplateBodyHelper,\n): (LayoutHelper & { readonly: boolean })[] {\n const layouts = templateBody.layouts.map((l) => ({ ...l, readonly: true }));\n // eslint-disable-next-line no-restricted-syntax\n for (const { at, ...layout } of taskBody.inserts) {\n layouts.splice(at, 0, { ...layout, readonly: false });\n }\n return layouts;\n}\n\nexport {\n type TaskBodyHelper,\n addLayoutOfHelper,\n removeLayoutOfHelper,\n updateLayoutOfHelper,\n} from './body';\n","import { assignDependencies } from '~/helpers/permissions/decorator';\n\nimport { getTask, upsertTask, type Task } from '~/modules/tasks';\n\nexport * from './editor';\n\n/**\n * Change enable state of a task\n *\n * @param taskOrId Task or Task's id\n * @param enabled New state\n *\n * @returns Updated task\n */\n// eslint-disable-next-line import/prefer-default-export\nexport async function changeTaskEnableState(\n taskOrId: Omit<Task, 'template'> | string,\n enabled: boolean,\n): Promise<Task> {\n const base = await getTask(taskOrId);\n\n const task = await upsertTask({\n id: base.id,\n name: base.name,\n description: base.description,\n extendedId: base.extendedId,\n namespaceId: base.namespaceId,\n nextRun: base.nextRun,\n recurrence: base.recurrence,\n targets: base.targets,\n template: base.template,\n lastExtended: base.lastExtended,\n enabled,\n });\n\n return task;\n}\nassignDependencies(changeTaskEnableState, [getTask, upsertTask]);\n"],"names":["createTaskBodyHelper","index","dateField","inserts","filters","_a","filter","createTaskBodyHelperFrom","template","l","createTaskLayoutHelperFrom","taskBodyHelperToJSON","taskLayoutHelperToJSON","addLayoutOfHelper","body","layout","removeLayoutOfHelper","updateLayoutOfHelper","oldLayout","newLayout","hashTask","task","objectHash","createTaskHelper","name","description","namespaceId","extendedId","targets","recurrence","nextRun","enabled","lastExtended","lastRun","id","createdAt","updatedAt","createTaskHelperFrom","taskHelperToJSON","hasTaskChanged","getLayoutsOfHelpers","taskBody","templateBody","layouts","__spreadProps","__spreadValues","_b","at","__objRest","changeTaskEnableState","taskOrId","__async","base","getTask","upsertTask","assignDependencies"],"mappings":"u/BAiBgB,SAAAA,EACdC,EAAgB,GAChBC,EAAoB,GACpBC,EAA8B,CAAA,EAC9BC,EAA4B,GACZ,OACT,MAAA,CACL,QAAS,EACT,UAAAF,EACA,QAAAC,EACA,QAAS,IAAI,KAAIE,EAAAD,GAAA,YAAAA,EAAS,IAAKE,GAAW,CAACA,EAAO,KAAMA,CAAM,KAA7C,KAAAD,EAAmD,CAAA,CAAE,EACtE,MAAAJ,CACF,CACF,CAEO,SAASM,EAAyBC,EAA4C,CAC5E,OAAAR,EACLQ,EAAS,MACTA,EAAS,UACTA,EAAS,QAAQ,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AAAzC,EAAa,IAAA0C,GAAbD,EAAoB/B,EAAAiC,EAApBF,EAAoB,CAAP,OACHH,EAAA,OAAOI,EAAI,EAAGH,EAAAC,EAAA,GAAK9B,GAAL,CAAa,SAAU,IAAO,EAE/C,OAAA4B,CACT,CCxHsB,SAAAM,EACpBC,EACAnB,EACe,QAAAoB,EAAA,sBACT,MAAAC,EAAO,MAAMC,EAAA,QAAQH,CAAQ,EAgB5B,OAdM,MAAMI,aAAW,CAC5B,GAAIF,EAAK,GACT,KAAMA,EAAK,KACX,YAAaA,EAAK,YAClB,WAAYA,EAAK,WACjB,YAAaA,EAAK,YAClB,QAASA,EAAK,QACd,WAAYA,EAAK,WACjB,QAASA,EAAK,QACd,SAAUA,EAAK,SACf,aAAcA,EAAK,aACnB,QAAArB,CAAA,CACD,CAGH,GACAwB,EAAA,mBAAmBN,EAAuB,CAACI,UAASC,EAAAA,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"tasks.js","sources":["../../src/helpers/tasks/recurrence.ts","../../src/helpers/tasks/editor/body.ts","../../src/helpers/tasks/editor/index.ts","../../src/helpers/tasks/index.ts"],"sourcesContent":["import { add, type Duration } from 'date-fns';\nimport type { TaskRecurrence } from '~/modules/tasks';\n\n/**\n * Calculate next run date for the task\n *\n * @param initial Initial date of the task\n * @param recurrence The task recurrence\n *\n * @returns The new date of the task\n */\n// eslint-disable-next-line import/prefer-default-export\nexport function calcNextDateFromRecurrence(initial: Date, recurrence: TaskRecurrence): Date {\n const duration: Duration = {};\n\n switch (recurrence) {\n case 'DAILY':\n duration.days = 1;\n break;\n case 'WEEKLY':\n duration.weeks = 1;\n break;\n case 'MONTHLY':\n duration.months = 1;\n break;\n case 'QUARTERLY':\n duration.months = 3;\n break;\n case 'BIENNIAL':\n duration.months = 6;\n break;\n case 'YEARLY':\n duration.years = 1;\n break;\n default:\n throw new Error('Recurrence not found');\n }\n\n return add(initial, duration);\n}\n","import type { TemplateFilter } from '~/modules/templates';\nimport type { Task } from '~/modules/tasks';\n\nimport {\n createTaskLayoutHelperFrom,\n taskLayoutHelperToJSON,\n type TaskLayoutHelper,\n} from '../../templates/editor/layouts';\n\nexport interface TaskBodyHelper {\n readonly version: number;\n filters: Map<string, TemplateFilter>;\n index: string;\n dateField?: string;\n inserts: TaskLayoutHelper[];\n}\n\nexport function createTaskBodyHelper(\n index: string = '',\n dateField: string = '',\n inserts: TaskLayoutHelper[] = [],\n filters: TemplateFilter[] = [],\n): TaskBodyHelper {\n return {\n version: 2,\n dateField,\n inserts,\n filters: new Map(filters?.map((filter) => [filter.name, filter]) ?? []),\n index,\n };\n}\n\nexport function createTaskBodyHelperFrom(template: Task['template']): TaskBodyHelper {\n return createTaskBodyHelper(\n template.index,\n template.dateField,\n template.inserts?.map((l) => createTaskLayoutHelperFrom(l)) ?? [],\n template.filters,\n );\n}\n\nexport function taskBodyHelperToJSON(template: TaskBodyHelper): Task['template'] {\n return {\n version: template.version,\n index: template.index,\n inserts: template.inserts.map((l) => taskLayoutHelperToJSON(l)),\n dateField: template.dateField,\n filters: Array.from(template.filters.values()),\n };\n}\n\nexport function addLayoutOfHelper(\n body: TaskBodyHelper,\n layout: TaskLayoutHelper,\n): TaskBodyHelper {\n if (body.inserts.some((l) => l.id === layout.id)) {\n throw new Error(`Layout \"${layout.id}\" already exists`);\n }\n body.inserts.splice(layout.at, 0, layout);\n return body;\n}\n\nexport function removeLayoutOfHelper(\n body: TaskBodyHelper,\n layout: TaskLayoutHelper,\n): TaskBodyHelper {\n const template = body;\n template.inserts = body.inserts.filter((l) => l.id !== layout.id);\n return body;\n}\n\nexport function updateLayoutOfHelper(\n body: TaskBodyHelper,\n oldLayout: TaskLayoutHelper,\n newLayout: TaskLayoutHelper,\n): TaskBodyHelper {\n const index = body.inserts.findIndex((l) => l.id === oldLayout.id);\n if (index < 0) {\n throw new Error(`Layout \"${oldLayout.id}\" not found`);\n }\n const template = body;\n template.inserts[index] = newLayout;\n return body;\n}\n","import objectHash from 'object-hash';\n\nimport type { Task } from '~/modules/tasks';\nimport type { InputTask, LastExtended, TaskRecurrence } from '~/modules/tasks/types';\n\nimport type { TemplateBodyHelper } from '../../templates/editor/body';\nimport type { AnyLayoutHelper } from '../../templates/editor/layouts';\nimport { calcNextDateFromRecurrence } from '../recurrence';\nimport {\n createTaskBodyHelper,\n createTaskBodyHelperFrom,\n taskBodyHelperToJSON,\n type TaskBodyHelper,\n} from './body';\n\nexport interface TaskHelper {\n readonly id: string;\n name: string;\n description: string;\n namespaceId: string;\n extendedId: string;\n template: TaskBodyHelper;\n targets: string[];\n recurrence: TaskRecurrence;\n nextRun: Date;\n enabled: boolean;\n readonly lastExtended?: LastExtended | null;\n readonly lastRun?: Date;\n readonly createdAt: Date;\n readonly updatedAt?: Date;\n readonly hash: string;\n}\n\nfunction hashTask(task: TaskHelper | Task): string {\n return objectHash({\n name: task.name,\n description: task.description,\n extendedId: task.extendedId,\n template: task.template,\n targets: task.targets,\n recurrence: task.recurrence,\n nextRun: task.nextRun,\n enabled: task.enabled,\n });\n}\n\nexport function createTaskHelper(\n name: string = '',\n description: string = '',\n namespaceId: string = '',\n extendedId: string = '',\n template?: TaskBodyHelper,\n targets: string[] = [],\n recurrence: TaskRecurrence = 'DAILY',\n nextRun?: Date,\n enabled: boolean = true,\n lastExtended?: LastExtended,\n lastRun?: Date,\n id: string = '',\n createdAt: Date = new Date(),\n updatedAt?: Date,\n): TaskHelper {\n const task = {\n id,\n name,\n description,\n namespaceId,\n extendedId,\n template: template ?? createTaskBodyHelper(),\n targets,\n recurrence,\n nextRun: nextRun ?? calcNextDateFromRecurrence(new Date(), recurrence),\n enabled,\n lastExtended,\n lastRun,\n createdAt,\n updatedAt,\n hash: '',\n };\n\n task.hash = hashTask(task);\n\n return task;\n}\n\nexport function createTaskHelperFrom(task: Task): TaskHelper {\n return createTaskHelper(\n task.name,\n task.description,\n task.namespaceId,\n task.extendedId,\n createTaskBodyHelperFrom(task.template),\n task.targets,\n task.recurrence,\n task.nextRun,\n task.enabled,\n task.lastExtended ?? undefined,\n task.lastRun,\n task.id,\n task.createdAt,\n task.updatedAt,\n );\n}\n\nexport function taskHelperToJSON(task: TaskHelper): InputTask {\n return {\n name: task.name,\n description: task.description,\n namespaceId: task.namespaceId,\n extendedId: task.extendedId,\n template: taskBodyHelperToJSON(task.template),\n targets: task.targets,\n recurrence: task.recurrence,\n nextRun: task.nextRun,\n enabled: task.enabled,\n lastExtended: task.lastExtended,\n };\n}\n\nexport function hasTaskChanged(task: TaskHelper): boolean {\n return task.hash !== hashTask(task);\n}\n\nexport function getLayoutsOfHelpers(\n taskBody: TaskBodyHelper,\n templateBody: TemplateBodyHelper,\n): (AnyLayoutHelper & { readonly: boolean })[] {\n const layouts = templateBody.layouts.map((l) => ({ ...l, readonly: true }));\n // eslint-disable-next-line no-restricted-syntax\n for (const { at, ...layout } of taskBody.inserts) {\n layouts.splice(at, 0, { ...layout, readonly: false });\n }\n return layouts;\n}\n\nexport {\n type TaskBodyHelper,\n createTaskBodyHelper,\n createTaskBodyHelperFrom,\n addLayoutOfHelper,\n removeLayoutOfHelper,\n updateLayoutOfHelper,\n} from './body';\n","import { assignDependencies } from '~/helpers/permissions/decorator';\n\nimport { getTask, upsertTask, type Task } from '~/modules/tasks';\n\nexport * from './editor';\nexport * from './recurrence';\n\n/**\n * Change enable state of a task\n *\n * @param taskOrId Task or Task's id\n * @param enabled New state\n *\n * @returns Updated task\n */\n// eslint-disable-next-line import/prefer-default-export\nexport async function changeTaskEnableState(\n taskOrId: Omit<Task, 'template'> | string,\n enabled: boolean,\n): Promise<Task> {\n const base = await getTask(taskOrId);\n\n const task = await upsertTask({\n id: base.id,\n name: base.name,\n description: base.description,\n extendedId: base.extendedId,\n namespaceId: base.namespaceId,\n nextRun: base.nextRun,\n recurrence: base.recurrence,\n targets: base.targets,\n template: base.template,\n lastExtended: base.lastExtended,\n enabled,\n });\n\n return task;\n}\nassignDependencies(changeTaskEnableState, [getTask, upsertTask]);\n"],"names":["calcNextDateFromRecurrence","initial","recurrence","duration","add","createTaskBodyHelper","index","dateField","inserts","filters","_a","filter","createTaskBodyHelperFrom","template","_b","l","createTaskLayoutHelperFrom","taskBodyHelperToJSON","taskLayoutHelperToJSON","addLayoutOfHelper","body","layout","removeLayoutOfHelper","updateLayoutOfHelper","oldLayout","newLayout","hashTask","task","objectHash","createTaskHelper","name","description","namespaceId","extendedId","targets","nextRun","enabled","lastExtended","lastRun","id","createdAt","updatedAt","createTaskHelperFrom","taskHelperToJSON","hasTaskChanged","getLayoutsOfHelpers","taskBody","templateBody","layouts","__spreadProps","__spreadValues","at","__objRest","changeTaskEnableState","taskOrId","__async","base","getTask","upsertTask","assignDependencies"],"mappings":"6gCAYgB,SAAAA,EAA2BC,EAAeC,EAAkC,CAC1F,MAAMC,EAAqB,CAAC,EAE5B,OAAQD,EAAY,CAClB,IAAK,QACHC,EAAS,KAAO,EAChB,MACF,IAAK,SACHA,EAAS,MAAQ,EACjB,MACF,IAAK,UACHA,EAAS,OAAS,EAClB,MACF,IAAK,YACHA,EAAS,OAAS,EAClB,MACF,IAAK,WACHA,EAAS,OAAS,EAClB,MACF,IAAK,SACHA,EAAS,MAAQ,EACjB,MACF,QACQ,MAAA,IAAI,MAAM,sBAAsB,CAAA,CAGnC,OAAAC,EAAA,IAAIH,EAASE,CAAQ,CAC9B,CCtBgB,SAAAE,EACdC,EAAgB,GAChBC,EAAoB,GACpBC,EAA8B,CAAA,EAC9BC,EAA4B,GACZ,OACT,MAAA,CACL,QAAS,EACT,UAAAF,EACA,QAAAC,EACA,QAAS,IAAI,KAAIE,EAAAD,GAAA,YAAAA,EAAS,IAAKE,GAAW,CAACA,EAAO,KAAMA,CAAM,KAA7C,KAAAD,EAAmD,CAAA,CAAE,EACtE,MAAAJ,CACF,CACF,CAEO,SAASM,EAAyBC,EAA4C,SAC5E,OAAAR,EACLQ,EAAS,MACTA,EAAS,WACTC,GAAAJ,EAAAG,EAAS,UAAT,YAAAH,EAAkB,IAAKK,GAAMC,6BAA2BD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EAAA+B,EAApBtC,EAAoB,CAAP,OACHkC,EAAA,OAAOG,EAAI,EAAGF,EAAAC,EAAA,GAAK7B,GAAL,CAAa,SAAU,IAAO,EAE/C,OAAA2B,CACT,CCrHsB,SAAAK,EACpBC,EACAlB,EACe,QAAAmB,EAAA,sBACT,MAAAC,EAAO,MAAMC,EAAA,QAAQH,CAAQ,EAgB5B,OAdM,MAAMI,aAAW,CAC5B,GAAIF,EAAK,GACT,KAAMA,EAAK,KACX,YAAaA,EAAK,YAClB,WAAYA,EAAK,WACjB,YAAaA,EAAK,YAClB,QAASA,EAAK,QACd,WAAYA,EAAK,WACjB,QAASA,EAAK,QACd,SAAUA,EAAK,SACf,aAAcA,EAAK,aACnB,QAAApB,CAAA,CACD,CAGH,GACAuB,EAAA,mBAAmBN,EAAuB,CAACI,UAASC,EAAAA,UAAU,CAAC"}
|
package/dist/helpers/tasks.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
var
|
|
1
|
+
var A = Object.defineProperty, O = Object.defineProperties;
|
|
2
2
|
var F = Object.getOwnPropertyDescriptors;
|
|
3
3
|
var u = Object.getOwnPropertySymbols;
|
|
4
4
|
var x = Object.prototype.hasOwnProperty, h = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var f = (e, r, n) => r in e ?
|
|
5
|
+
var f = (e, r, n) => r in e ? A(e, r, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[r] = n, m = (e, r) => {
|
|
6
6
|
for (var n in r || (r = {}))
|
|
7
7
|
x.call(r, n) && f(e, n, r[n]);
|
|
8
8
|
if (u)
|
|
9
9
|
for (var n of u(r))
|
|
10
10
|
h.call(r, n) && f(e, n, r[n]);
|
|
11
11
|
return e;
|
|
12
|
-
},
|
|
12
|
+
}, l = (e, r) => O(e, F(r));
|
|
13
13
|
var I = (e, r) => {
|
|
14
14
|
var n = {};
|
|
15
15
|
for (var t in e)
|
|
@@ -19,45 +19,73 @@ var I = (e, r) => {
|
|
|
19
19
|
r.indexOf(t) < 0 && h.call(e, t) && (n[t] = e[t]);
|
|
20
20
|
return n;
|
|
21
21
|
};
|
|
22
|
-
var
|
|
23
|
-
var
|
|
22
|
+
var T = (e, r, n) => new Promise((t, a) => {
|
|
23
|
+
var d = (s) => {
|
|
24
24
|
try {
|
|
25
|
-
|
|
25
|
+
i(n.next(s));
|
|
26
26
|
} catch (c) {
|
|
27
|
-
|
|
27
|
+
a(c);
|
|
28
28
|
}
|
|
29
|
-
}, o = (
|
|
29
|
+
}, o = (s) => {
|
|
30
30
|
try {
|
|
31
|
-
|
|
31
|
+
i(n.throw(s));
|
|
32
32
|
} catch (c) {
|
|
33
|
-
|
|
33
|
+
a(c);
|
|
34
34
|
}
|
|
35
|
-
},
|
|
36
|
-
|
|
35
|
+
}, i = (s) => s.done ? t(s.value) : Promise.resolve(s.value).then(d, o);
|
|
36
|
+
i((n = n.apply(e, r)).next());
|
|
37
37
|
});
|
|
38
|
-
import { b as
|
|
39
|
-
import { a as
|
|
40
|
-
import
|
|
41
|
-
import {
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
import { b as N } from "../decorator-DBkj--6g.mjs";
|
|
39
|
+
import { a as E, u as H } from "../methods-sTFYWEAr.mjs";
|
|
40
|
+
import Y from "object-hash";
|
|
41
|
+
import { add as v } from "date-fns";
|
|
42
|
+
import { a as D, t as B } from "../tasks-1x680qAf.mjs";
|
|
43
|
+
function S(e, r) {
|
|
44
|
+
const n = {};
|
|
45
|
+
switch (r) {
|
|
46
|
+
case "DAILY":
|
|
47
|
+
n.days = 1;
|
|
48
|
+
break;
|
|
49
|
+
case "WEEKLY":
|
|
50
|
+
n.weeks = 1;
|
|
51
|
+
break;
|
|
52
|
+
case "MONTHLY":
|
|
53
|
+
n.months = 1;
|
|
54
|
+
break;
|
|
55
|
+
case "QUARTERLY":
|
|
56
|
+
n.months = 3;
|
|
57
|
+
break;
|
|
58
|
+
case "BIENNIAL":
|
|
59
|
+
n.months = 6;
|
|
60
|
+
break;
|
|
61
|
+
case "YEARLY":
|
|
62
|
+
n.years = 1;
|
|
63
|
+
break;
|
|
64
|
+
default:
|
|
65
|
+
throw new Error("Recurrence not found");
|
|
66
|
+
}
|
|
67
|
+
return v(e, n);
|
|
68
|
+
}
|
|
69
|
+
function L(e = "", r = "", n = [], t = []) {
|
|
70
|
+
var a;
|
|
44
71
|
return {
|
|
45
72
|
version: 2,
|
|
46
73
|
dateField: r,
|
|
47
74
|
inserts: n,
|
|
48
|
-
filters: new Map((
|
|
75
|
+
filters: new Map((a = t == null ? void 0 : t.map((d) => [d.name, d])) != null ? a : []),
|
|
49
76
|
index: e
|
|
50
77
|
};
|
|
51
78
|
}
|
|
52
79
|
function J(e) {
|
|
53
|
-
|
|
80
|
+
var r, n;
|
|
81
|
+
return L(
|
|
54
82
|
e.index,
|
|
55
83
|
e.dateField,
|
|
56
|
-
e.inserts.map((
|
|
84
|
+
(n = (r = e.inserts) == null ? void 0 : r.map((t) => D(t))) != null ? n : [],
|
|
57
85
|
e.filters
|
|
58
86
|
);
|
|
59
87
|
}
|
|
60
|
-
function
|
|
88
|
+
function M(e) {
|
|
61
89
|
return {
|
|
62
90
|
version: e.version,
|
|
63
91
|
index: e.index,
|
|
@@ -66,25 +94,26 @@ function N(e) {
|
|
|
66
94
|
filters: Array.from(e.filters.values())
|
|
67
95
|
};
|
|
68
96
|
}
|
|
69
|
-
function
|
|
97
|
+
function z(e, r) {
|
|
70
98
|
if (e.inserts.some((n) => n.id === r.id))
|
|
71
99
|
throw new Error(`Layout "${r.id}" already exists`);
|
|
72
100
|
return e.inserts.splice(r.at, 0, r), e;
|
|
73
101
|
}
|
|
74
|
-
function
|
|
102
|
+
function G(e, r) {
|
|
75
103
|
const n = e;
|
|
76
104
|
return n.inserts = e.inserts.filter((t) => t.id !== r.id), e;
|
|
77
105
|
}
|
|
78
106
|
function P(e, r, n) {
|
|
79
|
-
const t = e.inserts.findIndex((
|
|
107
|
+
const t = e.inserts.findIndex((d) => d.id === r.id);
|
|
80
108
|
if (t < 0)
|
|
81
109
|
throw new Error(`Layout "${r.id}" not found`);
|
|
82
|
-
const
|
|
83
|
-
return
|
|
110
|
+
const a = e;
|
|
111
|
+
return a.inserts[t] = n, e;
|
|
84
112
|
}
|
|
85
|
-
function
|
|
86
|
-
return
|
|
113
|
+
function w(e) {
|
|
114
|
+
return Y({
|
|
87
115
|
name: e.name,
|
|
116
|
+
description: e.description,
|
|
88
117
|
extendedId: e.extendedId,
|
|
89
118
|
template: e.template,
|
|
90
119
|
targets: e.targets,
|
|
@@ -93,28 +122,27 @@ function y(e) {
|
|
|
93
122
|
enabled: e.enabled
|
|
94
123
|
});
|
|
95
124
|
}
|
|
96
|
-
function $(e = "", r = "", n = "", t = "",
|
|
125
|
+
function $(e = "", r = "", n = "", t = "", a, d = [], o = "DAILY", i, s = !0, c, g, y = "", R = /* @__PURE__ */ new Date(), b) {
|
|
97
126
|
const p = {
|
|
98
|
-
id:
|
|
127
|
+
id: y,
|
|
99
128
|
name: e,
|
|
100
129
|
description: r,
|
|
101
130
|
namespaceId: n,
|
|
102
131
|
extendedId: t,
|
|
103
|
-
template:
|
|
104
|
-
targets:
|
|
132
|
+
template: a != null ? a : L(),
|
|
133
|
+
targets: d,
|
|
105
134
|
recurrence: o,
|
|
106
|
-
nextRun:
|
|
107
|
-
|
|
108
|
-
enabled: i,
|
|
135
|
+
nextRun: i != null ? i : S(/* @__PURE__ */ new Date(), o),
|
|
136
|
+
enabled: s,
|
|
109
137
|
lastExtended: c,
|
|
110
|
-
lastRun:
|
|
111
|
-
createdAt:
|
|
112
|
-
updatedAt:
|
|
138
|
+
lastRun: g,
|
|
139
|
+
createdAt: R,
|
|
140
|
+
updatedAt: b,
|
|
113
141
|
hash: ""
|
|
114
142
|
};
|
|
115
|
-
return p.hash =
|
|
143
|
+
return p.hash = w(p), p;
|
|
116
144
|
}
|
|
117
|
-
function
|
|
145
|
+
function V(e) {
|
|
118
146
|
var r;
|
|
119
147
|
return $(
|
|
120
148
|
e.name,
|
|
@@ -133,39 +161,35 @@ function Q(e) {
|
|
|
133
161
|
e.updatedAt
|
|
134
162
|
);
|
|
135
163
|
}
|
|
136
|
-
function
|
|
164
|
+
function X(e) {
|
|
137
165
|
return {
|
|
138
|
-
id: e.id,
|
|
139
166
|
name: e.name,
|
|
140
167
|
description: e.description,
|
|
141
168
|
namespaceId: e.namespaceId,
|
|
142
169
|
extendedId: e.extendedId,
|
|
143
|
-
template:
|
|
170
|
+
template: M(e.template),
|
|
144
171
|
targets: e.targets,
|
|
145
172
|
recurrence: e.recurrence,
|
|
146
173
|
nextRun: e.nextRun,
|
|
147
174
|
enabled: e.enabled,
|
|
148
|
-
lastExtended: e.lastExtended
|
|
149
|
-
lastRun: e.lastRun,
|
|
150
|
-
createdAt: e.createdAt,
|
|
151
|
-
updatedAt: e.updatedAt
|
|
175
|
+
lastExtended: e.lastExtended
|
|
152
176
|
};
|
|
153
177
|
}
|
|
154
|
-
function
|
|
155
|
-
return e.hash !==
|
|
178
|
+
function Z(e) {
|
|
179
|
+
return e.hash !== w(e);
|
|
156
180
|
}
|
|
157
|
-
function
|
|
158
|
-
const n = r.layouts.map((
|
|
181
|
+
function _(e, r) {
|
|
182
|
+
const n = r.layouts.map((d) => l(m({}, d), { readonly: !0 }));
|
|
159
183
|
for (const t of e.inserts) {
|
|
160
|
-
const
|
|
161
|
-
n.splice(
|
|
184
|
+
const a = t, { at: d } = a, o = I(a, ["at"]);
|
|
185
|
+
n.splice(d, 0, l(m({}, o), { readonly: !1 }));
|
|
162
186
|
}
|
|
163
187
|
return n;
|
|
164
188
|
}
|
|
165
189
|
function j(e, r) {
|
|
166
|
-
return
|
|
167
|
-
const n = yield
|
|
168
|
-
return yield
|
|
190
|
+
return T(this, null, function* () {
|
|
191
|
+
const n = yield E(e);
|
|
192
|
+
return yield H({
|
|
169
193
|
id: n.id,
|
|
170
194
|
name: n.name,
|
|
171
195
|
description: n.description,
|
|
@@ -180,16 +204,19 @@ function j(e, r) {
|
|
|
180
204
|
});
|
|
181
205
|
});
|
|
182
206
|
}
|
|
183
|
-
|
|
207
|
+
N(j, [E, H]);
|
|
184
208
|
export {
|
|
185
|
-
|
|
209
|
+
z as addLayoutOfHelper,
|
|
210
|
+
S as calcNextDateFromRecurrence,
|
|
186
211
|
j as changeTaskEnableState,
|
|
212
|
+
L as createTaskBodyHelper,
|
|
213
|
+
J as createTaskBodyHelperFrom,
|
|
187
214
|
$ as createTaskHelper,
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
215
|
+
V as createTaskHelperFrom,
|
|
216
|
+
_ as getLayoutsOfHelpers,
|
|
217
|
+
Z as hasTaskChanged,
|
|
218
|
+
G as removeLayoutOfHelper,
|
|
219
|
+
X as taskHelperToJSON,
|
|
193
220
|
P as updateLayoutOfHelper
|
|
194
221
|
};
|
|
195
222
|
//# sourceMappingURL=tasks.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tasks.mjs","sources":["../../src/helpers/tasks/editor/body.ts","../../src/helpers/tasks/editor/index.ts","../../src/helpers/tasks/index.ts"],"sourcesContent":["import type { TemplateFilter } from '~/modules/templates';\nimport type { Task } from '~/modules/tasks';\n\nimport {\n createTaskLayoutHelperFrom,\n taskLayoutHelperToJSON,\n type TaskLayoutHelper,\n} from '../../templates/editor/layouts';\n\nexport interface TaskBodyHelper {\n readonly version: number;\n filters: Map<string, TemplateFilter>;\n index: string;\n dateField?: string;\n inserts: TaskLayoutHelper[];\n}\n\nexport function createTaskBodyHelper(\n index: string = '',\n dateField: string = '',\n inserts: TaskLayoutHelper[] = [],\n filters: TemplateFilter[] = [],\n): TaskBodyHelper {\n return {\n version: 2,\n dateField,\n inserts,\n filters: new Map(filters?.map((filter) => [filter.name, filter]) ?? []),\n index,\n };\n}\n\nexport function createTaskBodyHelperFrom(template: Task['template']): TaskBodyHelper {\n return createTaskBodyHelper(\n template.index,\n template.dateField,\n template.inserts.map((l) => createTaskLayoutHelperFrom(l)),\n template.filters,\n );\n}\n\nexport function taskBodyHelperToJSON(template: TaskBodyHelper): Task['template'] {\n return {\n version: template.version,\n index: template.index,\n inserts: template.inserts.map((l) => taskLayoutHelperToJSON(l)),\n dateField: template.dateField,\n filters: Array.from(template.filters.values()),\n };\n}\n\nexport function addLayoutOfHelper(\n body: TaskBodyHelper,\n layout: TaskLayoutHelper,\n): TaskBodyHelper {\n if (body.inserts.some((l) => l.id === layout.id)) {\n throw new Error(`Layout \"${layout.id}\" already exists`);\n }\n body.inserts.splice(layout.at, 0, layout);\n return body;\n}\n\nexport function removeLayoutOfHelper(\n body: TaskBodyHelper,\n layout: TaskLayoutHelper,\n): TaskBodyHelper {\n const template = body;\n template.inserts = body.inserts.filter((l) => l.id !== layout.id);\n return body;\n}\n\nexport function updateLayoutOfHelper(\n body: TaskBodyHelper,\n oldLayout: TaskLayoutHelper,\n newLayout: TaskLayoutHelper,\n): TaskBodyHelper {\n const index = body.inserts.findIndex((l) => l.id === oldLayout.id);\n if (index < 0) {\n throw new Error(`Layout \"${oldLayout.id}\" not found`);\n }\n const template = body;\n template.inserts[index] = newLayout;\n return body;\n}\n","import objectHash from 'object-hash';\n\nimport type { Task } from '~/modules/tasks';\nimport type { LastExtended, TaskRecurrence } from '~/modules/tasks/types';\n\nimport type { TemplateBodyHelper } from '../../templates/editor/body';\nimport type { LayoutHelper } from '../../templates/editor/layouts';\nimport {\n createTaskBodyHelper,\n createTaskBodyHelperFrom,\n taskBodyHelperToJSON,\n type TaskBodyHelper,\n} from './body';\n\nexport interface TaskHelper {\n readonly id: string;\n name: string;\n description: string;\n namespaceId: string;\n extendedId: string;\n template: TaskBodyHelper;\n targets: string[];\n recurrence: TaskRecurrence;\n nextRun: Date;\n enabled: boolean;\n readonly lastExtended?: LastExtended | null;\n readonly lastRun?: Date;\n readonly createdAt: Date;\n readonly updatedAt?: Date;\n readonly hash: string;\n}\n\nfunction hashTask(task: TaskHelper | Task): string {\n return objectHash({\n name: task.name,\n extendedId: task.extendedId,\n template: task.template,\n targets: task.targets,\n recurrence: task.recurrence,\n nextRun: task.nextRun,\n enabled: task.enabled,\n });\n}\n\nexport function createTaskHelper(\n name: string = '',\n description: string = '',\n namespaceId: string = '',\n extendedId: string = '',\n template?: TaskBodyHelper,\n targets: string[] = [],\n recurrence: TaskRecurrence = 'DAILY',\n nextRun?: Date,\n enabled: boolean = true,\n lastExtended?: LastExtended,\n lastRun?: Date,\n id: string = '',\n createdAt: Date = new Date(),\n updatedAt?: Date,\n): TaskHelper {\n const task = {\n id,\n name,\n description,\n namespaceId,\n extendedId,\n template: template ?? createTaskBodyHelper(),\n targets,\n recurrence,\n nextRun: nextRun ?? new Date(), // TODO: recurrence\n enabled,\n lastExtended,\n lastRun,\n createdAt,\n updatedAt,\n hash: '',\n };\n\n task.hash = hashTask(task);\n\n return task;\n}\n\nexport function createTaskHelperFrom(task: Task): TaskHelper {\n return createTaskHelper(\n task.name,\n task.description,\n task.namespaceId,\n task.extendedId,\n createTaskBodyHelperFrom(task.template),\n task.targets,\n task.recurrence,\n task.nextRun,\n task.enabled,\n task.lastExtended ?? undefined,\n task.lastRun,\n task.id,\n task.createdAt,\n task.updatedAt,\n );\n}\n\nexport function taskHelperToJSON(task: TaskHelper): Task {\n return {\n id: task.id,\n name: task.name,\n description: task.description,\n namespaceId: task.namespaceId,\n extendedId: task.extendedId,\n template: taskBodyHelperToJSON(task.template),\n targets: task.targets,\n recurrence: task.recurrence,\n nextRun: task.nextRun,\n enabled: task.enabled,\n lastExtended: task.lastExtended,\n lastRun: task.lastRun,\n createdAt: task.createdAt,\n updatedAt: task.updatedAt,\n };\n}\n\nexport function hasTaskChanged(task: TaskHelper): boolean {\n return task.hash !== hashTask(task);\n}\n\nexport function getLayoutsOfHelpers(\n taskBody: TaskBodyHelper,\n templateBody: TemplateBodyHelper,\n): (LayoutHelper & { readonly: boolean })[] {\n const layouts = templateBody.layouts.map((l) => ({ ...l, readonly: true }));\n // eslint-disable-next-line no-restricted-syntax\n for (const { at, ...layout } of taskBody.inserts) {\n layouts.splice(at, 0, { ...layout, readonly: false });\n }\n return layouts;\n}\n\nexport {\n type TaskBodyHelper,\n addLayoutOfHelper,\n removeLayoutOfHelper,\n updateLayoutOfHelper,\n} from './body';\n","import { assignDependencies } from '~/helpers/permissions/decorator';\n\nimport { getTask, upsertTask, type Task } from '~/modules/tasks';\n\nexport * from './editor';\n\n/**\n * Change enable state of a task\n *\n * @param taskOrId Task or Task's id\n * @param enabled New state\n *\n * @returns Updated task\n */\n// eslint-disable-next-line import/prefer-default-export\nexport async function changeTaskEnableState(\n taskOrId: Omit<Task, 'template'> | string,\n enabled: boolean,\n): Promise<Task> {\n const base = await getTask(taskOrId);\n\n const task = await upsertTask({\n id: base.id,\n name: base.name,\n description: base.description,\n extendedId: base.extendedId,\n namespaceId: base.namespaceId,\n nextRun: base.nextRun,\n recurrence: base.recurrence,\n targets: base.targets,\n template: base.template,\n lastExtended: base.lastExtended,\n enabled,\n });\n\n return task;\n}\nassignDependencies(changeTaskEnableState, [getTask, upsertTask]);\n"],"names":["createTaskBodyHelper","index","dateField","inserts","filters","_a","filter","createTaskBodyHelperFrom","template","l","createTaskLayoutHelperFrom","taskBodyHelperToJSON","taskLayoutHelperToJSON","addLayoutOfHelper","body","layout","removeLayoutOfHelper","updateLayoutOfHelper","oldLayout","newLayout","hashTask","task","objectHash","createTaskHelper","name","description","namespaceId","extendedId","targets","recurrence","nextRun","enabled","lastExtended","lastRun","id","createdAt","updatedAt","createTaskHelperFrom","taskHelperToJSON","hasTaskChanged","getLayoutsOfHelpers","taskBody","templateBody","layouts","__spreadProps","__spreadValues","_b","at","__objRest","changeTaskEnableState","taskOrId","__async","base","getTask","upsertTask","assignDependencies"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBgB,SAAAA,EACdC,IAAgB,IAChBC,IAAoB,IACpBC,IAA8B,CAAA,GAC9BC,IAA4B,IACZ;;AACT,SAAA;AAAA,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AAAA,MACd,UAAUA,EAAK;AAAA,MACf,cAAcA,EAAK;AAAA,MACnB,SAAArB;AAAA,IAAA,CACD;AAAA,EAGH;AAAA;AACAwB,EAAmBN,GAAuB,CAACI,GAASC,CAAU,CAAC;"}
|
|
1
|
+
{"version":3,"file":"tasks.mjs","sources":["../../src/helpers/tasks/recurrence.ts","../../src/helpers/tasks/editor/body.ts","../../src/helpers/tasks/editor/index.ts","../../src/helpers/tasks/index.ts"],"sourcesContent":["import { add, type Duration } from 'date-fns';\nimport type { TaskRecurrence } from '~/modules/tasks';\n\n/**\n * Calculate next run date for the task\n *\n * @param initial Initial date of the task\n * @param recurrence The task recurrence\n *\n * @returns The new date of the task\n */\n// eslint-disable-next-line import/prefer-default-export\nexport function calcNextDateFromRecurrence(initial: Date, recurrence: TaskRecurrence): Date {\n const duration: Duration = {};\n\n switch (recurrence) {\n case 'DAILY':\n duration.days = 1;\n break;\n case 'WEEKLY':\n duration.weeks = 1;\n break;\n case 'MONTHLY':\n duration.months = 1;\n break;\n case 'QUARTERLY':\n duration.months = 3;\n break;\n case 'BIENNIAL':\n duration.months = 6;\n break;\n case 'YEARLY':\n duration.years = 1;\n break;\n default:\n throw new Error('Recurrence not found');\n }\n\n return add(initial, duration);\n}\n","import type { TemplateFilter } from '~/modules/templates';\nimport type { Task } from '~/modules/tasks';\n\nimport {\n createTaskLayoutHelperFrom,\n taskLayoutHelperToJSON,\n type TaskLayoutHelper,\n} from '../../templates/editor/layouts';\n\nexport interface TaskBodyHelper {\n readonly version: number;\n filters: Map<string, TemplateFilter>;\n index: string;\n dateField?: string;\n inserts: TaskLayoutHelper[];\n}\n\nexport function createTaskBodyHelper(\n index: string = '',\n dateField: string = '',\n inserts: TaskLayoutHelper[] = [],\n filters: TemplateFilter[] = [],\n): TaskBodyHelper {\n return {\n version: 2,\n dateField,\n inserts,\n filters: new Map(filters?.map((filter) => [filter.name, filter]) ?? []),\n index,\n };\n}\n\nexport function createTaskBodyHelperFrom(template: Task['template']): TaskBodyHelper {\n return createTaskBodyHelper(\n template.index,\n template.dateField,\n template.inserts?.map((l) => createTaskLayoutHelperFrom(l)) ?? [],\n template.filters,\n );\n}\n\nexport function taskBodyHelperToJSON(template: TaskBodyHelper): Task['template'] {\n return {\n version: template.version,\n index: template.index,\n inserts: template.inserts.map((l) => taskLayoutHelperToJSON(l)),\n dateField: template.dateField,\n filters: Array.from(template.filters.values()),\n };\n}\n\nexport function addLayoutOfHelper(\n body: TaskBodyHelper,\n layout: TaskLayoutHelper,\n): TaskBodyHelper {\n if (body.inserts.some((l) => l.id === layout.id)) {\n throw new Error(`Layout \"${layout.id}\" already exists`);\n }\n body.inserts.splice(layout.at, 0, layout);\n return body;\n}\n\nexport function removeLayoutOfHelper(\n body: TaskBodyHelper,\n layout: TaskLayoutHelper,\n): TaskBodyHelper {\n const template = body;\n template.inserts = body.inserts.filter((l) => l.id !== layout.id);\n return body;\n}\n\nexport function updateLayoutOfHelper(\n body: TaskBodyHelper,\n oldLayout: TaskLayoutHelper,\n newLayout: TaskLayoutHelper,\n): TaskBodyHelper {\n const index = body.inserts.findIndex((l) => l.id === oldLayout.id);\n if (index < 0) {\n throw new Error(`Layout \"${oldLayout.id}\" not found`);\n }\n const template = body;\n template.inserts[index] = newLayout;\n return body;\n}\n","import objectHash from 'object-hash';\n\nimport type { Task } from '~/modules/tasks';\nimport type { InputTask, LastExtended, TaskRecurrence } from '~/modules/tasks/types';\n\nimport type { TemplateBodyHelper } from '../../templates/editor/body';\nimport type { AnyLayoutHelper } from '../../templates/editor/layouts';\nimport { calcNextDateFromRecurrence } from '../recurrence';\nimport {\n createTaskBodyHelper,\n createTaskBodyHelperFrom,\n taskBodyHelperToJSON,\n type TaskBodyHelper,\n} from './body';\n\nexport interface TaskHelper {\n readonly id: string;\n name: string;\n description: string;\n namespaceId: string;\n extendedId: string;\n template: TaskBodyHelper;\n targets: string[];\n recurrence: TaskRecurrence;\n nextRun: Date;\n enabled: boolean;\n readonly lastExtended?: LastExtended | null;\n readonly lastRun?: Date;\n readonly createdAt: Date;\n readonly updatedAt?: Date;\n readonly hash: string;\n}\n\nfunction hashTask(task: TaskHelper | Task): string {\n return objectHash({\n name: task.name,\n description: task.description,\n extendedId: task.extendedId,\n template: task.template,\n targets: task.targets,\n recurrence: task.recurrence,\n nextRun: task.nextRun,\n enabled: task.enabled,\n });\n}\n\nexport function createTaskHelper(\n name: string = '',\n description: string = '',\n namespaceId: string = '',\n extendedId: string = '',\n template?: TaskBodyHelper,\n targets: string[] = [],\n recurrence: TaskRecurrence = 'DAILY',\n nextRun?: Date,\n enabled: boolean = true,\n lastExtended?: LastExtended,\n lastRun?: Date,\n id: string = '',\n createdAt: Date = new Date(),\n updatedAt?: Date,\n): TaskHelper {\n const task = {\n id,\n name,\n description,\n namespaceId,\n extendedId,\n template: template ?? createTaskBodyHelper(),\n targets,\n recurrence,\n nextRun: nextRun ?? calcNextDateFromRecurrence(new Date(), recurrence),\n enabled,\n lastExtended,\n lastRun,\n createdAt,\n updatedAt,\n hash: '',\n };\n\n task.hash = hashTask(task);\n\n return task;\n}\n\nexport function createTaskHelperFrom(task: Task): TaskHelper {\n return createTaskHelper(\n task.name,\n task.description,\n task.namespaceId,\n task.extendedId,\n createTaskBodyHelperFrom(task.template),\n task.targets,\n task.recurrence,\n task.nextRun,\n task.enabled,\n task.lastExtended ?? undefined,\n task.lastRun,\n task.id,\n task.createdAt,\n task.updatedAt,\n );\n}\n\nexport function taskHelperToJSON(task: TaskHelper): InputTask {\n return {\n name: task.name,\n description: task.description,\n namespaceId: task.namespaceId,\n extendedId: task.extendedId,\n template: taskBodyHelperToJSON(task.template),\n targets: task.targets,\n recurrence: task.recurrence,\n nextRun: task.nextRun,\n enabled: task.enabled,\n lastExtended: task.lastExtended,\n };\n}\n\nexport function hasTaskChanged(task: TaskHelper): boolean {\n return task.hash !== hashTask(task);\n}\n\nexport function getLayoutsOfHelpers(\n taskBody: TaskBodyHelper,\n templateBody: TemplateBodyHelper,\n): (AnyLayoutHelper & { readonly: boolean })[] {\n const layouts = templateBody.layouts.map((l) => ({ ...l, readonly: true }));\n // eslint-disable-next-line no-restricted-syntax\n for (const { at, ...layout } of taskBody.inserts) {\n layouts.splice(at, 0, { ...layout, readonly: false });\n }\n return layouts;\n}\n\nexport {\n type TaskBodyHelper,\n createTaskBodyHelper,\n createTaskBodyHelperFrom,\n addLayoutOfHelper,\n removeLayoutOfHelper,\n updateLayoutOfHelper,\n} from './body';\n","import { assignDependencies } from '~/helpers/permissions/decorator';\n\nimport { getTask, upsertTask, type Task } from '~/modules/tasks';\n\nexport * from './editor';\nexport * from './recurrence';\n\n/**\n * Change enable state of a task\n *\n * @param taskOrId Task or Task's id\n * @param enabled New state\n *\n * @returns Updated task\n */\n// eslint-disable-next-line import/prefer-default-export\nexport async function changeTaskEnableState(\n taskOrId: Omit<Task, 'template'> | string,\n enabled: boolean,\n): Promise<Task> {\n const base = await getTask(taskOrId);\n\n const task = await upsertTask({\n id: base.id,\n name: base.name,\n description: base.description,\n extendedId: base.extendedId,\n namespaceId: base.namespaceId,\n nextRun: base.nextRun,\n recurrence: base.recurrence,\n targets: base.targets,\n template: base.template,\n lastExtended: base.lastExtended,\n enabled,\n });\n\n return task;\n}\nassignDependencies(changeTaskEnableState, [getTask, upsertTask]);\n"],"names":["calcNextDateFromRecurrence","initial","recurrence","duration","add","createTaskBodyHelper","index","dateField","inserts","filters","_a","filter","createTaskBodyHelperFrom","template","_b","l","createTaskLayoutHelperFrom","taskBodyHelperToJSON","taskLayoutHelperToJSON","addLayoutOfHelper","body","layout","removeLayoutOfHelper","updateLayoutOfHelper","oldLayout","newLayout","hashTask","task","objectHash","createTaskHelper","name","description","namespaceId","extendedId","targets","nextRun","enabled","lastExtended","lastRun","id","createdAt","updatedAt","createTaskHelperFrom","taskHelperToJSON","hasTaskChanged","getLayoutsOfHelpers","taskBody","templateBody","layouts","__spreadProps","__spreadValues","at","__objRest","changeTaskEnableState","taskOrId","__async","base","getTask","upsertTask","assignDependencies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