semanticdb-v2 2.0.0-alpha.4 → 2.0.0-alpha.5

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 (44) hide show
  1. package/README.md +26 -10
  2. package/dist/compiler/compile-cte.d.ts +1 -1
  3. package/dist/errors.d.ts +2 -1
  4. package/dist/executor/components.d.ts +8 -3
  5. package/dist/executor/fetch-entities.d.ts +2 -0
  6. package/dist/executor/types.d.ts +9 -3
  7. package/dist/i18n/index.d.ts +4 -0
  8. package/dist/i18n/locales/en-US.d.ts +2 -0
  9. package/dist/i18n/locales/zh-CN.d.ts +2 -0
  10. package/dist/i18n/registry.d.ts +13 -0
  11. package/dist/i18n/types.d.ts +9 -0
  12. package/dist/index.d.ts +4 -2
  13. package/dist/normalizer/core.d.ts +5 -0
  14. package/dist/normalizer/default-pred-name.d.ts +2 -0
  15. package/dist/normalizer/index.d.ts +1 -0
  16. package/dist/normalizer/property-resolve.d.ts +1 -0
  17. package/dist/operators/builtins/period-name.d.ts +2 -1
  18. package/dist/operators/index.d.ts +1 -0
  19. package/dist/operators/registry.d.ts +1 -1
  20. package/dist/operators/resolve.d.ts +3 -0
  21. package/dist/operators/types.d.ts +17 -8
  22. package/dist/physical/clickhouse-provider.d.ts +8 -0
  23. package/dist/physical/provider.d.ts +4 -0
  24. package/dist/planner/index.d.ts +1 -1
  25. package/dist/planner/semantics/annual-periods.d.ts +11 -0
  26. package/dist/planner/semantics/index.d.ts +1 -0
  27. package/dist/planner/semantics/lifecycle/classification.d.ts +5 -7
  28. package/dist/planner/semantics/lifecycle/query-policy.d.ts +2 -3
  29. package/dist/planner/semantics/lifecycle/rule.d.ts +2 -2
  30. package/dist/planner/semantics/observation/index.d.ts +2 -0
  31. package/dist/planner/semantics/observation/periods.d.ts +19 -0
  32. package/dist/planner/semantics/validity/classification.d.ts +14 -0
  33. package/dist/planner/semantics/validity/index.d.ts +6 -0
  34. package/dist/planner/semantics/validity/periods.d.ts +16 -0
  35. package/dist/planner/semantics/validity/query-policy.d.ts +4 -0
  36. package/dist/planner/semantics/validity/rule.d.ts +2 -0
  37. package/dist/planner/types.d.ts +31 -0
  38. package/dist/schema/dependent-projection.d.ts +8 -0
  39. package/dist/schema/index.d.ts +1 -0
  40. package/dist/semantic-types/index.d.ts +1 -1
  41. package/dist/semantic-types/types.d.ts +8 -1
  42. package/dist/semanticdb.esm.js +3 -3
  43. package/dist/semanticdb.js +3 -3
  44. package/package.json +2 -1
