semanticdb-v2 2.0.0-alpha.10 → 2.0.0-alpha.12

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 (80) hide show
  1. package/README.md +39 -15
  2. package/dist/cache/types.d.ts +2 -1
  3. package/dist/compiler/compile-computation.d.ts +6 -0
  4. package/dist/compiler/compile-source.d.ts +5 -0
  5. package/dist/executor/component-properties.d.ts +22 -0
  6. package/dist/executor/components.d.ts +7 -3
  7. package/dist/executor/execute-query.d.ts +1 -0
  8. package/dist/executor/execute.d.ts +1 -1
  9. package/dist/executor/federated-execution.d.ts +2 -1
  10. package/dist/executor/fetch-entities.d.ts +2 -2
  11. package/dist/executor/index.d.ts +1 -1
  12. package/dist/executor/merge-by-id.d.ts +3 -0
  13. package/dist/executor/partition.d.ts +18 -0
  14. package/dist/executor/random-data.d.ts +5 -0
  15. package/dist/executor/result-hydrator/entity-fetch-conditions.d.ts +4 -0
  16. package/dist/executor/result-hydrator/index.d.ts +1 -0
  17. package/dist/executor/result-hydrator/types.d.ts +7 -0
  18. package/dist/executor/runtime-execution.d.ts +6 -0
  19. package/dist/executor/sample.d.ts +6 -0
  20. package/dist/executor/types.d.ts +23 -13
  21. package/dist/file-import/index.d.ts +2 -0
  22. package/dist/file-import/read-file.d.ts +2 -0
  23. package/dist/file-import/types.d.ts +31 -0
  24. package/dist/index.d.ts +11 -6
  25. package/dist/logicform/dimensions.d.ts +16 -0
  26. package/dist/logicform/index.d.ts +2 -0
  27. package/dist/logicform-types.d.ts +22 -2
  28. package/dist/normalizer/core.d.ts +8 -1
  29. package/dist/normalizer/index.d.ts +1 -0
  30. package/dist/normalizer/main-time-range.d.ts +9 -0
  31. package/dist/normalizer/public-logicform.d.ts +14 -0
  32. package/dist/normalizer/query.d.ts +3 -2
  33. package/dist/normalizer/random-data.d.ts +2 -0
  34. package/dist/operators/builtins/period-name.d.ts +3 -0
  35. package/dist/operators/builtins/time-range.d.ts +2 -2
  36. package/dist/operators/formula-text.d.ts +10 -0
  37. package/dist/operators/index.d.ts +2 -1
  38. package/dist/operators/registry.d.ts +8 -1
  39. package/dist/operators/types.d.ts +115 -25
  40. package/dist/permissions/index.d.ts +2 -1
  41. package/dist/permissions/metric-permissions.d.ts +9 -0
  42. package/dist/permissions/permissions.d.ts +4 -3
  43. package/dist/permissions/types.d.ts +5 -0
  44. package/dist/physical/connection.d.ts +4 -0
  45. package/dist/physical/db-connector.d.ts +10 -0
  46. package/dist/physical/duckdb-coordinator-provider.d.ts +3 -23
  47. package/dist/physical/duckdb-dataset.d.ts +23 -0
  48. package/dist/physical/duckdb-provider.d.ts +26 -0
  49. package/dist/physical/duckdb-sql.d.ts +33 -0
  50. package/dist/physical/import-types.d.ts +23 -0
  51. package/dist/physical/import-validation.d.ts +14 -0
  52. package/dist/physical/index.d.ts +4 -0
  53. package/dist/physical/postgresql-provider.d.ts +1 -0
  54. package/dist/physical/provider.d.ts +4 -0
  55. package/dist/planner/build-lineage.d.ts +1 -1
  56. package/dist/planner/create-logical-plan.d.ts +15 -2
  57. package/dist/planner/index.d.ts +3 -2
  58. package/dist/planner/mapping-granularity.d.ts +1 -1
  59. package/dist/planner/materialize-computations.d.ts +3 -0
  60. package/dist/planner/select-schema-mapping.d.ts +16 -1
  61. package/dist/planner/types.d.ts +52 -9
  62. package/dist/planner/udf-inputs.d.ts +6 -0
  63. package/dist/plugins/types.d.ts +4 -2
  64. package/dist/schema/index.d.ts +1 -0
  65. package/dist/schema/relation-keys.d.ts +11 -0
  66. package/dist/schema-mappings/computations.d.ts +3 -0
  67. package/dist/schema-mappings/index.d.ts +5 -1
  68. package/dist/schema-mappings/registry.d.ts +1 -0
  69. package/dist/schema-mappings/source.d.ts +11 -0
  70. package/dist/schema-mappings/sql-inputs.d.ts +7 -0
  71. package/dist/schema-mappings/supported-dimensions.d.ts +10 -0
  72. package/dist/schema-mappings/types.d.ts +107 -15
  73. package/dist/schema-mappings/yiask.d.ts +6 -18
  74. package/dist/semantic-types/index.d.ts +1 -1
  75. package/dist/semantic-types/types.d.ts +50 -2
  76. package/dist/semanticdb.esm.js +6 -5
  77. package/dist/semanticdb.js +6 -5
  78. package/dist/utils/format-date.d.ts +3 -0
  79. package/package.json +5 -3
  80. package/dist/executor/evaluate.d.ts +0 -4
@@ -1,3 +1,4 @@
1
+ import type { ImportRowsRequest, ImportRowsResult } from './import-types';
1
2
  export type DataRow = Record<string, unknown>;
2
3
  export type SqlParameters = readonly unknown[];
