semanticdb-v2 2.0.0-alpha.11 → 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 (72) 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/merge-by-id.d.ts +3 -0
  9. package/dist/executor/partition.d.ts +1 -0
  10. package/dist/executor/random-data.d.ts +5 -0
  11. package/dist/executor/result-hydrator/entity-fetch-conditions.d.ts +4 -0
  12. package/dist/executor/result-hydrator/index.d.ts +1 -0
  13. package/dist/executor/result-hydrator/types.d.ts +7 -0
  14. package/dist/executor/runtime-execution.d.ts +6 -0
  15. package/dist/executor/sample.d.ts +6 -0
  16. package/dist/executor/types.d.ts +9 -3
  17. package/dist/file-import/index.d.ts +2 -0
  18. package/dist/file-import/read-file.d.ts +2 -0
  19. package/dist/file-import/types.d.ts +31 -0
  20. package/dist/index.d.ts +8 -5
  21. package/dist/logicform-types.d.ts +22 -2
  22. package/dist/normalizer/core.d.ts +7 -0
  23. package/dist/normalizer/index.d.ts +1 -0
  24. package/dist/normalizer/main-time-range.d.ts +9 -0
  25. package/dist/normalizer/public-logicform.d.ts +14 -0
  26. package/dist/normalizer/query.d.ts +3 -2
  27. package/dist/normalizer/random-data.d.ts +2 -0
  28. package/dist/operators/builtins/period-name.d.ts +3 -0
  29. package/dist/operators/builtins/time-range.d.ts +2 -2
  30. package/dist/operators/formula-text.d.ts +10 -0
  31. package/dist/operators/index.d.ts +2 -1
  32. package/dist/operators/registry.d.ts +8 -1
  33. package/dist/operators/types.d.ts +107 -24
  34. package/dist/permissions/index.d.ts +2 -1
  35. package/dist/permissions/metric-permissions.d.ts +9 -0
  36. package/dist/permissions/permissions.d.ts +4 -3
  37. package/dist/permissions/types.d.ts +5 -0
  38. package/dist/physical/connection.d.ts +4 -0
  39. package/dist/physical/db-connector.d.ts +10 -0
  40. package/dist/physical/duckdb-coordinator-provider.d.ts +3 -23
  41. package/dist/physical/duckdb-dataset.d.ts +23 -0
  42. package/dist/physical/duckdb-provider.d.ts +26 -0
  43. package/dist/physical/duckdb-sql.d.ts +33 -0
  44. package/dist/physical/import-types.d.ts +23 -0
  45. package/dist/physical/import-validation.d.ts +14 -0
  46. package/dist/physical/index.d.ts +4 -0
  47. package/dist/physical/postgresql-provider.d.ts +1 -0
  48. package/dist/physical/provider.d.ts +4 -0
  49. package/dist/planner/build-lineage.d.ts +1 -1
  50. package/dist/planner/create-logical-plan.d.ts +11 -2
  51. package/dist/planner/index.d.ts +3 -2
  52. package/dist/planner/mapping-granularity.d.ts +1 -1
  53. package/dist/planner/materialize-computations.d.ts +3 -0
  54. package/dist/planner/select-schema-mapping.d.ts +15 -3
  55. package/dist/planner/types.d.ts +40 -9
  56. package/dist/planner/udf-inputs.d.ts +6 -0
  57. package/dist/plugins/types.d.ts +4 -2
  58. package/dist/schema/index.d.ts +1 -0
  59. package/dist/schema/relation-keys.d.ts +11 -0
  60. package/dist/schema-mappings/computations.d.ts +3 -0
  61. package/dist/schema-mappings/index.d.ts +4 -1
  62. package/dist/schema-mappings/source.d.ts +11 -0
  63. package/dist/schema-mappings/sql-inputs.d.ts +7 -0
  64. package/dist/schema-mappings/types.d.ts +103 -17
  65. package/dist/schema-mappings/yiask.d.ts +6 -19
  66. package/dist/semantic-types/types.d.ts +21 -1
  67. package/dist/semanticdb.esm.js +6 -5
  68. package/dist/semanticdb.js +6 -5
  69. package/dist/utils/format-date.d.ts +3 -0
  70. package/package.json +5 -3
  71. package/dist/executor/evaluate.d.ts +0 -4
  72. package/dist/planner/build-mapping-source-plan.d.ts +0 -6
@@ -1,26 +1,38 @@
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;
19
- readonly sql?: string;
27
+ readonly calculation?: PropertyMappingCalculation;
28
+ readonly propertyId?: string;
20
29
  }
21
- export declare const hasPropertySql: (mapping: SchemaMappingDefinition) => boolean;
22
30
  export declare const mappedPropertyColumn: (mapping: SchemaMappingDefinition, schema: ResolvedSemanticSchema, reference: string) => string | undefined;
