@mongrov/analytics 0.1.0-alpha.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.
- package/LICENSE +21 -0
- package/dist/core/errors.d.ts +21 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +26 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/factory.d.ts +9 -0
- package/dist/core/factory.d.ts.map +1 -0
- package/dist/core/factory.js +11 -0
- package/dist/core/factory.js.map +1 -0
- package/dist/core/hooks.d.ts +27 -0
- package/dist/core/hooks.d.ts.map +1 -0
- package/dist/core/hooks.js +23 -0
- package/dist/core/hooks.js.map +1 -0
- package/dist/core/index.d.ts +12 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +13 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/types.d.ts +121 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +10 -0
- package/dist/core/types.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/rules/index.d.ts +2 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +2 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/sync/index.d.ts +2 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +2 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +2 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/ui/index.d.ts +2 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +2 -0
- package/dist/ui/index.js.map +1 -0
- package/package.json +89 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Mongrov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error taxonomy for @mongrov/analytics core.
|
|
3
|
+
*
|
|
4
|
+
* Full code set frozen in T-16 (Phase 7 — Error taxonomy). This file
|
|
5
|
+
* ships the class and code union so stubs can throw typed errors from
|
|
6
|
+
* day one; downstream phases add more codes without breaking imports.
|
|
7
|
+
*/
|
|
8
|
+
export type AnalyticsErrorCode = 'engine_open_failed' | 'extension_load_failed' | 'attach_failed' | 'token_vendor_failed' | 'migration_failed' | 'query_failed' | 'not_attached' | 'not_ready' | 'not_implemented';
|
|
9
|
+
export declare class AnalyticsError extends Error {
|
|
10
|
+
readonly code: AnalyticsErrorCode;
|
|
11
|
+
readonly cause?: unknown;
|
|
12
|
+
constructor(code: AnalyticsErrorCode, message: string, cause?: unknown);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Thrown by unimplemented stubs. Distinct class so tests can assert on
|
|
16
|
+
* "this surface isn't wired yet" without ambiguity against runtime errors.
|
|
17
|
+
*/
|
|
18
|
+
export declare class NotImplementedError extends AnalyticsError {
|
|
19
|
+
constructor(symbol: string);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,MAAM,kBAAkB,GAC1B,oBAAoB,GACpB,uBAAuB,GACvB,eAAe,GACf,qBAAqB,GACrB,kBAAkB,GAClB,cAAc,GACd,cAAc,GACd,WAAW,GACX,iBAAiB,CAAA;AAErB,qBAAa,cAAe,SAAQ,KAAK;IACvC,SAAgB,IAAI,EAAE,kBAAkB,CAAA;IACxC,SAAgB,KAAK,CAAC,EAAE,OAAO,CAAA;gBAEnB,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAMvE;AAED;;;GAGG;AACH,qBAAa,mBAAoB,SAAQ,cAAc;gBACzC,MAAM,EAAE,MAAM;CAI3B"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error taxonomy for @mongrov/analytics core.
|
|
3
|
+
*
|
|
4
|
+
* Full code set frozen in T-16 (Phase 7 — Error taxonomy). This file
|
|
5
|
+
* ships the class and code union so stubs can throw typed errors from
|
|
6
|
+
* day one; downstream phases add more codes without breaking imports.
|
|
7
|
+
*/
|
|
8
|
+
export class AnalyticsError extends Error {
|
|
9
|
+
constructor(code, message, cause) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = 'AnalyticsError';
|
|
12
|
+
this.code = code;
|
|
13
|
+
this.cause = cause;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Thrown by unimplemented stubs. Distinct class so tests can assert on
|
|
18
|
+
* "this surface isn't wired yet" without ambiguity against runtime errors.
|
|
19
|
+
*/
|
|
20
|
+
export class NotImplementedError extends AnalyticsError {
|
|
21
|
+
constructor(symbol) {
|
|
22
|
+
super('not_implemented', `${symbol} is not implemented in @mongrov/analytics@0.1.0-alpha.0`);
|
|
23
|
+
this.name = 'NotImplementedError';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAaH,MAAM,OAAO,cAAe,SAAQ,KAAK;IAIvC,YAAY,IAAwB,EAAE,OAAe,EAAE,KAAe;QACpE,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAA;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,mBAAoB,SAAQ,cAAc;IACrD,YAAY,MAAc;QACxB,KAAK,CAAC,iBAAiB,EAAE,GAAG,MAAM,yDAAyD,CAAC,CAAA;QAC5F,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAA;IACnC,CAAC;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AnalyticsConfig, AnalyticsEngine } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Wires config into engine + warehouse + machine.
|
|
4
|
+
*
|
|
5
|
+
* Stub in T-02. Full wiring lands in T-10 (Phase 4 — factory) once the
|
|
6
|
+
* engine (T-03/04), warehouse (T-05/06/07/08), and machine (T-09) exist.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createAnalytics(_config: AnalyticsConfig): AnalyticsEngine;
|
|
9
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/core/factory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAE/D;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,eAAe,GAAG,eAAe,CAEzE"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NotImplementedError } from './errors';
|
|
2
|
+
/**
|
|
3
|
+
* Wires config into engine + warehouse + machine.
|
|
4
|
+
*
|
|
5
|
+
* Stub in T-02. Full wiring lands in T-10 (Phase 4 — factory) once the
|
|
6
|
+
* engine (T-03/04), warehouse (T-05/06/07/08), and machine (T-09) exist.
|
|
7
|
+
*/
|
|
8
|
+
export function createAnalytics(_config) {
|
|
9
|
+
throw new NotImplementedError('createAnalytics');
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src/core/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAG9C;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,OAAwB;IACtD,MAAM,IAAI,mBAAmB,CAAC,iBAAiB,CAAC,CAAA;AAClD,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AnalyticsState, Insight } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* React hooks over the analytics engine. Stubs in T-02; real wiring via
|
|
4
|
+
* `useSyncExternalStore` on `engine.subscribe()` lands in Phase 5 (T-11/12/13).
|
|
5
|
+
*
|
|
6
|
+
* React is an optional peer, so these stubs deliberately do not import
|
|
7
|
+
* React — they simply throw NotImplementedError. This keeps @mongrov/analytics
|
|
8
|
+
* consumable from non-React runtimes (Node CLI, background workers) until
|
|
9
|
+
* the hooks are actually implemented.
|
|
10
|
+
*/
|
|
11
|
+
export declare function useAnalytics(): {
|
|
12
|
+
state: AnalyticsState;
|
|
13
|
+
isReady: boolean;
|
|
14
|
+
isAttached: boolean;
|
|
15
|
+
error: Error | null;
|
|
16
|
+
};
|
|
17
|
+
export declare function useTimeseries<T = unknown>(_key: string | undefined, _sql: string, _params?: Record<string, unknown>): {
|
|
18
|
+
data: T[] | undefined;
|
|
19
|
+
loading: boolean;
|
|
20
|
+
error: Error | null;
|
|
21
|
+
refetch: () => Promise<void>;
|
|
22
|
+
};
|
|
23
|
+
export declare function useInsight(_id: string): {
|
|
24
|
+
insight: Insight | undefined;
|
|
25
|
+
loading: boolean;
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/core/hooks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEtD;;;;;;;;GAQG;AAGH,wBAAgB,YAAY,IAAI;IAC9B,KAAK,EAAE,cAAc,CAAA;IACrB,OAAO,EAAE,OAAO,CAAA;IAChB,UAAU,EAAE,OAAO,CAAA;IACnB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;CACpB,CAEA;AAGD,wBAAgB,aAAa,CAAC,CAAC,GAAG,OAAO,EACvC,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC;IACD,IAAI,EAAE,CAAC,EAAE,GAAG,SAAS,CAAA;IACrB,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;IACnB,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC7B,CAEA;AAGD,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG;IACvC,OAAO,EAAE,OAAO,GAAG,SAAS,CAAA;IAC5B,OAAO,EAAE,OAAO,CAAA;CACjB,CAEA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { NotImplementedError } from './errors';
|
|
2
|
+
/**
|
|
3
|
+
* React hooks over the analytics engine. Stubs in T-02; real wiring via
|
|
4
|
+
* `useSyncExternalStore` on `engine.subscribe()` lands in Phase 5 (T-11/12/13).
|
|
5
|
+
*
|
|
6
|
+
* React is an optional peer, so these stubs deliberately do not import
|
|
7
|
+
* React — they simply throw NotImplementedError. This keeps @mongrov/analytics
|
|
8
|
+
* consumable from non-React runtimes (Node CLI, background workers) until
|
|
9
|
+
* the hooks are actually implemented.
|
|
10
|
+
*/
|
|
11
|
+
// T-11 — public shape per analytics-core/spec.md §Hooks
|
|
12
|
+
export function useAnalytics() {
|
|
13
|
+
throw new NotImplementedError('useAnalytics');
|
|
14
|
+
}
|
|
15
|
+
// T-12 — public shape per analytics-core/spec.md §Hooks
|
|
16
|
+
export function useTimeseries(_key, _sql, _params) {
|
|
17
|
+
throw new NotImplementedError('useTimeseries');
|
|
18
|
+
}
|
|
19
|
+
// T-13 — public shape per analytics-core/spec.md §Hooks
|
|
20
|
+
export function useInsight(_id) {
|
|
21
|
+
throw new NotImplementedError('useInsight');
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/core/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAG9C;;;;;;;;GAQG;AAEH,wDAAwD;AACxD,MAAM,UAAU,YAAY;IAM1B,MAAM,IAAI,mBAAmB,CAAC,cAAc,CAAC,CAAA;AAC/C,CAAC;AAED,wDAAwD;AACxD,MAAM,UAAU,aAAa,CAC3B,IAAwB,EACxB,IAAY,EACZ,OAAiC;IAOjC,MAAM,IAAI,mBAAmB,CAAC,eAAe,CAAC,CAAA;AAChD,CAAC;AAED,wDAAwD;AACxD,MAAM,UAAU,UAAU,CAAC,GAAW;IAIpC,MAAM,IAAI,mBAAmB,CAAC,YAAY,CAAC,CAAA;AAC7C,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @mongrov/analytics core — public surface.
|
|
3
|
+
*
|
|
4
|
+
* Stubs land in T-02; concrete implementations replace them per the
|
|
5
|
+
* phased tasks in `.specifica/features/analytics-core/tasks.md`.
|
|
6
|
+
*/
|
|
7
|
+
export { createAnalytics } from './factory';
|
|
8
|
+
export { useAnalytics, useInsight, useTimeseries } from './hooks';
|
|
9
|
+
export { AnalyticsError, NotImplementedError } from './errors';
|
|
10
|
+
export type { AnalyticsErrorCode } from './errors';
|
|
11
|
+
export type { AnalyticsAppender, AnalyticsConfig, AnalyticsEngine, AnalyticsLogger, AnalyticsState, AttachContext, EventBus, FamilyMembersProvider, Insight, KVStore, TenantScope, TokenContext, TokenResponse, TokenVendor, Unsubscribe, } from './types';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAG3C,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAGjE,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAC9D,YAAY,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAGlD,YAAY,EACV,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,eAAe,EACf,cAAc,EACd,aAAa,EACb,QAAQ,EACR,qBAAqB,EACrB,OAAO,EACP,OAAO,EACP,WAAW,EACX,YAAY,EACZ,aAAa,EACb,WAAW,EACX,WAAW,GACZ,MAAM,SAAS,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @mongrov/analytics core — public surface.
|
|
3
|
+
*
|
|
4
|
+
* Stubs land in T-02; concrete implementations replace them per the
|
|
5
|
+
* phased tasks in `.specifica/features/analytics-core/tasks.md`.
|
|
6
|
+
*/
|
|
7
|
+
// Factory (T-02 stub → T-10 real)
|
|
8
|
+
export { createAnalytics } from './factory';
|
|
9
|
+
// Hooks (T-02 stubs → T-11/12/13 real)
|
|
10
|
+
export { useAnalytics, useInsight, useTimeseries } from './hooks';
|
|
11
|
+
// Errors
|
|
12
|
+
export { AnalyticsError, NotImplementedError } from './errors';
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,kCAAkC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAE3C,uCAAuC;AACvC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAEjE,SAAS;AACT,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public type surface for @mongrov/analytics core.
|
|
3
|
+
*
|
|
4
|
+
* Shapes are the minimum required by the T-02 stub API. Concrete
|
|
5
|
+
* semantics land in later phases (engine wrapper T-03, warehouse T-05,
|
|
6
|
+
* machine T-09, factory T-10, retention T-14). Rich unions like
|
|
7
|
+
* MetricId + METRIC_METADATA land in T-07.
|
|
8
|
+
*/
|
|
9
|
+
/** Fire-and-forget unsubscribe. */
|
|
10
|
+
export type Unsubscribe = () => void;
|
|
11
|
+
/** Tenant scope for attach + token contexts. */
|
|
12
|
+
export type TenantScope = 'family' | 'org';
|
|
13
|
+
/** Machine state per analytics-core/spec.md §State machine. */
|
|
14
|
+
export type AnalyticsState = 'idle' | 'opening' | 'ready' | 'attaching' | 'attached' | 'detaching' | 'error';
|
|
15
|
+
export interface AttachContext {
|
|
16
|
+
brand: string;
|
|
17
|
+
tenantScope: TenantScope;
|
|
18
|
+
tenantId: string;
|
|
19
|
+
userId: string;
|
|
20
|
+
}
|
|
21
|
+
export interface TokenContext {
|
|
22
|
+
brand: string;
|
|
23
|
+
tenantScope: TenantScope;
|
|
24
|
+
tenantId: string;
|
|
25
|
+
}
|
|
26
|
+
export interface TokenResponse {
|
|
27
|
+
token: string;
|
|
28
|
+
expiresAt: Date;
|
|
29
|
+
scopeClaims: {
|
|
30
|
+
brand: string;
|
|
31
|
+
tenantScope: TenantScope;
|
|
32
|
+
tenantId: string;
|
|
33
|
+
permissions: ('read' | 'write')[];
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export interface TokenVendor {
|
|
37
|
+
fetch(context: TokenContext): Promise<TokenResponse>;
|
|
38
|
+
}
|
|
39
|
+
/** App-provided family membership. Reads Family.memberIds from RxDB in v1. */
|
|
40
|
+
export type FamilyMembersProvider = (ctx: {
|
|
41
|
+
brand: string;
|
|
42
|
+
familyId: string;
|
|
43
|
+
}) => Promise<string[]>;
|
|
44
|
+
export interface AnalyticsLogger {
|
|
45
|
+
debug(message: string, meta?: Record<string, unknown>): void;
|
|
46
|
+
info(message: string, meta?: Record<string, unknown>): void;
|
|
47
|
+
warn(message: string, meta?: Record<string, unknown>): void;
|
|
48
|
+
error(message: string, meta?: Record<string, unknown>): void;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Structural KVStore contract used by the analytics package. Kept local so
|
|
52
|
+
* this package does not require a value-level import from @mongrov/db.
|
|
53
|
+
* The app supplies an implementation (typically @mongrov/db KVStore).
|
|
54
|
+
*/
|
|
55
|
+
export interface KVStore {
|
|
56
|
+
get<T = unknown>(key: string): Promise<T | undefined>;
|
|
57
|
+
set<T = unknown>(key: string, value: T): Promise<void>;
|
|
58
|
+
delete(key: string): Promise<void>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Structural EventBus contract from @mongrov/data-access. Optional peer:
|
|
62
|
+
* populated when analytics-sync emits invalidation events. Full glob
|
|
63
|
+
* semantics documented in data-access/spec.md.
|
|
64
|
+
*/
|
|
65
|
+
export interface EventBus {
|
|
66
|
+
emit<T>(name: string, payload: T): void;
|
|
67
|
+
subscribe<T>(name: string, handler: (payload: T) => void): Unsubscribe;
|
|
68
|
+
subscribePattern<T>(pattern: string, handler: (name: string, payload: T) => void): Unsubscribe;
|
|
69
|
+
}
|
|
70
|
+
export interface AnalyticsConfig {
|
|
71
|
+
storage: KVStore;
|
|
72
|
+
logger?: AnalyticsLogger;
|
|
73
|
+
warehouseUriBuilder: (brand: string, tenantScope: TenantScope, tenantId: string) => string;
|
|
74
|
+
catalogEndpoint: string;
|
|
75
|
+
tokenVendor: TokenVendor;
|
|
76
|
+
familyMembersProvider: FamilyMembersProvider;
|
|
77
|
+
retention: Record<string, {
|
|
78
|
+
days: number;
|
|
79
|
+
}>;
|
|
80
|
+
extensions?: string[];
|
|
81
|
+
dbPath?: string;
|
|
82
|
+
duckdb?: {
|
|
83
|
+
memoryLimit?: string;
|
|
84
|
+
threads?: string;
|
|
85
|
+
};
|
|
86
|
+
eventBus?: EventBus;
|
|
87
|
+
}
|
|
88
|
+
export interface AnalyticsAppender {
|
|
89
|
+
appendRow(values: unknown[]): void;
|
|
90
|
+
flush(): void;
|
|
91
|
+
close(): void;
|
|
92
|
+
}
|
|
93
|
+
export interface AnalyticsEngine {
|
|
94
|
+
attach(ctx: AttachContext): Promise<void>;
|
|
95
|
+
detach(): Promise<void>;
|
|
96
|
+
execute<T = unknown>(sql: string, params?: Record<string, unknown>): Promise<T[]>;
|
|
97
|
+
stream<T = unknown>(sql: string, params?: Record<string, unknown>): AsyncIterable<T[]>;
|
|
98
|
+
createAppender(table: string): AnalyticsAppender;
|
|
99
|
+
readonly state: AnalyticsState;
|
|
100
|
+
subscribe(listener: (s: AnalyticsState) => void): Unsubscribe;
|
|
101
|
+
setRetention(days: number): Promise<void>;
|
|
102
|
+
close(): Promise<void>;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Insight row shape as read from the `insight` DuckDB table.
|
|
106
|
+
* The full schema is frozen in T-06 (schemas.ts); this stub matches the
|
|
107
|
+
* columns needed by `useInsight()` in v0.1.0.
|
|
108
|
+
*/
|
|
109
|
+
export interface Insight {
|
|
110
|
+
id: string;
|
|
111
|
+
brand: string;
|
|
112
|
+
familyId: string;
|
|
113
|
+
userId: string;
|
|
114
|
+
ruleId?: string;
|
|
115
|
+
severity: 'info' | 'warn' | 'critical';
|
|
116
|
+
observedAt: Date;
|
|
117
|
+
observedValue?: number;
|
|
118
|
+
thresholdValue?: number;
|
|
119
|
+
payload?: Record<string, unknown>;
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,mCAAmC;AACnC,MAAM,MAAM,WAAW,GAAG,MAAM,IAAI,CAAA;AAEpC,gDAAgD;AAChD,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,KAAK,CAAA;AAE1C,+DAA+D;AAC/D,MAAM,MAAM,cAAc,GACtB,MAAM,GACN,SAAS,GACT,OAAO,GACP,WAAW,GACX,UAAU,GACV,WAAW,GACX,OAAO,CAAA;AAIX,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,WAAW,CAAA;IACxB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;C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A;IACtC,UAAU,EAAE,IAAI,CAAA;IAChB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAClC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public type surface for @mongrov/analytics core.
|
|
3
|
+
*
|
|
4
|
+
* Shapes are the minimum required by the T-02 stub API. Concrete
|
|
5
|
+
* semantics land in later phases (engine wrapper T-03, warehouse T-05,
|
|
6
|
+
* machine T-09, factory T-10, retention T-14). Rich unions like
|
|
7
|
+
* MetricId + METRIC_METADATA land in T-07.
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @mongrov/analytics — DuckDB + R2 Iceberg local analytics
|
|
3
|
+
*
|
|
4
|
+
* Root subpath re-exports the core surface. Subpaths:
|
|
5
|
+
* - @mongrov/analytics → core (engine, factory, hooks)
|
|
6
|
+
* - @mongrov/analytics/rules → structured threshold rule engine
|
|
7
|
+
* - @mongrov/analytics/tools → typed AI SDK tools + MCP server
|
|
8
|
+
* - @mongrov/analytics/sync → firmware mapper + sensor sink + R2 push/fetch
|
|
9
|
+
* - @mongrov/analytics/ui → UI primitives (subpath reserved)
|
|
10
|
+
*
|
|
11
|
+
* See `.specifica/features/analytics-core/spec.md` for scope.
|
|
12
|
+
*/
|
|
13
|
+
export * from './core';
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,cAAc,QAAQ,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @mongrov/analytics — DuckDB + R2 Iceberg local analytics
|
|
3
|
+
*
|
|
4
|
+
* Root subpath re-exports the core surface. Subpaths:
|
|
5
|
+
* - @mongrov/analytics → core (engine, factory, hooks)
|
|
6
|
+
* - @mongrov/analytics/rules → structured threshold rule engine
|
|
7
|
+
* - @mongrov/analytics/tools → typed AI SDK tools + MCP server
|
|
8
|
+
* - @mongrov/analytics/sync → firmware mapper + sensor sink + R2 push/fetch
|
|
9
|
+
* - @mongrov/analytics/ui → UI primitives (subpath reserved)
|
|
10
|
+
*
|
|
11
|
+
* See `.specifica/features/analytics-core/spec.md` for scope.
|
|
12
|
+
*/
|
|
13
|
+
export * from './core';
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,cAAc,QAAQ,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sync/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sync/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ui/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAA"}
|
package/dist/ui/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ui/index.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mongrov/analytics",
|
|
3
|
+
"version": "0.1.0-alpha.0",
|
|
4
|
+
"description": "DuckDB + R2 Iceberg local analytics for @mongrov apps",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/mongrov/mongrov-packages.git",
|
|
9
|
+
"directory": "packages/analytics"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"react-native",
|
|
13
|
+
"expo",
|
|
14
|
+
"duckdb",
|
|
15
|
+
"iceberg",
|
|
16
|
+
"analytics",
|
|
17
|
+
"r2",
|
|
18
|
+
"cloudflare"
|
|
19
|
+
],
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=18"
|
|
22
|
+
},
|
|
23
|
+
"main": "dist/index.js",
|
|
24
|
+
"types": "dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.js",
|
|
29
|
+
"default": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./rules": {
|
|
32
|
+
"types": "./dist/rules/index.d.ts",
|
|
33
|
+
"import": "./dist/rules/index.js",
|
|
34
|
+
"default": "./dist/rules/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./tools": {
|
|
37
|
+
"types": "./dist/tools/index.d.ts",
|
|
38
|
+
"import": "./dist/tools/index.js",
|
|
39
|
+
"default": "./dist/tools/index.js"
|
|
40
|
+
},
|
|
41
|
+
"./sync": {
|
|
42
|
+
"types": "./dist/sync/index.d.ts",
|
|
43
|
+
"import": "./dist/sync/index.js",
|
|
44
|
+
"default": "./dist/sync/index.js"
|
|
45
|
+
},
|
|
46
|
+
"./ui": {
|
|
47
|
+
"types": "./dist/ui/index.d.ts",
|
|
48
|
+
"import": "./dist/ui/index.js",
|
|
49
|
+
"default": "./dist/ui/index.js"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"files": [
|
|
53
|
+
"dist"
|
|
54
|
+
],
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"@mongrov/types": "^0.4.0",
|
|
57
|
+
"react": ">=19",
|
|
58
|
+
"react-native": ">=0.81",
|
|
59
|
+
"react-native-duckdb": ">=1.0.0",
|
|
60
|
+
"@mongrov/db": "0.3.0"
|
|
61
|
+
},
|
|
62
|
+
"peerDependenciesMeta": {
|
|
63
|
+
"react": {
|
|
64
|
+
"optional": true
|
|
65
|
+
},
|
|
66
|
+
"react-native": {
|
|
67
|
+
"optional": true
|
|
68
|
+
},
|
|
69
|
+
"react-native-duckdb": {
|
|
70
|
+
"optional": true
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"devDependencies": {
|
|
74
|
+
"typescript": "^5.9.3",
|
|
75
|
+
"vitest": "^2.1.9",
|
|
76
|
+
"xstate": "^5.30.0",
|
|
77
|
+
"zod": "^3.23.8",
|
|
78
|
+
"@mongrov/db": "0.3.0",
|
|
79
|
+
"@mongrov/types": "0.4.0"
|
|
80
|
+
},
|
|
81
|
+
"scripts": {
|
|
82
|
+
"build": "tsc -p tsconfig.build.json",
|
|
83
|
+
"clean": "rm -rf dist",
|
|
84
|
+
"prebuild": "pnpm run clean",
|
|
85
|
+
"test": "vitest run",
|
|
86
|
+
"test:watch": "vitest",
|
|
87
|
+
"typecheck": "tsc --noEmit"
|
|
88
|
+
}
|
|
89
|
+
}
|