@ezpaarse-project/ezreeport-sdk-js 2.1.0-beta.1 → 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.
@@ -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-C4AhJDkW.js';
4
- import { J as Job, G as GenerationData, M as MailData, a as MailError, P as PaginatedJobs, b as JobStatus } from '../index-6ma-WCUD.js';
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
 
@@ -1,6 +1,6 @@
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 { b as TaskBodyLayout } from '../types-C4AhJDkW.js';
3
+ import { b as TaskBodyLayout } from '../types-DP1QhOKe.js';
4
4
  import { AnyFigureHelper } from './figures.js';
5
5
  import '../types-DcoMmjs3.js';
6
6
  import '../namespaces.js';
@@ -1,6 +1,6 @@
1
- import { T as TaskPreset } from '../types-BGlpjxH9.js';
1
+ import { T as TaskPreset } from '../types-DtBHOMlQ.js';
2
2
  import '../types-DcoMmjs3.js';
3
- import '../types-C4AhJDkW.js';
3
+ import '../types-DP1QhOKe.js';
4
4
  import '../namespaces.js';
5
5
 
6
6
  /**
@@ -1,4 +1,4 @@
1
- import { T as Task, a as TaskRecurrence, L as LastExtended, I as InputTask } from '../types-C4AhJDkW.js';
1
+ import { T as Task, a as TaskRecurrence, L as LastExtended, I as InputTask } from '../types-DP1QhOKe.js';
2
2
  import { T as TemplateBodyHelper } from '../body-ADynkNh0.js';
3
3
  import { TaskLayoutHelper, AnyLayoutHelper } from './layouts.js';
4
4
  import { c as TemplateFilter } from '../types-DcoMmjs3.js';
@@ -1,2 +1,2 @@
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){return T(e.index,e.dateField,e.inserts.map(n=>L.createTaskLayoutHelperFrom(n)),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;
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/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","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","_b","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,CAC5E,OAAAR,EACLQ,EAAS,MACTA,EAAS,UACTA,EAAS,QAAQ,IAAKC,GAAMC,EAAAA,2BAA2BD,CAAC,CAAC,EACzDD,EAAS,OACX,CACF,CAEO,SAASG,EAAqBH,EAA4C,CACxE,MAAA,CACL,QAASA,EAAS,QAClB,MAAOA,EAAS,MAChB,QAASA,EAAS,QAAQ,IAAKC,GAAMG,EAAAA,uBAAuBH,CAAC,CAAC,EA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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,CAAC,KAAzD,KAAAD,EAA+D,CAAC,EAChED,EAAS,OACX,CACF,CAEO,SAASI,EAAqBJ,EAA4C,CACxE,MAAA,CACL,QAASA,EAAS,QAClB,MAAOA,EAAS,MAChB,QAASA,EAAS,QAAQ,IAAKE,GAAMG,EAAAA,uBAAuBH,CAAC,CAAC,EAC9D,UAAWF,EAAS,UACpB,QAAS,MAAM,KAAKA,E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AAW,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"}
@@ -77,10 +77,11 @@ function L(e = "", r = "", n = [], t = []) {
77
77
  };
78
78
  }
79
79
  function J(e) {
80
+ var r, n;
80
81
  return L(
81
82
  e.index,
82
83
  e.dateField,
83
- e.inserts.map((r) => D(r)),
84
+ (n = (r = e.inserts) == null ? void 0 : r.map((t) => D(t))) != null ? n : [],
84
85
  e.filters
85
86
  );
86
87
  }
@@ -1 +1 @@
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","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","_b","at","__objRest","changeTaskEnableState","taskOrId","__async","base","getTask","upsertTask","assignDependencies"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYgB,SAAAA,EAA2BC,GAAeC,GAAkC;AAC1F,QAAMC,IAAqB,CAAC;AAE5B,UAAQD,GAAY;AAAA,IAClB,KAAK;AACH,MAAAC,EAAS,OAAO;AAChB;AAAA,IACF,KAAK;AACH,MAAAA,EAAS,QAAQ;AACjB;AAAA,IACF,KAAK;AACH,MAAAA,EAAS,SAAS;AAClB;AAAA,IACF,KAAK;AACH,MAAAA,EAAS,SAAS;AAClB;AAAA,IACF,KAAK;AACH,MAAAA,EAAS,SAAS;AAClB;AAAA,IACF,KAAK;AACH,MAAAA,EAAS,QAAQ;AACjB;AAAA,IACF;AACQ,YAAA,IAAI,MAAM,sBAAsB;AAAA,EAAA;AAGnC,SAAAC,EAAIH,GAASE,CAAQ;AAC9B;ACtBgB,SAAAE,EACdC,IAAgB,IAChBC,IAAoB,IACpBC,IAA8B,CAAA,GAC9BC,IAA4B,IACZ;;AACT,SAAA;AAAA,IACL,SAAS;AAAA,IACT,WAAAF;AAAA,IACA,SAAAC;AAAA,IACA,SAAS,IAAI,KAAIE,IAAAD,KAAA,gBAAAA,EAAS,IAAI,CAACE,MAAW,CAACA,EAAO,MAAMA,CAAM,OAA7C,OAAAD,IAAmD,CAAA,CAAE;AAAA,IACtE,OAAAJ;AAAA,EACF;AACF;AAEO,SAASM,EAAyBC,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AA,IACjB,UAAUV,EAAqBU,EAAK,QAAQ;AAAA,IAC5C,SAASA,EAAK;AAAA,IACd,YAAYA,EAAK;AAAA,IACjB,SAASA,EAAK;AAAA,IACd,SAASA,EAAK;AAAA,IACd,cAAcA,EAAK;AAAA,EACrB;AACF;AAEO,SAASiB,EAAejB,GAA2B;AACjD,SAAAA,EAAK,SAASD,EAASC,CAAI;AACpC;AAEgB,SAAAkB,EACdC,GACAC,GAC6C;AACvC,QAAAC,IAAUD,EAAa,QAAQ,IAAI,CAAChC,MAAOkC,EAAAC,EAAA,IAAKnC,IAAL,EAAQ,UAAU,GAAO,EAAA;AAE1E,aAAWJ,KAAqBmC,EAAS,SAC/B;AADV,UAAAK,IAAAxC,GAAa,MAAAyC,MAAbD,GAAoB9B,IAAAgC,EAApBF,GAAoB,CAAP;AACH,IAAAH,EAAA,OAAOI,GAAI,GAAGH,EAAAC,EAAA,IAAK7B,IAAL,EAAa,UAAU,KAAO;AAAA;AAE/C,SAAA2B;AACT;ACrHsB,SAAAM,EACpBC,GACAnB,GACe;AAAA,SAAAoB,EAAA;AACT,UAAAC,IAAO,MAAMC,EAAQH,CAAQ;AAgB5B,WAdM,MAAMI,EAAW;AAAA,MAC5B,IAAIF,EAAK;AAAA,MACT,MAAMA,EAAK;AAAA,MACX,aAAaA,EAAK;AAAA,MAClB,YAAYA,EAAK;AAAA,MACjB,aAAaA,EAAK;AAAA,MAClB,SAASA,EAAK;AAAA,MACd,YAAYA,EAAK;AAAA,MACjB,SAASA,EAAK;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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYgB,SAAAA,EAA2BC,GAAeC,GAAkC;AAC1F,QAAMC,IAAqB,CAAC;AAE5B,UAAQD,GAAY;AAAA,IAClB,KAAK;AACH,MAAAC,EAAS,OAAO;AAChB;AAAA,IACF,KAAK;AACH,MAAAA,EAAS,QAAQ;AACjB;AAAA,IACF,KAAK;AACH,MAAAA,EAAS,SAAS;AAClB;AAAA,IACF,K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AA2B;AACT;ACrHsB,SAAAK,EACpBC,GACAlB,GACe;AAAA,SAAAmB,EAAA;AACT,UAAAC,IAAO,MAAMC,EAAQH,CAAQ;AAgB5B,WAdM,MAAMI,EAAW;AAAA,MAC5B,IAAIF,EAAK;AAAA,MACT,MAAMA,EAAK;AAAA,MACX,aAAaA,EAAK;AAAA,MAClB,YAAYA,EAAK;AAAA,MACjB,aAAaA,EAAK;AAAA,MAClB,SAASA,EAAK;AAAA,MACd,YAAYA,EAAK;AAAA,MACjB,SAASA,EAAK;AAAA,MACd,UAAUA,EAAK;AAAA,MACf,cAAcA,EAAK;AAAA,MACnB,SAAApB;AAAA,IAAA,CACD;AAAA,EAGH;AAAA;AACAuB,EAAmBN,GAAuB,CAACI,GAASC,CAAU,CAAC;"}
@@ -1,6 +1,6 @@
1
1
  import { A as ApiRequestOptions, S as SdkPaginated } from './api-C_g0ldUn.js';
2
2
  import { c as ReportPeriod } from './types-jXqGnCKQ.js';
3
- import { T as Task } from './types-C4AhJDkW.js';
3
+ import { T as Task } from './types-DP1QhOKe.js';
4
4
 
5
5
  interface GenerationData {
6
6
  task: Omit<Task, 'namespace' | 'extends'>;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { A as ApiRequestOptions, S as SdkPaginated } from './api-C_g0ldUn.js';
2
2
 
3
- var version = "2.1.0-beta.1";
3
+ var version = "2.1.0-beta.2";
4
4
 
5
5
  type ApiAuthOptions = {
6
6
  token?: string;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./fetch-Hd-ajPIl.js"),r="2.1.0-beta.1";exports.prepareClient=e.prepareClient;exports.version=r;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./fetch-Hd-ajPIl.js"),r="2.1.0-beta.2";exports.prepareClient=e.prepareClient;exports.version=r;
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { p } from "./fetch-xZFTa3q1.mjs";
2
- const e = "2.1.0-beta.1";
2
+ const e = "2.1.0-beta.2";
3
3
  export {
4
4
  p as prepareClient,
5
5
  e as version
package/dist/queues.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export { G as GenerationData, I as InputQueue, J as Job, b as JobStatus, M as MailData, a as MailError, Q as Queue, g as getAllQueues, d as getJob, c as getQueue, e as getQueueJobs, r as retryJob, u as updateQueue } from './index-6ma-WCUD.js';
1
+ export { G as GenerationData, I as InputQueue, J as Job, b as JobStatus, M as MailData, a as MailError, Q as Queue, g as getAllQueues, d as getJob, c as getQueue, e as getQueueJobs, r as retryJob, u as updateQueue } from './index-DfRKlMeG.js';
2
2
  import './api-C_g0ldUn.js';
3
3
  import './types-jXqGnCKQ.js';
4
- import './types-C4AhJDkW.js';
4
+ import './types-DP1QhOKe.js';
5
5
  import './namespaces.js';
6
6
  import './types-DcoMmjs3.js';
package/dist/reports.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { T as Task } from './types-C4AhJDkW.js';
1
+ import { T as Task } from './types-DP1QhOKe.js';
2
2
  import { R as ReportResult, a as ReportFiles } from './types-jXqGnCKQ.js';
3
3
  export { e as ReportDetails, b as ReportErrorCause, c as ReportPeriod, d as ReportStats } from './types-jXqGnCKQ.js';
4
4
  import './namespaces.js';
@@ -1,5 +1,5 @@
1
1
  import { A as ApiRequestOptions, S as SdkPaginated } from './api-C_g0ldUn.js';
2
- import { T as Task } from './types-C4AhJDkW.js';
2
+ import { T as Task } from './types-DP1QhOKe.js';
3
3
  import './namespaces.js';
4
4
  import './types-DcoMmjs3.js';
5
5
 
@@ -1,6 +1,6 @@
1
1
  import { A as ApiRequestOptions, S as SdkPaginated } from './api-C_g0ldUn.js';
2
- import { T as Task } from './types-C4AhJDkW.js';
3
- import { T as TaskPreset, I as InputTaskPreset, A as AdditionalDataForPreset } from './types-BGlpjxH9.js';
2
+ import { T as Task } from './types-DP1QhOKe.js';
3
+ import { T as TaskPreset, I as InputTaskPreset, A as AdditionalDataForPreset } from './types-DtBHOMlQ.js';
4
4
  import './namespaces.js';
5
5
  import './types-DcoMmjs3.js';
6
6
 
package/dist/tasks.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { A as ApiRequestOptions, S as SdkPaginated } from './api-C_g0ldUn.js';
2
- import { T as Task, I as InputTask } from './types-C4AhJDkW.js';
3
- export { L as LastExtended, c as TaskBody, b as TaskBodyLayout, a as TaskRecurrence } from './types-C4AhJDkW.js';
2
+ import { T as Task, I as InputTask } from './types-DP1QhOKe.js';
3
+ export { L as LastExtended, c as TaskBody, b as TaskBodyLayout, a as TaskRecurrence } from './types-DP1QhOKe.js';
4
4
  import './namespaces.js';
5
5
  import './types-DcoMmjs3.js';
6
6
 
@@ -22,7 +22,7 @@ interface TaskBody {
22
22
  /** Global filters used when fetching data */
23
23
  filters?: TemplateFilter[];
24
24
  /** Layouts used when rendering data, added to the ones from the template. */
25
- inserts: TaskBodyLayout[];
25
+ inserts?: TaskBodyLayout[];
26
26
  }
27
27
  interface LastExtended {
28
28
  /** Old template ID */
@@ -1,5 +1,5 @@
1
1
  import { f as TemplateTag, c as TemplateFilter } from './types-DcoMmjs3.js';
2
- import { a as TaskRecurrence } from './types-C4AhJDkW.js';
2
+ import { a as TaskRecurrence } from './types-DP1QhOKe.js';
3
3
 
4
4
  interface TaskPreset {
5
5
  /** Preset ID */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ezpaarse-project/ezreeport-sdk-js",
3
- "version": "2.1.0-beta.1",
3
+ "version": "2.1.0-beta.2",
4
4
  "description": "JS SDK to communicate with ezReeport API",
5
5
  "homepage": "https://github.com/ezpaarse-project/ezreeport#readme",
6
6
  "bugs": {