@contractspec/example.analytics-dashboard 3.9.8 → 3.9.10

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.
Files changed (112) hide show
  1. package/dist/browser/dashboard/dashboard.enum.js +1 -34
  2. package/dist/browser/dashboard/dashboard.operation.js +1 -289
  3. package/dist/browser/dashboard/dashboard.presentation.js +1 -200
  4. package/dist/browser/dashboard/dashboard.schema.js +1 -126
  5. package/dist/browser/dashboard/dashboard.test-spec.js +1 -213
  6. package/dist/browser/dashboard/index.js +1 -299
  7. package/dist/browser/dashboard.feature.js +1 -683
  8. package/dist/browser/datasource/posthog-datasource.js +4 -289
  9. package/dist/browser/docs/analytics-dashboard.docblock.js +5 -49
  10. package/dist/browser/docs/index.js +5 -49
  11. package/dist/browser/events.js +1 -81
  12. package/dist/browser/example.js +1 -42
  13. package/dist/browser/handlers/analytics.handlers.js +4 -278
  14. package/dist/browser/handlers/index.js +7 -571
  15. package/dist/browser/handlers/query.handlers.js +4 -294
  16. package/dist/browser/index.js +12 -2317
  17. package/dist/browser/query/index.js +1 -159
  18. package/dist/browser/query/query.enum.js +1 -11
  19. package/dist/browser/query/query.operation.js +1 -154
  20. package/dist/browser/query/query.presentation.js +1 -122
  21. package/dist/browser/query/query.schema.js +1 -70
  22. package/dist/browser/query/query.test-spec.js +1 -113
  23. package/dist/browser/query-engine/index.js +4 -491
  24. package/dist/browser/seeders/index.js +2 -20
  25. package/dist/browser/ui/AnalyticsDashboard.js +1 -1115
  26. package/dist/browser/ui/AnalyticsDashboard.widgets.js +1 -94
  27. package/dist/browser/ui/AnalyticsQueriesTable.js +1 -188
  28. package/dist/browser/ui/hooks/index.js +1 -660
  29. package/dist/browser/ui/hooks/useAnalyticsData.js +1 -657
  30. package/dist/browser/ui/index.js +5 -1283
  31. package/dist/browser/ui/renderers/analytics.markdown.js +5 -756
  32. package/dist/browser/ui/renderers/index.js +5 -756
  33. package/dist/browser/visualizations/catalog.js +1 -457
  34. package/dist/browser/visualizations/index.js +1 -611
  35. package/dist/browser/visualizations/specs.breakdown.js +1 -140
  36. package/dist/browser/visualizations/specs.performance.js +1 -198
  37. package/dist/browser/visualizations/widgets.js +1 -595
  38. package/dist/dashboard/dashboard.enum.js +1 -34
  39. package/dist/dashboard/dashboard.operation.js +1 -289
  40. package/dist/dashboard/dashboard.presentation.js +1 -200
  41. package/dist/dashboard/dashboard.schema.js +1 -126
  42. package/dist/dashboard/dashboard.test-spec.js +1 -213
  43. package/dist/dashboard/index.js +1 -299
  44. package/dist/dashboard.feature.js +1 -683
  45. package/dist/datasource/posthog-datasource.js +4 -289
  46. package/dist/docs/analytics-dashboard.docblock.js +5 -49
  47. package/dist/docs/index.js +5 -49
  48. package/dist/events.js +1 -81
  49. package/dist/example.js +1 -42
  50. package/dist/handlers/analytics.handlers.js +4 -278
  51. package/dist/handlers/index.js +7 -571
  52. package/dist/handlers/query.handlers.js +4 -294
  53. package/dist/index.js +12 -2317
  54. package/dist/node/dashboard/dashboard.enum.js +1 -34
  55. package/dist/node/dashboard/dashboard.operation.js +1 -289
  56. package/dist/node/dashboard/dashboard.presentation.js +1 -200
  57. package/dist/node/dashboard/dashboard.schema.js +1 -126
  58. package/dist/node/dashboard/dashboard.test-spec.js +1 -213
  59. package/dist/node/dashboard/index.js +1 -299
  60. package/dist/node/dashboard.feature.js +1 -683
  61. package/dist/node/datasource/posthog-datasource.js +4 -289
  62. package/dist/node/docs/analytics-dashboard.docblock.js +5 -49
  63. package/dist/node/docs/index.js +5 -49
  64. package/dist/node/events.js +1 -81
  65. package/dist/node/example.js +1 -42
  66. package/dist/node/handlers/analytics.handlers.js +4 -278
  67. package/dist/node/handlers/index.js +7 -571
  68. package/dist/node/handlers/query.handlers.js +4 -294
  69. package/dist/node/index.js +12 -2317
  70. package/dist/node/query/index.js +1 -159
  71. package/dist/node/query/query.enum.js +1 -11
  72. package/dist/node/query/query.operation.js +1 -154
  73. package/dist/node/query/query.presentation.js +1 -122
  74. package/dist/node/query/query.schema.js +1 -70
  75. package/dist/node/query/query.test-spec.js +1 -113
  76. package/dist/node/query-engine/index.js +4 -491
  77. package/dist/node/seeders/index.js +2 -20
  78. package/dist/node/ui/AnalyticsDashboard.js +1 -1115
  79. package/dist/node/ui/AnalyticsDashboard.widgets.js +1 -94
  80. package/dist/node/ui/AnalyticsQueriesTable.js +1 -188
  81. package/dist/node/ui/hooks/index.js +1 -660
  82. package/dist/node/ui/hooks/useAnalyticsData.js +1 -657
  83. package/dist/node/ui/index.js +5 -1283
  84. package/dist/node/ui/renderers/analytics.markdown.js +5 -756
  85. package/dist/node/ui/renderers/index.js +5 -756
  86. package/dist/node/visualizations/catalog.js +1 -457
  87. package/dist/node/visualizations/index.js +1 -611
  88. package/dist/node/visualizations/specs.breakdown.js +1 -140
  89. package/dist/node/visualizations/specs.performance.js +1 -198
  90. package/dist/node/visualizations/widgets.js +1 -595
  91. package/dist/query/index.js +1 -159
  92. package/dist/query/query.enum.js +1 -11
  93. package/dist/query/query.operation.js +1 -154
  94. package/dist/query/query.presentation.js +1 -122
  95. package/dist/query/query.schema.js +1 -70
  96. package/dist/query/query.test-spec.js +1 -113
  97. package/dist/query-engine/index.js +4 -491
  98. package/dist/seeders/index.js +2 -20
  99. package/dist/ui/AnalyticsDashboard.js +1 -1115
  100. package/dist/ui/AnalyticsDashboard.widgets.js +1 -94
  101. package/dist/ui/AnalyticsQueriesTable.js +1 -188
  102. package/dist/ui/hooks/index.js +1 -660
  103. package/dist/ui/hooks/useAnalyticsData.js +1 -657
  104. package/dist/ui/index.js +5 -1283
  105. package/dist/ui/renderers/analytics.markdown.js +5 -756
  106. package/dist/ui/renderers/index.js +5 -756
  107. package/dist/visualizations/catalog.js +1 -457
  108. package/dist/visualizations/index.js +1 -611
  109. package/dist/visualizations/specs.breakdown.js +1 -140
  110. package/dist/visualizations/specs.performance.js +1 -198
  111. package/dist/visualizations/widgets.js +1 -595
  112. package/package.json +13 -13
