@powerhousedao/analytics-engine-browser 0.3.0 → 0.5.0

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,9 +1,7 @@
1
- import { MemoryAnalyticsStore } from "./MemoryAnalyticsStore.js";
2
- import { SqlQueryLogger, SqlResultsLogger } from "@powerhousedao/analytics-engine-knex";
3
- import { IAnalyticsProfiler } from "@powerhousedao/analytics-engine-core";
4
- import { PGlite } from "@electric-sql/pglite";
1
+ import { MemoryAnalyticsStore, MemoryAnalyticsStoreOptions } from "./MemoryAnalyticsStore.js";
2
+ export type BrowserAnalyticsStoreOptions = MemoryAnalyticsStoreOptions & {
3
+ databaseName: string;
4
+ };
5
5
  export declare class BrowserAnalyticsStore extends MemoryAnalyticsStore {
6
- private _dbName;
7
- constructor(databaseName: string, queryLogger?: SqlQueryLogger, resultsLogger?: SqlResultsLogger, profiler?: IAnalyticsProfiler);
8
- instance(): Promise<PGlite>;
6
+ constructor(options?: BrowserAnalyticsStoreOptions);
9
7
  }
@@ -1,16 +1,14 @@
1
- import { MemoryAnalyticsStore } from "./MemoryAnalyticsStore.js";
1
+ import { MemoryAnalyticsStore, } from "./MemoryAnalyticsStore.js";
2
2
  import { IdbFs, PGlite } from "@electric-sql/pglite";