3
4
  export type DatePart = 'second' | 'minute' | 'hour' | 'weekday' | 'day' | 'week' | 'month' | 'quarter' | 'year';
@@ -100,5 +101,8 @@ export interface CoreComputeProvider extends SqlRenderCapabilities {
100
101
  /** Optional physical metadata capability, independent of semantic Schemas. */
101
102
  getTableList?(request: TableListRequest): Promise<DatabaseTable[]>;
102
103
  describeTable?(request: DescribeTableRequest): Promise<TableDescription>;
104
+ importRows?(request: ImportRowsRequest): Promise<ImportRowsResult>;
105
+ /** Published dataset revision, used to isolate cached queries across imports. */
106
+ getDataVersion?(): Promise<string | undefined>;
103
107
  close(): Promise<void>;
104
108
  }
@@ -2,4 +2,4 @@ import type { OperatorRegistry } from '../operators/index';
2
2
  import type { CoreComputeProvider } from '../physical/index';
3
3
  import type { ResolvedSemanticSchema } from '../semantic-types/index';
4
4
  import type { LogicalPlan, QueryLineage } from './types';
5
- export declare const buildLineage: (plan: LogicalPlan, schema: ResolvedSemanticSchema, provider: CoreComputeProvider, operators?: OperatorRegistry, providerForConnection?: (connectionId: string) => CoreComputeProvider) => QueryLineage;
5
+ export declare const buildLineage: (plan: LogicalPlan, schema: ResolvedSemanticSchema, provider: CoreComputeProvider, operators?: OperatorRegistry, providerForConnection?: (connectionId: string) => CoreComputeProvider, resolveSchema?: (schemaId: string) => ResolvedSemanticSchema) => QueryLineage;
@@ -1,15 +1,28 @@
1
- import type { LogicformType } from '../logicform-types';
1
+ import type { LogicformType, PredItemType } from '../logicform-types';
2
2
  import type { OperatorRegistry } from '../operators/index';
3
3
  import { SchemaMappingRegistry } from '../schema-mappings/index';
4
4
  import type { SchemaMappingSelection } from '../schema-mappings/index';
5
5
  import type { SemanticDBPlugin } from '../plugins/index';
6
- import type { ResolvedSemanticSchema } from '../semantic-types/index';
6
+ import type { ResolvedSemanticSchema, SemanticTypeRegistry } from '../semantic-types/index';
7
7
  import type { ResolvedSemanticProperty } from '../semantic-types/index';
8
+ import type { ResultProperty } from '../operators/index';
8
9
  import { type PlannerSemanticRegistry } from './semantics/index';
9
10
  import type { LogicalPlan } from './types';
11
+ export declare const createResultProperty: (property: ResultProperty) => ResolvedSemanticProperty;
10
12
  export declare const createResultSchema: (plan: LogicalPlan, sourceSchema: ResolvedSemanticSchema) => ResolvedSemanticSchema;
11
13
  export declare const createDerivedSourceSchema: (sourcePlan: LogicalPlan, outerSchema: ResolvedSemanticSchema) => ResolvedSemanticSchema;