23
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;
24
36
  export declare const selectSchemaMapping: (logicform: LogicformType, schema: ResolvedSemanticSchema, mappings: SchemaMappingRegistry, options?: {
25
37
  readonly mappingCandidates?: readonly string[];
26
38
  readonly preferredConnectionId?: string;
@@ -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,12 +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;
131
151
  /** Two projection layers for the target Schema Mapping and its UDFs. */
132
152
  readonly targetMappingSourcePlan?: LogicalPlan;
133
153
  readonly targetAlias: string;
134
154
  readonly targetColumn: string;
155
+ readonly sourceExpression?: Expression;
156
+ readonly targetExpression?: Expression;
135
157
  readonly targetSql?: string;
136
158
  readonly targetTimestampColumn?: string;
137
159
  readonly temporalCondition?: TemporalJoinConditionPlan;
@@ -154,8 +176,7 @@ export type TemporalJoinConditionPlan = {
154
176
  export interface EnrichmentJoinPlan {
155
177
  readonly kind: 'enrichment-left';
156
178
  readonly id: string;
157
- readonly source: string;
158
- readonly sourceSql?: string;
179
+ readonly source: ResolvedMappingSource;
159
180
  readonly alias: string;
160
181
  readonly baseAlias: string;
161
182
  readonly keys: readonly {
@@ -223,19 +244,28 @@ export type RowIdentityPlan = {
223
244
  };
224
245
  export interface LogicalPlan {
225
246
  readonly schemaId: string;
226
- readonly source: string;
247
+ readonly source: ResolvedMappingSource | undefined;
227
248
  /** Physical connection selected for this plan's source mapping. */
228
249
  readonly connectionId?: string;
229
- /** Trusted derived-table SQL supplied by the selected physical mapping. */
230
- readonly sourceSql?: string;
231
250
  /** Two projection layers for the physical Mapping and Schema UDFs. */
232
251
  readonly mappingSourcePlan?: LogicalPlan;
233
252
  /** Physical mapping selected by the Planner for this logical Schema. */
234
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
+ }[];
235
263
  /** Child relations combined by their compatible group identity. */
236
264
  readonly subplans?: readonly LogicalPlan[];
237
265
  /** Vertically combine disjoint aggregate shards by summing matching output groups. */
238
266
  readonly sumPartition?: true;
267
+ /** Vertically combine disjoint physical detail rows. */
268
+ readonly rowPartition?: true;
239
269
  /** Enumerated group values corresponding to subplans, combined vertically. */
240
270
  readonly splitGroup?: {
241
271
  readonly name: string;
@@ -259,6 +289,7 @@ export interface LogicalPlan {
259
289
  readonly columnProperties?: readonly ResultProperty[];
260
290
  readonly groupBy: readonly ProjectionPlan[];
261
291
  readonly query?: Readonly<Record<string, unknown>>;
292
+ readonly physicalQueryFilters?: readonly PhysicalQueryFilterPlan[];
262
293
  readonly having?: Readonly<Record<string, unknown>>;
263
294
  readonly orderBy: readonly OrderPlan[];
264
295
  readonly pagination?: PaginationPlan;
@@ -282,11 +313,11 @@ export interface QueryLineage {
282
313
  readonly schemaId: string;
283
314
  readonly schemaName: string;
284
315
  readonly physicalTable: string;
285
- readonly provider: CoreComputeProvider['kind'];
316
+ readonly provider: CoreComputeProvider['kind'] | 'runtime';
286
317
  readonly connectionId?: string;
287
318
  readonly connections?: readonly {
288
319
  readonly connectionId: string;
289
- readonly provider: CoreComputeProvider['kind'];
320
+ readonly provider: CoreComputeProvider['kind'] | 'runtime';
290
321
  }[];
291
322
  };
292
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;
@@ -2,7 +2,10 @@ export { SchemaMappingRegistry } from './registry';
2
2
  export { getSupportedDimensions } from './supported-dimensions';
3
3
  export { parseDailyExpireAt } from './freshness';
4
4
  export { isMappingTimeGranularity, isSchemaMappingGranularity, } from './granularity';
5
- 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';
6
6
  export type { SchemaMappingPredDefinition, SchemaMappingPredMatch, } from './types';
7
7
  export { fromYiAskSchemaMapping } from './yiask';
8
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';
@@ -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[];
@@ -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,6 +33,54 @@ 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;
@@ -29,19 +95,40 @@ export interface SchemaMappingPredDefinition {
29
95
  /** Physical column used as the matched PredItem's operator input. */
30
96
  readonly column: string;
31
97
  }
32
- export interface SchemaMappingItem {
33
- readonly sourceColumn?: string;
34
- /** Trusted physical SQL expression, evaluated before the Schema Property's udf.sql. */
35
- readonly propertySql?: string;
36
- /** Enrichment id that owns sourceColumn. Missing means the mapping's base source. */
37
- readonly sourceRef?: string;
38
- readonly mappingType?: 'property' | 'predItem' | 'ignored';
39
- /** Direct targets for a property item; one property path (ID/name segments) for a predItem. */
40
- readonly propertyTarget?: readonly string[];
41
- readonly predItem?: PredItemType;
42
- /** 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;
43
103
  readonly granularity?: SchemaMappingGranularity;
44
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
+ }
45
132
  export interface SchemaMappingEnrichmentKey {
46
133
  /** Physical column on the mapping's base source. */
47
134
  readonly baseColumn: string;
@@ -56,8 +143,7 @@ export interface SchemaMappingPointTemporalDefinition {
56
143
  /** A same-connection physical extension of one logical Schema. */
57
144
  export interface SchemaMappingEnrichmentDefinition {
58
145
  readonly id: string;
59
- readonly source: string;
60
- readonly sourceSql?: string;
146
+ readonly source: SchemaMappingSource;
61
147
  readonly on: readonly SchemaMappingEnrichmentKey[];
62
148
  readonly temporal?: SchemaMappingPointTemporalDefinition;
63
149
  /** Missing means queries depending on this enrichment are not cached. */
@@ -69,14 +155,14 @@ export interface SchemaMappingDefinition {
69
155
  readonly schemaId: string;
70
156
  /** Database connection used by this physical mapping. */
71
157
  readonly connectionId: string;
72
- /** Stable physical source identity used by connection routing, lineage, and cache invalidation. */
73
- readonly source: string;
74
- /** Optional trusted query compiled as a derived-table source instead of reading source directly. */
75
- readonly sourceSql?: string;
158
+ /** Physical row set supplied by a table or a trusted SQL query. */
159
+ readonly source: SchemaMappingSource;
76
160
  /** Optional physical tables that extend base rows without becoming logical Schema relations. */
77
161
  readonly enrichments?: readonly SchemaMappingEnrichmentDefinition[];
78
162
  /** Unified logical-to-physical mappings for properties and conditional PredItems. */
79
163
  readonly mappings?: readonly SchemaMappingItem[];
164
+ /** Entity paths handled directly by physical source columns for query and groupby. */
165
+ readonly queryPathMappings?: readonly QueryPathMappingDefinition[];
80
166
  /** Higher values win when multiple candidates cover the same LogicForm. */
81
167
  readonly priority?: number;
82
168
  /** Missing means queries depending on this physical source are not cached. */
@@ -1,26 +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 propertySql?: string;
7
- readonly sourceRef?: string;
8
- readonly mappingType?: 'property' | 'predItem' | 'ignored';
9
- readonly propertyTarget?: readonly string[];
10
- readonly predItem?: PredItemType;
11
- readonly granularity?: SchemaMappingGranularity;
12
- }
2
+ import type { SchemaMappingDefinition, SchemaMappingSource, SchemaMappingEnrichmentDefinition, SchemaMappingItem, QueryPathMappingDefinition } from './types';
3
+ export type YiAskSchemaMappingItem = SchemaMappingItem;
13
4
  export interface YiAskSchemaMappingRecord {
14
5
  readonly id: string | number;
15
- readonly schemaSid: string;
16
- readonly datasourceSid: string;
17
- readonly sourceMode?: 'table' | 'demo';
18
- readonly tablePath?: string;
19
- readonly sourceSql?: string;
20
- readonly physicalDatabase?: string;
21
- readonly physicalSchema?: string;
22
- readonly physicalTable?: string;
6
+ readonly schemaId: string;
7
+ readonly connectionId: string;
8
+ readonly source: SchemaMappingSource;
23
9
  readonly enrichments?: readonly SchemaMappingEnrichmentDefinition[];
10
+ readonly queryPathMappings?: readonly QueryPathMappingDefinition[];
24
11
  readonly mappings: readonly YiAskSchemaMappingItem[];
25
12
  readonly enabled?: boolean;
26
13
  }
@@ -56,9 +56,20 @@ export interface ResolvedSemanticSchemaMetadata {
56
56
  /** Extension point for legacy plugin metadata removed from the canonical Schema shape. */
57
57
  export interface LegacySemanticSchemaMetadata {
58
58
  }
59
- export interface SemanticPropertyDraft extends Omit<PropertyTypeDraft, '_id' | '_sid' | 'id' | 'sid' | 'type' | 'primal_type' | 'isArray' | 'granularity' | 'is_observation' | 'is_snapshot' | 'temporalSemantics' | 'is_dynamic' | 'udf' | 'is_comparable' | 'comparable_order' | 'hierarchy'> {
59
+ export interface SemanticPropertyDraft extends Omit<PropertyTypeDraft, '_id' | '_sid' | 'id' | 'sid' | 'type' | 'primal_type' | 'isArray' | 'granularity' | 'is_observation' | 'is_snapshot' | 'temporalSemantics' | 'is_dynamic' | 'udf' | 'is_comparable' | 'comparable_order' | 'hierarchy' | 'componentProperties'> {
60
60
  readonly id?: string;
61
+ /** Readable calculation exposed on result Schema properties. */
62
+ readonly formulaText?: string | null;
61
63
  readonly type: string;
64
+ /** Relationship cardinality declared by the caller. */
65
+ readonly ref_cardinality?: 'one-to-one' | 'many-to-one' | 'one-to-many' | 'many-to-many';
66
+ /** Caller-supplied virtual relation; scalar one-to-one objects are reverse references. */
67
+ readonly is_virtual?: boolean;
68
+ /** Optional provenance to disambiguate the original reverse-reference foreign key. */
69
+ readonly reverse_ref?: {
70
+ readonly schemaId: string;
71
+ readonly propertyId: string;
72
+ };
62
73
  readonly primal_type?: PrimalType;
63
74
  readonly isArray?: boolean;
64
75
  readonly granularity?: TimeGranularity;
@@ -66,16 +77,21 @@ export interface SemanticPropertyDraft extends Omit<PropertyTypeDraft, '_id' | '
66
77
  readonly is_dynamic?: boolean;
67
78
  readonly udf?: PropertySqlDefinition;
68
79
  readonly comparable?: ComparableCategoryDefinition;
80
+ readonly componentProperties?: readonly SemanticPropertyDraft[];
69
81
  }
70
82
  export interface ResolvedSemanticProperty extends Omit<SemanticPropertyDraft, 'id' | 'primal_type' | 'isArray' | 'is_dynamic'> {
71
83
  readonly id: string;
72
84
  readonly primal_type: PrimalType;
73
85
  readonly isArray: boolean;
74
86
  readonly is_dynamic?: boolean;
87
+ /** Child metric metadata exposed on computed result Schema properties. */
88
+ readonly componentProperties?: readonly ResolvedSemanticProperty[];
75
89
  }
76
90
  export interface SemanticSchemaDraft extends Omit<SchemaTypeDraft, '_id' | 'id' | 'sid' | 'properties' | 'db' | 'from' | 'fromSQL' | 'projections' | keyof SemanticSchemaMetadata | keyof LegacySemanticSchemaMetadata>, SemanticSchemaMetadata {
77
91
  readonly [key: string]: unknown;
78
92
  readonly id: string;
93
+ /** Registered custom aggregate/component/runtime operator names available on this Schema. */
94
+ readonly metrics?: readonly string[];
79
95
  /** Marks the single Schema whose complete rows are loaded as calendar execution context. */
80
96
  readonly is_calendar?: boolean;
81
97
  readonly partition?: LogicformPartition;
@@ -84,6 +100,8 @@ export interface SemanticSchemaDraft extends Omit<SchemaTypeDraft, '_id' | 'id'
84
100
  export interface ResolvedSemanticSchema extends Omit<SchemaTypeDraft, '_id' | 'id' | 'sid' | 'properties' | 'db' | 'from' | 'fromSQL' | 'projections' | keyof SemanticSchemaMetadata | keyof LegacySemanticSchemaMetadata>, ResolvedSemanticSchemaMetadata {
85
101
  readonly [key: string]: unknown;
86
102
  readonly id: string;
103
+ /** Registered custom aggregate/component/runtime operator names available on this Schema. */
104
+ readonly metrics?: readonly string[];
87
105
  readonly is_calendar?: boolean;
88
106
  readonly partition?: LogicformPartition;
89
107
  readonly properties: readonly ResolvedSemanticProperty[];
@@ -93,6 +111,8 @@ export interface SemanticTypeNormalizeContext {
93
111
  readonly property: ResolvedSemanticProperty;
94
112
  readonly now: Date;
95
113
  readonly requestTimeWatermark: (requestedUpperBound: Date) => Promise<Date | undefined>;
114
+ /** Observe a complete date condition without changing its normalization semantics. */
115
+ readonly onDateQueryNormalized?: (requested: unknown, effective: unknown, timeWatermark?: Date) => void;
96
116
  }
97
117
  /** Context used when deciding whether a value must be evaluated per time period. */
98
118
  export interface SemanticPeriodEvaluationContext {