@powerhousedao/analytics-engine-knex 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 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/>.
@@ -7,6 +7,6 @@ export declare class KnexQueryExecutor implements IKnexQueryExecutor {
7
7
  private readonly _profiler?;
8
8
  private _index;
9
9
  constructor(_queryLogger?: ((index: number, query: string) => void) | undefined, _resultsLogger?: ((index: number, results: any) => void) | undefined, _profiler?: IAnalyticsProfiler | undefined);
10
- execute<T extends {}, U>(query: Knex.QueryBuilder<T, U>): Promise<any>;
10
+ execute<T extends object, U>(query: Knex.QueryBuilder<T, U>): Promise<any>;
11
11
  }
12
12
  //# sourceMappingURL=KnexQueryExecutor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"KnexQueryExecutor.d.ts","sourceRoot":"","sources":["../../src/KnexQueryExecutor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAElE,qBAAa,iBAAkB,YAAW,kBAAkB;IAIxD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;IAC9B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC;IAChC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC;IAL7B,OAAO,CAAC,MAAM,CAAa;gBAGR,YAAY,CAAC,GAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,aAAA,EACrD,cAAc,CAAC,GAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,IAAI,aAAA,EACtD,SAAS,CAAC,EAAE,kBAAkB,YAAA;IAO3C,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC;CAqB7E"}