@@ -1,160 +1,2 @@
1
1
  // @bun
2
- // src/query/query.enum.ts
3
- import { defineEnum } from "@contractspec/lib.schema";
4
- var QueryTypeEnum = defineEnum("QueryType", [
5
- "SQL",
6
- "METRIC",
7
- "AGGREGATION",
8
- "CUSTOM"
9
- ]);
10
-
11
- // src/query/query.schema.ts
12
- import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
13
- var QueryModel = defineSchemaModel({
14
- name: "QueryModel",
15
- fields: {
16
- id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
17
- name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
18
- description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
19
- type: { type: QueryTypeEnum, isOptional: false },
20
- definition: { type: ScalarTypeEnum.JSON(), isOptional: false },
21
- sql: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
22
- cacheTtlSeconds: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
23
- isShared: { type: ScalarTypeEnum.Boolean(), isOptional: false },
24
- createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
25
- }
26
- });
27
- var QueryResultModel = defineSchemaModel({
28
- name: "QueryResultModel",
29
- fields: {
30
- queryId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
31
- data: { type: ScalarTypeEnum.JSON(), isOptional: false },
32
- columns: { type: ScalarTypeEnum.JSON(), isOptional: false },
33
- rowCount: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
34
- executionTimeMs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
35
- cachedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
36
- error: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
37
- }
38
- });
39
- var CreateQueryInputModel = defineSchemaModel({
40
- name: "CreateQueryInput",
41
- fields: {
42
- name: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
43
- description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
44
- type: { type: QueryTypeEnum, isOptional: false },
45
- definition: { type: ScalarTypeEnum.JSON(), isOptional: false },
46
- sql: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
47
- metricIds: {
48
- type: ScalarTypeEnum.String_unsecure(),
49
- isArray: true,
50
- isOptional: true
51
- },
52
- cacheTtlSeconds: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },
53
- isShared: { type: ScalarTypeEnum.Boolean(), isOptional: true }
54
- }
55
- });
56
- var ExecuteQueryInputModel = defineSchemaModel({
57
- name: "ExecuteQueryInput",
58
- fields: {
59
- queryId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
60
- parameters: { type: ScalarTypeEnum.JSON(), isOptional: true },
61
- dateRange: { type: ScalarTypeEnum.JSON(), isOptional: true },
62
- filters: { type: ScalarTypeEnum.JSON(), isOptional: true },
63
- forceRefresh: { type: ScalarTypeEnum.Boolean(), isOptional: true }
64
- }
65
- });
66
-
67
- // src/query/query.operation.ts
68
- import {
69
- defineCommand,
70
- defineQuery
71
- } from "@contractspec/lib.contracts-spec/operations";
72
- var OWNERS = ["@example.analytics-dashboard"];
73
- var CreateQueryContract = defineCommand({
74
- meta: {
75
- key: "analytics.query.create",
76
- version: "1.0.0",
77
- stability: "stable",
78
- owners: [...OWNERS],
79
- tags: ["analytics", "query", "create"],
80
- description: "Create a data query.",
81
- goal: "Define reusable data queries.",
82
- context: "Query builder."
83
- },
84
- io: { input: CreateQueryInputModel, output: QueryModel },
85
- policy: { auth: "user" },
86
- sideEffects: {
87
- emits: [
88
- {
89
- key: "analytics.query.created",
90
- version: "1.0.0",
91
- stability: "stable",
92
- owners: [...OWNERS],
93
- tags: ["analytics", "query", "created"],
94
- when: "Query created",
95
- payload: QueryModel
96
- }
97
- ],
98
- audit: ["analytics.query.created"]
99
- },
100
- acceptance: {
101
- scenarios: [
102
- {
103
- key: "create-query-happy-path",
104
- given: ["User is authenticated"],
105
- when: ["User submits valid query definition"],
106
- then: ["Query is created", "QueryCreated event is emitted"]
107
- }
108
- ],
109
- examples: [
110
- {
111
- key: "create-sql-query",
112
- input: {
113
- name: "Monthly Revenue",
114
- sql: "SELECT SUM(amount) FROM orders WHERE date >= :startDate"
115
- },
116
- output: { id: "query-123", name: "Monthly Revenue", type: "sql" }
117
- }
118
- ]
119
- }
120
- });
121
- var ExecuteQueryContract = defineQuery({
122
- meta: {
123
- key: "analytics.query.execute",
124
- version: "1.0.0",
125
- stability: "stable",
126
- owners: [...OWNERS],
127
- tags: ["analytics", "query", "execute"],
128
- description: "Execute a data query.",
129
- goal: "Fetch data for visualizations.",
130
- context: "Dashboard rendering."
131
- },
132
- io: { input: ExecuteQueryInputModel, output: QueryResultModel },
133
- policy: { auth: "user" },
134
- acceptance: {
135
- scenarios: [
136
- {
137
- key: "execute-query-happy-path",
138
- given: ["Query exists"],
139
- when: ["User executes query with parameters"],
140
- then: ["Query results are returned"]
141
- }
142
- ],
143
- examples: [
144
- {
145
- key: "execute-with-params",
146
- input: { queryId: "query-123", params: { startDate: "2025-01-01" } },
147
- output: { columns: ["total"], rows: [{ total: 50000 }], rowCount: 1 }
148
- }
149
- ]
150
- }
151
- });
152
- export {
153
- QueryTypeEnum,
154
- QueryResultModel,
155
- QueryModel,
156
- ExecuteQueryInputModel,
157
- ExecuteQueryContract,
158
- CreateQueryInputModel,
159
- CreateQueryContract
160
- };
2
+ import{defineEnum as I}from"@contractspec/lib.schema";var x=I("QueryType",["SQL","METRIC","AGGREGATION","CUSTOM"]);import{defineSchemaModel as C,ScalarTypeEnum as t}from"@contractspec/lib.schema";var G=C({name:"QueryModel",fields:{id:{type:t.String_unsecure(),isOptional:!1},name:{type:t.String_unsecure(),isOptional:!1},description:{type:t.String_unsecure(),isOptional:!0},type:{type:x,isOptional:!1},definition:{type:t.JSON(),isOptional:!1},sql:{type:t.String_unsecure(),isOptional:!0},cacheTtlSeconds:{type:t.Int_unsecure(),isOptional:!1},isShared:{type:t.Boolean(),isOptional:!1},createdAt:{type:t.DateTime(),isOptional:!1}}}),Q=C({name:"QueryResultModel",fields:{queryId:{type:t.String_unsecure(),isOptional:!1},data:{type:t.JSON(),isOptional:!1},columns:{type:t.JSON(),isOptional:!1},rowCount:{type:t.Int_unsecure(),isOptional:!1},executionTimeMs:{type:t.Int_unsecure(),isOptional:!1},cachedAt:{type:t.DateTime(),isOptional:!0},error:{type:t.String_unsecure(),isOptional:!0}}}),o=C({name:"CreateQueryInput",fields:{name:{type:t.NonEmptyString(),isOptional:!1},description:{type:t.String_unsecure(),isOptional:!0},type:{type:x,isOptional:!1},definition:{type:t.JSON(),isOptional:!1},sql:{type:t.String_unsecure(),isOptional:!0},metricIds:{type:t.String_unsecure(),isArray:!0,isOptional:!0},cacheTtlSeconds:{type:t.Int_unsecure(),isOptional:!0},isShared:{type:t.Boolean(),isOptional:!0}}}),A=C({name:"ExecuteQueryInput",fields:{queryId:{type:t.String_unsecure(),isOptional:!1},parameters:{type:t.JSON(),isOptional:!0},dateRange:{type:t.JSON(),isOptional:!0},filters:{type:t.JSON(),isOptional:!0},forceRefresh:{type:t.Boolean(),isOptional:!0}}});import{defineCommand as L,defineQuery as U}from"@contractspec/lib.contracts-spec/operations";var D=["@example.analytics-dashboard"],g=L({meta:{key:"analytics.query.create",version:"1.0.0",stability:"stable",owners:[...D],tags:["analytics","query","create"],description:"Create a data query.",goal:"Define reusable data queries.",context:"Query builder."},io:{input:o,output:G},policy:{auth:"user"},sideEffects:{emits:[{key:"analytics.query.created",version:"1.0.0",stability:"stable",owners:[...D],tags:["analytics","query","created"],when:"Query created",payload:G}],audit:["analytics.query.created"]},acceptance:{scenarios:[{key:"create-query-happy-path",given:["User is authenticated"],when:["User submits valid query definition"],then:["Query is created","QueryCreated event is emitted"]}],examples:[{key:"create-sql-query",input:{name:"Monthly Revenue",sql:"SELECT SUM(amount) FROM orders WHERE date >= :startDate"},output:{id:"query-123",name:"Monthly Revenue",type:"sql"}}]}}),j=U({meta:{key:"analytics.query.execute",version:"1.0.0",stability:"stable",owners:[...D],tags:["analytics","query","execute"],description:"Execute a data query.",goal:"Fetch data for visualizations.",context:"Dashboard rendering."},io:{input:A,output:Q},policy:{auth:"user"},acceptance:{scenarios:[{key:"execute-query-happy-path",given:["Query exists"],when:["User executes query with parameters"],then:["Query results are returned"]}],examples:[{key:"execute-with-params",input:{queryId:"query-123",params:{startDate:"2025-01-01"}},output:{columns:["total"],rows:[{total:50000}],rowCount:1}}]}});export{x as QueryTypeEnum,Q as QueryResultModel,G as QueryModel,A as ExecuteQueryInputModel,j as ExecuteQueryContract,o as CreateQueryInputModel,g as CreateQueryContract};
@@ -1,12 +1,2 @@
1
1
  // @bun
