@contractspec/example.analytics-dashboard 0.0.0-canary-20260113170453
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/README.md +281 -0
- package/dist/dashboard/dashboard.enum.d.ts +18 -0
- package/dist/dashboard/dashboard.enum.d.ts.map +1 -0
- package/dist/dashboard/dashboard.enum.js +43 -0
- package/dist/dashboard/dashboard.enum.js.map +1 -0
- package/dist/dashboard/dashboard.operation.d.ts +537 -0
- package/dist/dashboard/dashboard.operation.d.ts.map +1 -0
- package/dist/dashboard/dashboard.operation.js +213 -0
- package/dist/dashboard/dashboard.operation.js.map +1 -0
- package/dist/dashboard/dashboard.presentation.d.ts +9 -0
- package/dist/dashboard/dashboard.presentation.d.ts.map +1 -0
- package/dist/dashboard/dashboard.presentation.js +90 -0
- package/dist/dashboard/dashboard.presentation.js.map +1 -0
- package/dist/dashboard/dashboard.schema.d.ts +333 -0
- package/dist/dashboard/dashboard.schema.d.ts.map +1 -0
- package/dist/dashboard/dashboard.schema.js +236 -0
- package/dist/dashboard/dashboard.schema.js.map +1 -0
- package/dist/dashboard/dashboard.test-spec.d.ts +10 -0
- package/dist/dashboard/dashboard.test-spec.d.ts.map +1 -0
- package/dist/dashboard/dashboard.test-spec.js +233 -0
- package/dist/dashboard/dashboard.test-spec.js.map +1 -0
- package/dist/dashboard/index.d.ts +4 -0
- package/dist/dashboard/index.js +5 -0
- package/dist/dashboard.feature.d.ts +17 -0
- package/dist/dashboard.feature.d.ts.map +1 -0
- package/dist/dashboard.feature.js +177 -0
- package/dist/dashboard.feature.js.map +1 -0
- package/dist/docs/analytics-dashboard.docblock.d.ts +1 -0
- package/dist/docs/analytics-dashboard.docblock.js +114 -0
- package/dist/docs/analytics-dashboard.docblock.js.map +1 -0
- package/dist/docs/index.d.ts +1 -0
- package/dist/docs/index.js +1 -0
- package/dist/events.d.ts +149 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +128 -0
- package/dist/events.js.map +1 -0
- package/dist/example.d.ts +7 -0
- package/dist/example.d.ts.map +1 -0
- package/dist/example.js +58 -0
- package/dist/example.js.map +1 -0
- package/dist/handlers/analytics.handlers.d.ts +122 -0
- package/dist/handlers/analytics.handlers.d.ts.map +1 -0
- package/dist/handlers/analytics.handlers.js +310 -0
- package/dist/handlers/analytics.handlers.js.map +1 -0
- package/dist/handlers/index.d.ts +2 -0
- package/dist/handlers/index.js +3 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +13 -0
- package/dist/query/index.d.ts +4 -0
- package/dist/query/index.js +5 -0
- package/dist/query/query.enum.d.ts +10 -0
- package/dist/query/query.enum.d.ts.map +1 -0
- package/dist/query/query.enum.js +16 -0
- package/dist/query/query.enum.js.map +1 -0
- package/dist/query/query.operation.d.ts +181 -0
- package/dist/query/query.operation.d.ts.map +1 -0
- package/dist/query/query.operation.js +113 -0
- package/dist/query/query.operation.js.map +1 -0
- package/dist/query/query.presentation.d.ts +8 -0
- package/dist/query/query.presentation.d.ts.map +1 -0
- package/dist/query/query.presentation.js +60 -0
- package/dist/query/query.presentation.js.map +1 -0
- package/dist/query/query.schema.d.ts +143 -0
- package/dist/query/query.schema.d.ts.map +1 -0
- package/dist/query/query.schema.js +157 -0
- package/dist/query/query.schema.js.map +1 -0
- package/dist/query/query.test-spec.d.ts +8 -0
- package/dist/query/query.test-spec.d.ts.map +1 -0
- package/dist/query/query.test-spec.js +124 -0
- package/dist/query/query.test-spec.js.map +1 -0
- package/dist/query-engine/index.d.ts +106 -0
- package/dist/query-engine/index.d.ts.map +1 -0
- package/dist/query-engine/index.js +189 -0
- package/dist/query-engine/index.js.map +1 -0
- package/dist/seeders/index.d.ts +10 -0
- package/dist/seeders/index.d.ts.map +1 -0
- package/dist/seeders/index.js +19 -0
- package/dist/seeders/index.js.map +1 -0
- package/dist/ui/AnalyticsDashboard.d.ts +7 -0
- package/dist/ui/AnalyticsDashboard.d.ts.map +1 -0
- package/dist/ui/AnalyticsDashboard.js +265 -0
- package/dist/ui/AnalyticsDashboard.js.map +1 -0
- package/dist/ui/hooks/index.d.ts +2 -0
- package/dist/ui/hooks/index.js +5 -0
- package/dist/ui/hooks/useAnalyticsData.d.ts +23 -0
- package/dist/ui/hooks/useAnalyticsData.d.ts.map +1 -0
- package/dist/ui/hooks/useAnalyticsData.js +73 -0
- package/dist/ui/hooks/useAnalyticsData.js.map +1 -0
- package/dist/ui/index.d.ts +6 -0
- package/dist/ui/index.js +6 -0
- package/dist/ui/renderers/analytics.markdown.d.ts +28 -0
- package/dist/ui/renderers/analytics.markdown.d.ts.map +1 -0
- package/dist/ui/renderers/analytics.markdown.js +264 -0
- package/dist/ui/renderers/analytics.markdown.js.map +1 -0
- package/dist/ui/renderers/index.d.ts +2 -0
- package/dist/ui/renderers/index.js +3 -0
- package/package.json +101 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.schema.js","names":[],"sources":["../../src/query/query.schema.ts"],"sourcesContent":["import { defineSchemaModel, ScalarTypeEnum } from '@contractspec/lib.schema';\nimport { QueryTypeEnum } from './query.enum';\n\n/**\n * A data query.\n */\nexport const QueryModel = defineSchemaModel({\n name: 'QueryModel',\n fields: {\n id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n type: { type: QueryTypeEnum, isOptional: false },\n definition: { type: ScalarTypeEnum.JSON(), isOptional: false },\n sql: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n cacheTtlSeconds: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },\n isShared: { type: ScalarTypeEnum.Boolean(), isOptional: false },\n createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },\n },\n});\n\n/**\n * Query execution result.\n */\nexport const QueryResultModel = defineSchemaModel({\n name: 'QueryResultModel',\n fields: {\n queryId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n data: { type: ScalarTypeEnum.JSON(), isOptional: false },\n columns: { type: ScalarTypeEnum.JSON(), isOptional: false },\n rowCount: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },\n executionTimeMs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },\n cachedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },\n error: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n },\n});\n\n/**\n * Input for creating a query.\n */\nexport const CreateQueryInputModel = defineSchemaModel({\n name: 'CreateQueryInput',\n fields: {\n name: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },\n description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n type: { type: QueryTypeEnum, isOptional: false },\n definition: { type: ScalarTypeEnum.JSON(), isOptional: false },\n sql: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n metricIds: {\n type: ScalarTypeEnum.String_unsecure(),\n isArray: true,\n isOptional: true,\n },\n cacheTtlSeconds: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },\n isShared: { type: ScalarTypeEnum.Boolean(), isOptional: true },\n },\n});\n\n/**\n * Input for executing a query.\n */\nexport const ExecuteQueryInputModel = defineSchemaModel({\n name: 'ExecuteQueryInput',\n fields: {\n queryId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n parameters: { type: ScalarTypeEnum.JSON(), isOptional: true },\n dateRange: { type: ScalarTypeEnum.JSON(), isOptional: true },\n filters: { type: ScalarTypeEnum.JSON(), isOptional: true },\n forceRefresh: { type: ScalarTypeEnum.Boolean(), isOptional: true },\n },\n});\n"],"mappings":";;;;;;;AAMA,MAAa,aAAa,kBAAkB;CAC1C,MAAM;CACN,QAAQ;EACN,IAAI;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAO;EACjE,MAAM;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAO;EACnE,aAAa;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAM;EACzE,MAAM;G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C1E,UAAU;GAAE,MAAM,eAAe,SAAS;GAAE,YAAY;GAAM;EAC/D;CACF,CAAC;;;;AAKF,MAAa,yBAAyB,kBAAkB;CACtD,MAAM;CACN,QAAQ;EACN,SAAS;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAO;EACtE,YAAY;GAAE,MAAM,eAAe,MAAM;GAAE,YAAY;GAAM;EAC7D,WAAW;GAAE,MAAM,eAAe,MAAM;GAAE,YAAY;GAAM;EAC5D,SAAS;GAAE,MAAM,eAAe,MAAM;GAAE,YAAY;GAAM;EAC1D,cAAc;GAAE,MAAM,eAAe,SAAS;GAAE,YAAY;GAAM;EACnE;CACF,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as _contractspec_lib_contracts11 from "@contractspec/lib.contracts";
|
|
2
|
+
|
|
3
|
+
//#region src/query/query.test-spec.d.ts
|
|
4
|
+
declare const CreateQueryTest: _contractspec_lib_contracts11.TestSpec;
|
|
5
|
+
declare const ExecuteQueryTest: _contractspec_lib_contracts11.TestSpec;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { CreateQueryTest, ExecuteQueryTest };
|
|
8
|
+
//# sourceMappingURL=query.test-spec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.test-spec.d.ts","names":[],"sources":["../../src/query/query.test-spec.ts"],"sourcesContent":[],"mappings":";;;cAEa,iBAqDX,6BAAA,CArD0B;cAuDf,kBAoDX,6BAAA,CApD2B"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { defineTestSpec } from "@contractspec/lib.contracts";
|
|
2
|
+
|
|
3
|
+
//#region src/query/query.test-spec.ts
|
|
4
|
+
const CreateQueryTest = defineTestSpec({
|
|
5
|
+
meta: {
|
|
6
|
+
key: "analytics.query.create.test",
|
|
7
|
+
version: "1.0.0",
|
|
8
|
+
title: "Create Query Test",
|
|
9
|
+
description: "Verifies query creation flow",
|
|
10
|
+
owners: ["@example.analytics-dashboard"],
|
|
11
|
+
tags: [
|
|
12
|
+
"analytics",
|
|
13
|
+
"query",
|
|
14
|
+
"test"
|
|
15
|
+
],
|
|
16
|
+
stability: "stable"
|
|
17
|
+
},
|
|
18
|
+
target: {
|
|
19
|
+
type: "operation",
|
|
20
|
+
operation: {
|
|
21
|
+
key: "analytics.query.create",
|
|
22
|
+
version: "1.0.0"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
scenarios: [{
|
|
26
|
+
key: "success",
|
|
27
|
+
description: "Successfully create a query",
|
|
28
|
+
when: {
|
|
29
|
+
operation: {
|
|
30
|
+
key: "analytics.query.create",
|
|
31
|
+
version: "1.0.0"
|
|
32
|
+
},
|
|
33
|
+
input: {
|
|
34
|
+
name: "Revenue Query",
|
|
35
|
+
sql: "SELECT * FROM revenue"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
then: [{
|
|
39
|
+
type: "expectOutput",
|
|
40
|
+
match: {
|
|
41
|
+
name: "Revenue Query",
|
|
42
|
+
type: "sql"
|
|
43
|
+
}
|
|
44
|
+
}]
|
|
45
|
+
}, {
|
|
46
|
+
key: "error-invalid-sql",
|
|
47
|
+
description: "Fail with invalid SQL",
|
|
48
|
+
when: {
|
|
49
|
+
operation: {
|
|
50
|
+
key: "analytics.query.create",
|
|
51
|
+
version: "1.0.0"
|
|
52
|
+
},
|
|
53
|
+
input: {
|
|
54
|
+
name: "Bad Query",
|
|
55
|
+
sql: ""
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
then: [{
|
|
59
|
+
type: "expectError",
|
|
60
|
+
messageIncludes: "VALIDATION_ERROR"
|
|
61
|
+
}]
|
|
62
|
+
}]
|
|
63
|
+
});
|
|
64
|
+
const ExecuteQueryTest = defineTestSpec({
|
|
65
|
+
meta: {
|
|
66
|
+
key: "analytics.query.execute.test",
|
|
67
|
+
version: "1.0.0",
|
|
68
|
+
title: "Execute Query Test",
|
|
69
|
+
description: "Verifies query execution",
|
|
70
|
+
owners: ["@example.analytics-dashboard"],
|
|
71
|
+
tags: [
|
|
72
|
+
"analytics",
|
|
73
|
+
"query",
|
|
74
|
+
"test"
|
|
75
|
+
],
|
|
76
|
+
stability: "stable"
|
|
77
|
+
},
|
|
78
|
+
target: {
|
|
79
|
+
type: "operation",
|
|
80
|
+
operation: {
|
|
81
|
+
key: "analytics.query.execute",
|
|
82
|
+
version: "1.0.0"
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
scenarios: [{
|
|
86
|
+
key: "success",
|
|
87
|
+
description: "Successfully execute query",
|
|
88
|
+
when: {
|
|
89
|
+
operation: {
|
|
90
|
+
key: "analytics.query.execute",
|
|
91
|
+
version: "1.0.0"
|
|
92
|
+
},
|
|
93
|
+
input: {
|
|
94
|
+
queryId: "q-123",
|
|
95
|
+
params: { limit: 10 }
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
then: [{
|
|
99
|
+
type: "expectOutput",
|
|
100
|
+
match: { rowCount: 1 }
|
|
101
|
+
}]
|
|
102
|
+
}, {
|
|
103
|
+
key: "error-query-not-found",
|
|
104
|
+
description: "Fail when query not found",
|
|
105
|
+
when: {
|
|
106
|
+
operation: {
|
|
107
|
+
key: "analytics.query.execute",
|
|
108
|
+
version: "1.0.0"
|
|
109
|
+
},
|
|
110
|
+
input: {
|
|
111
|
+
queryId: "q-999",
|
|
112
|
+
params: {}
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
then: [{
|
|
116
|
+
type: "expectError",
|
|
117
|
+
messageIncludes: "NOT_FOUND"
|
|
118
|
+
}]
|
|
119
|
+
}]
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
//#endregion
|
|
123
|
+
export { CreateQueryTest, ExecuteQueryTest };
|
|
124
|
+
//# sourceMappingURL=query.test-spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.test-spec.js","names":[],"sources":["../../src/query/query.test-spec.ts"],"sourcesContent":["import { defineTestSpec } from '@contractspec/lib.contracts';\n\nexport const CreateQueryTest = defineTestSpec({\n meta: {\n key: 'analytics.query.create.test',\n version: '1.0.0',\n title: 'Create Query Test',\n description: 'Verifies query creation flow',\n owners: ['@example.analytics-dashboard'],\n tags: ['analytics', 'query', 'test'],\n stability: 'stable',\n },\n target: {\n type: 'operation',\n operation: { key: 'analytics.query.create', version: '1.0.0' },\n },\n scenarios: [\n {\n key: 'success',\n description: 'Successfully create a query',\n when: {\n operation: { key: 'analytics.query.create', version: '1.0.0' },\n input: {\n name: 'Revenue Query',\n sql: 'SELECT * FROM revenue',\n },\n },\n then: [\n {\n type: 'expectOutput',\n match: {\n name: 'Revenue Query',\n type: 'sql',\n },\n },\n ],\n },\n {\n key: 'error-invalid-sql',\n description: 'Fail with invalid SQL',\n when: {\n operation: { key: 'analytics.query.create', version: '1.0.0' },\n input: {\n name: 'Bad Query',\n sql: '',\n },\n },\n then: [\n {\n type: 'expectError',\n messageIncludes: 'VALIDATION_ERROR',\n },\n ],\n },\n ],\n});\n\nexport const ExecuteQueryTest = defineTestSpec({\n meta: {\n key: 'analytics.query.execute.test',\n version: '1.0.0',\n title: 'Execute Query Test',\n description: 'Verifies query execution',\n owners: ['@example.analytics-dashboard'],\n tags: ['analytics', 'query', 'test'],\n stability: 'stable',\n },\n target: {\n type: 'operation',\n operation: { key: 'analytics.query.execute', version: '1.0.0' },\n },\n scenarios: [\n {\n key: 'success',\n description: 'Successfully execute query',\n when: {\n operation: { key: 'analytics.query.execute', version: '1.0.0' },\n input: {\n queryId: 'q-123',\n params: { limit: 10 },\n },\n },\n then: [\n {\n type: 'expectOutput',\n match: {\n rowCount: 1,\n },\n },\n ],\n },\n {\n key: 'error-query-not-found',\n description: 'Fail when query not found',\n when: {\n operation: { key: 'analytics.query.execute', version: '1.0.0' },\n input: {\n queryId: 'q-999',\n params: {},\n },\n },\n then: [\n {\n type: 'expectError',\n messageIncludes: 'NOT_FOUND',\n },\n ],\n },\n ],\n});\n"],"mappings":";;;AAEA,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GACF;EACD,MAAM,CACJ;GACE,MAAM;GACN,iBAAiB;GAClB,CACF;EACF,CACF;CACF,CAAC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
//#region src/query-engine/index.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Analytics Query Engine
|
|
4
|
+
*
|
|
5
|
+
* Provides query execution and caching for analytics dashboards.
|
|
6
|
+
*/
|
|
7
|
+
interface QueryDefinition {
|
|
8
|
+
type: 'SQL' | 'METRIC' | 'AGGREGATION' | 'CUSTOM';
|
|
9
|
+
sql?: string;
|
|
10
|
+
metricIds?: string[];
|
|
11
|
+
aggregation?: AggregationDefinition;
|
|
12
|
+
custom?: CustomQueryDefinition;
|
|
13
|
+
}
|
|
14
|
+
interface AggregationDefinition {
|
|
15
|
+
source: string;
|
|
16
|
+
measures: MeasureDefinition[];
|
|
17
|
+
dimensions: DimensionDefinition[];
|
|
18
|
+
filters?: FilterDefinition[];
|
|
19
|
+
orderBy?: OrderByDefinition[];
|
|
20
|
+
limit?: number;
|
|
21
|
+
}
|
|
22
|
+
interface MeasureDefinition {
|
|
23
|
+
name: string;
|
|
24
|
+
field: string;
|
|
25
|
+
aggregation: 'COUNT' | 'SUM' | 'AVG' | 'MIN' | 'MAX' | 'COUNT_DISTINCT';
|
|
26
|
+
format?: string;
|
|
27
|
+
}
|
|
28
|
+
interface DimensionDefinition {
|
|
29
|
+
name: string;
|
|
30
|
+
field: string;
|
|
31
|
+
type?: 'TIME' | 'STRING' | 'NUMBER';
|
|
32
|
+
granularity?: 'HOUR' | 'DAY' | 'WEEK' | 'MONTH' | 'YEAR';
|
|
33
|
+
}
|
|
34
|
+
interface FilterDefinition {
|
|
35
|
+
field: string;
|
|
36
|
+
operator: 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'in' | 'nin' | 'contains' | 'between';
|
|
37
|
+
value: unknown;
|
|
38
|
+
}
|
|
39
|
+
interface OrderByDefinition {
|
|
40
|
+
field: string;
|
|
41
|
+
direction: 'ASC' | 'DESC';
|
|
42
|
+
}
|
|
43
|
+
interface CustomQueryDefinition {
|
|
44
|
+
handler: string;
|
|
45
|
+
parameters: Record<string, unknown>;
|
|
46
|
+
}
|
|
47
|
+
interface QueryParameters {
|
|
48
|
+
dateRange?: {
|
|
49
|
+
start: Date;
|
|
50
|
+
end: Date;
|
|
51
|
+
granularity?: string;
|
|
52
|
+
};
|
|
53
|
+
filters?: FilterDefinition[];
|
|
54
|
+
parameters?: Record<string, unknown>;
|
|
55
|
+
}
|
|
56
|
+
interface QueryResult {
|
|
57
|
+
data: Record<string, unknown>[];
|
|
58
|
+
columns: ColumnDefinition[];
|
|
59
|
+
rowCount: number;
|
|
60
|
+
executionTimeMs: number;
|
|
61
|
+
cached: boolean;
|
|
62
|
+
cachedAt?: Date;
|
|
63
|
+
error?: string;
|
|
64
|
+
}
|
|
65
|
+
interface ColumnDefinition {
|
|
66
|
+
name: string;
|
|
67
|
+
type: 'STRING' | 'NUMBER' | 'DATE' | 'BOOLEAN';
|
|
68
|
+
label?: string;
|
|
69
|
+
format?: string;
|
|
70
|
+
}
|
|
71
|
+
interface IQueryEngine {
|
|
72
|
+
execute(definition: QueryDefinition, params: QueryParameters): Promise<QueryResult>;
|
|
73
|
+
validateQuery(definition: QueryDefinition): {
|
|
74
|
+
valid: boolean;
|
|
75
|
+
errors: string[];
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
interface IQueryCache {
|
|
79
|
+
get(key: string): Promise<QueryResult | null>;
|
|
80
|
+
set(key: string, result: QueryResult, ttlSeconds: number): Promise<void>;
|
|
81
|
+
invalidate(pattern: string): Promise<void>;
|
|
82
|
+
}
|
|
83
|
+
declare class InMemoryQueryCache implements IQueryCache {
|
|
84
|
+
private cache;
|
|
85
|
+
get(key: string): Promise<QueryResult | null>;
|
|
86
|
+
set(key: string, result: QueryResult, ttlSeconds: number): Promise<void>;
|
|
87
|
+
invalidate(pattern: string): Promise<void>;
|
|
88
|
+
}
|
|
89
|
+
declare class BasicQueryEngine implements IQueryEngine {
|
|
90
|
+
private cache;
|
|
91
|
+
constructor(cache?: IQueryCache);
|
|
92
|
+
execute(definition: QueryDefinition, params: QueryParameters): Promise<QueryResult>;
|
|
93
|
+
validateQuery(definition: QueryDefinition): {
|
|
94
|
+
valid: boolean;
|
|
95
|
+
errors: string[];
|
|
96
|
+
};
|
|
97
|
+
private buildCacheKey;
|
|
98
|
+
private executeAggregation;
|
|
99
|
+
private executeMetric;
|
|
100
|
+
private executeSql;
|
|
101
|
+
private generateMockData;
|
|
102
|
+
}
|
|
103
|
+
declare function createQueryEngine(cache?: IQueryCache): IQueryEngine;
|
|
104
|
+
//#endregion
|
|
105
|
+
export { AggregationDefinition, BasicQueryEngine, ColumnDefinition, CustomQueryDefinition, DimensionDefinition, FilterDefinition, IQueryCache, IQueryEngine, InMemoryQueryCache, MeasureDefinition, OrderByDefinition, QueryDefinition, QueryParameters, QueryResult, createQueryEngine };
|
|
106
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/query-engine/index.ts"],"sourcesContent":[],"mappings":";;AAQA;AAQA;;;AAIY,UAZK,eAAA,CAYL;EACA,IAAA,EAAA,KAAA,GAAA,QAAA,GAAA,aAAA,GAAA,QAAA;EAAiB,GAAA,CAAA,EAAA,MAAA;EAIZ,SAAA,CAAA,EAAA,MAAA,EAAiB;EAOjB,WAAA,CAAA,EApBD,qBAoBoB;EAOnB,MAAA,CAAA,EA1BN,qBA0BsB;AAgBjC;AAKiB,UA5CA,qBAAA,CA4CqB;EAKrB,MAAA,EAAA,MAAA;EAEN,QAAA,EAjDC,iBAiDD,EAAA;EACF,UAAA,EAjDK,mBAiDL,EAAA;EAGG,OAAA,CAAA,EAnDA,gBAmDA,EAAA;EACG,OAAA,CAAA,EAnDH,iBAmDG,EAAA;EAAM,KAAA,CAAA,EAAA,MAAA;AAGrB;AACQ,UAnDS,iBA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BACP,QAAQ;4BACe;;;;;UAQX,WAAA;oBACG,QAAQ;2BACD,kCAAkC;+BAC9B;;cAGlB,kBAAA,YAA8B;;oBAGjB,QAAQ;2BAYtB,kCAEP;+BAKgC;;cAYxB,gBAAA,YAA4B;;sBAGnB;sBAKN,yBACJ,kBACP,QAAQ;4BAgEe;;;;;;;;;;iBAmKZ,iBAAA,SAA0B,cAAc"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
//#region src/query-engine/index.ts
|
|
2
|
+
var InMemoryQueryCache = class {
|
|
3
|
+
cache = /* @__PURE__ */ new Map();
|
|
4
|
+
async get(key) {
|
|
5
|
+
const entry = this.cache.get(key);
|
|
6
|
+
if (!entry) return null;
|
|
7
|
+
if (entry.expiresAt < /* @__PURE__ */ new Date()) {
|
|
8
|
+
this.cache.delete(key);
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
...entry.result,
|
|
13
|
+
cached: true,
|
|
14
|
+
cachedAt: entry.expiresAt
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
async set(key, result, ttlSeconds) {
|
|
18
|
+
const expiresAt = new Date(Date.now() + ttlSeconds * 1e3);
|
|
19
|
+
this.cache.set(key, {
|
|
20
|
+
result,
|
|
21
|
+
expiresAt
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
async invalidate(pattern) {
|
|
25
|
+
const regex = new RegExp(pattern);
|
|
26
|
+
for (const key of this.cache.keys()) if (regex.test(key)) this.cache.delete(key);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var BasicQueryEngine = class {
|
|
30
|
+
cache;
|
|
31
|
+
constructor(cache) {
|
|
32
|
+
this.cache = cache ?? new InMemoryQueryCache();
|
|
33
|
+
}
|
|
34
|
+
async execute(definition, params) {
|
|
35
|
+
const startTime = Date.now();
|
|
36
|
+
const validation = this.validateQuery(definition);
|
|
37
|
+
if (!validation.valid) return {
|
|
38
|
+
data: [],
|
|
39
|
+
columns: [],
|
|
40
|
+
rowCount: 0,
|
|
41
|
+
executionTimeMs: Date.now() - startTime,
|
|
42
|
+
cached: false,
|
|
43
|
+
error: validation.errors.join(", ")
|
|
44
|
+
};
|
|
45
|
+
const cacheKey = this.buildCacheKey(definition, params);
|
|
46
|
+
const cachedResult = await this.cache.get(cacheKey);
|
|
47
|
+
if (cachedResult) return cachedResult;
|
|
48
|
+
let result;
|
|
49
|
+
switch (definition.type) {
|
|
50
|
+
case "AGGREGATION":
|
|
51
|
+
if (!definition.aggregation) throw new Error("Aggregation definition is missing");
|
|
52
|
+
result = await this.executeAggregation(definition.aggregation, params);
|
|
53
|
+
break;
|
|
54
|
+
case "METRIC":
|
|
55
|
+
if (!definition.metricIds) throw new Error("Metric IDs are missing");
|
|
56
|
+
result = await this.executeMetric(definition.metricIds, params);
|
|
57
|
+
break;
|
|
58
|
+
case "SQL":
|
|
59
|
+
if (!definition.sql) throw new Error("SQL query is missing");
|
|
60
|
+
result = await this.executeSql(definition.sql, params);
|
|
61
|
+
break;
|
|
62
|
+
default: result = {
|
|
63
|
+
data: [],
|
|
64
|
+
columns: [],
|
|
65
|
+
rowCount: 0,
|
|
66
|
+
executionTimeMs: Date.now() - startTime,
|
|
67
|
+
cached: false,
|
|
68
|
+
error: `Unknown query type: ${definition.type}`
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
result.executionTimeMs = Date.now() - startTime;
|
|
72
|
+
result.cached = false;
|
|
73
|
+
await this.cache.set(cacheKey, result, 300);
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
validateQuery(definition) {
|
|
77
|
+
const errors = [];
|
|
78
|
+
if (!definition.type) errors.push("Query type is required");
|
|
79
|
+
switch (definition.type) {
|
|
80
|
+
case "SQL":
|
|
81
|
+
if (!definition.sql) errors.push("SQL query is required for SQL type");
|
|
82
|
+
break;
|
|
83
|
+
case "METRIC":
|
|
84
|
+
if (!definition.metricIds || definition.metricIds.length === 0) errors.push("Metric IDs are required for METRIC type");
|
|
85
|
+
break;
|
|
86
|
+
case "AGGREGATION":
|
|
87
|
+
if (!definition.aggregation) errors.push("Aggregation definition is required for AGGREGATION type");
|
|
88
|
+
else {
|
|
89
|
+
if (!definition.aggregation.source) errors.push("Aggregation source is required");
|
|
90
|
+
if (!definition.aggregation.measures || definition.aggregation.measures.length === 0) errors.push("At least one measure is required");
|
|
91
|
+
}
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
valid: errors.length === 0,
|
|
96
|
+
errors
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
buildCacheKey(definition, params) {
|
|
100
|
+
return JSON.stringify({
|
|
101
|
+
definition,
|
|
102
|
+
params
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
async executeAggregation(aggregation, params) {
|
|
106
|
+
const columns = [...aggregation.dimensions.map((d) => ({
|
|
107
|
+
name: d.name,
|
|
108
|
+
type: d.type === "NUMBER" ? "NUMBER" : d.type === "TIME" ? "DATE" : "STRING",
|
|
109
|
+
label: d.name
|
|
110
|
+
})), ...aggregation.measures.map((m) => ({
|
|
111
|
+
name: m.name,
|
|
112
|
+
type: "NUMBER",
|
|
113
|
+
label: m.name,
|
|
114
|
+
format: m.format
|
|
115
|
+
}))];
|
|
116
|
+
const data = this.generateMockData(aggregation, params);
|
|
117
|
+
return {
|
|
118
|
+
data,
|
|
119
|
+
columns,
|
|
120
|
+
rowCount: data.length,
|
|
121
|
+
executionTimeMs: 0,
|
|
122
|
+
cached: false
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
async executeMetric(metricIds, _params) {
|
|
126
|
+
const data = metricIds.map((id) => ({
|
|
127
|
+
metricId: id,
|
|
128
|
+
value: Math.random() * 1e3,
|
|
129
|
+
change: (Math.random() - .5) * 20
|
|
130
|
+
}));
|
|
131
|
+
return {
|
|
132
|
+
data,
|
|
133
|
+
columns: [
|
|
134
|
+
{
|
|
135
|
+
name: "metricId",
|
|
136
|
+
type: "STRING"
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: "value",
|
|
140
|
+
type: "NUMBER"
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
name: "change",
|
|
144
|
+
type: "NUMBER"
|
|
145
|
+
}
|
|
146
|
+
],
|
|
147
|
+
rowCount: data.length,
|
|
148
|
+
executionTimeMs: 0,
|
|
149
|
+
cached: false
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
async executeSql(_sql, _params) {
|
|
153
|
+
return {
|
|
154
|
+
data: [],
|
|
155
|
+
columns: [],
|
|
156
|
+
rowCount: 0,
|
|
157
|
+
executionTimeMs: 0,
|
|
158
|
+
cached: false,
|
|
159
|
+
error: "SQL execution not implemented in demo"
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
generateMockData(aggregation, params) {
|
|
163
|
+
const data = [];
|
|
164
|
+
const rowCount = 10;
|
|
165
|
+
const timeDimension = aggregation.dimensions.find((d) => d.type === "TIME");
|
|
166
|
+
for (let i = 0; i < rowCount; i++) {
|
|
167
|
+
const row = {};
|
|
168
|
+
for (const dim of aggregation.dimensions) if (dim.type === "TIME") {
|
|
169
|
+
const date = new Date(params.dateRange?.start ?? /* @__PURE__ */ new Date());
|
|
170
|
+
date.setDate(date.getDate() + i);
|
|
171
|
+
row[dim.name] = date.toISOString().split("T")[0];
|
|
172
|
+
} else row[dim.name] = `${dim.name}_${i % 5}`;
|
|
173
|
+
for (const measure of aggregation.measures) {
|
|
174
|
+
const baseValue = timeDimension ? 100 + i * 10 : Math.random() * 1e3;
|
|
175
|
+
const noise = (Math.random() - .5) * 20;
|
|
176
|
+
row[measure.name] = Math.round((baseValue + noise) * 100) / 100;
|
|
177
|
+
}
|
|
178
|
+
data.push(row);
|
|
179
|
+
}
|
|
180
|
+
return data;
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
function createQueryEngine(cache) {
|
|
184
|
+
return new BasicQueryEngine(cache);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
//#endregion
|
|
188
|
+
export { BasicQueryEngine, InMemoryQueryCache, createQueryEngine };
|
|
189
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/query-engine/index.ts"],"sourcesContent":["/**\n * Analytics Query Engine\n *\n * Provides query execution and caching for analytics dashboards.\n */\n\n// ============ Types ============\n\nexport interface QueryDefinition {\n type: 'SQL' | 'METRIC' | 'AGGREGATION' | 'CUSTOM';\n sql?: string;\n metricIds?: string[];\n aggregation?: AggregationDefinition;\n custom?: CustomQueryDefinition;\n}\n\nexport interface AggregationDefinition {\n source: string;\n measures: MeasureDefinition[];\n dimensions: DimensionDefinition[];\n filters?: FilterDefinition[];\n orderBy?: OrderByDefinition[];\n limit?: number;\n}\n\nexport interface MeasureDefinition {\n name: string;\n field: string;\n aggregation: 'COUNT' | 'SUM' | 'AVG' | 'MIN' | 'MAX' | 'COUNT_DISTINCT';\n format?: string;\n}\n\nexport interface DimensionDefinition {\n name: string;\n field: string;\n type?: 'TIME' | 'STRING' | 'NUMBER';\n granularity?: 'HOUR' | 'DAY' | 'WEEK' | 'MONTH' | 'YEAR';\n}\n\nexport interface FilterDefinition {\n field: string;\n operator:\n | 'eq'\n | 'neq'\n | 'gt'\n | 'gte'\n | 'lt'\n | 'lte'\n | 'in'\n | 'nin'\n | 'contains'\n | 'between';\n value: unknown;\n}\n\nexport interface OrderByDefinition {\n field: string;\n direction: 'ASC' | 'DESC';\n}\n\nexport interface CustomQueryDefinition {\n handler: string;\n parameters: Record<string, unknown>;\n}\n\nexport interface QueryParameters {\n dateRange?: {\n start: Date;\n end: Date;\n granularity?: string;\n };\n filters?: FilterDefinition[];\n parameters?: Record<string, unknown>;\n}\n\nexport interface QueryResult {\n data: Record<string, unknown>[];\n columns: ColumnDefinition[];\n rowCount: number;\n executionTimeMs: number;\n cached: boolean;\n cachedAt?: Date;\n error?: string;\n}\n\nexport interface ColumnDefinition {\n name: string;\n type: 'STRING' | 'NUMBER' | 'DATE' | 'BOOLEAN';\n label?: string;\n format?: string;\n}\n\n// ============ Query Engine Interface ============\n\nexport interface IQueryEngine {\n execute(\n definition: QueryDefinition,\n params: QueryParameters\n ): Promise<QueryResult>;\n validateQuery(definition: QueryDefinition): {\n valid: boolean;\n errors: string[];\n };\n}\n\n// ============ Query Cache ============\n\nexport interface IQueryCache {\n get(key: string): Promise<QueryResult | null>;\n set(key: string, result: QueryResult, ttlSeconds: number): Promise<void>;\n invalidate(pattern: string): Promise<void>;\n}\n\nexport class InMemoryQueryCache implements IQueryCache {\n private cache = new Map<string, { result: QueryResult; expiresAt: Date }>();\n\n async get(key: string): Promise<QueryResult | null> {\n const entry = this.cache.get(key);\n if (!entry) return null;\n if (entry.expiresAt < new Date()) {\n this.cache.delete(key);\n return null;\n }\n return { ...entry.result, cached: true, cachedAt: entry.expiresAt };\n }\n\n async set(\n key: string,\n result: QueryResult,\n ttlSeconds: number\n ): Promise<void> {\n const expiresAt = new Date(Date.now() + ttlSeconds * 1000);\n this.cache.set(key, { result, expiresAt });\n }\n\n async invalidate(pattern: string): Promise<void> {\n const regex = new RegExp(pattern);\n for (const key of this.cache.keys()) {\n if (regex.test(key)) {\n this.cache.delete(key);\n }\n }\n }\n}\n\n// ============ Basic Query Engine ============\n\nexport class BasicQueryEngine implements IQueryEngine {\n private cache: IQueryCache;\n\n constructor(cache?: IQueryCache) {\n this.cache = cache ?? new InMemoryQueryCache();\n }\n\n async execute(\n definition: QueryDefinition,\n params: QueryParameters\n ): Promise<QueryResult> {\n const startTime = Date.now();\n\n // Validate query\n const validation = this.validateQuery(definition);\n if (!validation.valid) {\n return {\n data: [],\n columns: [],\n rowCount: 0,\n executionTimeMs: Date.now() - startTime,\n cached: false,\n error: validation.errors.join(', '),\n };\n }\n\n // Check cache\n const cacheKey = this.buildCacheKey(definition, params);\n const cachedResult = await this.cache.get(cacheKey);\n if (cachedResult) {\n return cachedResult;\n }\n\n // Execute query based on type\n let result: QueryResult;\n switch (definition.type) {\n case 'AGGREGATION':\n if (!definition.aggregation) {\n throw new Error('Aggregation definition is missing');\n }\n result = await this.executeAggregation(definition.aggregation, params);\n break;\n case 'METRIC':\n if (!definition.metricIds) {\n throw new Error('Metric IDs are missing');\n }\n result = await this.executeMetric(definition.metricIds, params);\n break;\n case 'SQL':\n if (!definition.sql) {\n throw new Error('SQL query is missing');\n }\n result = await this.executeSql(definition.sql, params);\n break;\n default:\n result = {\n data: [],\n columns: [],\n rowCount: 0,\n executionTimeMs: Date.now() - startTime,\n cached: false,\n error: `Unknown query type: ${definition.type}`,\n };\n }\n\n result.executionTimeMs = Date.now() - startTime;\n result.cached = false;\n\n // Cache result\n await this.cache.set(cacheKey, result, 300);\n\n return result;\n }\n\n validateQuery(definition: QueryDefinition): {\n valid: boolean;\n errors: string[];\n } {\n const errors: string[] = [];\n\n if (!definition.type) {\n errors.push('Query type is required');\n }\n\n switch (definition.type) {\n case 'SQL':\n if (!definition.sql) {\n errors.push('SQL query is required for SQL type');\n }\n break;\n case 'METRIC':\n if (!definition.metricIds || definition.metricIds.length === 0) {\n errors.push('Metric IDs are required for METRIC type');\n }\n break;\n case 'AGGREGATION':\n if (!definition.aggregation) {\n errors.push(\n 'Aggregation definition is required for AGGREGATION type'\n );\n } else {\n if (!definition.aggregation.source) {\n errors.push('Aggregation source is required');\n }\n if (\n !definition.aggregation.measures ||\n definition.aggregation.measures.length === 0\n ) {\n errors.push('At least one measure is required');\n }\n }\n break;\n }\n\n return { valid: errors.length === 0, errors };\n }\n\n private buildCacheKey(\n definition: QueryDefinition,\n params: QueryParameters\n ): string {\n return JSON.stringify({ definition, params });\n }\n\n private async executeAggregation(\n aggregation: AggregationDefinition,\n params: QueryParameters\n ): Promise<QueryResult> {\n // In production, this would execute against a data warehouse\n // For demo, return mock data\n const columns: ColumnDefinition[] = [\n ...aggregation.dimensions.map((d) => ({\n name: d.name,\n type: (d.type === 'NUMBER'\n ? 'NUMBER'\n : d.type === 'TIME'\n ? 'DATE'\n : 'STRING') as ColumnDefinition['type'],\n label: d.name,\n })),\n ...aggregation.measures.map((m) => ({\n name: m.name,\n type: 'NUMBER' as const,\n label: m.name,\n format: m.format,\n })),\n ];\n\n // Mock data generation\n const data = this.generateMockData(aggregation, params);\n\n return {\n data,\n columns,\n rowCount: data.length,\n executionTimeMs: 0,\n cached: false,\n };\n }\n\n private async executeMetric(\n metricIds: string[],\n _params: QueryParameters\n ): Promise<QueryResult> {\n // In production, this would fetch from metering service\n const data = metricIds.map((id) => ({\n metricId: id,\n value: Math.random() * 1000,\n change: (Math.random() - 0.5) * 20,\n }));\n\n return {\n data,\n columns: [\n { name: 'metricId', type: 'STRING' },\n { name: 'value', type: 'NUMBER' },\n { name: 'change', type: 'NUMBER' },\n ],\n rowCount: data.length,\n executionTimeMs: 0,\n cached: false,\n };\n }\n\n private async executeSql(\n _sql: string,\n _params: QueryParameters\n ): Promise<QueryResult> {\n // In production, this would execute SQL against a database\n return {\n data: [],\n columns: [],\n rowCount: 0,\n executionTimeMs: 0,\n cached: false,\n error: 'SQL execution not implemented in demo',\n };\n }\n\n private generateMockData(\n aggregation: AggregationDefinition,\n params: QueryParameters\n ): Record<string, unknown>[] {\n const data: Record<string, unknown>[] = [];\n const rowCount = 10;\n\n // Generate time series data if there's a time dimension\n const timeDimension = aggregation.dimensions.find((d) => d.type === 'TIME');\n\n for (let i = 0; i < rowCount; i++) {\n const row: Record<string, unknown> = {};\n\n for (const dim of aggregation.dimensions) {\n if (dim.type === 'TIME') {\n const date = new Date(params.dateRange?.start ?? new Date());\n date.setDate(date.getDate() + i);\n row[dim.name] = date.toISOString().split('T')[0];\n } else {\n row[dim.name] = `${dim.name}_${i % 5}`;\n }\n }\n\n for (const measure of aggregation.measures) {\n const baseValue = timeDimension ? 100 + i * 10 : Math.random() * 1000;\n const noise = (Math.random() - 0.5) * 20;\n row[measure.name] = Math.round((baseValue + noise) * 100) / 100;\n }\n\n data.push(row);\n }\n\n return data;\n }\n}\n\n// ============ Factory ============\n\nexport function createQueryEngine(cache?: IQueryCache): IQueryEngine {\n return new BasicQueryEngine(cache);\n}\n"],"mappings":";AAiHA,IAAa,qBAAb,MAAuD;CACrD,AAAQ,wBAAQ,IAAI,KAAuD;CAE3E,MAAM,IAAI,KAA0C;EAClD,MAAM,QAAQ,KAAK,MAAM,IAAI,IAAI;AACjC,MAAI,CAAC,MAAO,QAAO;AACnB,MAAI,MAAM,4BAAY,IAAI,MAAM,EAAE;AAChC,QAAK,MAAM,OAAO,IAAI;AACtB,UAAO;;AAET,SAAO;GAAE,GAAG,MAAM;GAAQ,QAAQ;GAAM,UAAU,MAAM;GAAW;;CAGrE,MAAM,IACJ,KACA,QACA,YACe;EACf,MAAM,YAAY,IAAI,KAAK,KAAK,KAAK,GAAG,aAAa,IAAK;AAC1D,OAAK,MAAM,IAAI,KAAK;GAAE;GAAQ;GAAW,CAAC;;CAG5C,MAAM,WAAW,SAAgC;EAC/C,MAAM,QAAQ,IAAI,OAAO,QAAQ;AACjC,OAAK,MAAM,OAAO,KAAK,MAAM,MAAM,CACjC,KAAI,MAAM,KAAK,IAAI,CACjB,MAAK,MAAM,OAAO,IAAI;;;AAQ9B,IAAa,mBAAb,MAAsD;CACpD,AAAQ;CAER,YAAY,OAAqB;AAC/B,OAAK,QAAQ,SAAS,IAAI,oBAAoB;;CAGhD,MAAM,QACJ,YACA,QACsB;EACtB,MAAM,YAAY,KAAK,KAAK;EAG5B,MAAM,aAAa,KAAK,cAAc,WAAW;AACjD,MAAI,CAAC,WAAW,MACd,QAAO;GACL,MAAM,EAAE;GACR,SAAS,EAAE;GACX,UAAU;GACV,iBAAiB,KAAK,KAAK,GAAG;GAC9B,QAAQ;GACR,OAAO,WAAW,OAAO,KAAK,KAAK;GACpC;EAIH,MAAM,WAAW,KAAK,cAAc,YAAY,OAAO;EACvD,MAAM,eAAe,MAAM,KAAK,MAAM,IAAI,SAAS;AACnD,MAAI,aACF,QAAO;EAIT,IA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MAAM,OAAO,IAAI,KAAK,OAAO,WAAW,yBAAS,IAAI,MAAM,CAAC;AAC5D,SAAK,QAAQ,KAAK,SAAS,GAAG,EAAE;AAChC,QAAI,IAAI,QAAQ,KAAK,aAAa,CAAC,MAAM,IAAI,CAAC;SAE9C,KAAI,IAAI,QAAQ,GAAG,IAAI,KAAK,GAAG,IAAI;AAIvC,QAAK,MAAM,WAAW,YAAY,UAAU;IAC1C,MAAM,YAAY,gBAAgB,MAAM,IAAI,KAAK,KAAK,QAAQ,GAAG;IACjE,MAAM,SAAS,KAAK,QAAQ,GAAG,MAAO;AACtC,QAAI,QAAQ,QAAQ,KAAK,OAAO,YAAY,SAAS,IAAI,GAAG;;AAG9D,QAAK,KAAK,IAAI;;AAGhB,SAAO;;;AAMX,SAAgB,kBAAkB,OAAmC;AACnE,QAAO,IAAI,iBAAiB,MAAM"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DatabasePort } from "@contractspec/lib.runtime-sandbox";
|
|
2
|
+
|
|
3
|
+
//#region src/seeders/index.d.ts
|
|
4
|
+
declare function seedAnalyticsDashboard(params: {
|
|
5
|
+
projectId: string;
|
|
6
|
+
db: DatabasePort;
|
|
7
|
+
}): Promise<void>;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { seedAnalyticsDashboard };
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/seeders/index.ts"],"sourcesContent":[],"mappings":";;;iBAEsB,sBAAA;;EAAA,EAAA,EAEhB,YAFgB;IAGrB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/seeders/index.ts
|
|
2
|
+
async function seedAnalyticsDashboard(params) {
|
|
3
|
+
const { projectId, db } = params;
|
|
4
|
+
if ((await db.query(`SELECT COUNT(*) as count FROM analytics_dashboard WHERE "projectId" = $1`, [projectId])).rows[0]?.count > 0) return;
|
|
5
|
+
await db.execute(`INSERT INTO analytics_dashboard (id, "projectId", "organizationId", name, slug, description, status)
|
|
6
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7)`, [
|
|
7
|
+
"dash_1",
|
|
8
|
+
projectId,
|
|
9
|
+
"org_demo",
|
|
10
|
+
"Sales Overview",
|
|
11
|
+
"sales-overview",
|
|
12
|
+
"Sales performance dashboard",
|
|
13
|
+
"PUBLISHED"
|
|
14
|
+
]);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { seedAnalyticsDashboard };
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/seeders/index.ts"],"sourcesContent":["import type { DatabasePort } from '@contractspec/lib.runtime-sandbox';\n\nexport async function seedAnalyticsDashboard(params: {\n projectId: string;\n db: DatabasePort;\n}) {\n const { projectId, db } = params;\n\n const existing = await db.query(\n `SELECT COUNT(*) as count FROM analytics_dashboard WHERE \"projectId\" = $1`,\n [projectId]\n );\n if ((existing.rows[0]?.count as number) > 0) return;\n\n await db.execute(\n `INSERT INTO analytics_dashboard (id, \"projectId\", \"organizationId\", name, slug, description, status)\n VALUES ($1, $2, $3, $4, $5, $6, $7)`,\n [\n 'dash_1',\n projectId,\n 'org_demo',\n 'Sales Overview',\n 'sales-overview',\n 'Sales performance dashboard',\n 'PUBLISHED',\n ]\n );\n}\n"],"mappings":";AAEA,eAAsB,uBAAuB,QAG1C;CACD,MAAM,EAAE,WAAW,OAAO;AAM1B,MAJiB,MAAM,GAAG,MACxB,4EACA,CAAC,UAAU,CACZ,EACa,KAAK,IAAI,QAAmB,EAAG;AAE7C,OAAM,GAAG,QACP;2CAEA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
2
|
+
|
|
3
|
+
//#region src/ui/AnalyticsDashboard.d.ts
|
|
4
|
+
declare function AnalyticsDashboard(): react_jsx_runtime0.JSX.Element;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { AnalyticsDashboard };
|
|
7
|
+
//# sourceMappingURL=AnalyticsDashboard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnalyticsDashboard.d.ts","names":[],"sources":["../../src/ui/AnalyticsDashboard.tsx"],"sourcesContent":[],"mappings":";;;iBAoDgB,kBAAA,CAAA,GAAkB,kBAAA,CAAA,GAAA,CAAA"}
|