1
+ {"version":3,"file":"KnexQueryExecutor.d.ts","sourceRoot":"","sources":["../../src/KnexQueryExecutor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAElE,qBAAa,iBAAkB,YAAW,kBAAkB;IAIxD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;IAC9B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC;IAChC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC;IAL7B,OAAO,CAAC,MAAM,CAAa;gBAGR,YAAY,CAAC,GAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,aAAA,EACrD,cAAc,CAAC,GAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,IAAI,aAAA,EACtD,SAAS,CAAC,EAAE,kBAAkB,YAAA;IAO3C,OAAO,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAC/B,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,GAC7B,OAAO,CAAC,GAAG,CAAC;CAqBhB"}
package/dist/src/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // ../node_modules/.pnpm/luxon@3.7.2/node_modules/luxon/build/es6/luxon.mjs
1
+ // ../../../node_modules/.pnpm/luxon@3.7.2/node_modules/luxon/build/es6/luxon.mjs
2
2
  class LuxonError extends Error {
3
3
  }
4
4
 
@@ -4446,11 +4446,45 @@ function friendlyDateTime(dateTimeish) {
4446
4446
 
4447
4447
  // ../core/dist/src/index.js
4448
4448
  var AnalyticsSerializerTypes;
4449
- ((AnalyticsSerializerTypes2) => {
4449
+ (function(AnalyticsSerializerTypes2) {
4450
4450
  AnalyticsSerializerTypes2[AnalyticsSerializerTypes2["AnalyticsPath"] = 0] = "AnalyticsPath";
4451
4451
  AnalyticsSerializerTypes2[AnalyticsSerializerTypes2["AnalyticsPathSegment"] = 1] = "AnalyticsPathSegment";
4452
4452
  AnalyticsSerializerTypes2[AnalyticsSerializerTypes2["AnalyticsPeriod"] = 2] = "AnalyticsPeriod";
4453
- })(AnalyticsSerializerTypes ||= {});
4453
+ })(AnalyticsSerializerTypes || (AnalyticsSerializerTypes = {}));
4454
+ var AnalyticsPeriodType;
4455
+ (function(AnalyticsPeriodType2) {
4456
+ AnalyticsPeriodType2[AnalyticsPeriodType2["Year"] = 0] = "Year";
4457
+ AnalyticsPeriodType2[AnalyticsPeriodType2["Quarter"] = 1] = "Quarter";
4458
+ AnalyticsPeriodType2[AnalyticsPeriodType2["Month"] = 2] = "Month";
4459
+ })(AnalyticsPeriodType || (AnalyticsPeriodType = {}));
4460
+ var AnalyticsMetric;
4461
+ (function(AnalyticsMetric2) {
4462
+ AnalyticsMetric2[AnalyticsMetric2["Budget"] = 0] = "Budget";
4463
+ AnalyticsMetric2[AnalyticsMetric2["Forecast"] = 1] = "Forecast";
4464
+ AnalyticsMetric2[AnalyticsMetric2["Actuals"] = 2] = "Actuals";
4465
+ AnalyticsMetric2[AnalyticsMetric2["PaymentsOnChain"] = 3] = "PaymentsOnChain";
4466
+ AnalyticsMetric2[AnalyticsMetric2["PaymentsOffChainIncluded"] = 4] = "PaymentsOffChainIncluded";
4467
+ AnalyticsMetric2[AnalyticsMetric2["FTEs"] = 5] = "FTEs";
4468
+ })(AnalyticsMetric || (AnalyticsMetric = {}));
4469
+ var CompoundOperator;
4470
+ (function(CompoundOperator2) {
4471
+ CompoundOperator2[CompoundOperator2["VectorAdd"] = 0] = "VectorAdd";
4472
+ CompoundOperator2[CompoundOperator2["VectorSubtract"] = 1] = "VectorSubtract";
4473
+ CompoundOperator2[CompoundOperator2["ScalarMultiply"] = 2] = "ScalarMultiply";
4474
+ CompoundOperator2[CompoundOperator2["ScalarDivide"] = 3] = "ScalarDivide";
4475
+ })(CompoundOperator || (CompoundOperator = {}));
4476
+ var AnalyticsGranularity;
4477
+ (function(AnalyticsGranularity2) {
4478
+ AnalyticsGranularity2[AnalyticsGranularity2["Total"] = 0] = "Total";
4479
+ AnalyticsGranularity2[AnalyticsGranularity2["Annual"] = 1] = "Annual";
4480
+ AnalyticsGranularity2[AnalyticsGranularity2["SemiAnnual"] = 2] = "SemiAnnual";
4481
+ AnalyticsGranularity2[AnalyticsGranularity2["Quarterly"] = 3] = "Quarterly";
4482
+ AnalyticsGranularity2[AnalyticsGranularity2["Monthly"] = 4] = "Monthly";
4483
+ AnalyticsGranularity2[AnalyticsGranularity2["Weekly"] = 5] = "Weekly";
4484
+ AnalyticsGranularity2[AnalyticsGranularity2["Daily"] = 6] = "Daily";
4485
+ AnalyticsGranularity2[AnalyticsGranularity2["Hourly"] = 7] = "Hourly";
4486
+ })(AnalyticsGranularity || (AnalyticsGranularity = {}));
4487
+
4454
4488
  class AnalyticsPath {
4455
4489
  get segments() {
4456
4490
  return this._segments;
@@ -4475,7 +4509,7 @@ class AnalyticsPath {
4475
4509
  }
4476
4510
  toJSON() {
4477
4511
  return {
4478
- _t: 0,
4512
+ _t: AnalyticsSerializerTypes.AnalyticsPath,
4479
4513
  _v: this.toString()
4480
4514
  };
4481
4515
  }
@@ -4540,7 +4574,7 @@ class AnalyticsPathSegment {
4540
4574
  }
4541
4575
  toJSON() {
4542
4576
  return {
4543
- _t: 1,
4577
+ _t: AnalyticsSerializerTypes.AnalyticsPathSegment,
4544
4578
  _v: this.toString()
4545
4579
  };
4546
4580
  }
@@ -4571,17 +4605,197 @@ function parseSeparatedList(list, separator) {
4571
4605
  }
4572
4606
  return list.replaceAll("\\\\", substituteString).split(unescapedSeparatorPattern[separator]).map((e) => e.replaceAll(substituteString, "\\\\"));
4573
4607
  }
4574
- var AnalyticsGranularity;
4575
- ((AnalyticsGranularity2) => {
4576
- AnalyticsGranularity2[AnalyticsGranularity2["Total"] = 0] = "Total";
4577
- AnalyticsGranularity2[AnalyticsGranularity2["Annual"] = 1] = "Annual";
4578
- AnalyticsGranularity2[AnalyticsGranularity2["SemiAnnual"] = 2] = "SemiAnnual";
4579
- AnalyticsGranularity2[AnalyticsGranularity2["Quarterly"] = 3] = "Quarterly";
4580
- AnalyticsGranularity2[AnalyticsGranularity2["Monthly"] = 4] = "Monthly";
4581
- AnalyticsGranularity2[AnalyticsGranularity2["Weekly"] = 5] = "Weekly";
4582
- AnalyticsGranularity2[AnalyticsGranularity2["Daily"] = 6] = "Daily";
4583
- AnalyticsGranularity2[AnalyticsGranularity2["Hourly"] = 7] = "Hourly";
4584
- })(AnalyticsGranularity ||= {});
4608
+
4609
+ class AnalyticsPeriod {
4610
+ get type() {
4611
+ return this._type;
4612
+ }
4613
+ get year() {
4614
+ return this._year;
4615
+ }
4616
+ get quarter() {
4617
+ return this._quarter;
4618
+ }
4619
+ get month() {
4620
+ return this._month;
4621
+ }
4622
+ _type = AnalyticsPeriodType.Year;
4623
+ _year = 1970;
4624
+ _quarter = null;
4625
+ _month = null;
4626
+ toJSON() {
4627
+ return {
4628
+ _t: AnalyticsSerializerTypes.AnalyticsPeriod,
4629
+ _v: this.toString()
4630
+ };
4631
+ }
4632
+ static fromString(period) {
4633
+ let result;
4634
+ if (period.length === 4) {
4635
+ result = new AnalyticsPeriod(Number.parseInt(period));
4636
+ } else if (period.length === 7) {
4637
+ if (period[4] !== "/") {
4638
+ throw new Error(`Invalid period string: '${period}'`);
4639
+ } else if (period[5] === "Q") {
4640
+ result = new AnalyticsPeriod(Number.parseInt(period.slice(0, 4)), Number.parseInt(period[6]));
4641
+ } else {
4642
+ result = new AnalyticsPeriod(Number.parseInt(period.slice(0, 4)), undefined, Number.parseInt(period.slice(5)));
4643
+ }
4644
+ } else {
4645
+ throw new Error(`Invalid period string: '${period}'`);
4646
+ }
4647
+ return result;
4648
+ }
4649
+ static fillRange(p1, p2) {
4650
+ const obj1 = typeof p1 === "string" ? AnalyticsPeriod.fromString(p1) : p1, obj2 = typeof p2 === "string" ? AnalyticsPeriod.fromString(p2) : p2;
4651
+ if (obj1.type !== obj2.type) {
4652
+ throw new Error(`Cannot fill range of different type periods ${obj1.toString()} and ${obj2.toString()}.`);
4653
+ }
4654
+ const [first, last] = obj1.comesBefore(obj2) ? [obj1, obj2] : [obj2, obj1];
4655
+ const result = [first];
4656
+ let next = first.nextPeriod();
4657
+ while (next.comesBefore(last)) {
4658
+ result.push(next);
4659
+ next = next.nextPeriod();
4660
+ }
4661
+ if (!last.equals(first)) {
4662
+ result.push(last);
4663
+ }
4664
+ return result;
4665
+ }
4666
+ static normalizeQuarters(year, quarter) {
4667
+ const newYear = year + Math.floor((quarter - 1) / 4);
4668
+ const newQuarter = moduloButWithoutBugs(quarter - 1, 4) + 1;
4669
+ return [newYear, newQuarter, undefined];
4670
+ }
4671
+ static normalizeMonths(year, month) {
4672
+ const newYear = year + Math.floor((month - 1) / 12);
4673
+ const newMonth = moduloButWithoutBugs(month - 1, 12) + 1;
4674
+ const newQuarter = Math.floor((newMonth - 1) / 3) + 1;
4675
+ return [newYear, newQuarter, newMonth];
4676
+ }
4677
+ constructor(year, quarter, month) {
4678
+ this._initAsYear(year);
4679
+ if (quarter !== undefined) {
4680
+ this._initAsQuarter(quarter);
4681
+ }
4682
+ if (month !== undefined) {
4683
+ this._initAsMonth(month);
4684
+ }
4685
+ }
4686
+ equals(period) {
4687
+ return this.toString() === (typeof period === "string" ? period : period.toString());
4688
+ }
4689
+ toString() {
4690
+ let result = this._year + (this._type === AnalyticsPeriodType.Year ? "" : "/");
4691
+ if (this._type === AnalyticsPeriodType.Quarter) {
4692
+ result += "Q" + this._quarter;
4693
+ } else if (this._type === AnalyticsPeriodType.Month) {
4694
+ if (this._month < 10) {
4695
+ result += "0";
4696
+ }
4697
+ result += this._month;
4698
+ }
4699
+ return result;
4700
+ }
4701
+ startAsSqlDate() {
4702
+ let result = this._year + "-";
4703
+ switch (this._type) {
4704
+ case AnalyticsPeriodType.Month:
4705
+ result += (this._month < 10 ? "0" : "") + this.month;
4706
+ break;
4707
+ case AnalyticsPeriodType.Quarter: {
4708
+ const firstMonth = (this._quarter - 1) * 3 + 1;
4709
+ result += (firstMonth < 10 ? "0" : "") + firstMonth;
4710
+ break;
4711
+ }
4712
+ case AnalyticsPeriodType.Year:
4713
+ result += "01";
4714
+ break;
4715
+ }
4716
+ return result + "-01";
4717
+ }
4718
+ comesAfter(period) {
4719
+ return this._start() > period._end();
4720
+ }
4721
+ comesBefore(period) {
4722
+ return period._start() > this._end();
4723
+ }
4724
+ contains(period) {
4725
+ return this._start() <= period._start() && this._end() >= period._end();
4726
+ }
4727
+ firstMonth() {
4728
+ let month = this._month || 1;
4729
+ if (this._type === AnalyticsPeriodType.Quarter) {
4730
+ month = (this._quarter - 1) * 3 + 1;
4731
+ }
4732
+ return new AnalyticsPeriod(this._year, undefined, month);
4733
+ }
4734
+ lastMonth() {
4735
+ let month = this._month || 12;
4736
+ if (this._type === AnalyticsPeriodType.Quarter) {
4737
+ month = this._quarter * 3;
4738
+ }
4739
+ return new AnalyticsPeriod(this._year, undefined, month);
4740
+ }
4741
+ nextPeriod(n2 = 1) {
4742
+ return this._addPeriods(n2);
4743
+ }
4744
+ previousPeriod(n2 = 1) {
4745
+ return this._addPeriods(-n2);
4746
+ }
4747
+ _start() {
4748
+ return this._getNumericComparator(false);
4749
+ }
4750
+ _end() {
4751
+ return this._getNumericComparator(true);
4752
+ }
4753
+ _getNumericComparator(endOfPeriod) {
4754
+ 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);
4755
+ return result;
4756
+ }
4757
+ _addPeriods(periods) {
4758
+ let result;
4759
+ if (this._type === AnalyticsPeriodType.Year) {
4760
+ result = new AnalyticsPeriod(this._year + periods);
4761
+ } else if (this._type === AnalyticsPeriodType.Quarter) {
4762
+ const [y, q] = AnalyticsPeriod.normalizeQuarters(this._year, this._quarter + periods);
4763
+ result = new AnalyticsPeriod(y, q);
4764
+ } else {
4765
+ const [y, _, m] = AnalyticsPeriod.normalizeMonths(this._year, this._month + periods);
4766
+ result = new AnalyticsPeriod(y, undefined, m);
4767
+ }
4768
+ return result;
4769
+ }
4770
+ _initAsYear(year) {
4771
+ if (year < 1970 || year > 2100) {
4772
+ throw new Error(`Invalid period year: '${year}'`);
4773
+ }
4774
+ this._year = year;
4775
+ }
4776
+ _initAsQuarter(quarter) {
4777
+ if (quarter < 1 || quarter > 4) {
4778
+ throw new Error(`Invalid period quarter: ${quarter}`);
4779
+ }
4780
+ this._quarter = quarter;
4781
+ this._type = AnalyticsPeriodType.Quarter;
4782
+ }
4783
+ _initAsMonth(month) {
4784
+ if (month < 1 || month > 12) {
4785
+ throw new Error(`Invalid period month: ${month}`);
4786
+ }
4787
+ if (this.quarter == null) {
4788
+ this._initAsQuarter(Math.floor((month - 1) / 3) + 1);
4789
+ } else if (this.quarter !== Math.floor((month - 1) / 3) + 1) {
4790
+ throw new Error(`Period month ${month} outside of quarter ${this.quarter}`);
4791
+ }
4792
+ this._month = month;
4793
+ this._type = AnalyticsPeriodType.Month;
4794
+ }
4795
+ }
4796
+ function moduloButWithoutBugs(base, n2) {
4797
+ return (base % n2 + n2) % n2;
4798
+ }
4585
4799
 
4586
4800
  class LuxonError2 extends Error {
4587
4801
  }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@powerhousedao/analytics-engine-knex",
3
- "version": "0.6.3",
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/analytics-engine"
7
+ "url": "https://github.com/powerhouse-inc/powerhouse"
8
8
  },
9
9
  "publishConfig": {
10
10
  "access": "public"
@@ -13,27 +13,24 @@
13
13
  "exports": {
14
14
  ".": {
15
15
  "types": "./dist/src/index.d.ts",
16
- "default": "./dist/src/index.js"
16
+ "import": "./dist/src/index.js"
17
17
  }
18
18
  },
19
19
  "files": [
20
20
  "dist/src"
21
21
  ],
22
- "dependencies": {
22
+ "devDependencies": {
23
23
  "date-fns": "4.1.0",
24
24
  "knex": "3.1.0",
25
25
  "luxon": "3.7.2",
26
26
  "pg": "8.18.0",
27
- "@powerhousedao/analytics-engine-core": "0.6.3"
28
- },
29
- "devDependencies": {
30
27
  "@types/pg": "8.16.0",
31
- "vitest": "4.0.18",
32
- "@types/luxon": "3.7.1"
28
+ "vitest": "3.2.4",
29
+ "@types/luxon": "3.7.1",
30
+ "@powerhousedao/analytics-engine-core": "6.0.0-dev.65"
33
31
  },
34
32
  "scripts": {
35
- "dev": "pnpm tsc -b -w",
36
- "bundle": "bun run ./bundle.ts",
33
+ "build:bundle": "bun run ./bundle.ts",
37
34
  "test": "vitest --run ./**/*.test.ts"
38
35
  }
39
36
  }