2
- // src/query/query.enum.ts
3
- import { defineEnum } from "@contractspec/lib.schema";
4
- var QueryTypeEnum = defineEnum("QueryType", [
5
- "SQL",
6
- "METRIC",
7
- "AGGREGATION",
8
- "CUSTOM"
9
- ]);
10
- export {
11
- QueryTypeEnum
12
- };
2
+ import{defineEnum as e}from"@contractspec/lib.schema";var T=e("QueryType",["SQL","METRIC","AGGREGATION","CUSTOM"]);export{T as QueryTypeEnum};
@@ -1,155 +1,2 @@
1
1
  // @bun
2
- // src/query/query.enum.ts
3
- import { defineEnum } from "@contractspec/lib.schema";
4
- var QueryTypeEnum = defineEnum("QueryType", [
5
- "SQL",
6
- "METRIC",
7
- "AGGREGATION",
8
- "CUSTOM"
9
- ]);
10
-
11
- // src/query/query.schema.ts
12
- import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
13
- var QueryModel = defineSchemaModel({
14
- name: "QueryModel",
15
- fields: {
16
- id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
17
- name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
18
- description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
19
- type: { type: QueryTypeEnum, isOptional: false },
20
- definition: { type: ScalarTypeEnum.JSON(), isOptional: false },
21
- sql: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
22
- cacheTtlSeconds: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
23
- isShared: { type: ScalarTypeEnum.Boolean(), isOptional: false },
24
- createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
25
- }
26
- });
27
- var QueryResultModel = defineSchemaModel({
28
- name: "QueryResultModel",
29
- fields: {
30
- queryId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
31
- data: { type: ScalarTypeEnum.JSON(), isOptional: false },
32
- columns: { type: ScalarTypeEnum.JSON(), isOptional: false },
33
- rowCount: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
34
- executionTimeMs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
35
- cachedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
36
- error: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
37
- }
38
- });
39
- var CreateQueryInputModel = defineSchemaModel({
40
- name: "CreateQueryInput",
41
- fields: {
42
- name: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
43
- description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
44
- type: { type: QueryTypeEnum, isOptional: false },
45
- definition: { type: ScalarTypeEnum.JSON(), isOptional: false },
46
- sql: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
47
- metricIds: {
48
- type: ScalarTypeEnum.String_unsecure(),
49
- isArray: true,
50
- isOptional: true
51
- },
52
- cacheTtlSeconds: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },
53
- isShared: { type: ScalarTypeEnum.Boolean(), isOptional: true }
54
- }
55
- });
56
- var ExecuteQueryInputModel = defineSchemaModel({
57
- name: "ExecuteQueryInput",
58
- fields: {
59
- queryId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
60
- parameters: { type: ScalarTypeEnum.JSON(), isOptional: true },
61
- dateRange: { type: ScalarTypeEnum.JSON(), isOptional: true },
62
- filters: { type: ScalarTypeEnum.JSON(), isOptional: true },
63
- forceRefresh: { type: ScalarTypeEnum.Boolean(), isOptional: true }
64
- }
65
- });
66
-
67
- // src/query/query.operation.ts
68
- import {
69
- defineCommand,
70
- defineQuery
71
- } from "@contractspec/lib.contracts-spec/operations";
72
- var OWNERS = ["@example.analytics-dashboard"];
73
- var CreateQueryContract = defineCommand({
74
- meta: {
75
- key: "analytics.query.create",
76
- version: "1.0.0",
77
- stability: "stable",
78
- owners: [...OWNERS],
79
- tags: ["analytics", "query", "create"],
80
- description: "Create a data query.",
81
- goal: "Define reusable data queries.",
82
- context: "Query builder."
83
- },
84
- io: { input: CreateQueryInputModel, output: QueryModel },
85
- policy: { auth: "user" },
86
- sideEffects: {
87
- emits: [
88
- {
89
- key: "analytics.query.created",
90
- version: "1.0.0",
91
- stability: "stable",
92
- owners: [...OWNERS],
93
- tags: ["analytics", "query", "created"],
94
- when: "Query created",
95
- payload: QueryModel
96
- }
97
- ],
98
- audit: ["analytics.query.created"]
99
- },
100
- acceptance: {
101
- scenarios: [
102
- {
103
- key: "create-query-happy-path",
104
- given: ["User is authenticated"],
105
- when: ["User submits valid query definition"],
106
- then: ["Query is created", "QueryCreated event is emitted"]
107
- }
108
- ],
109
- examples: [
110
- {
111
- key: "create-sql-query",
112
- input: {
113
- name: "Monthly Revenue",
114
- sql: "SELECT SUM(amount) FROM orders WHERE date >= :startDate"
115
- },
116
- output: { id: "query-123", name: "Monthly Revenue", type: "sql" }
117
- }
118
- ]
119
- }
120
- });
121
- var ExecuteQueryContract = defineQuery({
122
- meta: {
123
- key: "analytics.query.execute",
124
- version: "1.0.0",
125
- stability: "stable",
126
- owners: [...OWNERS],
127
- tags: ["analytics", "query", "execute"],
128
- description: "Execute a data query.",
129
- goal: "Fetch data for visualizations.",
130
- context: "Dashboard rendering."
131
- },
132
- io: { input: ExecuteQueryInputModel, output: QueryResultModel },
133
- policy: { auth: "user" },
134
- acceptance: {
135
- scenarios: [
136
- {
137
- key: "execute-query-happy-path",
138
- given: ["Query exists"],
139
- when: ["User executes query with parameters"],
140
- then: ["Query results are returned"]
141
- }
142
- ],
143
- examples: [
144
- {
145
- key: "execute-with-params",
146
- input: { queryId: "query-123", params: { startDate: "2025-01-01" } },
147
- output: { columns: ["total"], rows: [{ total: 50000 }], rowCount: 1 }
148
- }
149
- ]
150
- }
151
- });
152
- export {
153
- ExecuteQueryContract,
154
- CreateQueryContract
155
- };
2
+ import{defineEnum as z}from"@contractspec/lib.schema";var L=z("QueryType",["SQL","METRIC","AGGREGATION","CUSTOM"]);import{defineSchemaModel as A,ScalarTypeEnum as G}from"@contractspec/lib.schema";var U=A({name:"QueryModel",fields:{id:{type:G.String_unsecure(),isOptional:!1},name:{type:G.String_unsecure(),isOptional:!1},description:{type:G.String_unsecure(),isOptional:!0},type:{type:L,isOptional:!1},definition:{type:G.JSON(),isOptional:!1},sql:{type:G.String_unsecure(),isOptional:!0},cacheTtlSeconds:{type:G.Int_unsecure(),isOptional:!1},isShared:{type:G.Boolean(),isOptional:!1},createdAt:{type:G.DateTime(),isOptional:!1}}}),k=A({name:"QueryResultModel",fields:{queryId:{type:G.String_unsecure(),isOptional:!1},data:{type:G.JSON(),isOptional:!1},columns:{type:G.JSON(),isOptional:!1},rowCount:{type:G.Int_unsecure(),isOptional:!1},executionTimeMs:{type:G.Int_unsecure(),isOptional:!1},cachedAt:{type:G.DateTime(),isOptional:!0},error:{type:G.String_unsecure(),isOptional:!0}}}),v=A({name:"CreateQueryInput",fields:{name:{type:G.NonEmptyString(),isOptional:!1},description:{type:G.String_unsecure(),isOptional:!0},type:{type:L,isOptional:!1},definition:{type:G.JSON(),isOptional:!1},sql:{type:G.String_unsecure(),isOptional:!0},metricIds:{type:G.String_unsecure(),isArray:!0,isOptional:!0},cacheTtlSeconds:{type:G.Int_unsecure(),isOptional:!0},isShared:{type:G.Boolean(),isOptional:!0}}}),w=A({name:"ExecuteQueryInput",fields:{queryId:{type:G.String_unsecure(),isOptional:!1},parameters:{type:G.JSON(),isOptional:!0},dateRange:{type:G.JSON(),isOptional:!0},filters:{type:G.JSON(),isOptional:!0},forceRefresh:{type:G.Boolean(),isOptional:!0}}});import{defineCommand as B,defineQuery as C}from"@contractspec/lib.contracts-spec/operations";var j=["@example.analytics-dashboard"],X=B({meta:{key:"analytics.query.create",version:"1.0.0",stability:"stable",owners:[...j],tags:["analytics","query","create"],description:"Create a data query.",goal:"Define reusable data queries.",context:"Query builder."},io:{input:v,output:U},policy:{auth:"user"},sideEffects:{emits:[{key:"analytics.query.created",version:"1.0.0",stability:"stable",owners:[...j],tags:["analytics","query","created"],when:"Query created",payload:U}],audit:["analytics.query.created"]},acceptance:{scenarios:[{key:"create-query-happy-path",given:["User is authenticated"],when:["User submits valid query definition"],then:["Query is created","QueryCreated event is emitted"]}],examples:[{key:"create-sql-query",input:{name:"Monthly Revenue",sql:"SELECT SUM(amount) FROM orders WHERE date >= :startDate"},output:{id:"query-123",name:"Monthly Revenue",type:"sql"}}]}}),Y=C({meta:{key:"analytics.query.execute",version:"1.0.0",stability:"stable",owners:[...j],tags:["analytics","query","execute"],description:"Execute a data query.",goal:"Fetch data for visualizations.",context:"Dashboard rendering."},io:{input:w,output:k},policy:{auth:"user"},acceptance:{scenarios:[{key:"execute-query-happy-path",given:["Query exists"],when:["User executes query with parameters"],then:["Query results are returned"]}],examples:[{key:"execute-with-params",input:{queryId:"query-123",params:{startDate:"2025-01-01"}},output:{columns:["total"],rows:[{total:50000}],rowCount:1}}]}});export{Y as ExecuteQueryContract,X as CreateQueryContract};
@@ -1,123 +1,2 @@
1
1
  // @bun
