@powerhousedao/analytics-engine-graphql 0.6.3 → 6.0.0-dev.65
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/LICENSE +1 -1
- package/dist/src/AnalyticsModel.d.ts +2 -1
- package/dist/src/AnalyticsModel.d.ts.map +1 -1
- package/dist/src/index.js +230 -16
- package/package.json +8 -11
package/LICENSE
CHANGED
|
@@ -658,4 +658,4 @@ specific requirements.
|
|
|
658
658
|
You should also get your employer (if you work as a programmer) or school,
|
|
659
659
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
|
660
660
|
For more information on this, and how to apply and follow the GNU AGPL, see
|
|
661
|
-
<https://www.gnu.org/licenses/>.
|
|
661
|
+
<https://www.gnu.org/licenses/>.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { AnalyticsQueryEngine } from "@powerhousedao/analytics-engine-core";
|
|
2
|
+
import { type AnalyticsQuery } from "@powerhousedao/analytics-engine-core";
|
|
2
3
|
export type queryFilter = {
|
|
3
4
|
start?: string;
|
|
4
5
|
end?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnalyticsModel.d.ts","sourceRoot":"","sources":["../../src/AnalyticsModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,cAAc,
|
|
1
|
+
{"version":3,"file":"AnalyticsModel.d.ts","sourceRoot":"","sources":["../../src/AnalyticsModel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EAGL,KAAK,cAAc,EACpB,MAAM,sCAAsC,CAAC;AAG9C,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,UAAU,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,kBAAkB,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,KAAK,mBAAmB,GAAG,WAAW,GAAG;IACvC,WAAW,EAAE,kBAAkB,EAAE,CAAC;CACnC,CAAC;AAEF,qBAAa,cAAc;aAIP,MAAM,EAAE,oBAAoB;IAH9C,WAAW,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;gBAG3B,MAAM,EAAE,oBAAoB,EAC5C,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI;IAKlC,KAAK,CAAC,MAAM,EAAE,WAAW;;;;;;;;;;;;IAmDzB,kBAAkB,CAAC,MAAM,EAAE,mBAAmB;IA+C9C,aAAa;IAIb,aAAa;CAI3B"}
|
package/dist/src/index.js
CHANGED
|
@@ -69,11 +69,45 @@ var AnalyticsResolvers = {
|
|
|
69
69
|
};
|
|
70
70
|
// ../core/dist/src/index.js
|
|
71
71
|
var AnalyticsSerializerTypes;
|
|
72
|
-
((AnalyticsSerializerTypes2)
|
|
72
|
+
(function(AnalyticsSerializerTypes2) {
|
|
73
73
|
AnalyticsSerializerTypes2[AnalyticsSerializerTypes2["AnalyticsPath"] = 0] = "AnalyticsPath";
|
|
74
74
|
AnalyticsSerializerTypes2[AnalyticsSerializerTypes2["AnalyticsPathSegment"] = 1] = "AnalyticsPathSegment";
|
|
75
75
|
AnalyticsSerializerTypes2[AnalyticsSerializerTypes2["AnalyticsPeriod"] = 2] = "AnalyticsPeriod";
|
|
76
|
-
})(AnalyticsSerializerTypes
|
|
76
|
+
})(AnalyticsSerializerTypes || (AnalyticsSerializerTypes = {}));
|
|
77
|
+
var AnalyticsPeriodType;
|
|
78
|
+
(function(AnalyticsPeriodType2) {
|
|
79
|
+
AnalyticsPeriodType2[AnalyticsPeriodType2["Year"] = 0] = "Year";
|
|
80
|
+
AnalyticsPeriodType2[AnalyticsPeriodType2["Quarter"] = 1] = "Quarter";
|
|
81
|
+
AnalyticsPeriodType2[AnalyticsPeriodType2["Month"] = 2] = "Month";
|
|
82
|
+
})(AnalyticsPeriodType || (AnalyticsPeriodType = {}));
|
|
83
|
+
var AnalyticsMetric;
|
|
84
|
+
(function(AnalyticsMetric2) {
|
|
85
|
+
AnalyticsMetric2[AnalyticsMetric2["Budget"] = 0] = "Budget";
|
|
86
|
+
AnalyticsMetric2[AnalyticsMetric2["Forecast"] = 1] = "Forecast";
|
|
87
|
+
AnalyticsMetric2[AnalyticsMetric2["Actuals"] = 2] = "Actuals";
|
|
88
|
+
AnalyticsMetric2[AnalyticsMetric2["PaymentsOnChain"] = 3] = "PaymentsOnChain";
|
|
89
|
+
AnalyticsMetric2[AnalyticsMetric2["PaymentsOffChainIncluded"] = 4] = "PaymentsOffChainIncluded";
|
|
90
|
+
AnalyticsMetric2[AnalyticsMetric2["FTEs"] = 5] = "FTEs";
|
|
91
|
+
})(AnalyticsMetric || (AnalyticsMetric = {}));
|
|
92
|
+
var CompoundOperator;
|
|
93
|
+
(function(CompoundOperator2) {
|
|
94
|
+
CompoundOperator2[CompoundOperator2["VectorAdd"] = 0] = "VectorAdd";
|
|
95
|
+
CompoundOperator2[CompoundOperator2["VectorSubtract"] = 1] = "VectorSubtract";
|
|
96
|
+
CompoundOperator2[CompoundOperator2["ScalarMultiply"] = 2] = "ScalarMultiply";
|
|
97
|
+
CompoundOperator2[CompoundOperator2["ScalarDivide"] = 3] = "ScalarDivide";
|
|
98
|
+
})(CompoundOperator || (CompoundOperator = {}));
|
|
99
|
+
var AnalyticsGranularity;
|
|
100
|
+
(function(AnalyticsGranularity2) {
|
|
101
|
+
AnalyticsGranularity2[AnalyticsGranularity2["Total"] = 0] = "Total";
|
|
102
|
+
AnalyticsGranularity2[AnalyticsGranularity2["Annual"] = 1] = "Annual";
|
|
103
|
+
AnalyticsGranularity2[AnalyticsGranularity2["SemiAnnual"] = 2] = "SemiAnnual";
|
|
104
|
+
AnalyticsGranularity2[AnalyticsGranularity2["Quarterly"] = 3] = "Quarterly";
|
|
105
|
+
AnalyticsGranularity2[AnalyticsGranularity2["Monthly"] = 4] = "Monthly";
|
|
106
|
+
AnalyticsGranularity2[AnalyticsGranularity2["Weekly"] = 5] = "Weekly";
|
|
107
|
+
AnalyticsGranularity2[AnalyticsGranularity2["Daily"] = 6] = "Daily";
|
|
108
|
+
AnalyticsGranularity2[AnalyticsGranularity2["Hourly"] = 7] = "Hourly";
|
|
109
|
+
})(AnalyticsGranularity || (AnalyticsGranularity = {}));
|
|
110
|
+
|
|
77
111
|
class AnalyticsPath {
|
|
78
112
|
get segments() {
|
|
79
113
|
return this._segments;
|
|
@@ -98,7 +132,7 @@ class AnalyticsPath {
|
|
|
98
132
|
}
|
|
99
133
|
toJSON() {
|
|
100
134
|
return {
|
|
101
|
-
_t:
|
|
135
|
+
_t: AnalyticsSerializerTypes.AnalyticsPath,
|
|
102
136
|
_v: this.toString()
|
|
103
137
|
};
|
|
104
138
|
}
|
|
@@ -163,7 +197,7 @@ class AnalyticsPathSegment {
|
|
|
163
197
|
}
|
|
164
198
|
toJSON() {
|
|
165
199
|
return {
|
|
166
|
-
_t:
|
|
200
|
+
_t: AnalyticsSerializerTypes.AnalyticsPathSegment,
|
|
167
201
|
_v: this.toString()
|
|
168
202
|
};
|
|
169
203
|
}
|
|
@@ -194,17 +228,197 @@ function parseSeparatedList(list, separator) {
|
|
|
194
228
|
}
|
|
195
229
|
return list.replaceAll("\\\\", substituteString).split(unescapedSeparatorPattern[separator]).map((e) => e.replaceAll(substituteString, "\\\\"));
|
|
196
230
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
231
|
+
|
|
232
|
+
class AnalyticsPeriod {
|
|
233
|
+
get type() {
|
|
234
|
+
return this._type;
|
|
235
|
+
}
|
|
236
|
+
get year() {
|
|
237
|
+
return this._year;
|
|
238
|
+
}
|
|
239
|
+
get quarter() {
|
|
240
|
+
return this._quarter;
|
|
241
|
+
}
|
|
242
|
+
get month() {
|
|
243
|
+
return this._month;
|
|
244
|
+
}
|
|
245
|
+
_type = AnalyticsPeriodType.Year;
|
|
246
|
+
_year = 1970;
|
|
247
|
+
_quarter = null;
|
|
248
|
+
_month = null;
|
|
249
|
+
toJSON() {
|
|
250
|
+
return {
|
|
251
|
+
_t: AnalyticsSerializerTypes.AnalyticsPeriod,
|
|
252
|
+
_v: this.toString()
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
static fromString(period) {
|
|
256
|
+
let result;
|
|
257
|
+
if (period.length === 4) {
|
|
258
|
+
result = new AnalyticsPeriod(Number.parseInt(period));
|
|
259
|
+
} else if (period.length === 7) {
|
|
260
|
+
if (period[4] !== "/") {
|
|
261
|
+
throw new Error(`Invalid period string: '${period}'`);
|
|
262
|
+
} else if (period[5] === "Q") {
|
|
263
|
+
result = new AnalyticsPeriod(Number.parseInt(period.slice(0, 4)), Number.parseInt(period[6]));
|
|
264
|
+
} else {
|
|
265
|
+
result = new AnalyticsPeriod(Number.parseInt(period.slice(0, 4)), undefined, Number.parseInt(period.slice(5)));
|
|
266
|
+
}
|
|
267
|
+
} else {
|
|
268
|
+
throw new Error(`Invalid period string: '${period}'`);
|
|
269
|
+
}
|
|
270
|
+
return result;
|
|
271
|
+
}
|
|
272
|
+
static fillRange(p1, p2) {
|
|
273
|
+
const obj1 = typeof p1 === "string" ? AnalyticsPeriod.fromString(p1) : p1, obj2 = typeof p2 === "string" ? AnalyticsPeriod.fromString(p2) : p2;
|
|
274
|
+
if (obj1.type !== obj2.type) {
|
|
275
|
+
throw new Error(`Cannot fill range of different type periods ${obj1.toString()} and ${obj2.toString()}.`);
|
|
276
|
+
}
|
|
277
|
+
const [first, last] = obj1.comesBefore(obj2) ? [obj1, obj2] : [obj2, obj1];
|
|
278
|
+
const result = [first];
|
|
279
|
+
let next = first.nextPeriod();
|
|
280
|
+
while (next.comesBefore(last)) {
|
|
281
|
+
result.push(next);
|
|
282
|
+
next = next.nextPeriod();
|
|
283
|
+
}
|
|
284
|
+
if (!last.equals(first)) {
|
|
285
|
+
result.push(last);
|
|
286
|
+
}
|
|
287
|
+
return result;
|
|
288
|
+
}
|
|
289
|
+
static normalizeQuarters(year, quarter) {
|
|
290
|
+
const newYear = year + Math.floor((quarter - 1) / 4);
|
|
291
|
+
const newQuarter = moduloButWithoutBugs(quarter - 1, 4) + 1;
|
|
292
|
+
return [newYear, newQuarter, undefined];
|
|
293
|
+
}
|
|
294
|
+
static normalizeMonths(year, month) {
|
|
295
|
+
const newYear = year + Math.floor((month - 1) / 12);
|
|
296
|
+
const newMonth = moduloButWithoutBugs(month - 1, 12) + 1;
|
|
297
|
+
const newQuarter = Math.floor((newMonth - 1) / 3) + 1;
|
|
298
|
+
return [newYear, newQuarter, newMonth];
|
|
299
|
+
}
|
|
300
|
+
constructor(year, quarter, month) {
|
|
301
|
+
this._initAsYear(year);
|
|
302
|
+
if (quarter !== undefined) {
|
|
303
|
+
this._initAsQuarter(quarter);
|
|
304
|
+
}
|
|
305
|
+
if (month !== undefined) {
|
|
306
|
+
this._initAsMonth(month);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
equals(period) {
|
|
310
|
+
return this.toString() === (typeof period === "string" ? period : period.toString());
|
|
311
|
+
}
|
|
312
|
+
toString() {
|
|
313
|
+
let result = this._year + (this._type === AnalyticsPeriodType.Year ? "" : "/");
|
|
314
|
+
if (this._type === AnalyticsPeriodType.Quarter) {
|
|
315
|
+
result += "Q" + this._quarter;
|
|
316
|
+
} else if (this._type === AnalyticsPeriodType.Month) {
|
|
317
|
+
if (this._month < 10) {
|
|
318
|
+
result += "0";
|
|
319
|
+
}
|
|
320
|
+
result += this._month;
|
|
321
|
+
}
|
|
322
|
+
return result;
|
|
323
|
+
}
|
|
324
|
+
startAsSqlDate() {
|
|
325
|
+
let result = this._year + "-";
|
|
326
|
+
switch (this._type) {
|
|
327
|
+
case AnalyticsPeriodType.Month:
|
|
328
|
+
result += (this._month < 10 ? "0" : "") + this.month;
|
|
329
|
+
break;
|
|
330
|
+
case AnalyticsPeriodType.Quarter: {
|
|
331
|
+
const firstMonth = (this._quarter - 1) * 3 + 1;
|
|
332
|
+
result += (firstMonth < 10 ? "0" : "") + firstMonth;
|
|
333
|
+
break;
|
|
334
|
+
}
|
|
335
|
+
case AnalyticsPeriodType.Year:
|
|
336
|
+
result += "01";
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
339
|
+
return result + "-01";
|
|
340
|
+
}
|
|
341
|
+
comesAfter(period) {
|
|
342
|
+
return this._start() > period._end();
|
|
343
|
+
}
|
|
344
|
+
comesBefore(period) {
|
|
345
|
+
return period._start() > this._end();
|
|
346
|
+
}
|
|
347
|
+
contains(period) {
|
|
348
|
+
return this._start() <= period._start() && this._end() >= period._end();
|
|
349
|
+
}
|
|
350
|
+
firstMonth() {
|
|
351
|
+
let month = this._month || 1;
|
|
352
|
+
if (this._type === AnalyticsPeriodType.Quarter) {
|
|
353
|
+
month = (this._quarter - 1) * 3 + 1;
|
|
354
|
+
}
|
|
355
|
+
return new AnalyticsPeriod(this._year, undefined, month);
|
|
356
|
+
}
|
|
357
|
+
lastMonth() {
|
|
358
|
+
let month = this._month || 12;
|
|
359
|
+
if (this._type === AnalyticsPeriodType.Quarter) {
|
|
360
|
+
month = this._quarter * 3;
|
|
361
|
+
}
|
|
362
|
+
return new AnalyticsPeriod(this._year, undefined, month);
|
|
363
|
+
}
|
|
364
|
+
nextPeriod(n = 1) {
|
|
365
|
+
return this._addPeriods(n);
|
|
366
|
+
}
|
|
367
|
+
previousPeriod(n = 1) {
|
|
368
|
+
return this._addPeriods(-n);
|
|
369
|
+
}
|
|
370
|
+
_start() {
|
|
371
|
+
return this._getNumericComparator(false);
|
|
372
|
+
}
|
|
373
|
+
_end() {
|
|
374
|
+
return this._getNumericComparator(true);
|
|
375
|
+
}
|
|
376
|
+
_getNumericComparator(endOfPeriod) {
|
|
377
|
+
const defaultQuarter = endOfPeriod ? 4 : 1, defaultMonth = ((this._quarter || defaultQuarter) - 1) * 3 + (endOfPeriod ? 3 : 1), result = this._year * 1000 + (this._quarter || defaultQuarter) * 100 + (this._month || defaultMonth);
|
|
378
|
+
return result;
|
|
379
|
+
}
|
|
380
|
+
_addPeriods(periods) {
|
|
381
|
+
let result;
|
|
382
|
+
if (this._type === AnalyticsPeriodType.Year) {
|
|
383
|
+
result = new AnalyticsPeriod(this._year + periods);
|
|
384
|
+
} else if (this._type === AnalyticsPeriodType.Quarter) {
|
|
385
|
+
const [y, q] = AnalyticsPeriod.normalizeQuarters(this._year, this._quarter + periods);
|
|
386
|
+
result = new AnalyticsPeriod(y, q);
|
|
387
|
+
} else {
|
|
388
|
+
const [y, _, m] = AnalyticsPeriod.normalizeMonths(this._year, this._month + periods);
|
|
389
|
+
result = new AnalyticsPeriod(y, undefined, m);
|
|
390
|
+
}
|
|
391
|
+
return result;
|
|
392
|
+
}
|
|
393
|
+
_initAsYear(year) {
|
|
394
|
+
if (year < 1970 || year > 2100) {
|
|
395
|
+
throw new Error(`Invalid period year: '${year}'`);
|
|
396
|
+
}
|
|
397
|
+
this._year = year;
|
|
398
|
+
}
|
|
399
|
+
_initAsQuarter(quarter) {
|
|
400
|
+
if (quarter < 1 || quarter > 4) {
|
|
401
|
+
throw new Error(`Invalid period quarter: ${quarter}`);
|
|
402
|
+
}
|
|
403
|
+
this._quarter = quarter;
|
|
404
|
+
this._type = AnalyticsPeriodType.Quarter;
|
|
405
|
+
}
|
|
406
|
+
_initAsMonth(month) {
|
|
407
|
+
if (month < 1 || month > 12) {
|
|
408
|
+
throw new Error(`Invalid period month: ${month}`);
|
|
409
|
+
}
|
|
410
|
+
if (this.quarter == null) {
|
|
411
|
+
this._initAsQuarter(Math.floor((month - 1) / 3) + 1);
|
|
412
|
+
} else if (this.quarter !== Math.floor((month - 1) / 3) + 1) {
|
|
413
|
+
throw new Error(`Period month ${month} outside of quarter ${this.quarter}`);
|
|
414
|
+
}
|
|
415
|
+
this._month = month;
|
|
416
|
+
this._type = AnalyticsPeriodType.Month;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
function moduloButWithoutBugs(base, n) {
|
|
420
|
+
return (base % n + n) % n;
|
|
421
|
+
}
|
|
208
422
|
|
|
209
423
|
class LuxonError extends Error {
|
|
210
424
|
}
|
|
@@ -4764,7 +4978,7 @@ class AnalyticsSubscriptionManager {
|
|
|
4764
4978
|
}
|
|
4765
4979
|
}
|
|
4766
4980
|
|
|
4767
|
-
//
|
|
4981
|
+
// ../../../node_modules/.pnpm/luxon@3.7.2/node_modules/luxon/build/es6/luxon.mjs
|
|
4768
4982
|
class LuxonError2 extends Error {
|
|
4769
4983
|
}
|
|
4770
4984
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerhousedao/analytics-engine-graphql",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "6.0.0-dev.65",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "https://github.com/powerhouse-inc/
|
|
7
|
+
"url": "https://github.com/powerhouse-inc/powerhouse"
|
|
8
8
|
},
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"access": "public"
|
|
@@ -13,23 +13,20 @@
|
|
|
13
13
|
"exports": {
|
|
14
14
|
".": {
|
|
15
15
|
"types": "./dist/src/index.d.ts",
|
|
16
|
-
"
|
|
16
|
+
"import": "./dist/src/index.js"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
20
20
|
"dist/src"
|
|
21
21
|
],
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"luxon": "3.7.2",
|
|
24
|
-
"@powerhousedao/analytics-engine-core": "0.6.3"
|
|
25
|
-
},
|
|
26
22
|
"devDependencies": {
|
|
27
|
-
"vitest": "
|
|
28
|
-
"@types/luxon": "3.7.1"
|
|
23
|
+
"vitest": "3.2.4",
|
|
24
|
+
"@types/luxon": "3.7.1",
|
|
25
|
+
"luxon": "3.7.2",
|
|
26
|
+
"@powerhousedao/analytics-engine-core": "6.0.0-dev.65"
|
|
29
27
|
},
|
|
30
28
|
"scripts": {
|
|
31
|
-
"dev": "pnpm tsc -b -w",
|
|
32
29
|
"test": "vitest --run ./**/*.test.ts",
|
|
33
|
-
"bundle": "bun run ./bundle.ts"
|
|
30
|
+
"build:bundle": "bun run ./bundle.ts"
|
|
34
31
|
}
|
|
35
32
|
}
|