3
3
  export class BrowserAnalyticsStore extends MemoryAnalyticsStore {
4
- _dbName;
5
- constructor(databaseName, queryLogger, resultsLogger, profiler) {
6
- super(queryLogger, resultsLogger, profiler);
7
- this._dbName = databaseName;
8
- }
9
- async instance() {
10
- return await PGlite.create({
11
- fs: new IdbFs(this._dbName),
12
- relaxedDurability: true,
13
- });
4
+ constructor(options = { databaseName: "analytics" }) {
5
+ if (!options.pgLiteFactory) {
6
+ options.pgLiteFactory = async () => PGlite.create({
7
+ fs: new IdbFs(options.databaseName),
8
+ relaxedDurability: true,
9
+ });
10
+ }
11
+ super(options);
14
12
  }
15
13
  }
16
14
  //# sourceMappingURL=BrowserAnalyticsStore.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BrowserAnalyticsStore.js","sourceRoot":"","sources":["../src/BrowserAnalyticsStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAMjE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAErD,MAAM,OAAO,qBAAsB,SAAQ,oBAAoB;IACrD,OAAO,CAAS;IAExB,YACE,YAAoB,EACpB,WAA4B,EAC5B,aAAgC,EAChC,QAA6B;QAE7B,KAAK,CAAC,WAAW,EAAE,aAAa,EAAE,QAAQ,CAAC,CAAC;QAE5C,IAAI,CAAC,OAAO,GAAG,YAAY,CAAC;IAC9B,CAAC;IAEQ,KAAK,CAAC,QAAQ;QACrB,OAAO,MAAM,MAAM,CAAC,MAAM,CAAC;YACzB,EAAE,EAAE,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC;YAC3B,iBAAiB,EAAE,IAAI;SACxB,CAAC,CAAC;IACL,CAAC;CACF"}
1
+ {"version":3,"file":"BrowserAnalyticsStore.js","sourceRoot":"","sources":["../src/BrowserAnalyticsStore.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,GAErB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAMrD,MAAM,OAAO,qBAAsB,SAAQ,oBAAoB;IAC7D,YACE,UAAwC,EAAE,YAAY,EAAE,WAAW,EAAE;QAErE,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;YAC3B,OAAO,CAAC,aAAa,GAAG,KAAK,IAAI,EAAE,CACjC,MAAM,CAAC,MAAM,CAAC;gBACZ,EAAE,EAAE,IAAI,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC;gBACnC,iBAAiB,EAAE,IAAI;aACxB,CAAC,CAAC;QACP,CAAC;QAED,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACF"}
@@ -1,15 +1,23 @@
1
1
  import { IAnalyticsProfiler } from "@powerhousedao/analytics-engine-core";
2
2
  import { KnexAnalyticsStore, SqlQueryLogger, SqlResultsLogger } from "@powerhousedao/analytics-engine-knex";
3
+ import { Knex } from "knex";
3
4
  import { PGlite } from "@electric-sql/pglite";
5
+ export type MemoryAnalyticsStoreOptions = {
6
+ pgLiteFactory?: () => Promise<PGlite>;
7
+ knex?: Knex;
8
+ queryLogger?: SqlQueryLogger;
9
+ resultsLogger?: SqlResultsLogger;
10
+ profiler?: IAnalyticsProfiler;
11
+ };
4
12
  export declare class MemoryAnalyticsStore extends KnexAnalyticsStore {
13
+ private _pgLiteFactory;
5
14
  private _queryLogger;
6
15
  private _resultsLogger;
7
16
  private _pgExecutor;
8
17
  private _profiler;
9
18
  private _sql;
10
- constructor(queryLogger?: SqlQueryLogger, resultsLogger?: SqlResultsLogger, profiler?: IAnalyticsProfiler);
19
+ constructor({ knex, pgLiteFactory, queryLogger, resultsLogger, profiler, }?: MemoryAnalyticsStoreOptions);
11
20
  init(): Promise<void>;
12
- protected instance(): Promise<PGlite>;
13
21
  raw(sql: string): Promise<any[]>;
14
22
  destroy(): Promise<void>;
15
23
  }
@@ -81,36 +81,38 @@ const initSql = `
81
81
 
82
82
  `;
83
83
  export class MemoryAnalyticsStore extends KnexAnalyticsStore {
84
+ _pgLiteFactory;
84
85
  _queryLogger;
85
86
  _resultsLogger;
86
87
  _pgExecutor;
87
88
  _profiler;
88
89
  _sql = null;
89
- constructor(queryLogger, resultsLogger, profiler) {
90
- const knex = knexFactory({
91
- client: "pg",
92
- useNullAsDefault: true,
93
- });
90
+ constructor({ knex, pgLiteFactory, queryLogger, resultsLogger, profiler, } = {}) {
94
91
  if (!profiler) {
95
92
  profiler = new PassthroughAnalyticsProfiler();
96
93
  }
97
94
  const executor = new PGLiteQueryExecutor(profiler, queryLogger, resultsLogger);
98
- super(executor, knex);
95
+ super({
96
+ executor,
97
+ knex: knex ||
98
+ knexFactory({
99
+ client: "pg",
100
+ useNullAsDefault: true,
101
+ }),
102
+ });
103
+ this._pgLiteFactory = pgLiteFactory || PGlite.create;
99
104
  this._queryLogger = queryLogger || (() => { });
100
105
  this._resultsLogger = resultsLogger || (() => { });
101
106
  this._profiler = profiler;
102
107
  this._pgExecutor = executor;
103
108
  }
104
109
  async init() {
105
- this._sql = await this.instance();
110
+ this._sql = await this._pgLiteFactory();
106
111
  // init executor
107
112
  this._pgExecutor.init(this._sql);
108
113
  // create tables if they do not exist
109
114
  await this._sql.exec(initSql);
110
115
  }
111
- instance() {
112
- return PGlite.create();
113
- }
114
116
  async raw(sql) {
115
117
  this._queryLogger(-1, sql);
116
118
  return await this._profiler.record("QueryRaw", async () => {
@@ -1 +1 @@
1
- {"version":3,"file":"MemoryAnalyticsStore.js","sourceRoot":"","sources":["../src/MemoryAnalyticsStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,4BAA4B,GAC7B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,kBAAkB,GAGnB,MAAM,sCAAsC,CAAC;AAE9C,OAAO,WAAW,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4Ef,CAAC;AAEF,MAAM,OAAO,oBAAqB,SAAQ,kBAAkB;IAClD,YAAY,CAAiB;IAC7B,cAAc,CAAmB;IACjC,WAAW,CAAsB;IACjC,SAAS,CAAqB;IAC9B,IAAI,GAAkB,IAAI,CAAC;IAEnC,YACE,WAA4B,EAC5B,aAAgC,EAChC,QAA6B;QAE7B,MAAM,IAAI,GAAG,WAAW,CAAC;YACvB,MAAM,EAAE,IAAI;YACZ,gBAAgB,EAAE,IA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
  export { MemoryAnalyticsStore } from "./MemoryAnalyticsStore.js";
2
2
  export { BrowserAnalyticsStore } from "./BrowserAnalyticsStore.js";
3
+ export type { MemoryAnalyticsStoreOptions } from "./MemoryAnalyticsStore.js";
4
+ export type { BrowserAnalyticsStoreOptions } from "./BrowserAnalyticsStore.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerhousedao/analytics-engine-browser",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "license": "AGPL-3.0-only",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -18,8 +18,6 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@electric-sql/pglite": "^0.2.12",
21
- "@powerhousedao/analytics-engine-core": "0.3.0",
22
- "@powerhousedao/analytics-engine-knex": "0.3.0",
23
21
  "date-fns": "^3.6.0",
24
22
  "events": "^3.3.0",
25
23
  "knex": "^3.1.0",
@@ -34,5 +32,9 @@
34
32
  "tsc-watch": "^6.2.0",
35
33
  "typescript": "^5.6.3",
36
34
  "vitest": "^2.1.1"
35
+ },
36
+ "peerDependencies": {
37
+ "@powerhousedao/analytics-engine-core": "0.4.0",
38
+ "@powerhousedao/analytics-engine-knex": "0.5.0"
37
39
  }
38
40
  }