2
- // src/query/query.enum.ts
3
- import { defineEnum } from "@contractspec/lib.schema";
4
- var QueryTypeEnum = defineEnum("QueryType", [
5
- "SQL",
6
- "METRIC",
7
- "AGGREGATION",
8
- "CUSTOM"
9
- ]);
10
-
11
- // src/query/query.schema.ts
12
- import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
13
- var QueryModel = defineSchemaModel({
14
- name: "QueryModel",
15
- fields: {
16
- id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
17
- name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
18
- description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
19
- type: { type: QueryTypeEnum, isOptional: false },
20
- definition: { type: ScalarTypeEnum.JSON(), isOptional: false },
21
- sql: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
22
- cacheTtlSeconds: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
23
- isShared: { type: ScalarTypeEnum.Boolean(), isOptional: false },
24
- createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
25
- }
26
- });
27
- var QueryResultModel = defineSchemaModel({
28
- name: "QueryResultModel",
29
- fields: {
30
- queryId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
31
- data: { type: ScalarTypeEnum.JSON(), isOptional: false },
32
- columns: { type: ScalarTypeEnum.JSON(), isOptional: false },
33
- rowCount: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
34
- executionTimeMs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
35
- cachedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
36
- error: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
37
- }
38
- });
39
- var CreateQueryInputModel = defineSchemaModel({
40
- name: "CreateQueryInput",
41
- fields: {
42
- name: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
43
- description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
44
- type: { type: QueryTypeEnum, isOptional: false },
45
- definition: { type: ScalarTypeEnum.JSON(), isOptional: false },
46
- sql: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
47
- metricIds: {
48
- type: ScalarTypeEnum.String_unsecure(),
49
- isArray: true,
50
- isOptional: true
51
- },
52
- cacheTtlSeconds: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },
53
- isShared: { type: ScalarTypeEnum.Boolean(), isOptional: true }
54
- }
55
- });
56
- var ExecuteQueryInputModel = defineSchemaModel({
57
- name: "ExecuteQueryInput",
58
- fields: {
59
- queryId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
60
- parameters: { type: ScalarTypeEnum.JSON(), isOptional: true },
61
- dateRange: { type: ScalarTypeEnum.JSON(), isOptional: true },
62
- filters: { type: ScalarTypeEnum.JSON(), isOptional: true },
63
- forceRefresh: { type: ScalarTypeEnum.Boolean(), isOptional: true }
64
- }
65
- });
66
-
67
- // src/query/query.presentation.ts
68
- import {
69
- definePresentation,
70
- StabilityEnum
71
- } from "@contractspec/lib.contracts-spec";
72
- var QueriesListPresentation = definePresentation({
73
- meta: {
74
- key: "analytics.query.list",
75
- version: "1.0.0",
76
- title: "Queries List",
77
- description: "List of saved queries",
78
- domain: "analytics",
79
- owners: ["@analytics-dashboard"],
80
- tags: ["analytics", "queries", "list"],
81
- stability: StabilityEnum.Experimental,
82
- goal: "Browse and manage saved data queries.",
83
- context: "The library of reusable data definitions."
84
- },
85
- source: {
86
- type: "component",
87
- framework: "react",
88
- componentKey: "QueriesList",
89
- props: QueryModel
90
- },
91
- targets: ["react", "markdown"],
92
- policy: {
93
- flags: ["analytics.queries.enabled"]
94
- }
95
- });
96
- var QueryBuilderPresentation = definePresentation({
97
- meta: {
98
- key: "analytics.query.builder",
99
- version: "1.0.0",
100
- title: "Query Builder",
101
- description: "Visual query builder interface",
102
- domain: "analytics",
103
- owners: ["@analytics-dashboard"],
104
- tags: ["analytics", "query", "builder"],
105
- stability: StabilityEnum.Experimental,
106
- goal: "Visually construct data queries and transformations.",
107
- context: "Developer tool for data analysis."
108
- },
109
- source: {
110
- type: "component",
111
- framework: "react",
112
- componentKey: "QueryBuilder",
113
- props: QueryModel
114
- },
115
- targets: ["react"],
116
- policy: {
117
- flags: ["analytics.queries.enabled"]
118
- }
119
- });
120
- export {
121
- QueryBuilderPresentation,
122
- QueriesListPresentation
123
- };
2
+ import{defineEnum as L}from"@contractspec/lib.schema";var C=L("QueryType",["SQL","METRIC","AGGREGATION","CUSTOM"]);import{defineSchemaModel as A,ScalarTypeEnum as G}from"@contractspec/lib.schema";var O=A({name:"QueryModel",fields:{id:{type:G.String_unsecure(),isOptional:!1},name:{type:G.String_unsecure(),isOptional:!1},description:{type:G.String_unsecure(),isOptional:!0},type:{type:C,isOptional:!1},definition:{type:G.JSON(),isOptional:!1},sql:{type:G.String_unsecure(),isOptional:!0},cacheTtlSeconds:{type:G.Int_unsecure(),isOptional:!1},isShared:{type:G.Boolean(),isOptional:!1},createdAt:{type:G.DateTime(),isOptional:!1}}}),v=A({name:"QueryResultModel",fields:{queryId:{type:G.String_unsecure(),isOptional:!1},data:{type:G.JSON(),isOptional:!1},columns:{type:G.JSON(),isOptional:!1},rowCount:{type:G.Int_unsecure(),isOptional:!1},executionTimeMs:{type:G.Int_unsecure(),isOptional:!1},cachedAt:{type:G.DateTime(),isOptional:!0},error:{type:G.String_unsecure(),isOptional:!0}}}),w=A({name:"CreateQueryInput",fields:{name:{type:G.NonEmptyString(),isOptional:!1},description:{type:G.String_unsecure(),isOptional:!0},type:{type:C,isOptional:!1},definition:{type:G.JSON(),isOptional:!1},sql:{type:G.String_unsecure(),isOptional:!0},metricIds:{type:G.String_unsecure(),isArray:!0,isOptional:!0},cacheTtlSeconds:{type:G.Int_unsecure(),isOptional:!0},isShared:{type:G.Boolean(),isOptional:!0}}}),x=A({name:"ExecuteQueryInput",fields:{queryId:{type:G.String_unsecure(),isOptional:!1},parameters:{type:G.JSON(),isOptional:!0},dateRange:{type:G.JSON(),isOptional:!0},filters:{type:G.JSON(),isOptional:!0},forceRefresh:{type:G.Boolean(),isOptional:!0}}});import{definePresentation as R,StabilityEnum as I}from"@contractspec/lib.contracts-spec";var F=R({meta:{key:"analytics.query.list",version:"1.0.0",title:"Queries List",description:"List of saved queries",domain:"analytics",owners:["@analytics-dashboard"],tags:["analytics","queries","list"],stability:I.Experimental,goal:"Browse and manage saved data queries.",context:"The library of reusable data definitions."},source:{type:"component",framework:"react",componentKey:"QueriesList",props:O},targets:["react","markdown"],policy:{flags:["analytics.queries.enabled"]}}),H=R({meta:{key:"analytics.query.builder",version:"1.0.0",title:"Query Builder",description:"Visual query builder interface",domain:"analytics",owners:["@analytics-dashboard"],tags:["analytics","query","builder"],stability:I.Experimental,goal:"Visually construct data queries and transformations.",context:"Developer tool for data analysis."},source:{type:"component",framework:"react",componentKey:"QueryBuilder",props:O},targets:["react"],policy:{flags:["analytics.queries.enabled"]}});export{H as QueryBuilderPresentation,F as QueriesListPresentation};
@@ -1,71 +1,2 @@
1
1
  // @bun