package/README.md CHANGED
@@ -34,8 +34,9 @@ const response = await Logicform.execute(
34
34
  connections: [{
35
35
  id: 'analytics',
36
36
  kind: 'clickhouse',
37
- url: 'http://localhost:8123',
38
- username: 'default',
37
+ host: 'localhost',
38
+ port: 8123,
39
+ user: 'default',
39
40
  password: process.env.CLICKHOUSE_PASSWORD,
40
41
  database: 'analytics',
41
42
  }],
@@ -56,19 +57,28 @@ query shaped as `{ schema, query }` is part of its parent LogicForm and inherits
56
57
 
57
58
  PredItems without an explicit `name` receive a human-readable name during normalization. Generated
58
59
  names default to Chinese; pass `locale: 'en-US'` in `ExecuteOptions` for the built-in English
59
- names. Every operator owns its localized default names and receives the requested locale directly:
60
+ names. SemanticDB ships `zh-CN` and `en-US` locale files backed by i18next. Applications can add or
61
+ override locale files through `ExecuteOptions.locales`:
60
62
 
61
63
  ```ts
62
- operators.register({
63
- name: '$weightedAverage',
64
- defaultName: ({ operandName, locale }) => locale.toLowerCase().startsWith('en')
65
- ? `Weighted average of ${operandName}`
66
- : `${operandName}加权平均值`,
67
- kind: 'aggregate',
68
- toSQL: ({ column }) => `weighted_avg(${column})`,
64
+ await Logicform.execute(logicform, {
65
+ locale: 'ja-JP',
66
+ locales: {
67
+ locale: 'ja-JP',
68
+ messages: {
69
+ 'operator.$sum': '{operandName}の合計',
70
+ 'component.numerator': '{outputName} 分子',
71
+ 'component.denominator': '{outputName} 分母',
72
+ },
73
+ },
74
+ // schemas, schemaMappings, connections, ...
69
75
  });
70
76
  ```
71
77
 
78
+ Locale lookup uses the exact locale first, then the matching language, and finally `zh-CN`.
79
+ Multiple locale files can be supplied as an array. A custom operator still owns its fallback name
80
+ through `defaultName()` and can call the context's `t()` helper when it defines translation keys.
81
+
72
82
  The same locale applies to `preds`, `groupby`, nested expressions, custom-function subqueries,
73
83
  and entity-population queries. A PredItem's normalized `query` is included in its
74
84
  generated name, for example `门店为上海的销售额合计`. Operator-specific `args` also participate
@@ -181,6 +191,12 @@ Composite metrics are regular `OperatorDefinition` values with `kind: 'component
181
191
  them in the same `OperatorRegistry` as scalar and aggregate operators. Operator names are free-form;
182
192
  the `$` prefix is a convention used by built-in operators, not a requirement.
183
193
 
194
+ Every composite component is exposed in result rows by default. Its `name` is its final result-column
195
+ name and may contain Chinese characters or spaces. Built-ins derive child names from the parent output,
196
+ for example `总销售额占比分子` and `总销售额占比分母`. Operators do not return `outputName` or an
197
+ exposure flag; the executor owns the parent output binding. Components are joined on groupby output
198
+ names shared by both sides unless an exceptional custom operator explicitly supplies `joinKeys`.
199
+
184
200
  See [Register an operator](docs/register-operator.md) for the component contract.
185
201
 
186
202
  The root entry point accepts a `connections` array of `DatabaseConnection` items. Every item has a unique `id`; set `kind` to `mysql`,
@@ -24,4 +24,4 @@ export interface PreparedCteQuery {
24
24
  * CTE preserves those ranges while allowing the provider to execute one query.
25
25
  */
26
26
  export declare const compileCteQueries: (units: readonly PreparedCteQuery[], outputPlan: LogicalPlan, provider: CoreComputeProvider, operators?: OperatorRegistry) => CompiledQuery;
27
- export declare const compileCteCalculation: (calculation: OperatorComponentCalculation, components: readonly PreparedCteComponent[], outputPlan: LogicalPlan, provider: CoreComputeProvider, operators: OperatorRegistry) => CompiledQuery;
27
+ export declare const compileCteCalculation: (calculation: OperatorComponentCalculation, components: readonly PreparedCteComponent[], outputPlan: LogicalPlan, outputName: string, provider: CoreComputeProvider, operators: OperatorRegistry) => CompiledQuery;
package/dist/errors.d.ts CHANGED
@@ -1,7 +1,8 @@
1
+ import { type LocaleRegistry } from './i18n/index';
1
2
  export declare class SemanticDBError extends Error {
2
3
  readonly code: string;
3
4
  readonly details?: Readonly<Record<string, unknown>> | undefined;
4
5
  constructor(code: string, message: string, details?: Readonly<Record<string, unknown>> | undefined);
5
6
  /** Return the user-facing message for an execution locale. */
6
- localizedMessage(locale?: string): string;
7
+ localizedMessage(locale?: string, locales?: LocaleRegistry): string;
7
8
  }
@@ -1,9 +1,14 @@
1
1
  import type { LogicformType } from '../logicform-types';
2
- import type { OperatorExecutionComponent, OperatorRegistry } from '../operators/index';
2
+ import type { OperatorComponentCalculation, OperatorJavaScriptCalculation, OperatorQueryComponent, OperatorRegistry } from '../operators/index';
3
3
  import type { DataRow } from '../physical/index';
4
4
  import type { LogicalPlan } from '../planner/index';
5
5
  import type { ResolvedSemanticSchema } from '../semantic-types/index';
6
- export type ExecutionUnit = OperatorExecutionComponent;
7
- export declare const createExecutionUnits: (logicform: LogicformType, plan: LogicalPlan, schema: ResolvedSemanticSchema, operators: OperatorRegistry, resolveSchema: (schemaId: string) => ResolvedSemanticSchema, sourceLogicform?: LogicformType) => readonly ExecutionUnit[] | undefined;
6
+ import { type LocaleTranslate } from '../i18n/index';
7
+ export type ExecutionUnit = OperatorQueryComponent | (OperatorComponentCalculation & {
8
+ readonly outputName: string;
9
+ }) | (OperatorJavaScriptCalculation & {
10
+ readonly outputName: string;
11
+ });
12
+ export declare const createExecutionUnits: (logicform: LogicformType, plan: LogicalPlan, schema: ResolvedSemanticSchema, operators: OperatorRegistry, resolveSchema: (schemaId: string) => ResolvedSemanticSchema, sourceLogicform?: LogicformType, locale?: string, t?: LocaleTranslate) => readonly ExecutionUnit[] | undefined;
8
13
  export declare const mergeComponentRows: (results: readonly (readonly DataRow[])[], groupNames: readonly string[]) => DataRow[];
9
14
  export declare const mergeExecutionResults: (results: readonly (readonly DataRow[])[], plan: LogicalPlan) => DataRow[];
@@ -9,10 +9,12 @@ import type { Permissions } from '../permissions/index';
9
9
  import type { ResolvedSemanticSchema, SemanticTypeRegistry } from '../semantic-types/index';
10
10
  import type { EntityFetchRequest } from './result-hydrator/index';
11
11
  import type { SemanticDBPlugin } from '../plugins/index';
12
+ import type { LocaleRegistry } from '../i18n/index';
12
13
  interface FetchEntityOptions {
13
14
  readonly version: string;
14
15
  readonly operators: OperatorRegistry;
15
16
  readonly locale?: string;
17
+ readonly localeRegistry?: LocaleRegistry;
16
18
  readonly schemaMappings: SchemaMappingRegistry;
17
19
  readonly semanticTypes: SemanticTypeRegistry;
18
20
  readonly plugins?: readonly SemanticDBPlugin[];
@@ -1,4 +1,4 @@
1
- import type { OperatorRegistry } from '../operators/index';
1
+ import type { OperatorDefinition, OperatorRegistry } from '../operators/index';
2
2
  import type { CoreComputeProvider, DataRow, SqlParameters } from '../physical/index';
3
3
  import type { DatabaseConnection } from '../physical/index';
4
4
  import type { LogicalPlan, QueryLineage } from '../planner/index';
@@ -8,6 +8,7 @@ import type { LogicformType, PublicLogicformType } from '../logicform-types';
8
8
  import type { QueryCacheExecutionOptions } from '../cache/index';
9
9
  import type { Permissions } from '../permissions/index';
10
10
  import type { SemanticDBPlugin } from '../plugins/index';
11
+ import type { LocaleInput, LocaleRegistry } from '../i18n/index';
11
12
  export type ExecuteProgressEvent = {
12
13
  readonly stage: 'started';
13
14
  readonly logicform: LogicformType;
@@ -56,11 +57,14 @@ export type ProgressCallback = (event: ExecuteProgressEvent) => void | Promise<v
56
57
  interface ExecuteBaseOptions {
57
58
  readonly schemas: Readonly<Record<string, SemanticSchemaDraft>>;
58
59
  readonly semanticTypes?: SemanticTypeRegistry;
59
- readonly operators?: OperatorRegistry;
60
+ /** Caller-defined operators supplied as plain definition objects. */
61
+ readonly operators?: OperatorDefinition | readonly OperatorDefinition[];
60
62
  /** Caller-owned capability plugins appended to the built-in plugin set for this execution. */
61
63
  readonly plugins?: readonly SemanticDBPlugin[];
62
64
  /** Locale for generated human-readable PredItem names. Defaults to zh-CN. */
63
65
  readonly locale?: string;
66
+ /** Additional or overriding locale files used by generated names and messages. */
67
+ readonly locales?: LocaleInput;
64
68
  /** Table, row, and column permissions for this execution. */
65
69
  readonly permissions?: Permissions;
66
70
  /** Optional caller-owned cache shared across executions. */
@@ -77,7 +81,9 @@ export interface ExecuteOptions extends ExecuteBaseOptions {
77
81
  readonly connections: readonly DatabaseConnection[];
78
82
  }
79
83
  /** Internal execution seam used by executor tests after a provider has been resolved. */
80
- export interface InternalExecuteOptions extends ExecuteBaseOptions {
84
+ export interface InternalExecuteOptions extends Omit<ExecuteBaseOptions, 'operators'> {
85
+ readonly operators?: OperatorRegistry;
86
+ readonly localeRegistry?: LocaleRegistry;
81
87
  readonly provider: CoreComputeProvider;
82
88
  readonly schemaMappings: SchemaMappingRegistry;
83
89
  /** Selected connection for public execution; omitted only by internal provider tests. */
@@ -0,0 +1,4 @@
1
+ export { createLocaleRegistry, defaultLocaleRegistry, LocaleRegistry } from './registry';
2
+ export type { LocaleDefinition, LocaleInput, LocaleTranslate } from './types';
3
+ export { enUS } from './locales/en-US';
4
+ export { zhCN } from './locales/zh-CN';
@@ -0,0 +1,2 @@
1
+ import type { LocaleDefinition } from '../types';
2
+ export declare const enUS: LocaleDefinition;
@@ -0,0 +1,2 @@
1
+ import type { LocaleDefinition } from '../types';
2
+ export declare const zhCN: LocaleDefinition;
@@ -0,0 +1,13 @@
1
+ import type { LocaleDefinition, LocaleInput, LocaleTranslate } from './types';
2
+ export declare class LocaleRegistry {
3
+ private readonly definitions;
4
+ private readonly i18n;
5
+ constructor(locales?: LocaleInput);
6
+ register(locales: LocaleInput | undefined): this;
7
+ resolve(locale?: string): LocaleDefinition;
8
+ has(locale: string): boolean;
9
+ translate(locale: string, key: string, fallback?: string, values?: Readonly<Record<string, unknown>>): string;
10
+ translator(locale?: string): LocaleTranslate;
11
+ }
12
+ export declare const createLocaleRegistry: (locales?: LocaleInput) => LocaleRegistry;
13
+ export declare const defaultLocaleRegistry: LocaleRegistry;
@@ -0,0 +1,9 @@
1
+ /** A locale file consumed by SemanticDB's naming and error messages. */
2
+ export interface LocaleDefinition {
3
+ /** BCP-47 locale tag, for example `zh-CN` or `en-US`. */
4
+ readonly locale: string;
5
+ /** Translation messages keyed by a stable SemanticDB message key. */
6
+ readonly messages: Readonly<Record<string, string>>;
7
+ }
8
+ export type LocaleInput = LocaleDefinition | readonly LocaleDefinition[];
9
+ export type LocaleTranslate = (key: string, fallback?: string, values?: Readonly<Record<string, unknown>>) => string;
package/dist/index.d.ts CHANGED
@@ -1,17 +1,19 @@
1
+ export { createLocaleRegistry, defaultLocaleRegistry, LocaleRegistry, enUS, zhCN, } from './i18n/index';
2
+ export type { LocaleDefinition, LocaleInput, LocaleTranslate } from './i18n/index';
1
3
  export declare const Logicform: Readonly<{
2
4
  execute: (inputLogicform: import("./logicform-types").LogicformType, inputOptions: import(".").ExecuteOptions) => Promise<import(".").ExecuteResult>;
3
5
  close: () => Promise<void>;
4
6
  }>;
5
7
  export { SemanticDBError } from './errors';
6
8
  export { builtinSemanticTypes, createSemanticTypeRegistry, resolveSchema, SemanticTypeRegistry, validateResolvedSchema, } from './semantic-types/index';
7
- export { builtinOperators, createOperatorRegistry, OperatorRegistry, } from './operators/index';
9
+ export { builtinOperators, createOperatorRegistry, OperatorRegistry, resolveOperator, } from './operators/index';
8
10
  export type { LegacySchemaPluginContext, SchemaMetadataPlugin, SemanticDBPlugin, } from './plugins/index';
9
11
  export { SchemaMappingRegistry, fromYiAskSchemaMapping, } from './schema-mappings/index';
10
12
  export type { AbsoluteDateValue, CompareOperator, CalendarDateValue, DateTimeValue, DateValue, EntityIdType, ExpressionItemType, LogicformType, PublicLogicformType, PeriodShiftTime, PredItemType, QueryLogicalOperand, RecursiveQueryType, RelationQueryType, QueryType, QueryValueType, QueryValueTypeWithCompareOperator, RelativeDateValue, RepresentationType, } from './logicform-types';
11
13
  export { CALENDAR_DATES_TABLE, CALENDAR_RELATIONS_TABLE, CALENDAR_SYSTEM_SCHEMA_IDS, calendarSystemSchemas, ProviderCalendarRelationStore, resolveCalendarPeriod, resolveCalendarPeriodFromStore, selectCalendarDates, } from './calendar/index';
12
14
  export type { CalendarAlignment, CalendarComparison, CalendarDateRow, CalendarRelation, CalendarRelationRow, ResolvedCalendarPeriod, } from './calendar/index';
13
15
  export type { CalendarRelationStore } from './calendar/index';
14
- export type { PrimalType, PropertySqlDefinition, ResolvedSemanticProperty, ResolvedSemanticSchema, SemanticTypeNormalizeContext, SemanticPropertyDraft, SemanticSchemaDraft, SemanticTypeDefinition, SemanticTypeResultContext, SemanticTypeResultProperty, TemporalSemantics, TimeGranularity, TimeWatermarkPolicy, } from './semantic-types/index';
16
+ export type { PrimalType, PropertyHierarchyDefinition, PropertySqlDefinition, ResolvedSemanticProperty, ResolvedSemanticSchema, SemanticTypeNormalizeContext, SemanticPropertyDraft, SemanticSchemaDraft, SemanticTypeDefinition, SemanticTypeResultContext, SemanticTypeResultProperty, TemporalSemantics, TimeGranularity, TimeWatermarkPolicy, } from './semantic-types/index';
15
17
  export type { HierarchyDefinition, HierarchyLevelDefinition, ResolvedHierarchyDefinition, } from './plugins/hierarchy/index';
16
18
  export type { DataRow, SqlParameters, DatabaseConnection, } from './physical/index';
17
19
  export type { OperatorDefinition, OperatorDefaultNameContext, OperatorComponentContext, OperatorComponentCalculation, OperatorComponentQuery, OperatorExecutionComponent, OperatorPlanInputContext, OperatorPlannedInput, OperatorGroupKeyShift, OperatorJavaScriptCalculation, OperatorQueryComponent, OperatorEvaluateContext, OperatorOutputPropertyContext, OperatorSqlCapabilities, OperatorSqlContext, ResultProperty, ResultPropertyTemporalMetadata, } from './operators/index';
@@ -2,12 +2,17 @@ import type { LogicformType } from '../logicform-types';
2
2
  import type { OperatorRegistry } from '../operators/index';
3
3
  import type { ResolvedSemanticProperty, ResolvedSemanticSchema, SemanticTypeRegistry } from '../semantic-types/index';
4
4
  import type { SemanticDBPlugin } from '../plugins/index';
5
+ import type { LocaleInput, LocaleRegistry } from '../i18n/index';
5
6
  export interface NormalizeLogicformOptions {
6
7
  readonly semanticTypes: SemanticTypeRegistry;
7
8
  readonly operators?: OperatorRegistry;
8
9
  readonly plugins?: readonly SemanticDBPlugin[];
9
10
  /** Locale used for generated human-readable PredItem names. Defaults to zh-CN. */
10
11
  readonly locale?: string;
12
+ /** Additional or overriding locale files used for generated names. */
13
+ readonly locales?: LocaleInput;
14
+ /** Internal registry shared by recursive normalization calls. */
15
+ readonly localeRegistry?: LocaleRegistry;
11
16
  readonly now?: Date;
12
17
  readonly resolveSchema?: (schemaId: string) => ResolvedSemanticSchema;
13
18
  readonly requestTimeWatermark?: (schema: ResolvedSemanticSchema, property: ResolvedSemanticProperty, requestedUpperBound: Date) => Promise<Date | undefined>;
@@ -1,6 +1,8 @@
1
1
  import type { PredItemType } from '../logicform-types';
2
2
  import type { OperatorRegistry } from '../operators/index';
3
+ import { type LocaleRegistry } from '../i18n/index';
3
4
  export interface DefaultPredNameOptions {
4
5
  readonly locale?: string;
6
+ readonly localeRegistry?: LocaleRegistry;
5
7
  }
6
8
  export declare const defaultPredName: (pred: PredItemType, operators: OperatorRegistry, options?: DefaultPredNameOptions) => string;
@@ -1,3 +1,4 @@
1
1
  export { normalizeLogicform } from './normalize-logicform';
2
2
  export { defaultPredName } from './default-pred-name';
3
3
  export { assertSupportedLogicformVersion } from './version';
4
+ export { inferPropertyResolvePath } from './property-resolve';
@@ -1,5 +1,6 @@
1
1
  import type { LogicformType } from '../logicform-types';
2
2
  import type { ResolvedSemanticSchema } from '../semantic-types/index';
3
3
  import type { NormalizeLogicformOptions } from './core';
4
+ export declare const inferPropertyResolvePath: (rootSchema: ResolvedSemanticSchema, reference: string, targetSchema: ResolvedSemanticSchema, resolveSchema?: (schemaId: string) => ResolvedSemanticSchema) => string | undefined;
4
5
  /** Adds cross-Schema aliases after both legacy and v2 forms share normalization. */
5
6
  export declare const normalizePropertyResolve: (logicform: LogicformType, rootSchema: ResolvedSemanticSchema, options: NormalizeLogicformOptions) => LogicformType;
@@ -1 +1,2 @@
1
- export declare const periodComparisonName: (args: Readonly<Record<string, unknown>>, locale: string) => string;
1
+ import type { LocaleTranslate } from '../../i18n/index';
2
+ export declare const periodComparisonName: (args: Readonly<Record<string, unknown>>, locale: string, t?: LocaleTranslate) => string;
@@ -1,6 +1,7 @@
1
1
  import type { SemanticDBPlugin } from '../plugins/index';
2
2
  import { OperatorRegistry } from './registry';
3
3
  export { OperatorRegistry } from './registry';
4
+ export { resolveOperator } from './resolve';
4
5
  export { bindTrustedSqlExpression } from './sql-expression';
5
6
  export type { OperatorDefinition, OperatorDefaultNameContext, OperatorComponentContext, OperatorComponentCalculation, OperatorComponentQuery, OperatorExecutionComponent, OperatorGroupKeyShift, OperatorJavaScriptCalculation, OperatorQueryComponent, OperatorEvaluateContext, OperatorOutputPropertyContext, OperatorObservationPolicy, OperatorObservationPolicyContext, OperatorNormalizePredContext, OperatorPlanExpressionContext, OperatorPeriodEvaluationContext, OperatorPlanInputContext, OperatorPlannedInput, OperatorRewriteLogicformContext, OperatorValidatePlanContext, OperatorSqlCapabilities, OperatorSqlContext, ResultProperty, ResultPropertyTemporalMetadata, } from './types';
6
7
  export declare const builtinOperators: readonly import("./types").OperatorDefinition[];
@@ -2,7 +2,7 @@ import type { OperatorDefinition, OperatorPeriodEvaluationContext } from './type
2
2
  export declare class OperatorRegistry {
3
3
  #private;
4
4
  constructor(definitions?: readonly OperatorDefinition[]);
5
- register(definition: OperatorDefinition): this;
5
+ register(input: OperatorDefinition): this;
6
6
  get(name: string): OperatorDefinition;
7
7
  requiresPerPeriodEvaluation(name: string, context: OperatorPeriodEvaluationContext): boolean;
8
8
  has(name: string): boolean;
@@ -0,0 +1,3 @@
1
+ import type { OperatorDefinition } from './types';
2
+ /** Resolve an operator definition loaded from JSON or another untyped source. */
3
+ export declare const resolveOperator: (input: unknown) => OperatorDefinition;
@@ -2,6 +2,7 @@ import type { PrimalType, ResolvedSemanticProperty, ResolvedSemanticSchema, Time
2
2
  import type { LogicformType, PredItemType } from '../logicform-types';
3
3
  import type { DataRow } from '../physical/index';
4
4
  import type { Expression } from '../planner/index';
5
+ import type { LocaleTranslate } from '../i18n/index';
5
6
  export interface OperatorSqlCapabilities {
6
7
  /** Produce a dialect-specific aggregate function around an expression. */
7
8
  aggregateFunction(name: string, expression?: string): string;
@@ -13,8 +14,10 @@ export interface OperatorSqlCapabilities {
13
14
  dateShift(expression: string, granularity: TimeGranularity, offset: number): string;
14
15
  /** Render a period boundary directly when the dialect has a concise native form. */
15
16
  datePeriodBoundary?(expression: string, granularity: TimeGranularity, boundary: 'start' | 'end'): string;
17
+ /** Render a NULL-ignoring scalar extremum using a dialect-native expression. */
18
+ scalarExtremum?(operator: 'least' | 'greatest', expressions: readonly string[]): string;
16
19
  /** Bind a literal as a SQL parameter. */
17
- value(value: unknown): string;
20
+ value(value: unknown, type?: string): string;
18
21
  /** Compile a field-local LogicForm condition against an expression. */
19
22
  condition(expression: string, condition: unknown): string;
20
23
  }
@@ -51,7 +54,7 @@ export interface ResultProperty {
51
54
  readonly temporal?: ResultPropertyTemporalMetadata;
52
55
  }
53
56
  export interface ResultPropertyTemporalMetadata {
54
- readonly kind: 'period-boundary' | 'period-shift' | 'date-bucket' | 'lifecycle';
57
+ readonly kind: 'period-boundary' | 'period-shift' | 'date-bucket' | 'validity' | 'lifecycle';
55
58
  readonly boundary?: 'start' | 'end';
56
59
  readonly sourceProperty?: string;
57
60
  readonly requestedRange?: {
@@ -100,8 +103,10 @@ export interface OperatorDefaultNameContext {
100
103
  readonly inputNames: readonly string[];
101
104
  /** Operator-specific LogicForm arguments. */
102
105
  readonly args: Readonly<Record<string, unknown>>;
103
- /** Requested locale. Each operator owns its own localized default names. */
106
+ /** Requested locale for generated names. */
104
107
  readonly locale: string;
108
+ /** Translate a stable message key using the requested locale. */
109
+ readonly t?: LocaleTranslate;
105
110
  }
106
111
  export interface OperatorPlanInputContext {
107
112
  /** Canonical property or relation reference supplied as this operator's direct pred. */
@@ -158,6 +163,10 @@ export interface OperatorComponentContext {
158
163
  readonly pred: PredItemType;
159
164
  /** Final output alias assigned by the planner. */
160
165
  readonly outputName: string;
166
+ /** Requested locale for child component names. */
167
+ readonly locale: string;
168
+ /** Translate a stable message key using the requested locale. */
169
+ readonly t: LocaleTranslate;
161
170
  readonly schema: ResolvedSemanticSchema;
162
171
  /** Resolve Schemas referenced by object relation paths used by this component. */
163
172
  readonly resolveSchema: (schemaId: string) => ResolvedSemanticSchema;
@@ -179,27 +188,27 @@ export interface OperatorQueryComponent {
179
188
  readonly groupKeyShifts?: readonly OperatorGroupKeyShift[];
180
189
  }
181
190
  export interface OperatorComponentQuery {
191
+ /** Final result-column name for this child component. */
182
192
  readonly name: string;
183
193
  readonly logicform: LogicformType;
184
194
  readonly prepare?: boolean;
185
195
  readonly mapResult?: (rows: readonly DataRow[]) => DataRow[];
186
196
  readonly groupKeyShifts?: readonly OperatorGroupKeyShift[];
187
- /** Group output names used to join this component back to the first component. */
197
+ /**
198
+ * Group output names used to join this component back to the first component.
199
+ * When omitted, the compiler joins on the groupby outputs shared by both components.
200
+ */
188
201
  readonly joinKeys?: readonly string[];
189
202
  }
190
203
  export interface OperatorComponentCalculation {
191
204
  readonly components: readonly OperatorComponentQuery[];
192
205
  /** Provider-independent formula referring to component names. */
193
206
  readonly expression: string;
194
- readonly outputName?: string;
195
- readonly exposeComponents?: boolean;
196
207
  }
197
208
  export interface OperatorJavaScriptCalculation {
198
209
  readonly kind: 'js';
199
210
  readonly components: readonly OperatorComponentQuery[];
200
- readonly outputName: string;
201
211
  readonly mergeRow: (values: DataRow) => unknown;
202
- readonly exposeComponents?: boolean;
203
212
  }
204
213
  export type OperatorExecutionComponent = OperatorQueryComponent | OperatorComponentCalculation | OperatorJavaScriptCalculation;
205
214
  /**
@@ -12,8 +12,14 @@ export interface ClickHouseClientLike {
12
12
  close(): Promise<void>;
13
13
  }
14
14
  export interface ClickHouseProviderOptions {
15
+ /** Full HTTP endpoint. Takes precedence over host and port. */
15
16
  readonly url?: string;
17
+ /** Host-style connection fields accepted by the shared datasource contract. */
18
+ readonly host?: string;
19
+ readonly port?: number;
16
20
  readonly username?: string;
21
+ /** Alias used by the shared datasource contract. username takes precedence. */
22
+ readonly user?: string;
17
23
  readonly password?: string;
18
24
  readonly database?: string;
19
25
  readonly client?: ClickHouseClientLike;
@@ -29,6 +35,8 @@ export declare class ClickHouseProvider implements CoreComputeProvider {
29
35
  displayQuery(sql: string, parameters: readonly unknown[]): string;
30
36
  dateBucket(expression: string, level: string): string;
31
37
  dateShift(expression: string, granularity: string, offset: number): string;
38
+ castValue(expression: string, type: string): string;
39
+ scalarExtremum(operator: 'least' | 'greatest', expressions: readonly string[]): string;
32
40
  aggregateFunction(name: string, expression?: string): string;
33
41
  stringify(expression: string): string;
34
42
  concat(expressions: readonly string[]): string;
@@ -14,6 +14,10 @@ export interface SqlRenderCapabilities {
14
14
  dateBucket(expression: string, level: string): string;
15
15
  dateShift(expression: string, granularity: string, offset: number): string;
16
16
  datePeriodBoundary?(expression: string, granularity: string, boundary: 'start' | 'end'): string;
17
+ /** Cast a bound literal to the semantic type required by the SQL expression. */
18
+ castValue?(expression: string, type: string): string;
19
+ /** Render a NULL-ignoring scalar extremum without a correlated subquery. */
20
+ scalarExtremum?(operator: 'least' | 'greatest', expressions: readonly string[]): string;
17
21
  aggregateFunction(name: string, expression?: string): string;
18
22
  stringify(expression: string): string;
19
23
  concat(expressions: readonly string[]): string;
@@ -1,7 +1,7 @@
1
1
  export { buildLineage } from './build-lineage';
2
2
  export { createDerivedSourceSchema, createLogicalPlan, createResultSchema } from './create-logical-plan';
3
3
  export type { CreateLogicalPlanOptions } from './create-logical-plan';
4
- export type { Expression, ArrayExpansionPlan, FieldReferencePlan, GroupLimitPlan, JoinPlan, LogicalQuerySubquery, LogicalRecursiveQuery, LogicalOrdinalQuery, LineageColumnSource, LineageOutput, LogicalPlan, OrderPlan, PaginationPlan, ProjectionPlan, QueryLineage, RowIdentityPlan, } from './types';
4
+ export type { Expression, ArrayExpansionPlan, FieldReferencePlan, GroupLimitPlan, JoinPlan, LogicalQuerySubquery, LogicalRecursiveQuery, LogicalOrdinalQuery, LineageColumnSource, LineageOutput, LogicalPlan, OrderPlan, ObservationPeriodPlan, PaginationPlan, ProjectionPlan, QueryLineage, RowIdentityPlan, ValidityPeriodPlan, } from './types';
5
5
  export { isLogicalQuerySubquery, isLogicalRecursiveQuery } from './types';
6
6
  export { isLogicalOrdinalQuery } from './types';
7
7
  export * from './semantics/index';
@@ -0,0 +1,11 @@
1
+ export interface AnnualPeriod {
2
+ readonly label: string;
3
+ readonly start: string;
4
+ readonly end: string;
5
+ }
6
+ export interface AnnualPeriodErrorContext {
7
+ readonly codePrefix: 'VALIDITY' | 'OBSERVATION';
8
+ readonly label: string;
9
+ }
10
+ /** Expand one bounded time condition into natural-year boundaries. */
11
+ export declare const resolveAnnualPeriods: (condition: unknown, context: AnnualPeriodErrorContext) => readonly AnnualPeriod[];
@@ -1,4 +1,5 @@
1
1
  export * from './observation/index';
2
+ export * from './validity/index';
2
3
  export * from './lifecycle/index';
3
4
  export { PlannerSemanticRegistry } from './registry';
4
5
  export type { PlannerSemanticResolution, PlannerSemanticQueryContext, PlannerSemanticRule, PlannerSemanticRuleContext, } from './registry';
@@ -1,7 +1,5 @@
1
- import type { ResolvedSemanticProperty, ResolvedSemanticSchema } from '../../../semantic-types/index';
2
- export interface LifecycleProperties {
3
- readonly timestamp: ResolvedSemanticProperty;
4
- readonly start: ResolvedSemanticProperty;
5
- readonly end: ResolvedSemanticProperty;
6
- }
7
- export declare const resolveLifecycleProperties: (schema: Pick<ResolvedSemanticSchema, "type" | "properties">) => LifecycleProperties | undefined;
1
+ import type { ValidityProperties } from '../validity/classification';
2
+ /** Compatibility alias. Lifecycle is the single-row validity case. */
3
+ export type LifecycleProperties = ValidityProperties;
4
+ /** Compatibility alias for resolveValidityProperties. */
5
+ export declare const resolveLifecycleProperties: (schema: Pick<import("../../..").ResolvedSemanticSchema, "type" | "properties" | "temporalSemantics">) => ValidityProperties | undefined;
@@ -1,3 +1,2 @@
1
- import type { QueryType } from '../../../logicform-types';
2
- import type { LifecycleProperties } from './classification';
3
- export declare const applyLifecycleQuery: (query: QueryType | undefined, properties: LifecycleProperties) => QueryType | undefined;
1
+ /** Compatibility alias for applyValidityQuery. */
2
+ export { applyValidityQuery as applyLifecycleQuery } from '../validity/query-policy';
@@ -1,2 +1,2 @@
1
- import type { PlannerSemanticRule } from '../registry';
2
- export declare const lifecycleSemanticRule: PlannerSemanticRule;
1
+ /** Compatibility alias for validitySemanticRule. */
2
+ export declare const lifecycleSemanticRule: import("..").PlannerSemanticRule;
@@ -1,4 +1,6 @@
1
1
  export { isObservationProperty, observationProperties, } from './classification';
2
2
  export { resolveObservationOperatorPolicy, type ObservationOperatorPolicy, } from './operator-policy';
3
3
  export type { ObservationOperator, ObservationTemporalMetadata, } from './types';
4
+ export { removeObservationTimeCondition, resolveObservationPeriodSpec, } from './periods';
5
+ export type { ObservationPeriodMetric, ObservationPeriodSpec, } from './periods';
4
6
  export { observationSemanticRule } from './rule';
@@ -0,0 +1,19 @@
1
+ import type { LogicformType, PredItemType, QueryType } from '../../../logicform-types';
2
+ import type { ResolvedSemanticProperty, ResolvedSemanticSchema } from '../../../semantic-types/index';
3
+ export interface ObservationPeriodMetric {
4
+ readonly pred: PredItemType;
5
+ readonly effectivePred: PredItemType;
6
+ }
7
+ export interface ObservationPeriodSpec {
8
+ readonly group: PredItemType;
9
+ readonly timestamp: ResolvedSemanticProperty;
10
+ readonly boundary: 'start' | 'end';
11
+ readonly metrics: readonly ObservationPeriodMetric[];
12
+ readonly periods: readonly {
13
+ readonly label: string;
14
+ readonly asOf: string;
15
+ }[];
16
+ }
17
+ export declare const removeObservationTimeCondition: (query: QueryType | undefined, timestamp: ResolvedSemanticProperty) => QueryType | undefined;
18
+ /** Plan grouped snapshot metrics as one lookup of the latest observation per period. */
19
+ export declare const resolveObservationPeriodSpec: (logicform: LogicformType, schema: ResolvedSemanticSchema) => ObservationPeriodSpec | undefined;
@@ -0,0 +1,14 @@
1
+ import type { ResolvedSemanticProperty, ResolvedSemanticSchema } from '../../../semantic-types/index';
2
+ /** Property roles that define an entity whose rows are valid over a time interval. */
3
+ export interface ValidityProperties {
4
+ readonly id: ResolvedSemanticProperty;
5
+ readonly timestamp: ResolvedSemanticProperty;
6
+ readonly start: ResolvedSemanticProperty;
7
+ readonly end: ResolvedSemanticProperty;
8
+ }
9
+ /**
10
+ * Valid-time semantics are structural: an entity with one stable ID and one
11
+ * start/end interval is a valid-time entity. The ID may repeat physically;
12
+ * non-overlapping intervals select the row version that is valid at a point.
13
+ */
14
+ export declare const resolveValidityProperties: (schema: Pick<ResolvedSemanticSchema, "type" | "properties" | "temporalSemantics">) => ValidityProperties | undefined;
@@ -0,0 +1,6 @@
1
+ export { resolveValidityProperties } from './classification';
2
+ export type { ValidityProperties } from './classification';
3
+ export { applyValidityQuery } from './query-policy';
4
+ export { hasValidityTimeGroup, removeValidityTimeCondition, resolveValidityPeriodSpec, } from './periods';
5
+ export type { ValidityPeriod, ValidityPeriodSpec } from './periods';
6
+ export { validitySemanticRule } from './rule';
@@ -0,0 +1,16 @@
1
+ import type { LogicformType, PredItemType, QueryType } from '../../../logicform-types';
2
+ import type { TimeGranularity } from '../../../semantic-types/index';
3
+ import type { ValidityProperties } from './classification';
4
+ export interface ValidityPeriod {
5
+ readonly label: string;
6
+ readonly asOf: string;
7
+ }
8
+ export interface ValidityPeriodSpec {
9
+ readonly group: PredItemType;
10
+ readonly granularity: TimeGranularity;
11
+ readonly periods: readonly ValidityPeriod[];
12
+ }
13
+ export declare const hasValidityTimeGroup: (logicform: LogicformType, properties: ValidityProperties) => boolean;
14
+ export declare const removeValidityTimeCondition: (query: QueryType | undefined, properties: ValidityProperties) => QueryType | undefined;
15
+ /** Resolve a bounded virtual-time grouping into explicit period-end instants. */
16
+ export declare const resolveValidityPeriodSpec: (logicform: LogicformType, properties: ValidityProperties) => ValidityPeriodSpec | undefined;
@@ -0,0 +1,4 @@
1
+ import type { QueryType } from '../../../logicform-types';
2
+ import type { ValidityProperties } from './classification';
3
+ /** Rewrite a public time-axis condition to the half-open validity interval [start, end). */
4
+ export declare const applyValidityQuery: (query: QueryType | undefined, properties: ValidityProperties) => QueryType | undefined;
@@ -0,0 +1,2 @@
1
+ import type { PlannerSemanticRule } from '../registry';
2
+ export declare const validitySemanticRule: PlannerSemanticRule;
@@ -120,6 +120,9 @@ export interface JoinPlan {
120
120
  readonly targetSql?: string;
121
121
  readonly targetTimestampColumn?: string;
122
122
  readonly targetTimestampGranularity?: TimeGranularity;
123
+ /** Half-open validity interval columns on a versioned entity target. */
124
+ readonly targetValidityStartColumn?: string;
125
+ readonly targetValidityEndColumn?: string;
123
126
  readonly sourceArrayExpansionPath?: string;
124
127
  }
125
128
  export interface ArrayExpansionPlan {
@@ -144,6 +147,30 @@ export interface GroupLimitPlan {
144
147
  readonly partitionBy: readonly string[];
145
148
  readonly orderBy: readonly OrderPlan[];
146
149
  }
150
+ export interface ValidityPeriodPlan {
151
+ readonly alias: string;
152
+ readonly labelColumn: string;
153
+ readonly asOfColumn: string;
154
+ readonly sourceAlias: string;
155
+ readonly startColumn: string;
156
+ readonly endColumn: string;
157
+ readonly periods: readonly {
158
+ readonly label: string;
159
+ readonly asOf: string;
160
+ }[];
161
+ }
162
+ export interface ObservationPeriodPlan {
163
+ readonly alias: string;
164
+ readonly labelColumn: string;
165
+ readonly asOfColumn: string;
166
+ readonly sourceAlias: string;
167
+ readonly lookupAlias: string;
168
+ readonly timestampColumn: string;
169
+ readonly periods: readonly {
170
+ readonly label: string;
171
+ readonly asOf: string;
172
+ }[];
173
+ }
147
174
  export type RowIdentityPlan = {
148
175
  readonly kind: 'group';
149
176
  readonly names: readonly string[];
@@ -176,6 +203,10 @@ export interface LogicalPlan {
176
203
  readonly fieldReferences?: Readonly<Record<string, FieldReferencePlan>>;
177
204
  readonly joins?: readonly JoinPlan[];
178
205
  readonly arrayExpansions?: readonly ArrayExpansionPlan[];
206
+ /** Period spine used to evaluate a valid-time entity once per requested period. */
207
+ readonly validityPeriods?: ValidityPeriodPlan;
208
+ /** Period spine used to select the latest snapshot at each requested boundary. */
209
+ readonly observationPeriods?: ObservationPeriodPlan;
179
210
  readonly projections: readonly ProjectionPlan[];
180
211
  readonly columnProperties?: readonly ResultProperty[];
181
212
  readonly groupBy: readonly ProjectionPlan[];
@@ -0,0 +1,8 @@
1
+ import type { PredItemType } from '../logicform-types';
2
+ import type { ResolvedSemanticSchema } from '../semantic-types/index';
3
+ /**
4
+ * Returns true when a scalar projection is functionally dependent on one of
5
+ * the supplied group keys. Same-Schema hierarchy uses `up`; scalar object
6
+ * relations use the relation key itself.
7
+ */
8
+ export declare const isDependentProjection: (pred: PredItemType, groupby: readonly PredItemType[], schema: ResolvedSemanticSchema, resolveSchema?: (schemaId: string) => ResolvedSemanticSchema) => boolean;