@@ -39,6 +39,7 @@ import {
3939 resolveObjectRef ,
4040 resolveTableName ,
4141 resolveTableSchema ,
42+ stripPackage ,
4243 type MetaData ,
4344 type MetaDimension ,
4445 type MetaField ,
@@ -74,14 +75,15 @@ import {
7475 ERR_CUBE_UNMAPPABLE_DIMENSION ,
7576 ERR_CUBE_UNMAPPABLE_JOIN ,
7677 ERR_CUBE_UNMAPPABLE_REPORT ,
78+ ERR_CUBE_UNSUPPORTED_DIALECT ,
7779} from "./cube-errors.js" ;
7880import {
81+ defaultedRawMemberName ,
7982 dimensionColumn ,
8083 docOf ,
8184 grainsOf ,
8285 measureMembers ,
8386 memberKey ,
84- rawMeasureName ,
8587 segmentSpec ,
8688 type MemberContext ,
8789} from "./cube-members.js" ;
@@ -162,8 +164,7 @@ interface SpinePlan {
162164
163165/** Entity short names along a `@via` path, for messages. */
164166function pathText ( from : MetaObject , path : Path ) : string {
165- const short = ( key : string ) : string => ( key . includes ( "::" ) ? key . slice ( key . lastIndexOf ( "::" ) + 2 ) : key ) ;
166- return [ from . name , ...path . map ( ( s ) => short ( s . targetEntity ) ) ] . join ( " -> " ) ;
167+ return [ from . name , ...path . map ( ( s ) => stripPackage ( s . targetEntity ) ) ] . join ( " -> " ) ;
167168}
168169
169170interface CubeDraft {
@@ -200,7 +201,10 @@ interface CubeDraft {
200201export function buildCubeModel ( root : MetaRoot , options : CubeModelOptions ) : CubeModel {
201202 // CubeDialect admits only these; a caller outside the type system gets a refusal, not SQLite SQL.
202203 if ( options . dialect !== "postgres" && options . dialect !== "mysql" ) {
203- throw new Error ( `buildCubeModel: dialect '${ String ( options . dialect ) } ' is not a Cube data source this exporter writes (postgres, mysql).` ) ;
204+ throw new CubeModelError (
205+ ERR_CUBE_UNSUPPORTED_DIALECT ,
206+ `dialect '${ String ( options . dialect ) } ' is not a Cube data source this exporter writes (postgres, mysql).` ,
207+ ) ;
204208 }
205209 return new CubeModelBuilder ( root , options ) . build ( ) ;
206210}
@@ -215,7 +219,7 @@ export function hasReportingVocabulary(obj: MetaObject): boolean {
215219}
216220
217221function hopLabel ( node : MetaData ) : string {
218- const kind = node . type === TYPE_IDENTITY ? "identity.reference" : `relationship .${ node . subType } ` ;
222+ const kind = node . type === TYPE_IDENTITY ? ` ${ TYPE_IDENTITY } . ${ IDENTITY_SUBTYPE_REFERENCE } ` : `${ TYPE_RELATIONSHIP } .${ node . subType } ` ;
219223 return `${ kind } '${ memberKey ( node ) } '` ;
220224}
221225
@@ -275,7 +279,7 @@ class CubeModelBuilder {
275279 private readonly options : CubeModelOptions ,
276280 ) {
277281 this . d = options . dialect ;
278- this . mc = { root, dialect : options . dialect , extract : { columnNamingStrategy : options . columnNamingStrategy } } ;
282+ this . mc = { root, dialect : this . d , extract : { columnNamingStrategy : options . columnNamingStrategy } } ;
279283 }
280284
281285 build ( ) : CubeModel {
@@ -871,8 +875,9 @@ class CubeModelBuilder {
871875 const needed = new Set < string > ( ) ;
872876 const need = ( m : MetaMeasure ) : void => {
873877 needed . add ( m . name ) ;
874- // ADR-0039: defaultValue() resolves, as measureMembers reads it.
875- if ( ! m . isRatio ( ) && m . defaultValue ( ) !== undefined ) needed . add ( rawMeasureName ( m . name ) ) ;
878+ // The `<m>Raw` twin is earned by one rule, in `defaultedRawMemberName`, shared with measureMembers.
879+ const raw = defaultedRawMemberName ( m ) ;
880+ if ( raw !== undefined ) needed . add ( raw ) ;
876881 } ;
877882 for ( const f of shape . fields ) {
878883 const m = f . measure ;
@@ -953,9 +958,9 @@ class CubeModelBuilder {
953958 const pairs = fkFields . map ( ( fk , i ) => {
954959 const fkCol = joinColumnFor ( fkEntity , fk , this . mc . extract ) ;
955960 const keyCol = joinColumnFor ( keyEntity , keyFields [ i ] ! , this . mc . extract ) ;
956- return h . fkOnSelf
957- ? ` ${ cubeColumn ( fkCol , this . d , renderer ) } = ${ joinedColumn ( h . joined . name , keyCol , this . d , renderer ) } `
958- : `${ cubeColumn ( keyCol , this . d , renderer ) } = ${ joinedColumn ( h . joined . name , fkCol , this . d , renderer ) } ` ;
961+ // One predicate shape, both directions: self's column left, the joined cube's column right.
962+ const [ selfCol , joinedCol ] : [ string , string ] = h . fkOnSelf ? [ fkCol , keyCol ] : [ keyCol , fkCol ] ;
963+ return `${ cubeColumn ( selfCol , this . d , renderer ) } = ${ joinedColumn ( h . joined . name , joinedCol , this . d , renderer ) } ` ;
959964 } ) ;
960965 return { name : h . joined . name , relationship : h . relationship , sql : pairs . join ( " AND " ) } ;
961966 }
0 commit comments