2
- // src/query/query.enum.ts
3
- import { defineEnum } from "@contractspec/lib.schema";
4
- var QueryTypeEnum = defineEnum("QueryType", [
5
- "SQL",
6
- "METRIC",
7
- "AGGREGATION",
8
- "CUSTOM"
9
- ]);
10
-
11
- // src/query/query.schema.ts
12
- import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
13
- var QueryModel = defineSchemaModel({
14
- name: "QueryModel",
15
- fields: {
16
- id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
17
- name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
18
- description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
19
- type: { type: QueryTypeEnum, isOptional: false },
20
- definition: { type: ScalarTypeEnum.JSON(), isOptional: false },
21
- sql: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
22
- cacheTtlSeconds: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
23
- isShared: { type: ScalarTypeEnum.Boolean(), isOptional: false },
24
- createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
25
- }
26
- });
27
- var QueryResultModel = defineSchemaModel({
28
- name: "QueryResultModel",
29
- fields: {
30
- queryId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
31
- data: { type: ScalarTypeEnum.JSON(), isOptional: false },
32
- columns: { type: ScalarTypeEnum.JSON(), isOptional: false },
33
- rowCount: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
34
- executionTimeMs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
35
- cachedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
36
- error: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
37
- }
38
- });
39
- var CreateQueryInputModel = defineSchemaModel({
40
- name: "CreateQueryInput",
41
- fields: {
42
- name: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
43
- description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
44
- type: { type: QueryTypeEnum, isOptional: false },
45
- definition: { type: ScalarTypeEnum.JSON(), isOptional: false },
46
- sql: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
47
- metricIds: {
48
- type: ScalarTypeEnum.String_unsecure(),
49
- isArray: true,
50
- isOptional: true
51
- },
52
- cacheTtlSeconds: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },
53
- isShared: { type: ScalarTypeEnum.Boolean(), isOptional: true }
54
- }
55
- });
56
- var ExecuteQueryInputModel = defineSchemaModel({
57
- name: "ExecuteQueryInput",
58
- fields: {
59
- queryId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
60
- parameters: { type: ScalarTypeEnum.JSON(), isOptional: true },
61
- dateRange: { type: ScalarTypeEnum.JSON(), isOptional: true },
62
- filters: { type: ScalarTypeEnum.JSON(), isOptional: true },
63
- forceRefresh: { type: ScalarTypeEnum.Boolean(), isOptional: true }
64
- }
65
- });
66
- export {
67
- QueryResultModel,
68
- QueryModel,
69
- ExecuteQueryInputModel,
70
- CreateQueryInputModel
71
- };
2
+ import{defineEnum as O}from"@contractspec/lib.schema";var C=O("QueryType",["SQL","METRIC","AGGREGATION","CUSTOM"]);import{defineSchemaModel as A,ScalarTypeEnum as G}from"@contractspec/lib.schema";var Q=A({name:"QueryModel",fields:{id:{type:G.String_unsecure(),isOptional:!1},name:{type:G.String_unsecure(),isOptional:!1},description:{type:G.String_unsecure(),isOptional:!0},type:{type:C,isOptional:!1},definition:{type:G.JSON(),isOptional:!1},sql:{type:G.String_unsecure(),isOptional:!0},cacheTtlSeconds:{type:G.Int_unsecure(),isOptional:!1},isShared:{type:G.Boolean(),isOptional:!1},createdAt:{type:G.DateTime(),isOptional:!1}}}),U=A({name:"QueryResultModel",fields:{queryId:{type:G.String_unsecure(),isOptional:!1},data:{type:G.JSON(),isOptional:!1},columns:{type:G.JSON(),isOptional:!1},rowCount:{type:G.Int_unsecure(),isOptional:!1},executionTimeMs:{type:G.Int_unsecure(),isOptional:!1},cachedAt:{type:G.DateTime(),isOptional:!0},error:{type:G.String_unsecure(),isOptional:!0}}}),j=A({name:"CreateQueryInput",fields:{name:{type:G.NonEmptyString(),isOptional:!1},description:{type:G.String_unsecure(),isOptional:!0},type:{type:C,isOptional:!1},definition:{type:G.JSON(),isOptional:!1},sql:{type:G.String_unsecure(),isOptional:!0},metricIds:{type:G.String_unsecure(),isArray:!0,isOptional:!0},cacheTtlSeconds:{type:G.Int_unsecure(),isOptional:!0},isShared:{type:G.Boolean(),isOptional:!0}}}),k=A({name:"ExecuteQueryInput",fields:{queryId:{type:G.String_unsecure(),isOptional:!1},parameters:{type:G.JSON(),isOptional:!0},dateRange:{type:G.JSON(),isOptional:!0},filters:{type:G.JSON(),isOptional:!0},forceRefresh:{type:G.Boolean(),isOptional:!0}}});export{U as QueryResultModel,Q as QueryModel,k as ExecuteQueryInputModel,j as CreateQueryInputModel};
@@ -1,114 +1,2 @@
1
1
  // @bun
