@happyvertical/smrt-reports 0.37.1 → 0.37.3
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/dist/aggregate.js +1 -5
- package/dist/compiler.js +138 -185
- package/dist/compiler.js.map +1 -1
- package/dist/decorators.js +53 -68
- package/dist/decorators.js.map +1 -1
- package/dist/index.js +80 -152
- package/dist/index.js.map +1 -1
- package/dist/manifest.json +2 -2
- package/dist/refresh.js +423 -667
- package/dist/refresh.js.map +1 -1
- package/dist/scheduler.js +330 -395
- package/dist/scheduler.js.map +1 -1
- package/dist/smrt-knowledge.json +7 -7
- package/dist/state.js +305 -305
- package/dist/state.js.map +1 -1
- package/dist/types.js +0 -2
- package/package.json +9 -9
- package/dist/aggregate.js.map +0 -1
- package/dist/types.js.map +0 -1
package/dist/state.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.js","sources":["../src/state.ts"],"sourcesContent":["import {\n field,\n SmrtCollection,\n SmrtObject,\n smrt,\n} from '@happyvertical/smrt-core';\nimport { TenantScoped, tenantId } from '@happyvertical/smrt-tenancy';\nimport type { DatabaseInterface } from '@happyvertical/sql';\nimport type { ReportRefreshMode, ReportRefreshTrigger } from './types.js';\n\nexport const REPORT_RUNS_TABLE = '_smrt_report_runs';\nexport const REPORT_WATERMARKS_TABLE = '_smrt_report_watermarks';\nexport const REPORT_LOCKS_TABLE = '_smrt_report_locks';\nexport const REPORT_SCHEDULES_TABLE = '_smrt_report_schedules';\nexport const REPORT_REFRESH_TASKS_TABLE = '_smrt_report_refresh_tasks';\n\nexport const REPORT_RUNTIME_TABLES = [\n REPORT_RUNS_TABLE,\n REPORT_WATERMARKS_TABLE,\n REPORT_LOCKS_TABLE,\n] as const;\n\nexport const REPORT_SCHEDULER_TABLES = [\n REPORT_SCHEDULES_TABLE,\n REPORT_REFRESH_TASKS_TABLE,\n] as const;\n\nexport type ReportRunStatus = 'running' | 'success' | 'failed' | 'skipped';\nexport type ReportScheduleStatus = 'active' | 'paused' | 'disabled' | 'error';\n\nexport function scopeKeyForTenant(tenantId: string | null | undefined): string {\n return tenantId ? `tenant:${tenantId}` : 'global';\n}\n\nexport async function assertReportTablesReady(\n db: DatabaseInterface,\n tables: readonly string[] = REPORT_RUNTIME_TABLES,\n): Promise<void> {\n for (const table of tables) {\n const ready = await db.tableExists(table);\n if (!ready) {\n throw new Error(\n `Report runtime table '${table}' does not exist. ` +\n 'Run smrt db:migrate before refreshing reports.',\n );\n }\n }\n}\n\nconst INTERNAL_SURFACE = {\n api: false,\n cli: {\n include: ['list', 'get'],\n skipApiCheck: true,\n http: false,\n },\n mcp: false,\n};\n\n@TenantScoped({ mode: 'optional' })\n@smrt({\n tableName: '_smrt_report_runs',\n ...INTERNAL_SURFACE,\n})\nexport class SmrtReportRun extends SmrtObject {\n @tenantId({ nullable: true })\n tenantId: string | null = null;\n\n @field({ type: 'text', required: true })\n scopeKey: string = 'global';\n\n @field({ type: 'text', required: true })\n reportClass: string = '';\n\n @field({ type: 'text', required: true })\n sourceClass: string = '';\n\n @field({ type: 'text', required: true })\n mode: ReportRefreshMode = 'rebuild';\n\n @field({ type: 'text', required: true })\n trigger: ReportRefreshTrigger = 'manual';\n\n @field({ type: 'text', required: true })\n status: ReportRunStatus = 'running';\n\n @field({ type: 'datetime', required: true })\n startedAt: Date = new Date();\n\n @field({ type: 'datetime', nullable: true })\n completedAt: Date | null = null;\n\n @field({ type: 'integer', required: true })\n rowCount: number = 0;\n\n @field({ type: 'integer', required: true })\n changedGroupCount: number = 0;\n\n @field({ type: 'text', nullable: true })\n watermarkBefore: string | null = null;\n\n @field({ type: 'text', nullable: true })\n watermarkAfter: string | null = null;\n\n @field({ type: 'text', nullable: true })\n error: string | null = null;\n\n @field({ type: 'json' })\n metadata: Record<string, unknown> = {};\n}\n\nexport class SmrtReportRunCollection extends SmrtCollection<SmrtReportRun> {\n static readonly _itemClass = SmrtReportRun;\n}\n\n@TenantScoped({ mode: 'optional' })\n@smrt({\n tableName: '_smrt_report_watermarks',\n conflictColumns: [\n 'report_class',\n 'scope_key',\n 'source_class',\n 'watermark_column',\n ],\n ...INTERNAL_SURFACE,\n})\nexport class SmrtReportWatermark extends SmrtObject {\n @tenantId({ nullable: true })\n tenantId: string | null = null;\n\n @field({ type: 'text', required: true })\n scopeKey: string = 'global';\n\n @field({ type: 'text', required: true })\n reportClass: string = '';\n\n @field({ type: 'text', required: true })\n sourceClass: string = '';\n\n @field({ type: 'text', required: true })\n watermarkColumn: string = '';\n\n @field({ type: 'text', nullable: true })\n watermarkValue: string | null = null;\n\n @field({ type: 'text', nullable: true })\n lastRunId: string | null = null;\n}\n\nexport class SmrtReportWatermarkCollection extends SmrtCollection<SmrtReportWatermark> {\n static readonly _itemClass = SmrtReportWatermark;\n}\n\n@TenantScoped({ mode: 'optional' })\n@smrt({\n tableName: '_smrt_report_locks',\n conflictColumns: ['report_class', 'scope_key'],\n ...INTERNAL_SURFACE,\n})\nexport class SmrtReportLock extends SmrtObject {\n @tenantId({ nullable: true })\n tenantId: string | null = null;\n\n @field({ type: 'text', required: true })\n scopeKey: string = 'global';\n\n @field({ type: 'text', required: true })\n reportClass: string = '';\n\n @field({ type: 'text', nullable: true })\n ownerId: string | null = null;\n\n @field({ type: 'datetime', nullable: true })\n acquiredAt: Date | null = null;\n\n @field({ type: 'datetime', nullable: true })\n heartbeatAt: Date | null = null;\n\n @field({ type: 'datetime', nullable: true })\n expiresAt: Date | null = null;\n}\n\nexport class SmrtReportLockCollection extends SmrtCollection<SmrtReportLock> {\n static readonly _itemClass = SmrtReportLock;\n}\n\n@TenantScoped({ mode: 'optional' })\n@smrt({\n tableName: '_smrt_report_schedules',\n conflictColumns: ['report_class', 'scope_key', 'cron', 'mode'],\n ...INTERNAL_SURFACE,\n})\nexport class SmrtReportSchedule extends SmrtObject {\n @tenantId({ nullable: true })\n tenantId: string | null = null;\n\n @field({ type: 'text', required: true })\n scopeKey: string = 'global';\n\n @field({ type: 'text', required: true })\n reportClass: string = '';\n\n @field({ type: 'text', required: true })\n cron: string = '';\n\n @field({ type: 'text', required: true })\n trigger: ReportRefreshTrigger = 'schedule';\n\n @field({ type: 'text', required: true })\n mode: ReportRefreshMode = 'incremental';\n\n @field({ type: 'boolean', required: true })\n enabled: boolean = true;\n\n @field({ type: 'text', required: true })\n status: ReportScheduleStatus = 'active';\n\n @field({ type: 'datetime', nullable: true })\n nextRun: Date | null = null;\n\n @field({ type: 'datetime', nullable: true })\n lastRun: Date | null = null;\n\n @field({ type: 'text', nullable: true })\n lastStatus: 'success' | 'failed' | null = null;\n\n @field({ type: 'text', nullable: true })\n lastError: string | null = null;\n\n @field({ type: 'integer', required: true })\n runCount: number = 0;\n\n @field({ type: 'integer', required: true })\n successCount: number = 0;\n\n @field({ type: 'integer', required: true })\n failureCount: number = 0;\n\n @field({ type: 'integer', required: true })\n runningCount: number = 0;\n\n @field({ type: 'integer', required: true })\n maxConcurrent: number = 1;\n\n @field({ type: 'text', required: true })\n queue: string = 'reports';\n\n @field({ type: 'integer', required: true })\n priority: number = 70;\n\n @field({ type: 'integer', required: true })\n timeout: number = 3600000;\n}\n\nexport class SmrtReportScheduleCollection extends SmrtCollection<SmrtReportSchedule> {\n static readonly _itemClass = SmrtReportSchedule;\n}\n"],"names":["tenantId"],"mappings":";;;;;;;;;;;;AAUO,MAAM,oBAAoB;AAC1B,MAAM,0BAA0B;AAChC,MAAM,qBAAqB;AAC3B,MAAM,yBAAyB;AAC/B,MAAM,6BAA6B;AAEnC,MAAM,wBAAwB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AACF;AAEO,MAAM,0BAA0B;AAAA,EACrC;AAAA,EACA;AACF;AAKO,SAAS,kBAAkBA,WAA6C;AAC7E,SAAOA,YAAW,UAAUA,SAAQ,KAAK;AAC3C;AAEA,eAAsB,wBACpB,IACA,SAA4B,uBACb;AACf,aAAW,SAAS,QAAQ;AAC1B,UAAM,QAAQ,MAAM,GAAG,YAAY,KAAK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ts"],"sourcesContent":["import {\n field,\n SmrtCollection,\n SmrtObject,\n smrt,\n} from '@happyvertical/smrt-core';\nimport { TenantScoped, tenantId } from '@happyvertical/smrt-tenancy';\nimport type { DatabaseInterface } from '@happyvertical/sql';\nimport type { ReportRefreshMode, ReportRefreshTrigger } from './types.js';\n\nexport const REPORT_RUNS_TABLE = '_smrt_report_runs';\nexport const REPORT_WATERMARKS_TABLE = '_smrt_report_watermarks';\nexport const REPORT_LOCKS_TABLE = '_smrt_report_locks';\nexport const REPORT_SCHEDULES_TABLE = '_smrt_report_schedules';\nexport const REPORT_REFRESH_TASKS_TABLE = '_smrt_report_refresh_tasks';\n\nexport const REPORT_RUNTIME_TABLES = [\n REPORT_RUNS_TABLE,\n REPORT_WATERMARKS_TABLE,\n REPORT_LOCKS_TABLE,\n] as const;\n\nexport const REPORT_SCHEDULER_TABLES = [\n REPORT_SCHEDULES_TABLE,\n REPORT_REFRESH_TASKS_TABLE,\n] as const;\n\nexport type ReportRunStatus = 'running' | 'success' | 'failed' | 'skipped';\nexport type ReportScheduleStatus = 'active' | 'paused' | 'disabled' | 'error';\n\nexport function scopeKeyForTenant(tenantId: string | null | undefined): string {\n return tenantId ? `tenant:${tenantId}` : 'global';\n}\n\nexport async function assertReportTablesReady(\n db: DatabaseInterface,\n tables: readonly string[] = REPORT_RUNTIME_TABLES,\n): Promise<void> {\n for (const table of tables) {\n const ready = await db.tableExists(table);\n if (!ready) {\n throw new Error(\n `Report runtime table '${table}' does not exist. ` +\n 'Run smrt db:migrate before refreshing reports.',\n );\n }\n }\n}\n\nconst INTERNAL_SURFACE = {\n api: false,\n cli: {\n include: ['list', 'get'],\n skipApiCheck: true,\n http: false,\n },\n mcp: false,\n};\n\n@TenantScoped({ mode: 'optional' })\n@smrt({\n tableName: '_smrt_report_runs',\n ...INTERNAL_SURFACE,\n})\nexport class SmrtReportRun extends SmrtObject {\n @tenantId({ nullable: true })\n tenantId: string | null = null;\n\n @field({ type: 'text', required: true })\n scopeKey: string = 'global';\n\n @field({ type: 'text', required: true })\n reportClass: string = '';\n\n @field({ type: 'text', required: true })\n sourceClass: string = '';\n\n @field({ type: 'text', required: true })\n mode: ReportRefreshMode = 'rebuild';\n\n @field({ type: 'text', required: true })\n trigger: ReportRefreshTrigger = 'manual';\n\n @field({ type: 'text', required: true })\n status: ReportRunStatus = 'running';\n\n @field({ type: 'datetime', required: true })\n startedAt: Date = new Date();\n\n @field({ type: 'datetime', nullable: true })\n completedAt: Date | null = null;\n\n @field({ type: 'integer', required: true })\n rowCount: number = 0;\n\n @field({ type: 'integer', required: true })\n changedGroupCount: number = 0;\n\n @field({ type: 'text', nullable: true })\n watermarkBefore: string | null = null;\n\n @field({ type: 'text', nullable: true })\n watermarkAfter: string | null = null;\n\n @field({ type: 'text', nullable: true })\n error: string | null = null;\n\n @field({ type: 'json' })\n metadata: Record<string, unknown> = {};\n}\n\nexport class SmrtReportRunCollection extends SmrtCollection<SmrtReportRun> {\n static readonly _itemClass = SmrtReportRun;\n}\n\n@TenantScoped({ mode: 'optional' })\n@smrt({\n tableName: '_smrt_report_watermarks',\n conflictColumns: [\n 'report_class',\n 'scope_key',\n 'source_class',\n 'watermark_column',\n ],\n ...INTERNAL_SURFACE,\n})\nexport class SmrtReportWatermark extends SmrtObject {\n @tenantId({ nullable: true })\n tenantId: string | null = null;\n\n @field({ type: 'text', required: true })\n scopeKey: string = 'global';\n\n @field({ type: 'text', required: true })\n reportClass: string = '';\n\n @field({ type: 'text', required: true })\n sourceClass: string = '';\n\n @field({ type: 'text', required: true })\n watermarkColumn: string = '';\n\n @field({ type: 'text', nullable: true })\n watermarkValue: string | null = null;\n\n @field({ type: 'text', nullable: true })\n lastRunId: string | null = null;\n}\n\nexport class SmrtReportWatermarkCollection extends SmrtCollection<SmrtReportWatermark> {\n static readonly _itemClass = SmrtReportWatermark;\n}\n\n@TenantScoped({ mode: 'optional' })\n@smrt({\n tableName: '_smrt_report_locks',\n conflictColumns: ['report_class', 'scope_key'],\n ...INTERNAL_SURFACE,\n})\nexport class SmrtReportLock extends SmrtObject {\n @tenantId({ nullable: true })\n tenantId: string | null = null;\n\n @field({ type: 'text', required: true })\n scopeKey: string = 'global';\n\n @field({ type: 'text', required: true })\n reportClass: string = '';\n\n @field({ type: 'text', nullable: true })\n ownerId: string | null = null;\n\n @field({ type: 'datetime', nullable: true })\n acquiredAt: Date | null = null;\n\n @field({ type: 'datetime', nullable: true })\n heartbeatAt: Date | null = null;\n\n @field({ type: 'datetime', nullable: true })\n expiresAt: Date | null = null;\n}\n\nexport class SmrtReportLockCollection extends SmrtCollection<SmrtReportLock> {\n static readonly _itemClass = SmrtReportLock;\n}\n\n@TenantScoped({ mode: 'optional' })\n@smrt({\n tableName: '_smrt_report_schedules',\n conflictColumns: ['report_class', 'scope_key', 'cron', 'mode'],\n ...INTERNAL_SURFACE,\n})\nexport class SmrtReportSchedule extends SmrtObject {\n @tenantId({ nullable: true })\n tenantId: string | null = null;\n\n @field({ type: 'text', required: true })\n scopeKey: string = 'global';\n\n @field({ type: 'text', required: true })\n reportClass: string = '';\n\n @field({ type: 'text', required: true })\n cron: string = '';\n\n @field({ type: 'text', required: true })\n trigger: ReportRefreshTrigger = 'schedule';\n\n @field({ type: 'text', required: true })\n mode: ReportRefreshMode = 'incremental';\n\n @field({ type: 'boolean', required: true })\n enabled: boolean = true;\n\n @field({ type: 'text', required: true })\n status: ReportScheduleStatus = 'active';\n\n @field({ type: 'datetime', nullable: true })\n nextRun: Date | null = null;\n\n @field({ type: 'datetime', nullable: true })\n lastRun: Date | null = null;\n\n @field({ type: 'text', nullable: true })\n lastStatus: 'success' | 'failed' | null = null;\n\n @field({ type: 'text', nullable: true })\n lastError: string | null = null;\n\n @field({ type: 'integer', required: true })\n runCount: number = 0;\n\n @field({ type: 'integer', required: true })\n successCount: number = 0;\n\n @field({ type: 'integer', required: true })\n failureCount: number = 0;\n\n @field({ type: 'integer', required: true })\n runningCount: number = 0;\n\n @field({ type: 'integer', required: true })\n maxConcurrent: number = 1;\n\n @field({ type: 'text', required: true })\n queue: string = 'reports';\n\n @field({ type: 'integer', required: true })\n priority: number = 70;\n\n @field({ type: 'integer', required: true })\n timeout: number = 3600000;\n}\n\nexport class SmrtReportScheduleCollection extends SmrtCollection<SmrtReportSchedule> {\n static readonly _itemClass = SmrtReportSchedule;\n}\n"],"mappings":";;;;;;;;;;;AAUO,IAAM,oBAAoB;AAC1B,IAAM,0BAA0B;AAChC,IAAM,qBAAqB;AAC3B,IAAM,yBAAyB;AAC/B,IAAM,6BAA6B;AAEnC,IAAM,wBAAwB;CACnC;CACA;CACA;AACF;AAEO,IAAM,0BAA0B,CACrC,wBACA,0BACF;AAKO,SAAS,kBAAkBA,WAA6C;CAC7E,OAAOA,YAAW,UAAUA,cAAa;AAC3C;AAEA,eAAsB,wBACpB,IACA,SAA4B,uBACb;CACf,KAAA,MAAW,SAAS,QAElB,IAAI,CAAC,MADe,GAAG,YAAY,KAAK,GAEtC,MAAM,IAAI,MACR,yBAAyB,MAAK,iEAEhC;AAGN;AAEA,IAAM,mBAAmB;CACvB,KAAK;CACL,KAAK;EACH,SAAS,CAAC,QAAQ,KAAK;EACvB,cAAc;EACd,MAAM;CACR;CACA,KAAK;AACP;AAOO,IAAM,gBAAN,cAA4B,WAAW;CAE5C,WAA0B;CAG1B,WAAmB;CAGnB,cAAsB;CAGtB,cAAsB;CAGtB,OAA0B;CAG1B,UAAgC;CAGhC,SAA0B;CAG1B,4BAAkB,IAAI,KAAK;CAG3B,cAA2B;CAG3B,WAAmB;CAGnB,oBAA4B;CAG5B,kBAAiC;CAGjC,iBAAgC;CAGhC,QAAuB;CAGvB,WAAoC,CAAC;AACvC;AA3CE,gBAAA,CADC,SAAS,EAAE,UAAU,KAAK,CAAC,CAAA,GADjB,cAEX,WAAA,YAAA,CAAA;AAGA,gBAAA,CADC,MAAM;CAAE,MAAM;CAAQ,UAAU;AAAK,CAAC,CAAA,GAJ5B,cAKX,WAAA,YAAA,CAAA;AAGA,gBAAA,C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-1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@happyvertical/smrt-reports",
|
|
3
|
-
"version": "0.37.
|
|
3
|
+
"version": "0.37.3",
|
|
4
4
|
"description": "Materialized aggregate report models for SMRT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -43,17 +43,17 @@
|
|
|
43
43
|
"./manifest.json": "./dist/manifest.json"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@happyvertical/sql": "^0.74.
|
|
47
|
-
"@happyvertical/smrt-core": "0.37.
|
|
48
|
-
"@happyvertical/smrt-jobs": "0.37.
|
|
49
|
-
"@happyvertical/smrt-tenancy": "0.37.
|
|
46
|
+
"@happyvertical/sql": "^0.74.11",
|
|
47
|
+
"@happyvertical/smrt-core": "0.37.3",
|
|
48
|
+
"@happyvertical/smrt-jobs": "0.37.3",
|
|
49
|
+
"@happyvertical/smrt-tenancy": "0.37.3"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@types/node": "
|
|
52
|
+
"@types/node": "24.13.2",
|
|
53
53
|
"typescript": "^5.9.3",
|
|
54
|
-
"vite": "^
|
|
55
|
-
"vitest": "^4.
|
|
56
|
-
"@happyvertical/smrt-vitest": "0.37.
|
|
54
|
+
"vite": "^8.1.2",
|
|
55
|
+
"vitest": "^4.1.9",
|
|
56
|
+
"@happyvertical/smrt-vitest": "0.37.3"
|
|
57
57
|
},
|
|
58
58
|
"keywords": [
|
|
59
59
|
"ai",
|
package/dist/aggregate.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"aggregate.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|