semanticdb-v2 2.0.0-alpha.7 → 2.0.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -583,9 +583,10 @@ comments, or parameter placeholders. Property UDFs do not support the legacy `fu
583
583
  ### Query cache
584
584
 
585
585
  All compiled provider queries, including the internal time-watermark query, can share one
586
- caller-owned query cache. Redis is published from `semanticdb-v2/cache/redis`; cache identity
587
- includes namespace, connection id, provider, SQL, and parameters. Physical expiration belongs to each Schema
588
- mapping's `freshness` policy. See [Query cache and Redis](docs/query-cache.md).
586
+ internally managed Redis query cache. Pass its JSON connection configuration through `cache`;
587
+ cache identity includes namespace, connection id, provider, SQL, and parameters. Physical
588
+ expiration belongs to each Schema mapping's `freshness` policy. See
589
+ [Query cache and Redis](docs/query-cache.md).
589
590
 
590
591
  Schema mappings can also expose same-connection entity feature tables as lazy physical
591
592
  enrichments. A mapped feature property adds a `LEFT JOIN` only when referenced, and a point-in-time
@@ -598,14 +599,21 @@ separate Schema Mapping `dimensions` field. The planner selects a source that co
598
599
  the requested properties and physical time or hierarchy grain. See
599
600
  [Schema Mapping physical granularity](docs/schema-mapping-granularity.md).
600
601
 
601
- When Redis is shared with other applications, pass an application-specific key prefix:
602
+ When Redis is shared with other applications, pass an application-specific key prefix in the
603
+ execution JSON. SemanticDB reuses the connection by `cache.id`:
602
604
 
603
605
  ```ts