2
- // src/query/query.test-spec.ts
3
- import { defineTestSpec } from "@contractspec/lib.contracts-spec/tests";
4
- var 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: ["analytics", "query", "test"],
12
- stability: "stable"
13
- },
14
- target: {
15
- type: "operation",
16
- operation: { key: "analytics.query.create", version: "1.0.0" }
17
- },
18
- scenarios: [
19
- {
20
- key: "success",
21
- description: "Successfully create a query",
22
- when: {
23
- operation: { key: "analytics.query.create", version: "1.0.0" },
24
- input: {
25
- name: "Revenue Query",
26
- sql: "SELECT * FROM revenue"
27
- }
28
- },
29
- then: [
30
- {
31
- type: "expectOutput",
32
- match: {
33
- name: "Revenue Query",
34
- type: "sql"
35
- }
36
- }
37
- ]
38
- },
39
- {
40
- key: "error-invalid-sql",
41
- description: "Fail with invalid SQL",
42
- when: {
43
- operation: { key: "analytics.query.create", version: "1.0.0" },
44
- input: {
45
- name: "Bad Query",
46
- sql: ""
47
- }
48
- },
49
- then: [
50
- {
51
- type: "expectError",
52
- messageIncludes: "VALIDATION_ERROR"
53
- }
54
- ]
55
- }
56
- ]
57
- });
58
- var ExecuteQueryTest = defineTestSpec({
59
- meta: {
60
- key: "analytics.query.execute.test",
61
- version: "1.0.0",
62
- title: "Execute Query Test",
63
- description: "Verifies query execution",
64
- owners: ["@example.analytics-dashboard"],
65
- tags: ["analytics", "query", "test"],
66
- stability: "stable"
67
- },
68
- target: {
69
- type: "operation",
70
- operation: { key: "analytics.query.execute", version: "1.0.0" }
71
- },
72
- scenarios: [
73
- {
74
- key: "success",
75
- description: "Successfully execute query",
76
- when: {
77
- operation: { key: "analytics.query.execute", version: "1.0.0" },
78
- input: {
79
- queryId: "q-123",
80
- params: { limit: 10 }
81
- }
82
- },
83
- then: [
84
- {
85
- type: "expectOutput",
86
- match: {
87
- rowCount: 1
88
- }
89
- }
90
- ]
91
- },
92
- {
93
- key: "error-query-not-found",
94
- description: "Fail when query not found",
95
- when: {
96
- operation: { key: "analytics.query.execute", version: "1.0.0" },
97
- input: {
98
- queryId: "q-999",
99
- params: {}
100
- }
101
- },
102
- then: [
103
- {
104
- type: "expectError",
105
- messageIncludes: "NOT_FOUND"
106
- }
107
- ]
108
- }
109
- ]
110
- });
111
- export {
112
- ExecuteQueryTest,
113
- CreateQueryTest
114
- };
2
+ import{defineTestSpec as g}from"@contractspec/lib.contracts-spec/tests";var j=g({meta:{key:"analytics.query.create.test",version:"1.0.0",title:"Create Query Test",description:"Verifies query creation flow",owners:["@example.analytics-dashboard"],tags:["analytics","query","test"],stability:"stable"},target:{type:"operation",operation:{key:"analytics.query.create",version:"1.0.0"}},scenarios:[{key:"success",description:"Successfully create a query",when:{operation:{key:"analytics.query.create",version:"1.0.0"},input:{name:"Revenue Query",sql:"SELECT * FROM revenue"}},then:[{type:"expectOutput",match:{name:"Revenue Query",type:"sql"}}]},{key:"error-invalid-sql",description:"Fail with invalid SQL",when:{operation:{key:"analytics.query.create",version:"1.0.0"},input:{name:"Bad Query",sql:""}},then:[{type:"expectError",messageIncludes:"VALIDATION_ERROR"}]}]}),k=g({meta:{key:"analytics.query.execute.test",version:"1.0.0",title:"Execute Query Test",description:"Verifies query execution",owners:["@example.analytics-dashboard"],tags:["analytics","query","test"],stability:"stable"},target:{type:"operation",operation:{key:"analytics.query.execute",version:"1.0.0"}},scenarios:[{key:"success",description:"Successfully execute query",when:{operation:{key:"analytics.query.execute",version:"1.0.0"},input:{queryId:"q-123",params:{limit:10}}},then:[{type:"expectOutput",match:{rowCount:1}}]},{key:"error-query-not-found",description:"Fail when query not found",when:{operation:{key:"analytics.query.execute",version:"1.0.0"},input:{queryId:"q-999",params:{}}},then:[{type:"expectError",messageIncludes:"NOT_FOUND"}]}]});export{k as ExecuteQueryTest,j as CreateQueryTest};