12
14
  export interface CreateLogicalPlanOptions {
15
+ /** Executor authorization for each form, including forms introduced by operator rewrites. */
16
+ readonly authorizeLogicform?: (logicform: LogicformType) => void;
17
+ readonly semanticTypes?: SemanticTypeRegistry;
18
+ /** Authorize logical inputs introduced by Mapping computations. */
19
+ readonly authorizeComputationInput?: (schema: ResolvedSemanticSchema, reference: string) => void;
20
+ /** Original semantic projections for this generated query only, aligned with its preds. */
21
+ readonly semanticPreds?: readonly PredItemType[];
22
+ /** Normalized nested LogicForms whose asynchronous partition plans were prepared by the executor. */
23
+ readonly preplannedPartitions?: ReadonlyMap<string, LogicalPlan>;
24
+ /** Restrict the root physical Schema to one candidate during partition planning. */
25
+ readonly mappingCandidates?: readonly string[];
13
26
  readonly plugins?: readonly SemanticDBPlugin[];
14
27
  readonly resolveSchema?: (schemaId: string) => ResolvedSemanticSchema;
15
28
  /** Prefer physical mappings colocated with the execution's main connection. */
@@ -1,9 +1,10 @@
1
1
  export { buildLineage } from './build-lineage';
2
- export { createDerivedSourceSchema, createLogicalPlan, createResultSchema } from './create-logical-plan';
2
+ export { createDerivedSourceSchema, createLogicalPlan, createResultProperty, createResultSchema } from './create-logical-plan';
3
3
  export type { CreateLogicalPlanOptions } from './create-logical-plan';
4
- export type { Expression, ArrayExpansionPlan, EnrichmentJoinPlan, FieldReferencePlan, GroupLimitPlan, JoinPlan, LogicalQuerySubquery, LogicalQueryOperator, LogicalOrdinalQuery, LogicalExpressionQuery, LineageColumnSource, LineageOutput, LogicalPlan, OrderPlan, PaginationPlan, ProjectionPlan, QueryLineage, RowIdentityPlan, PeriodSourcePlan, TemporalJoinConditionPlan, } from './types';
4
+ export type { Expression, ArrayExpansionPlan, EnrichmentJoinPlan, FieldReferencePlan, GroupLimitPlan, JoinPlan, LogicalQuerySubquery, LogicalOutputReference, LogicalQueryOperator, LogicalOrdinalQuery, LogicalExpressionQuery, LineageColumnSource, LineageOutput, LogicalPlan, OrderPlan, PaginationPlan, PhysicalQueryFilterPlan, ProjectionPlan, QueryLineage, RowIdentityPlan, PeriodSourcePlan, TemporalJoinConditionPlan, } from './types';
5
5
  export { isLogicalQuerySubquery, isLogicalQueryOperator } from './types';
6
6
  export { isLogicalOrdinalQuery } from './types';
7
7
  export { isLogicalExpressionQuery } from './types';
8
+ export { isLogicalOutputReference } from './types';
8
9
  export * from './semantics/index';
9
10
  export { createPlannerSemanticRegistry } from './semantics/registry-defaults';
@@ -3,5 +3,5 @@ import type { SemanticDBPlugin } from '../plugins/index';
3
3
  import { type OperatorRegistry } from '../operators/index';
4
4
  import { type SchemaMappingDefinition } from '../schema-mappings/index';
5
5
  import type { ResolvedSemanticSchema } from '../semantic-types/index';
6
- /** Checks grouped-source Property coverage and delegates plugin-owned physical grains. */
6
+ /** Checks physical-grain Property coverage and delegates plugin-owned grains. */
7
7
  export declare const mappingGranularityReason: (logicform: LogicformType, schema: ResolvedSemanticSchema, mapping: SchemaMappingDefinition, resolveSchema?: (schemaId: string) => ResolvedSemanticSchema, plugins?: readonly SemanticDBPlugin[], operators?: OperatorRegistry) => string | undefined;
@@ -0,0 +1,3 @@
1
+ import type { LogicalPlan } from './types';
2
+ /** Isolate row computations from aggregate/query scopes, without SQL-text pruning. */
3
+ export declare const materializeComputations: (plan: LogicalPlan) => LogicalPlan;
@@ -1,25 +1,40 @@
1
1
  import type { LogicformType } from '../logicform-types';
2
2
  import type { SemanticDBPlugin } from '../plugins/index';
3
- import type { SchemaMappingDefinition, SchemaMappingRegistry, SchemaMappingSelection } from '../schema-mappings/index';
3
+ import type { SchemaMappingDefinition, PropertyMappingCalculation, SchemaMappingRegistry, SchemaMappingSelection } from '../schema-mappings/index';
4
4
  import type { ResolvedSemanticSchema } from '../semantic-types/index';
5
5
  import { type OperatorRegistry } from '../operators/index';
6
+ import type { PhysicalQueryFilterPlan } from './types';
6
7
  export interface PredMappingRewrite {
7
8
  readonly predIndex: number;
8
9
  readonly column: string;
9
10
  }
11
+ export interface GroupPathBinding {
12
+ readonly canonicalId: string;
13
+ readonly sourceColumn: string;
14
+ readonly targetSchemaId: string;
15
+ }
10
16
  export interface SelectedSchemaMapping {
11
17
  readonly mapping: SchemaMappingDefinition;
12
18
  readonly logicform: LogicformType;
13
19
  readonly predRewrites: readonly PredMappingRewrite[];
20
+ readonly physicalQueryFilters: readonly PhysicalQueryFilterPlan[];
21
+ readonly groupPathBindings: readonly GroupPathBinding[];
14
22
  readonly selection: SchemaMappingSelection;
15
23
  }
16
24
  export interface MappedPropertySource {
17
25
  readonly column: string;
18
26
  readonly sourceRef?: string;
27
+ readonly calculation?: PropertyMappingCalculation;
28
+ readonly propertyId?: string;
19
29
  }
20
30
  export declare const mappedPropertyColumn: (mapping: SchemaMappingDefinition, schema: ResolvedSemanticSchema, reference: string) => string | undefined;
21
31
  export declare const mappedPropertySource: (mapping: SchemaMappingDefinition, schema: ResolvedSemanticSchema, reference: string) => MappedPropertySource | undefined;
32
+ /** A physical column for the complete logical path, without traversing its relations. */
33
+ export declare const mappedPropertyPathSource: (mapping: SchemaMappingDefinition, schema: ResolvedSemanticSchema, reference: string, resolveSchema?: (schemaId: string) => ResolvedSemanticSchema) => MappedPropertySource | undefined;
34
+ /** A related entity's mapped ID column is also the root relation's value. */
35
+ export declare const mappedRelationIdSource: (mapping: SchemaMappingDefinition, schema: ResolvedSemanticSchema, reference: string, resolveSchema?: (schemaId: string) => ResolvedSemanticSchema) => MappedPropertySource | undefined;
22
36
  export declare const selectSchemaMapping: (logicform: LogicformType, schema: ResolvedSemanticSchema, mappings: SchemaMappingRegistry, options?: {
37
+ readonly mappingCandidates?: readonly string[];
23
38
  readonly preferredConnectionId?: string;
24
39
  readonly resolveSchema?: (schemaId: string) => ResolvedSemanticSchema;
25
40
  /** Extra plugins used by this execution; must also be supplied when registering plugin grains. */
@@ -1,3 +1,4 @@
1
+ import type { ResolvedMappingSource, PropertyMappingCalculation } from '../schema-mappings/index';
1
2
  import type { CoreComputeProvider } from '../physical/index';
2
3
  import type { LogicformType } from '../logicform-types';
3
4
  import type { ResultProperty } from '../operators/index';
@@ -11,6 +12,8 @@ export interface FieldReferencePlan {
11
12
  readonly column: string;
12
13
  readonly qualifier: string;
13
14
  readonly sql?: string;
15
+ /** Planned row-level value; inlined for single-use filters, otherwise materialized. */
16
+ readonly computation?: Expression;
14
17
  readonly timestampColumn?: string;
15
18
  /** Source alias that supplies $TS when it differs from the Property's Schema. */
16
19
  readonly timestampQualifier?: string;
@@ -19,10 +22,21 @@ export interface FieldReferencePlan {
19
22
  readonly normalizeStringArray?: boolean;
20
23
  readonly comparable?: ComparableCategoryDefinition;
21
24
  }
25
+ /** Filter against a column of the selected physical source. */
26
+ export interface PhysicalQueryFilterPlan {
27
+ readonly sourceColumn: string;
28
+ readonly value: string | number | boolean | LogicformType | LogicalQuerySubquery;
29
+ }
22
30
  export interface LogicalQuerySubquery {
23
31
  readonly kind: 'logicform-subquery';
24
32
  readonly plan: LogicalPlan;
25
33
  }
34
+ /** Reference to another projected output in a HAVING comparison. */
35
+ export interface LogicalOutputReference {
36
+ readonly kind: 'output-reference';
37
+ readonly name: string;
38
+ }
39
+ export declare const isLogicalOutputReference: (value: unknown) => value is LogicalOutputReference;
26
40
  export interface LogicalQueryOperator {
27
41
  readonly kind: 'query-operator';
28
42
  readonly operator: string;
@@ -51,6 +65,13 @@ export declare const isLogicalQueryOperator: (value: unknown) => value is Logica
51
65
  export declare const isLogicalOrdinalQuery: (value: unknown) => value is LogicalOrdinalQuery;
52
66
  export declare const isLogicalExpressionQuery: (value: unknown) => value is LogicalExpressionQuery;
53
67
  export type Expression = {
68
+ readonly kind: 'mapping-computation';
69
+ readonly definition: PropertyMappingCalculation & {
70
+ readonly id: string;
71
+ };
72
+ readonly inputs: Readonly<Record<string, Expression>>;
73
+ readonly alias: string;
74
+ } | {
54
75
  readonly kind: 'array-element';
55
76
  readonly schemaId: string;
56
77
  readonly property: string;
@@ -126,10 +147,13 @@ export interface JoinPlan {
126
147
  readonly targetSchemaId: string;
127
148
  /** Physical connection selected for the target Schema mapping. */
128
149
  readonly targetConnectionId?: string;
129
- readonly targetSource: string;
130
- readonly targetSourceSql?: string;
150
+ readonly targetSource: ResolvedMappingSource;
151
+ /** Two projection layers for the target Schema Mapping and its UDFs. */
152
+ readonly targetMappingSourcePlan?: LogicalPlan;
131
153
  readonly targetAlias: string;
132
154
  readonly targetColumn: string;
155
+ readonly sourceExpression?: Expression;
156
+ readonly targetExpression?: Expression;
133
157
  readonly targetSql?: string;
134
158
  readonly targetTimestampColumn?: string;
135
159
  readonly temporalCondition?: TemporalJoinConditionPlan;
@@ -152,8 +176,7 @@ export type TemporalJoinConditionPlan = {
152
176
  export interface EnrichmentJoinPlan {
153
177
  readonly kind: 'enrichment-left';
154
178
  readonly id: string;
155
- readonly source: string;
156
- readonly sourceSql?: string;
179
+ readonly source: ResolvedMappingSource;
157
180
  readonly alias: string;
158
181
  readonly baseAlias: string;
159
182
  readonly keys: readonly {
@@ -221,15 +244,34 @@ export type RowIdentityPlan = {
221
244
  };
222
245
  export interface LogicalPlan {
223
246
  readonly schemaId: string;
224
- readonly source: string;
247
+ readonly source: ResolvedMappingSource | undefined;
225
248
  /** Physical connection selected for this plan's source mapping. */
226
249
  readonly connectionId?: string;
227
- /** Trusted derived-table SQL supplied by the selected physical mapping. */
228
- readonly sourceSql?: string;
250
+ /** Two projection layers for the physical Mapping and Schema UDFs. */
251
+ readonly mappingSourcePlan?: LogicalPlan;
229
252
  /** Physical mapping selected by the Planner for this logical Schema. */
230
253
  readonly mappingId?: string;
254
+ /** Only computation sources actually required by this plan. */
255
+ readonly computationSources?: readonly {
256
+ readonly id: string;
257
+ readonly alias: string;
258
+ readonly source: string;
259
+ readonly schemaId: string;
260
+ readonly mappingSource: string;
261
+ readonly connectionId: string;
262
+ }[];
231
263
  /** Child relations combined by their compatible group identity. */
232
264
  readonly subplans?: readonly LogicalPlan[];
265
+ /** Vertically combine disjoint aggregate shards by summing matching output groups. */
266
+ readonly sumPartition?: true;
267
+ /** Vertically combine disjoint physical detail rows. */
268
+ readonly rowPartition?: true;
269
+ /** Enumerated group values corresponding to subplans, combined vertically. */
270
+ readonly splitGroup?: {
271
+ readonly name: string;
272
+ readonly values: readonly string[];
273
+ readonly groupNames: readonly string[];
274
+ };
233
275
  /** Optional query plan compiled as the derived-table source of this plan. */
234
276
  readonly sourcePlan?: LogicalPlan;
235
277
  /** Normalized LogicForm corresponding to sourcePlan when generated rewrites need execution. */
@@ -247,6 +289,7 @@ export interface LogicalPlan {
247
289
  readonly columnProperties?: readonly ResultProperty[];
248
290
  readonly groupBy: readonly ProjectionPlan[];
249
291
  readonly query?: Readonly<Record<string, unknown>>;
292
+ readonly physicalQueryFilters?: readonly PhysicalQueryFilterPlan[];
250
293
  readonly having?: Readonly<Record<string, unknown>>;
251
294
  readonly orderBy: readonly OrderPlan[];
252
295
  readonly pagination?: PaginationPlan;
@@ -270,11 +313,11 @@ export interface QueryLineage {
270
313
  readonly schemaId: string;
271
314
  readonly schemaName: string;
272
315
  readonly physicalTable: string;
273
- readonly provider: CoreComputeProvider['kind'];
316
+ readonly provider: CoreComputeProvider['kind'] | 'runtime';
274
317
  readonly connectionId?: string;
275
318
  readonly connections?: readonly {
276
319
  readonly connectionId: string;
277
- readonly provider: CoreComputeProvider['kind'];
320
+ readonly provider: CoreComputeProvider['kind'] | 'runtime';
278
321
  }[];
279
322
  };
280
323
  readonly outputs: readonly LineageOutput[];
@@ -0,0 +1,6 @@
1
+ import type { ResolvedSemanticSchema } from '../semantic-types/index';
2
+ /** Give Schema UDFs explicit logical inputs while preserving quoted string contents. */
3
+ export declare const bindUdfInputs: (sql: string, schema: ResolvedSemanticSchema) => {
4
+ sql: string;
5
+ references: Readonly<Record<string, string>>;
6
+ };
@@ -3,7 +3,7 @@ import type { LocaleDefinition } from '../i18n/types';
3
3
  import type { PlannerSemanticRule } from '../planner/semantics/registry';
4
4
  import type { CoreComputeProvider, DataRow } from '../physical/provider';
5
5
  import type { LogicformType, PredItemType, QueryType } from '../logicform-types';
6
- import type { SchemaMappingDefinition, SchemaMappingItem } from '../schema-mappings/types';
6
+ import type { SchemaMappingDefinition, SchemaMappingItem, SchemaMappingSource, ResolvedMappingSource } from '../schema-mappings/index';
7
7
  import type { ResolvedSemanticProperty, ResolvedSemanticSchema, SemanticSchemaDraft, SemanticTypeDefinition, TimeWatermarkPolicy } from '../semantic-types/types';
8
8
  export interface SchemaMetadataPlugin {
9
9
  readonly keys: readonly string[];
@@ -47,6 +47,8 @@ export interface QueryOperatorPlanContext {
47
47
  readonly schema: ResolvedSemanticSchema;
48
48
  readonly property: ResolvedSemanticProperty;
49
49
  readonly connectionId: string;
50
+ /** Resolve public source configuration for planning, rendering and dependency tracking. */
51
+ readonly resolveSource: (source: SchemaMappingSource) => ResolvedMappingSource;
50
52
  readonly resolveSchema?: (schemaId: string) => ResolvedSemanticSchema;
51
53
  readonly resolveMapping: (schemaId: string, preferredConnectionId?: string) => SchemaMappingDefinition;
52
54
  }
@@ -54,7 +56,7 @@ export interface QueryOperatorCompileContext {
54
56
  readonly field: string;
55
57
  readonly provider: CoreComputeProvider;
56
58
  readonly bind: (value: unknown) => string;
57
- readonly renderSource: (source: string, sourceSql?: string) => string;
59
+ readonly renderSource: (source: unknown) => string;
58
60
  }
59
61
  export interface QueryOperatorAuthorizeContext {
60
62
  readonly schema: ResolvedSemanticSchema;
@@ -1,4 +1,5 @@
1
1
  export { buildFieldMap, getProperty, getSchema, } from './schema-registry';
2
+ export { isReverseRelation, resolvePropertyValuePath, resolveRelationKeys } from './relation-keys';
2
3
  export { resolvePropertyPath } from './resolve-property-path';
3
4
  export { isDependentProjection } from './dependent-projection';
4
5
  export { isConcreteEntityId, resolveEntityFilterProperty, resolveEntityIdProperty, } from './entity-identity';
@@ -0,0 +1,11 @@
1
+ import type { ResolvedSemanticProperty } from '../semantic-types/index';
2
+ import type { ResolvedPropertyPath, ResolvedRelationSegment, ResolvedSchemaLookup } from './resolve-property-path';
3
+ /** Virtual scalar one-to-one objects are supplied by the metadata owner. */
4
+ export declare const isReverseRelation: (property: ResolvedSemanticProperty) => boolean;
5
+ /** Join keys are semantic properties; physical mappings are applied by the planner. */
6
+ export declare const resolveRelationKeys: (relation: ResolvedRelationSegment) => {
7
+ readonly source: ResolvedSemanticProperty;
8
+ readonly target: ResolvedSemanticProperty;
9
+ };
10
+ /** A reverse entity's value is the related row's ID, never the local entity ID. */
11
+ export declare const resolvePropertyValuePath: (path: ResolvedPropertyPath, lookup?: ResolvedSchemaLookup) => ResolvedPropertyPath;
@@ -0,0 +1,3 @@
1
+ import type { SchemaMappingDefinition, PropertyMappingCalculation } from './types';
2
+ export declare const computationInputNames: (definition: PropertyMappingCalculation) => readonly string[];
3
+ export declare const validateMappingValues: (mapping: SchemaMappingDefinition) => void;
@@ -1,7 +1,11 @@
1
1
  export { SchemaMappingRegistry } from './registry';
2
+ export { getSupportedDimensions } from './supported-dimensions';
2
3
  export { parseDailyExpireAt } from './freshness';
3
4
  export { isMappingTimeGranularity, isSchemaMappingGranularity, } from './granularity';
4
- export type { SchemaMappingDefinition, SchemaMappingEnrichmentDefinition, SchemaMappingEnrichmentKey, SchemaMappingItem, SchemaMappingGranularity, SchemaMappingGranularityExtensions, SchemaMappingPointTemporalDefinition, SchemaMappingSelection, RejectedSchemaMapping, SourceFreshnessPolicy, } from './types';
5
+ export type { SchemaMappingDefinition, SchemaMappingSource, ResolvedMappingSource, PropertyMappingCalculation, PropertyMappingValue, PropertyMapping, PredItemMapping, IgnoredMapping, ComputationExpression, ComputationInput, SchemaMappingEnrichmentDefinition, SchemaMappingEnrichmentKey, SchemaMappingItem, QueryPathBinding, QueryPathMappingDefinition, SchemaMappingGranularity, SchemaMappingGranularityExtensions, SchemaMappingPointTemporalDefinition, SchemaMappingSelection, RejectedSchemaMapping, SourceFreshnessPolicy, } from './types';
5
6
  export type { SchemaMappingPredDefinition, SchemaMappingPredMatch, } from './types';
6
7
  export { fromYiAskSchemaMapping } from './yiask';
7
8
  export type { YiAskSchemaMappingItem, YiAskSchemaMappingRecord } from './yiask';
9
+ export { computationInputNames } from './computations';
10
+ export { sqlValueParts } from './sql-inputs';
11
+ export { sourceIdentity, sqlIdentity, resolveMappingSource, schemaMappingIdentity, isResolvedMappingSource } from './source';
@@ -7,6 +7,7 @@ export declare class SchemaMappingRegistry {
7
7
  register(definition: SchemaMappingDefinition): this;
8
8
  get(schemaId: string, connectionId?: string): SchemaMappingDefinition;
9
9
  list(schemaId: string): readonly SchemaMappingDefinition[];
10
+ findById(schemaId: string, mappingId: string): SchemaMappingDefinition | undefined;
10
11
  definitions(): readonly SchemaMappingDefinition[];
11
12
  findSource(schemaId: string, source: string, connectionId?: string): SchemaMappingDefinition | undefined;
12
13
  }
@@ -0,0 +1,11 @@
1
+ import type { ResolvedMappingSource, SchemaMappingDefinition, SchemaMappingSource } from './types';
2
+ /** Opaque SQL contents share an identity scheme without parsing their semantics. */
3
+ export declare const sqlIdentity: (sql: string) => string;
4
+ /** SQL source identity follows its contents rather than a fictitious table name. */
5
+ export declare const resolveMappingSource: (source: SchemaMappingSource) => ResolvedMappingSource;
6
+ export declare const sourceIdentity: (source: SchemaMappingSource) => string;
7
+ export declare const schemaMappingIdentity: (mapping: SchemaMappingDefinition) => string;
8
+ /** Check opaque plugin payloads without reinterpreting public source configuration. */
9
+ export declare const isResolvedMappingSource: (value: unknown) => value is ResolvedMappingSource;
10
+ export declare const validateMappingSource: (source: unknown) => void;
11
+ export declare const rejectObsoleteSourceFields: (container: object) => void;
@@ -0,0 +1,7 @@
1
+ export type SqlValuePart = string | {
2
+ readonly input: string;
3
+ };
4
+ /** Preserve trusted SQL verbatim, resolving only {{input}} outside literals, identifiers and comments.
5
+ * SQL syntax, scalar cardinality and allowed operations are the database's responsibility.
6
+ */
7
+ export declare const sqlValueParts: (sql: string) => readonly SqlValuePart[];
@@ -0,0 +1,10 @@
1
+ import type { SchemaTypeDraft } from 'semanticdb-core';
2
+ import type { SemanticSchemaDraft } from '../semantic-types/index';
3
+ import type { SchemaMappingRegistry } from './registry';
4
+ /**
5
+ * Dimensions declared by at least one physical Mapping for this Schema.
6
+ * Returns canonical property-name paths. This is a discoverability union:
7
+ * metric coverage, time grain, and combinations of dimensions still require
8
+ * planning a concrete LogicForm.
9
+ */
10
+ export declare const getSupportedDimensions: (schemaId: string, schemas: Readonly<Record<string, SemanticSchemaDraft | SchemaTypeDraft>>, schemaMappings: SchemaMappingRegistry) => readonly string[];
@@ -1,5 +1,23 @@
1
1
  import type { PredItemType, QueryType } from '../logicform-types';
2
2
  import type { TimeGranularity } from '../semantic-types/index';
3
+ /** A table or a trusted SQL query supplying a complete row set. */
4
+ export type SchemaMappingSource = {
5
+ readonly kind: 'table';
6
+ readonly table: string;
7
+ } | {
8
+ readonly kind: 'sql';
9
+ readonly sql: string;
10
+ };
11
+ /** Validated row-set source passed unchanged through planning and compilation. */
12
+ export type ResolvedMappingSource = {
13
+ readonly kind: 'table';
14
+ readonly identity: string;
15
+ readonly path: readonly string[];
16
+ } | {
17
+ readonly kind: 'sql';
18
+ readonly identity: string;
19
+ readonly sql: string;
20
+ };
3
21
  /** Plugin-owned physical grains extend this interface through module augmentation. */
4
22
  export interface SchemaMappingGranularityExtensions {
5
23
  }
@@ -15,10 +33,59 @@ export type SourceFreshnessPolicy = {
15
33
  } | {
16
34
  readonly mode: 'manual';
17
35
  };
36
+ /** Structured, row-level expressions. Values are bound parameters, never SQL text. */
37
+ export type ComputationExpression = {
38
+ readonly input: string;
39
+ } | {
40
+ readonly value: string | number | boolean | null;
41
+ } | {
42
+ readonly op: 'eq' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte' | 'like' | 'add' | 'subtract' | 'multiply' | 'divide';
43
+ readonly left: ComputationExpression;
44
+ readonly right: ComputationExpression;
45
+ } | {
46
+ readonly op: 'and' | 'or' | 'coalesce';
47
+ readonly args: readonly ComputationExpression[];
48
+ } | {
49
+ readonly op: 'not' | 'isNull' | 'isNotNull';
50
+ readonly arg: ComputationExpression;
51
+ } | {
52
+ readonly op: 'case';
53
+ readonly cases: readonly {
54
+ readonly when: ComputationExpression;
55
+ readonly then: ComputationExpression;
56
+ }[];
57
+ readonly else: ComputationExpression;
58
+ };
59
+ export type ComputationInput = {
60
+ readonly property: string;
61
+ readonly sourceColumn?: never;
62
+ } | {
63
+ readonly sourceColumn: string;
64
+ readonly sourceRef?: string;
65
+ readonly property?: never;
66
+ };
67
+ /** A scalar calculation owned by one Property mapping. */
68
+ export type PropertyMappingCalculation = {
69
+ readonly inputs: Readonly<Record<string, ComputationInput>>;
70
+ } & ({
71
+ readonly kind: 'expression';
72
+ readonly expression: ComputationExpression;
73
+ } | {
74
+ readonly kind: 'sql';
75
+ readonly sql: string;
76
+ /** Cache policy for this opaque SQL expression, including any internal table reads. */
77
+ readonly freshness?: SourceFreshnessPolicy;
78
+ });
79
+ export type PropertyMappingValue = {
80
+ readonly kind: 'column';
81
+ readonly column: string;
82
+ readonly sourceRef?: string;
83
+ } | PropertyMappingCalculation;
18
84
  export interface SchemaMappingPredMatch {
19
85
  /** Defaults to the owning mapping's Schema. */
20
86
  readonly schema?: string;
21
- readonly operator: string;
87
+ /** Restricts the match to one operator. Missing matches any aggregate operator. */
88
+ readonly operator?: string;
22
89
  readonly pred: string;
23
90
  /** Required conjunctive conditions across the LogicForm and PredItem queries. */
24
91
  readonly query?: QueryType;
@@ -28,16 +95,40 @@ export interface SchemaMappingPredDefinition {
28
95
  /** Physical column used as the matched PredItem's operator input. */
29
96
  readonly column: string;
30
97
  }
31
- export interface SchemaMappingItem {
32
- readonly sourceColumn?: string;
33
- /** Enrichment id that owns sourceColumn. Missing means the mapping's base source. */
34
- readonly sourceRef?: string;
35
- readonly mappingType?: 'property' | 'predItem' | 'ignored';
36
- readonly propertyTarget?: readonly string[];
37
- readonly predItem?: PredItemType;
38
- /** Finest physical grain of a mapped Property. */
98
+ export interface PropertyMapping {
99
+ readonly mappingType: 'property';
100
+ /** One logical Property ID, or an ID path for a directly mapped related Property. */
101
+ readonly propertyId: string;
102
+ readonly value: PropertyMappingValue;
39
103
  readonly granularity?: SchemaMappingGranularity;
40
104
  }
105
+ export interface PredItemMapping {
106
+ readonly mappingType: 'predItem';
107
+ readonly sourceColumn: string;
108
+ readonly predItem: PredItemType;
109
+ /** Optional exact dimension path encoded by the conditional column. */
110
+ readonly propertyTarget?: readonly string[];
111
+ }
112
+ export interface IgnoredMapping {
113
+ readonly mappingType: 'ignored';
114
+ readonly sourceColumn: string;
115
+ }
116
+ export type SchemaMappingItem = PropertyMapping | PredItemMapping | IgnoredMapping;
117
+ export type QueryPathBinding = {
118
+ readonly sourceColumn: string;
119
+ readonly mappingType: 'literal';
120
+ readonly value: string | number | boolean;
121
+ } | {
122
+ readonly sourceColumn: string;
123
+ readonly mappingType: 'value';
124
+ /** Path to the matched entity relation value. */
125
+ readonly valuePath: readonly string[];
126
+ };
127
+ /** Map an entity relation path in a root query or groupby to physical columns. */
128
+ export interface QueryPathMappingDefinition {
129
+ readonly path: readonly string[];
130
+ readonly bindings: readonly QueryPathBinding[];
131
+ }
41
132
  export interface SchemaMappingEnrichmentKey {
42
133
  /** Physical column on the mapping's base source. */
43
134
  readonly baseColumn: string;
@@ -52,8 +143,7 @@ export interface SchemaMappingPointTemporalDefinition {
52
143
  /** A same-connection physical extension of one logical Schema. */
53
144
  export interface SchemaMappingEnrichmentDefinition {
54
145
  readonly id: string;
55
- readonly source: string;
56
- readonly sourceSql?: string;
146
+ readonly source: SchemaMappingSource;
57
147
  readonly on: readonly SchemaMappingEnrichmentKey[];
58
148
  readonly temporal?: SchemaMappingPointTemporalDefinition;
59
149
  /** Missing means queries depending on this enrichment are not cached. */
@@ -65,14 +155,14 @@ export interface SchemaMappingDefinition {
65
155
  readonly schemaId: string;
66
156
  /** Database connection used by this physical mapping. */
67
157
  readonly connectionId: string;
68
- /** Stable physical source identity used by connection routing, lineage, and cache invalidation. */
69
- readonly source: string;
70
- /** Optional trusted query compiled as a derived-table source instead of reading source directly. */
71
- readonly sourceSql?: string;
158
+ /** Physical row set supplied by a table or a trusted SQL query. */
159
+ readonly source: SchemaMappingSource;
72
160
  /** Optional physical tables that extend base rows without becoming logical Schema relations. */
73
161
  readonly enrichments?: readonly SchemaMappingEnrichmentDefinition[];
74
162
  /** Unified logical-to-physical mappings for properties and conditional PredItems. */
75
163
  readonly mappings?: readonly SchemaMappingItem[];
164
+ /** Entity paths handled directly by physical source columns for query and groupby. */
165
+ readonly queryPathMappings?: readonly QueryPathMappingDefinition[];
76
166
  /** Higher values win when multiple candidates cover the same LogicForm. */
77
167
  readonly priority?: number;
78
168
  /** Missing means queries depending on this physical source are not cached. */
@@ -81,6 +171,8 @@ export interface SchemaMappingDefinition {
81
171
  export interface RejectedSchemaMapping {
82
172
  readonly mappingId: string;
83
173
  readonly reason: string;
174
+ /** Dimension Properties required by the query but unavailable on this Mapping. */
175
+ readonly missingDimensions?: readonly string[];
84
176
  }
85
177
  /** Planner diagnostics for one physical Schema mapping decision. */
86
178
  export interface SchemaMappingSelection {
@@ -1,25 +1,13 @@
1
1
  import type { SemanticDBPlugin } from '../plugins/index';
2
- import type { PredItemType } from '../logicform-types';
3
- import type { SchemaMappingDefinition, SchemaMappingEnrichmentDefinition, SchemaMappingGranularity } from './types';
4
- export interface YiAskSchemaMappingItem {
5
- readonly sourceColumn?: string;
6
- readonly sourceRef?: string;
7
- readonly mappingType?: 'property' | 'predItem' | 'ignored';
8
- readonly propertyTarget?: readonly string[];
9
- readonly predItem?: PredItemType;
10
- readonly granularity?: SchemaMappingGranularity;
11
- }
2
+ import type { SchemaMappingDefinition, SchemaMappingSource, SchemaMappingEnrichmentDefinition, SchemaMappingItem, QueryPathMappingDefinition } from './types';
3
+ export type YiAskSchemaMappingItem = SchemaMappingItem;
12
4
  export interface YiAskSchemaMappingRecord {
13
5
  readonly id: string | number;
14
- readonly schemaSid: string;
15
- readonly datasourceSid: string;
16
- readonly sourceMode?: 'table' | 'demo';
17
- readonly tablePath?: string;
18
- readonly sourceSql?: string;
19
- readonly physicalDatabase?: string;
20
- readonly physicalSchema?: string;
21
- readonly physicalTable?: string;
6
+ readonly schemaId: string;
7
+ readonly connectionId: string;
8
+ readonly source: SchemaMappingSource;
22
9
  readonly enrichments?: readonly SchemaMappingEnrichmentDefinition[];
10
+ readonly queryPathMappings?: readonly QueryPathMappingDefinition[];
23
11
  readonly mappings: readonly YiAskSchemaMappingItem[];
24
12
  readonly enabled?: boolean;
25
13
  }
@@ -5,7 +5,7 @@ export { SemanticTypeRegistry } from './registry';
5
5
  export { resolveSchema } from './resolve-schema';
6
6
  export { validateResolvedSchema } from './validate-resolved-schema';
7
7
  export { normalizePrimalQuery } from './primal-types/index';
8
- export type { ComparableCategoryDefinition, PropertyHierarchyDefinition, PropertySqlDefinition, PrimalType, ResolvedSemanticProperty, ResolvedSemanticSchema, LegacySemanticSchemaMetadata, ResolvedSemanticSchemaMetadata, SemanticSchemaMetadata, SemanticTypeNormalizeContext, SemanticPeriodEvaluationContext, SemanticTypeResultContext, SemanticTypeResultProperty, SemanticPropertyDraft, SemanticSchemaDraft, SemanticTypeDefinition, TimeGranularity, TimeWatermarkPolicy, } from './types';
8
+ export type { ComparableCategoryDefinition, PropertyHierarchyDefinition, PropertySqlDefinition, LogicformPartition, LogicformPartitionContext, LogicformPartitionShard, PrimalType, ResolvedSemanticProperty, ResolvedSemanticSchema, LegacySemanticSchemaMetadata, ResolvedSemanticSchemaMetadata, SemanticSchemaMetadata, SemanticTypeNormalizeContext, SemanticPeriodEvaluationContext, SemanticTypeResultContext, SemanticTypeResultProperty, SemanticPropertyDraft, SemanticSchemaDraft, SemanticTypeDefinition, TimeGranularity, TimeWatermarkPolicy, } from './types';
9
9
  export declare const createSemanticTypeRegistry: (plugins?: readonly SemanticDBPlugin[]) => SemanticTypeRegistry;
10
10
  /** Copies a caller-owned Registry and appends plugin types without mutating the input. */
11
11
  export declare const addPluginSemanticTypes: (registry: SemanticTypeRegistry, plugins: readonly SemanticDBPlugin[]) => SemanticTypeRegistry;