604
- import { createRedisQueryCache } from 'semanticdb-v2/cache/redis';
605
-
606
- const cache = await createRedisQueryCache({
607
- url: process.env.REDIS_URL,
608
- keyPrefix: process.env.REDIS_KEY_PREFIX,
606
+ await Logicform.execute(logicform, {
607
+ schemas,
608
+ schemaMappings,
609
+ connections,
610
+ cache: {
611
+ id: 'redis-main',
612
+ kind: 'redis',
613
+ url: process.env.REDIS_URL ?? 'redis://localhost:6379/0',
614
+ keyPrefix: process.env.REDIS_KEY_PREFIX,
615
+ namespace: 'tenant-a:mysql-sales',
616
+ },
609
617
  });
610
618
  ```
611
619
 
@@ -1,3 +1,4 @@
1
1
  export { nextDailyExpiration, resolveQueryExpiration, } from './expiry';
2
2
  export { queryCacheIdentityHash, sourceCacheIndexHash, } from './identity';
3
- export type { QueryCache, QueryCacheExecutionOptions, QueryCacheIdentity, QueryCacheWriteOptions, } from './types';
3
+ export type { InvalidateQueryCacheSourceOptions, QueryCache, QueryCacheConfiguration, QueryCacheExecutionOptions, QueryCacheIdentity, QueryCacheWriteOptions, } from './types';
4
+ export { QueryCacheManager } from './manager';
@@ -0,0 +1,5 @@
1
+ import type { InvalidateQueryCacheSourceOptions } from './types';
2
+ /** Operations for internally managed query-cache connections. */
3
+ export declare const QueryCacheManager: Readonly<{
4
+ invalidateSource: ({ cache, source }: InvalidateQueryCacheSourceOptions) => Promise<void>;
5
+ }>;
@@ -0,0 +1,14 @@
1
+ import type { QueryCache, QueryCacheConfiguration, QueryCacheExecutionOptions } from './types';
2
+ type QueryCacheConnection = Omit<QueryCacheConfiguration, 'namespace'>;
3
+ type QueryCacheFactory = (connection: QueryCacheConnection) => Promise<QueryCache>;
4
+ /** Internally owns and reuses cache connections by stable configuration id. */
5
+ export declare class QueryCacheRegistry {
6
+ #private;
7
+ private readonly create;
8
+ constructor(create?: QueryCacheFactory);
9
+ get(configuration: QueryCacheConfiguration): Promise<QueryCacheExecutionOptions>;
10
+ close(): Promise<void>;
11
+ }
12
+ export declare const resolveQueryCache: (configuration: QueryCacheConfiguration) => Promise<QueryCacheExecutionOptions>;
13
+ export declare const closeQueryCaches: () => Promise<void>;
14
+ export {};
@@ -27,3 +27,18 @@ export interface QueryCacheExecutionOptions {
27
27
  /** Isolates tenants and physical data sources that can produce identical SQL. */
28
28
  readonly namespace: string;
29
29
  }
30
+ /** Redis connection and cache namespace supplied as JSON at the public execution boundary. */
31
+ export interface QueryCacheConfiguration {
32
+ /** Stable identity used to reuse one internally managed Redis connection. */
33
+ readonly id: string;
34
+ readonly kind: 'redis';
35
+ readonly url: string;
36
+ readonly keyPrefix?: string;
37
+ /** Isolates tenants and physical data sources that can produce identical SQL. */
38
+ readonly namespace: string;
39
+ }
40
+ export interface InvalidateQueryCacheSourceOptions {
41
+ readonly cache: QueryCacheConfiguration;
42
+ /** Physical Schema Mapping source to invalidate. */
43
+ readonly source: string;
44
+ }
@@ -0,0 +1 @@
1
+ export declare const closeSemanticDB: () => Promise<void>;
@@ -2,7 +2,8 @@ import type { CompiledQuery } from '../compiler/index';
2
2
  import type { DataRow } from '../physical/index';
3
3
  import type { LogicalPlan } from '../planner/index';
4
4
  import type { SchemaMappingDefinition, SchemaMappingRegistry } from '../schema-mappings/index';
5
- import type { InternalExecuteOptions } from './types';
5
+ import type { InternalExecuteOptions, SqlExecutionSource } from './types';
6
+ export type SqlExecutionSourceReporter = (source: SqlExecutionSource) => void;
6
7
  export interface PhysicalQuerySource {
7
8
  readonly schemaId: string;
8
9
  readonly source: string;
@@ -13,6 +14,6 @@ export interface PhysicalQuerySource {
13
14
  export declare const resolvePhysicalSourceMapping: (source: PhysicalQuerySource, mappings: SchemaMappingRegistry) => SchemaMappingDefinition | undefined;
14
15
  export declare const collectPlanSources: (plan: LogicalPlan) => readonly PhysicalQuerySource[];
15
16
  export declare const mergePhysicalSources: (groups: readonly (readonly PhysicalQuerySource[])[]) => readonly PhysicalQuerySource[];
16
- export declare const executeCompiledQuery: (compiled: CompiledQuery, sources: readonly PhysicalQuerySource[], options: Pick<InternalExecuteOptions, "cache" | "provider" | "schemaMappings" | "signal" | "connectionId">) => Promise<DataRow[]>;
17
+ export declare const executeCompiledQuery: (compiled: CompiledQuery, sources: readonly PhysicalQuerySource[], options: Pick<InternalExecuteOptions, "cache" | "provider" | "schemaMappings" | "signal" | "connectionId">, reportExecutionSource?: SqlExecutionSourceReporter) => Promise<DataRow[]>;
17
18
  /** Apply final SQL shaping after all plans, views, and derived sources are compiled. */
18
19
  export declare const shortenCompiledQuery: (compiled: CompiledQuery) => CompiledQuery;
@@ -4,6 +4,7 @@ import type { OperatorRegistry } from '../operators/index';
4
4
  import type { CoreComputeProvider, DataRow } from '../physical/index';
5
5
  import type { LogicalPlan } from '../planner/index';
6
6
  import type { SchemaMappingRegistry } from '../schema-mappings/index';
7
+ import type { SqlExecutionSourceReporter } from './execute-query';
7
8
  import type { InternalExecuteOptions } from './types';
8
9
  export declare const coordinatorConnectionId = "__semanticdb_coordinator__";
9
10
  export interface FederatedCompiledQuery {
@@ -21,7 +22,7 @@ interface FederatedExecutionOptions {
21
22
  readonly cache?: InternalExecuteOptions['cache'];
22
23
  readonly signal?: AbortSignal;
23
24
  readonly maxMaterializedRows: number;
24
- readonly onCompiled: (query: FederatedCompiledQuery) => void;
25
+ readonly onCompiled: (query: FederatedCompiledQuery) => SqlExecutionSourceReporter;
25
26
  }
26
27
  export interface FederatedExecutionResult {
27
28
  readonly rows: DataRow[];
@@ -9,6 +9,7 @@ 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 { SqlExecutionSourceReporter } from './execute-query';
12
13
  import type { LocaleRegistry } from '../i18n/index';
13
14
  interface FetchEntityOptions {
14
15
  readonly version: string;
@@ -25,7 +26,7 @@ interface FetchEntityOptions {
25
26
  readonly preferredConnectionId?: string;
26
27
  readonly cache?: QueryCacheExecutionOptions;
27
28
  readonly signal?: AbortSignal;
28
- readonly onCompiled?: (compiled: CompiledQuery, logicform: LogicformType, provider: CoreComputeProvider, connectionId?: string) => void;
29
+ readonly onCompiled?: (compiled: CompiledQuery, logicform: LogicformType, provider: CoreComputeProvider, connectionId?: string) => SqlExecutionSourceReporter | undefined;
29
30
  }
30
31
  export declare const fetchEntities: (request: EntityFetchRequest, options: FetchEntityOptions) => Promise<DataRow[]>;
31
32
  export {};
@@ -1,3 +1,3 @@
1
1
  export { execute } from './execute';
2
2
  export { closeConnections } from './connection-registry';
3
- export type { ExecuteOptions, ExecuteFailureResult, ExecuteProgressEvent, ExecuteResult, ExecuteSuccessResult, ExecutedSql, ExecutedSqlType, PartialExecuteResult, ProgressCallback, } from './types';
3
+ export type { ExecuteOptions, ExecuteFailureResult, ExecuteProgressEvent, ExecuteResult, ExecuteSuccessResult, ExecutedSql, ExecutedSqlType, SqlExecutionSource, PartialExecuteResult, ProgressCallback, } from './types';
@@ -1,11 +1,11 @@
1
- import type { OperatorDefinition, OperatorRegistry } from '../operators/index';
1
+ import type { OperatorDefinition, OperatorExecutionContext, OperatorRegistry } from '../operators/index';
2
2
  import type { CoreComputeProvider, DataRow, ProviderRegistry, SqlParameters } from '../physical/index';
3
3
  import type { DatabaseConnection } from '../physical/index';
4
4
  import type { LogicalPlan, QueryLineage } from '../planner/index';
5
5
  import type { SchemaMappingDefinition, SchemaMappingRegistry, SchemaMappingSelection } from '../schema-mappings/index';
6
6
  import type { ResolvedSemanticSchema, SemanticSchemaDraft, SemanticTypeRegistry, TimeWatermarkPolicy } from '../semantic-types/index';
7
7
  import type { LogicformType, PublicLogicformType } from '../logicform-types';
8
- import type { QueryCacheExecutionOptions } from '../cache/index';
8
+ import type { QueryCacheConfiguration, QueryCacheExecutionOptions } from '../cache/index';
9
9
  import type { Permissions } from '../permissions/index';
10
10
  import type { SemanticDBPlugin } from '../plugins/index';
11
11
  import type { LocaleInput, LocaleRegistry } from '../i18n/index';
@@ -69,8 +69,6 @@ interface ExecuteBaseOptions {
69
69
  readonly locales?: LocaleInput;
70
70
  /** Table, row, and column permissions for this execution. */
71
71
  readonly permissions?: Permissions;
72
- /** Optional caller-owned cache shared across executions. */
73
- readonly cache?: QueryCacheExecutionOptions;
74
72
  readonly onProgress?: ProgressCallback;
75
73
  readonly signal?: AbortSignal;
76
74
  /** Default time watermark policy; Schema and Property policies override it. */
@@ -88,12 +86,16 @@ export interface ExecuteOptions extends ExecuteBaseOptions {
88
86
  readonly connections: readonly DatabaseConnection[];
89
87
  /** Provider factories used for built-in or application-defined connection kinds. */
90
88
  readonly providerRegistry?: ProviderRegistry;
89
+ /** JSON configuration for an internally owned and reused query-cache connection. */
90
+ readonly cache?: QueryCacheConfiguration;
91
91
  }
92
92
  /** Internal execution seam used by executor tests after a provider has been resolved. */
93
93
  export interface InternalExecuteOptions extends Omit<ExecuteBaseOptions, 'operators'> {
94
94
  readonly operators?: OperatorRegistry;
95
95
  /** The public execution boundary has already merged built-in, plugin, and explicit Operators. */
96
96
  readonly operatorsResolved?: boolean;
97
+ /** Present for nested executions to reuse or intentionally suppress calendar preloading. */
98
+ readonly executionContext?: OperatorExecutionContext;
97
99
  /** The public execution boundary has already merged plugin SemanticTypes. */
98
100
  readonly semanticTypesResolved?: boolean;
99
101
  readonly localeRegistry?: LocaleRegistry;
@@ -101,6 +103,8 @@ export interface InternalExecuteOptions extends Omit<ExecuteBaseOptions, 'operat
101
103
  /** Resolve providers for additional physical connections in a federated execution. */
102
104
  readonly providerForConnection?: (connectionId: string) => CoreComputeProvider;
103
105
  readonly schemaMappings: SchemaMappingRegistry;
106
+ /** Cache connection already resolved at the public execution boundary. */
107
+ readonly cache?: QueryCacheExecutionOptions;
104
108
  /** Selected connection for public execution; omitted only by internal provider tests. */
105
109
  readonly connectionId?: string;
106
110
  }
@@ -136,6 +140,7 @@ export interface ExecuteFailureResult {
136
140
  }
137
141
  export type ExecuteResult = ExecuteSuccessResult | ExecuteFailureResult;
138
142
  export type ExecutedSqlType = 'computation' | 'semantic-resolution' | 'total';
143
+ export type SqlExecutionSource = 'cache' | 'database';
139
144
  export interface ExecutedSql {
140
145
  /** Why this SQL participates in the LogicForm execution. */
141
146
  readonly type: ExecutedSqlType;
@@ -151,6 +156,8 @@ export interface ExecutedSql {
151
156
  readonly parameters: SqlParameters;
152
157
  /** Dialect-formatted diagnostic SQL. SemanticDB never executes this string. */
153
158
  readonly displaySql: string;
159
+ /** Actual row source. Absent only before execution, such as in the compiled progress event. */
160
+ readonly executionSource?: SqlExecutionSource;
154
161
  }
155
162
  export type PartialExecuteResult = Partial<ExecuteSuccessResult>;
156
163
  export {};
package/dist/index.d.ts CHANGED
@@ -9,19 +9,17 @@ export { builtinSemanticTypes, createSemanticTypeRegistry, resolveSchema, Semant
9
9
  export { builtinOperators, createOperatorRegistry, OperatorRegistry, resolveOperator, } from './operators/index';
10
10
  export type { LegacySchemaPluginContext, MappingGranularityContext, MappingGranularityPlugin, OutputHandlerContext, OutputHandlerDefinition, IntervalSemanticProperties, IntervalSemanticsDefinition, PlannerPeriodDefinition, PlannerPeriodEvaluation, RelationSemanticsDefinition, RelationTemporalPlan, TimeWatermarkLogicformContext, PropertyMetadataPlugin, QueryOperatorCompileContext, QueryOperatorAuthorizeContext, QueryOperatorDefinition, QueryOperatorNormalizeContext, QueryOperatorPhysicalSource, QueryOperatorPlanContext, QueryOperatorPlanResult, SchemaMetadataPlugin, SchemaMappingPlugin, SemanticDBPlugin, } from './plugins/index';
11
11
  export { SchemaMappingRegistry, fromYiAskSchemaMapping, } from './schema-mappings/index';
12
- export type { AbsoluteDateValue, CompareOperator, DatePartQueryComparison, DatePartQueryOperand, CalendarDateValue, DateTimeValue, DateValue, EntityIdType, ExpressionItemType, LogicformType, NumericQueryComparison, NumericQueryOperand, PublicLogicformType, PeriodShiftTime, PredItemType, QueryLogicalOperand, QueryExpressionType, RelationQueryType, QueryType, QueryValueType, QueryValueTypeWithCompareOperator, RelativeDateValue, RepresentationType, } from './logicform-types';
12
+ export type { AbsoluteDateValue, CompareOperator, DatePartQueryComparison, DatePartQueryOperand, DateTimeValue, DateValue, EntityIdType, ExpressionItemType, LogicformType, NumericQueryComparison, NumericQueryOperand, PublicLogicformType, PeriodShiftTime, PredItemType, QueryLogicalOperand, QueryExpressionType, RelationQueryType, QueryType, QueryValueType, QueryValueTypeWithCompareOperator, RelativeDateValue, RepresentationType, } from './logicform-types';
13
13
  export type { RecursiveQueryType } from './plugins/index';
14
- export { CALENDAR_DATES_TABLE, CALENDAR_RELATIONS_TABLE, CALENDAR_SYSTEM_SCHEMA_IDS, calendarSystemSchemas, ProviderCalendarRelationStore, resolveCalendarPeriod, resolveCalendarPeriodFromStore, selectCalendarDates, } from './calendar/index';
15
- export type { CalendarAlignment, CalendarComparison, CalendarDateRow, CalendarRelation, CalendarRelationRow, ResolvedCalendarPeriod, } from './calendar/index';
16
- export type { CalendarRelationStore } from './calendar/index';
17
14
  export type { PrimalType, PropertyHierarchyDefinition, PropertySqlDefinition, ResolvedSemanticProperty, ResolvedSemanticSchema, SemanticTypeNormalizeContext, SemanticPropertyDraft, SemanticSchemaDraft, SemanticTypeDefinition, SemanticTypeResultContext, SemanticTypeResultProperty, TimeGranularity, TimeWatermarkPolicy, } from './semantic-types/index';
18
15
  export type { DataRow, SqlParameters, BuiltinDatabaseConnection, DatabaseConnection, DatabaseConnectionBase, DatabaseConnectionExtensions, ProviderDefinition, ProviderKind, ProviderKindExtensions, } from './physical/index';
19
16
  export { DBConnector, ProviderRegistry } from './physical/index';
20
17
  export type { DBConnectorOptions, RunSQLOptions, GetTableListOptions, DescribeTableOptions, DescribeTableRequest, DatabaseColumn, TableDescription, DatabaseTable, SQLResult, TableListRequest, } from './physical/index';
21
- export type { OperatorDefinition, OperatorDefaultNameContext, OperatorComponentContext, OperatorComponentCalculation, OperatorComponentQuery, OperatorExecutionComponent, OperatorPlanInputContext, OperatorPlannedInput, OperatorGroupKeyShift, OperatorJavaScriptCalculation, OperatorQueryComponent, OperatorEvaluateContext, OperatorOutputPropertyContext, OperatorSqlCapabilities, OperatorSqlContext, ResultProperty, ResultPropertyTemporalMetadata, ResultPropertyTemporalMetadataExtensions, } from './operators/index';
18
+ export type { OperatorDefinition, OperatorDefaultNameContext, OperatorExecutionContext, OperatorComponentContext, OperatorComponentCalculation, OperatorComponentQuery, OperatorExecutionComponent, OperatorPlanInputContext, OperatorPlannedInput, OperatorGroupKeyShift, OperatorJavaScriptCalculation, OperatorQueryComponent, OperatorEvaluateContext, OperatorOutputPropertyContext, OperatorSqlCapabilities, OperatorSqlContext, ResultProperty, ResultPropertyTemporalMetadata, ResultPropertyTemporalMetadataExtensions, } from './operators/index';
22
19
  export type { SchemaMappingDefinition, SchemaMappingEnrichmentDefinition, SchemaMappingEnrichmentKey, SchemaMappingItem, SchemaMappingGranularity, SchemaMappingGranularityExtensions, SchemaMappingPointTemporalDefinition, SchemaMappingPredDefinition, SchemaMappingPredMatch, SchemaMappingSelection, RejectedSchemaMapping, SourceFreshnessPolicy, YiAskSchemaMappingItem, YiAskSchemaMappingRecord, } from './schema-mappings/index';
23
- export type { QueryCache, QueryCacheExecutionOptions, QueryCacheIdentity, QueryCacheWriteOptions, } from './cache/index';
24
- export type { ExecuteOptions, ExecuteFailureResult, ExecuteProgressEvent, ExecuteResult, ExecuteSuccessResult, ExecutedSql, ExecutedSqlType, PartialExecuteResult, ProgressCallback, } from './executor/index';
20
+ export { QueryCacheManager } from './cache/index';
21
+ export type { InvalidateQueryCacheSourceOptions, QueryCacheConfiguration, } from './cache/index';
22
+ export type { ExecuteOptions, ExecuteFailureResult, ExecuteProgressEvent, ExecuteResult, ExecuteSuccessResult, ExecutedSql, ExecutedSqlType, SqlExecutionSource, PartialExecuteResult, ProgressCallback, } from './executor/index';
25
23
  export type { ColumnPermissions, Permissions, SchemaPermissions, } from './permissions/index';
26
24
  export type { CreateLogicalPlanOptions, LogicalPlan, QueryLineage, } from './planner/index';
27
25
  export { PlannerSemanticRegistry, createPlannerSemanticRegistry, } from './planner/index';
@@ -19,21 +19,10 @@ export interface AbsoluteDateValue {
19
19
  readonly second?: number;
20
20
  readonly period?: 'am' | 'pm';
21
21
  }
22
- /** A business-calendar period resolved to natural days before planning. */
23
- export interface CalendarDateValue {
24
- readonly calendar: string;
25
- readonly key?: string;
26
- readonly year?: number;
27
- readonly quarter?: number;
28
- readonly month?: number;
29
- readonly week?: number;
30
- readonly day?: number;
31
- readonly relativeDay?: number | readonly number[];
32
- }
33
22
  /** Period reference used by operators such as `$periodShift`. */
34
23
  export type PeriodShiftTime = RelativeDateValue | AbsoluteDateValue;
35
24
  /** A date value before semantic-type normalization. */
36
- export type DateValue = string | RelativeDateValue | AbsoluteDateValue | CalendarDateValue;
25
+ export type DateValue = string | RelativeDateValue | AbsoluteDateValue;
37
26
  /** Stable entity identity. Numeric IDs must be safe integers. */
38
27
  export type EntityIdType = string | number;
39
28
  export type CompareOperator = '$eq' | '$gt' | '$gte' | '$lt' | '$lte' | '$ne' | '$in' | '$nin' | '$exists' | '$regex' | '$contains' | '$startsWith' | '$length' | '$and' | '$or' | '$second' | '$minute' | '$hour' | '$weekday' | '$day' | '$week' | '$month' | '$quarter' | '$year' | Extract<keyof QueryOperatorExtensions, string>;
@@ -3,6 +3,6 @@ import { OperatorRegistry } from './registry';
3
3
  export { OperatorRegistry } from './registry';
4
4
  export { resolveOperator } from './resolve';
5
5
  export { bindTrustedSqlExpression } from './sql-expression';
6
- export type { OperatorDefinition, OperatorDefaultNameContext, OperatorComponentContext, OperatorComponentCalculation, OperatorComponentQuery, OperatorExecutionComponent, OperatorGroupKeyShift, OperatorJavaScriptCalculation, OperatorQueryComponent, OperatorEvaluateContext, OperatorOutputPropertyContext, OperatorPeriodBoundaryPolicy, OperatorPeriodBoundaryPolicyContext, OperatorNormalizePredContext, OperatorPlanExpressionContext, OperatorPeriodEvaluationContext, OperatorPlanInputContext, OperatorPlannedInput, OperatorRewriteLogicformContext, OperatorValidatePlanContext, OperatorSqlCapabilities, OperatorSqlContext, ResultProperty, ResultPropertyTemporalMetadata, ResultPropertyTemporalMetadataExtensions, } from './types';
6
+ export type { OperatorDefinition, OperatorDefaultNameContext, OperatorExecutionContext, OperatorComponentContext, OperatorComponentCalculation, OperatorComponentQuery, OperatorExecutionComponent, OperatorGroupKeyShift, OperatorJavaScriptCalculation, OperatorQueryComponent, OperatorEvaluateContext, OperatorOutputPropertyContext, OperatorPeriodBoundaryPolicy, OperatorPeriodBoundaryPolicyContext, OperatorNormalizePredContext, OperatorPlanExpressionContext, OperatorPeriodEvaluationContext, OperatorPlanInputContext, OperatorPlannedInput, OperatorRewriteLogicformContext, OperatorValidatePlanContext, OperatorSqlCapabilities, OperatorSqlContext, ResultProperty, ResultPropertyTemporalMetadata, ResultPropertyTemporalMetadataExtensions, } from './types';
7
7
  export declare const builtinOperators: readonly import("./types").OperatorDefinition[];
8
8
  export declare const createOperatorRegistry: (plugins?: readonly SemanticDBPlugin[]) => OperatorRegistry;
@@ -1,7 +1,9 @@
1
- import type { OperatorDefinition, OperatorPeriodEvaluationContext } from './types';
1
+ import type { OperatorDefinition, OperatorExecutionContext, OperatorPeriodEvaluationContext } from './types';
2
2
  export declare class OperatorRegistry {
3
3
  #private;
4
- constructor(definitions?: readonly OperatorDefinition[]);
4
+ readonly executionContext: OperatorExecutionContext;
5
+ constructor(definitions?: readonly OperatorDefinition[], executionContext?: OperatorExecutionContext);
6
+ withExecutionContext(executionContext: OperatorExecutionContext): OperatorRegistry;
5
7
  register(input: OperatorDefinition): this;
6
8
  get(name: string): OperatorDefinition;
7
9
  requiresPerPeriodEvaluation(name: string, context: OperatorPeriodEvaluationContext): boolean;
@@ -3,6 +3,15 @@ import type { LogicformType, PredItemType } from '../logicform-types';
3
3
  import type { DataRow } from '../physical/index';
4
4
  import type { Expression, LogicalPlan } from '../planner/index';
5
5
  import type { LocaleTranslate } from '../i18n/index';
6
+ /** Immutable data shared by all Operator hooks during one LogicForm execution. */
7
+ export interface OperatorExecutionContext {
8
+ /** Complete rows from the unique Schema marked with `is_calendar`. */
9
+ readonly calendar?: readonly Readonly<DataRow>[];
10
+ }
11
+ interface OperatorHookContext {
12
+ /** Always supplied by the executor; optional for direct unit-level hook invocation. */
13
+ readonly executionContext?: OperatorExecutionContext;
14
+ }
6
15
  export interface OperatorSqlCapabilities {
7
16
  /** Produce a dialect-specific aggregate function around an expression. */
8
17
  aggregateFunction(name: string, expression?: string): string;
@@ -24,7 +33,7 @@ export interface OperatorSqlCapabilities {
24
33
  condition(expression: string, condition: unknown): string;
25
34
  }
26
35
  /** Context passed to an operator that pushes its computation into SQL. */
27
- export interface OperatorSqlContext {
36
+ export interface OperatorSqlContext extends OperatorHookContext {
28
37
  readonly sql: OperatorSqlCapabilities;
29
38
  /** SQL for the nested input expression, when this operator has one. */
30
39
  readonly expression?: string;
@@ -36,7 +45,7 @@ export interface OperatorSqlContext {
36
45
  readonly args: Readonly<Record<string, unknown>>;
37
46
  }
38
47
  /** Context passed to an operator evaluated after the provider returns rows. */
39
- export interface OperatorEvaluateContext {
48
+ export interface OperatorEvaluateContext extends OperatorHookContext {
40
49
  /** Value produced by the nested expression, or undefined for a propertyless operator. */
41
50
  readonly input: unknown;
42
51
  /** Operator-specific LogicForm arguments. */
@@ -82,7 +91,7 @@ export type ResultPropertyTemporalMetadata = {
82
91
  readonly date: string;
83
92
  }[];
84
93
  } | ResultPropertyTemporalMetadataExtensions[keyof ResultPropertyTemporalMetadataExtensions];
85
- export interface OperatorOutputPropertyContext {
94
+ export interface OperatorOutputPropertyContext extends OperatorHookContext {
86
95
  /** Final alias assigned to this operator's single output column. */
87
96
  readonly name: string;
88
97
  /** Original Schema property when the operator starts from a physical property. */
@@ -95,13 +104,13 @@ export interface OperatorOutputPropertyContext {
95
104
  readonly args: Readonly<Record<string, unknown>>;
96
105
  }
97
106
  /** Context used by operators whose value must be evaluated per time bucket. */
98
- export interface OperatorPeriodEvaluationContext {
107
+ export interface OperatorPeriodEvaluationContext extends OperatorHookContext {
99
108
  readonly logicform: LogicformType;
100
109
  readonly pred: PredItemType;
101
110
  readonly schema: ResolvedSemanticSchema;
102
111
  readonly inputProperty?: ResolvedSemanticProperty;
103
112
  }
104
- export interface OperatorDefaultNameContext {
113
+ export interface OperatorDefaultNameContext extends OperatorHookContext {
105
114
  /** Name produced by the direct pred inputs or localized row label. */
106
115
  readonly operandName: string;
107
116
  /** Name of a direct or nested pred input. */
@@ -115,7 +124,7 @@ export interface OperatorDefaultNameContext {
115
124
  /** Translate a stable message key using the requested locale. */
116
125
  readonly t?: LocaleTranslate;
117
126
  }
118
- export interface OperatorPlanInputContext {
127
+ export interface OperatorPlanInputContext extends OperatorHookContext {
119
128
  /** Canonical property or relation reference supplied as this operator's direct pred. */
120
129
  readonly reference: string;
121
130
  readonly args: Readonly<Record<string, unknown>>;
@@ -128,11 +137,11 @@ export interface OperatorPlannedInput {
128
137
  /** Provider-independent arguments resolved from semantic metadata. */
129
138
  readonly args: Readonly<Record<string, unknown>>;
130
139
  }
131
- export interface OperatorNormalizePredContext {
140
+ export interface OperatorNormalizePredContext extends OperatorHookContext {
132
141
  readonly pred: PredItemType;
133
142
  readonly schema: ResolvedSemanticSchema;
134
143
  }
135
- export interface OperatorPlanExpressionContext {
144
+ export interface OperatorPlanExpressionContext extends OperatorHookContext {
136
145
  readonly pred: PredItemType;
137
146
  readonly input?: Expression;
138
147
  readonly inputProperty?: ResultProperty;
@@ -142,32 +151,32 @@ export interface OperatorPlanExpressionContext {
142
151
  readonly getOperator: (name: string) => OperatorDefinition;
143
152
  readonly planQuery: (query: Readonly<Record<string, unknown>>) => Readonly<Record<string, unknown>>;
144
153
  }
145
- export interface OperatorPeriodBoundaryPolicyContext {
154
+ export interface OperatorPeriodBoundaryPolicyContext extends OperatorHookContext {
146
155
  readonly pred: PredItemType;
147
156
  }
148
157
  export interface OperatorPeriodBoundaryPolicy {
149
158
  readonly boundary: 'start' | 'end';
150
159
  readonly implicit: boolean;
151
160
  }
152
- export interface OperatorValidatePlanContext {
161
+ export interface OperatorValidatePlanContext extends OperatorHookContext {
153
162
  readonly pred: PredItemType;
154
163
  readonly groupByNames: readonly string[];
155
164
  readonly resolveGroupName: (reference: string) => string | undefined;
156
165
  readonly getOperator: (name: string) => OperatorDefinition;
157
166
  }
158
- export interface OperatorValidateGroupbyContext {
167
+ export interface OperatorValidateGroupbyContext extends OperatorHookContext {
159
168
  readonly pred: PredItemType;
160
169
  }
161
- export interface OperatorRewriteLogicformContext {
170
+ export interface OperatorRewriteLogicformContext extends OperatorHookContext {
162
171
  readonly logicform: LogicformType;
163
172
  readonly schema: ResolvedSemanticSchema;
164
173
  /** Resolve operator metadata while rewriting nested expressions. */
165
174
  readonly getOperator?: (name: string) => OperatorDefinition;
166
175
  }
167
- export interface OperatorComponentContext {
168
- /** Fully normalized LogicForm containing this top-level operator projection. */
176
+ export interface OperatorComponentContext extends OperatorHookContext {
177
+ /** Normalized input LogicForm; having, sort, limit, limitBy, and page stay on the merged result. */
169
178
  readonly logicform: LogicformType;
170
- /** Caller-authored normalized LogicForm before executor row policies were added. */
179
+ /** Caller-authored normalized input before executor row policies, with result operations removed. */
171
180
  readonly sourceLogicform?: LogicformType;
172
181
  /** The operator projection for which the component is being built. */
173
182
  readonly pred: PredItemType;
@@ -268,7 +277,7 @@ interface OperatorDefinitionBase {
268
277
  /** Validate semantics that apply only when this Operator is used as a group key. */
269
278
  readonly validateGroupby?: (context: OperatorValidateGroupbyContext) => void;
270
279
  /** The logical planner may fully lower a component, so no executor child query is needed. */
271
- readonly skipComponentExecution?: (context: {
280
+ readonly skipComponentExecution?: (context: OperatorHookContext & {
272
281
  readonly plan: LogicalPlan;
273
282
  }) => boolean;
274
283
  /** Expand high-level operator semantics into ordinary nested LogicForm objects before planning. */
@@ -1,13 +1,14 @@
1
1
  import type { PredItemType } from '../../logicform-types';
2
2
  import type { LogicformType, QueryType } from '../../logicform-types';
3
3
  import type { ResolvedSemanticProperty, ResolvedSemanticSchema } from '../../semantic-types/index';
4
- import type { OperatorDefinition, ResultProperty } from '../../operators/index';
4
+ import type { OperatorDefinition, OperatorExecutionContext, ResultProperty } from '../../operators/index';
5
5
  export interface PlannerSemanticRuleContext {
6
6
  readonly pred: PredItemType;
7
7
  readonly schema: ResolvedSemanticSchema;
8
8
  readonly sourceProperty?: ResolvedSemanticProperty;
9
9
  readonly outputProperty: ResultProperty;
10
10
  readonly operator?: OperatorDefinition;
11
+ readonly executionContext?: OperatorExecutionContext;
11
12
  }
12
13
  export interface PlannerSemanticQueryContext {
13
14
  readonly logicform: LogicformType;
@@ -1,10 +1,10 @@
1
1
  import type { PredItemType } from '../../logicform-types';
2
- import type { OperatorDefinition } from '../../operators/index';
2
+ import type { OperatorDefinition, OperatorExecutionContext } from '../../operators/index';
3
3
  declare const periodBoundaryOperator = "$periodValue";
4
4
  export interface ObservationOperatorPolicy {
5
5
  readonly operator: typeof periodBoundaryOperator;
6
6
  readonly boundary: 'start' | 'end';
7
7
  readonly implicit: boolean;
8
8
  }
9
- export declare const resolveObservationOperatorPolicy: (pred: Pick<PredItemType, "operator" | "args">, operator?: OperatorDefinition) => ObservationOperatorPolicy;
9
+ export declare const resolveObservationOperatorPolicy: (pred: Pick<PredItemType, "operator" | "args">, operator?: OperatorDefinition, executionContext?: OperatorExecutionContext) => ObservationOperatorPolicy;
10
10
  export {};
@@ -50,11 +50,14 @@ export interface ResolvedSemanticProperty extends Omit<SemanticPropertyDraft, 'i
50
50
  export interface SemanticSchemaDraft extends Omit<SchemaTypeDraft, '_id' | 'id' | 'sid' | 'properties' | 'db' | 'from' | 'fromSQL' | 'projections' | keyof SemanticSchemaMetadata | keyof LegacySemanticSchemaMetadata>, SemanticSchemaMetadata {
51
51
  readonly [key: string]: unknown;
52
52
  readonly id: string;
53
+ /** Marks the single Schema whose complete rows are loaded as calendar execution context. */
54
+ readonly is_calendar?: boolean;
53
55
  readonly properties: readonly SemanticPropertyDraft[];
54
56
  }
55
57
  export interface ResolvedSemanticSchema extends Omit<SchemaTypeDraft, '_id' | 'id' | 'sid' | 'properties' | 'db' | 'from' | 'fromSQL' | 'projections' | keyof SemanticSchemaMetadata | keyof LegacySemanticSchemaMetadata>, ResolvedSemanticSchemaMetadata {
56
58
  readonly [key: string]: unknown;
57
59
  readonly id: string;
60
+ readonly is_calendar?: boolean;
58
61
  readonly properties: readonly ResolvedSemanticProperty[];
59
62
  }
60
63
  export interface SemanticTypeNormalizeContext {