semanticdb-v2 2.0.0-alpha.1 → 2.0.0-alpha.3

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 (180) hide show
  1. package/README.md +24 -17
  2. package/dist/cache/redis-query-cache.js +1 -1
  3. package/dist/calendar/constants.d.ts +2 -2
  4. package/dist/compatibility/index.d.ts +1 -1
  5. package/dist/compatibility/logicform.d.ts +1 -7
  6. package/dist/compiler/compile-cte.d.ts +17 -2
  7. package/dist/compiler/index.d.ts +2 -1
  8. package/dist/compiler/shorten-sql.d.ts +1 -1
  9. package/dist/errors.d.ts +2 -0
  10. package/dist/executor/fetch-entities.d.ts +2 -1
  11. package/dist/executor/row-identity.d.ts +2 -1
  12. package/dist/executor/types.d.ts +14 -11
  13. package/dist/index.d.ts +5 -7
  14. package/dist/logicform-types.d.ts +11 -12
  15. package/dist/normalizer/core.d.ts +2 -2
  16. package/dist/normalizer/property-resolve.d.ts +5 -0
  17. package/dist/operators/builtins/constant.d.ts +2 -0
  18. package/dist/operators/builtins/period-value.d.ts +2 -0
  19. package/dist/operators/builtins/scalar-extremum.d.ts +3 -0
  20. package/dist/operators/index.d.ts +1 -1
  21. package/dist/operators/types.d.ts +25 -21
  22. package/dist/physical/clickhouse-provider.d.ts +1 -0
  23. package/dist/physical/mysql-protocol-provider.d.ts +2 -0
  24. package/dist/physical/oracle-provider.d.ts +1 -0
  25. package/dist/physical/postgresql-provider.d.ts +1 -0
  26. package/dist/physical/provider.d.ts +2 -0
  27. package/dist/physical/snowflake-provider.d.ts +1 -0
  28. package/dist/planner/semantics/observation/operator-policy.d.ts +1 -1
  29. package/dist/planner/semantics/observation/types.d.ts +1 -1
  30. package/dist/planner/types.d.ts +10 -2
  31. package/dist/plugins/hierarchy/types.d.ts +3 -2
  32. package/dist/schema/entity-identity.d.ts +1 -1
  33. package/dist/schema-mappings/index.d.ts +3 -1
  34. package/dist/schema-mappings/types.d.ts +9 -8
  35. package/dist/schema-mappings/yiask.d.ts +22 -0
  36. package/dist/semantic-types/index.d.ts +1 -1
  37. package/dist/semantic-types/types.d.ts +14 -2
  38. package/dist/semanticdb.js +3 -0
  39. package/package.json +4 -3
  40. package/dist/cache/expiry.js +0 -1
  41. package/dist/cache/identity.js +0 -1
  42. package/dist/cache/serialization.js +0 -1
  43. package/dist/calendar/constants.js +0 -1
  44. package/dist/calendar/provider-relation-store.js +0 -1
  45. package/dist/calendar/resolver.js +0 -1
  46. package/dist/calendar/system-schemas.js +0 -1
  47. package/dist/compatibility/logicform.js +0 -1
  48. package/dist/compiler/compile-cte.js +0 -1
  49. package/dist/compiler/compile-plan.js +0 -1
  50. package/dist/compiler/shorten-sql.js +0 -2
  51. package/dist/custom-functions/custom-functions.d.ts +0 -6
  52. package/dist/custom-functions/custom-functions.js +0 -1
  53. package/dist/custom-functions/index.d.ts +0 -3
  54. package/dist/custom-functions/operator-adapter.d.ts +0 -12
  55. package/dist/custom-functions/operator-adapter.js +0 -1
  56. package/dist/custom-functions/types.d.ts +0 -62
  57. package/dist/errors.js +0 -1
  58. package/dist/executor/compatibility.js +0 -1
  59. package/dist/executor/components.js +0 -1
  60. package/dist/executor/connection-registry.js +0 -1
  61. package/dist/executor/evaluate.js +0 -1
  62. package/dist/executor/execute-query.js +0 -1
  63. package/dist/executor/execute.js +0 -1
  64. package/dist/executor/fetch-entities.js +0 -1
  65. package/dist/executor/result-hydrator/entity-loader.js +0 -1
  66. package/dist/executor/result-hydrator/format-values.js +0 -1
  67. package/dist/executor/result-hydrator/hydrate-result.js +0 -1
  68. package/dist/executor/result-hydrator/missing-entity.js +0 -1
  69. package/dist/executor/result-hydrator/populate-entities.js +0 -1
  70. package/dist/executor/row-identity.js +0 -1
  71. package/dist/index.js +0 -1
  72. package/dist/logicform-types.js +0 -1
  73. package/dist/normalizer/core.js +0 -1
  74. package/dist/normalizer/default-pred-name.js +0 -1
  75. package/dist/normalizer/entity-id.js +0 -1
  76. package/dist/normalizer/groupby.js +0 -1
  77. package/dist/normalizer/normalize-logicform.js +0 -1
  78. package/dist/normalizer/pagination.js +0 -1
  79. package/dist/normalizer/pred-query-name.js +0 -1
  80. package/dist/normalizer/preds.js +0 -1
  81. package/dist/normalizer/query.js +0 -1
  82. package/dist/normalizer/version.js +0 -1
  83. package/dist/operators/builtins/abs.js +0 -1
  84. package/dist/operators/builtins/accumulate.js +0 -1
  85. package/dist/operators/builtins/add.js +0 -1
  86. package/dist/operators/builtins/arithmetic.js +0 -1
  87. package/dist/operators/builtins/average-per-period.js +0 -1
  88. package/dist/operators/builtins/avg.js +0 -1
  89. package/dist/operators/builtins/case.js +0 -1
  90. package/dist/operators/builtins/concat.js +0 -1
  91. package/dist/operators/builtins/count-distinct.js +0 -1
  92. package/dist/operators/builtins/count.js +0 -1
  93. package/dist/operators/builtins/date-bucket.js +0 -1
  94. package/dist/operators/builtins/divide.js +0 -1
  95. package/dist/operators/builtins/index.js +0 -1
  96. package/dist/operators/builtins/max.js +0 -1
  97. package/dist/operators/builtins/min.js +0 -1
  98. package/dist/operators/builtins/multiply.js +0 -1
  99. package/dist/operators/builtins/newly.js +0 -1
  100. package/dist/operators/builtins/period-boundary.js +0 -1
  101. package/dist/operators/builtins/period-difference.js +0 -1
  102. package/dist/operators/builtins/period-growth.js +0 -1
  103. package/dist/operators/builtins/period-name.js +0 -1
  104. package/dist/operators/builtins/period-shift.js +0 -1
  105. package/dist/operators/builtins/rank.js +0 -1
  106. package/dist/operators/builtins/row-number.js +0 -1
  107. package/dist/operators/builtins/share-of-total.js +0 -1
  108. package/dist/operators/builtins/sql.js +0 -1
  109. package/dist/operators/builtins/substring.js +0 -1
  110. package/dist/operators/builtins/subtract.js +0 -1
  111. package/dist/operators/builtins/sum.js +0 -1
  112. package/dist/operators/builtins/time-range.js +0 -1
  113. package/dist/operators/groupby.js +0 -1
  114. package/dist/operators/index.js +0 -1
  115. package/dist/operators/registry.js +0 -1
  116. package/dist/operators/sql-expression.js +0 -1
  117. package/dist/permissions/permissions.js +0 -1
  118. package/dist/physical/clickhouse-provider.js +0 -1
  119. package/dist/physical/connection.js +0 -1
  120. package/dist/physical/display-query.js +0 -1
  121. package/dist/physical/doris-provider.js +0 -1
  122. package/dist/physical/mysql-compatible-sql.js +0 -1
  123. package/dist/physical/mysql-protocol-provider.js +0 -1
  124. package/dist/physical/mysql-provider.js +0 -1
  125. package/dist/physical/oracle-provider.js +0 -1
  126. package/dist/physical/postgresql-provider.js +0 -1
  127. package/dist/physical/snowflake-provider.js +0 -1
  128. package/dist/physical/starrocks-provider.js +0 -1
  129. package/dist/planner/build-lineage.js +0 -1
  130. package/dist/planner/create-logical-plan.js +0 -1
  131. package/dist/planner/select-schema-mapping.js +0 -1
  132. package/dist/planner/semantics/lifecycle/classification.js +0 -1
  133. package/dist/planner/semantics/lifecycle/query-policy.js +0 -1
  134. package/dist/planner/semantics/lifecycle/rule.js +0 -1
  135. package/dist/planner/semantics/observation/classification.js +0 -1
  136. package/dist/planner/semantics/observation/operator-policy.js +0 -1
  137. package/dist/planner/semantics/observation/rule.js +0 -1
  138. package/dist/planner/semantics/registry-defaults.js +0 -1
  139. package/dist/planner/semantics/registry.js +0 -1
  140. package/dist/planner/types.js +0 -1
  141. package/dist/plugins/hierarchy/compatibility.js +0 -1
  142. package/dist/plugins/hierarchy/entity-identity.js +0 -1
  143. package/dist/plugins/hierarchy/index.js +0 -1
  144. package/dist/plugins/hierarchy/operator.js +0 -1
  145. package/dist/plugins/hierarchy/resolve-schema.js +0 -1
  146. package/dist/plugins/index.js +0 -1
  147. package/dist/schema/entity-identity.js +0 -1
  148. package/dist/schema/resolve-property-path.js +0 -1
  149. package/dist/schema/schema-registry.js +0 -1
  150. package/dist/schema-mappings/freshness.js +0 -1
  151. package/dist/schema-mappings/registry.js +0 -1
  152. package/dist/semantic-types/builtins/boolean.js +0 -1
  153. package/dist/semantic-types/builtins/category.js +0 -1
  154. package/dist/semantic-types/builtins/currency.js +0 -1
  155. package/dist/semantic-types/builtins/date.js +0 -1
  156. package/dist/semantic-types/builtins/duration.js +0 -1
  157. package/dist/semantic-types/builtins/end-date.js +0 -1
  158. package/dist/semantic-types/builtins/entity.js +0 -1
  159. package/dist/semantic-types/builtins/file.js +0 -1
  160. package/dist/semantic-types/builtins/human-name.js +0 -1
  161. package/dist/semantic-types/builtins/id.js +0 -1
  162. package/dist/semantic-types/builtins/image.js +0 -1
  163. package/dist/semantic-types/builtins/index.js +0 -1
  164. package/dist/semantic-types/builtins/int.js +0 -1
  165. package/dist/semantic-types/builtins/name.js +0 -1
  166. package/dist/semantic-types/builtins/number.js +0 -1
  167. package/dist/semantic-types/builtins/object.js +0 -1
  168. package/dist/semantic-types/builtins/order.js +0 -1
  169. package/dist/semantic-types/builtins/percentage.js +0 -1
  170. package/dist/semantic-types/builtins/start-date.js +0 -1
  171. package/dist/semantic-types/builtins/string.js +0 -1
  172. package/dist/semantic-types/builtins/timestamp.js +0 -1
  173. package/dist/semantic-types/index.js +0 -1
  174. package/dist/semantic-types/primal-types/date.js +0 -1
  175. package/dist/semantic-types/primal-types/index.js +0 -1
  176. package/dist/semantic-types/registry.js +0 -1
  177. package/dist/semantic-types/resolve-schema.js +0 -1
  178. package/dist/semantic-types/validate-resolved-schema.js +0 -1
  179. package/dist/utils/clone.js +0 -1
  180. /package/dist/operators/builtins/{period-boundary.d.ts → period-boundary-expression.d.ts} +0 -0
package/README.md CHANGED
@@ -8,16 +8,16 @@ SemanticDB creates the matching provider and owns its connection lifecycle.
8
8
 
9
9
  ```ts
10
10
  import { Logicform } from 'semanticdb-v2';
11
- import { SchemaMappingRegistry } from 'semanticdb-v2';
12
11
 
13
- const schemaMappings = new SchemaMappingRegistry([
12
+ const schemaMappings = [
14
13
  {
15
14
  schemaId: 'sales',
16
15
  connectionId: 'analytics',
17
16
  source: 'analytics.sales_detail',
17
+ mappings: [],
18
18
  freshness: { mode: 'ttl', ttlSeconds: 300 },
19
19
  },
20
- ]);
20
+ ];
21
21
 
22
22
  const response = await Logicform.execute(
23
23
  {
@@ -49,7 +49,7 @@ const response = await Logicform.execute(
49
49
  );
50
50
  ```
51
51
 
52
- Every executable LogicForm, including LogicForms used as subqueries, must declare `version`. This
52
+ Every executable LogicForm, including LogicForm objects used as subqueries, must declare `version`. This
53
53
  SDK accepts semantic versions greater than or equal to `2.0`; missing, malformed, or older versions
54
54
  fail with `UNSUPPORTED_LOGICFORM_VERSION` before Schema resolution or database access. A relation
55
55
  query shaped as `{ schema, query }` is part of its parent LogicForm and inherits the parent's version.
@@ -69,7 +69,7 @@ operators.register({
69
69
  });
70
70
  ```
71
71
 
72
- The same locale applies to `preds`, `groupby`, nested expressions, custom-function components,
72
+ The same locale applies to `preds`, `groupby`, nested expressions, custom-function subqueries,
73
73
  and entity-population queries. A PredItem's normalized `query` is included in its
74
74
  generated name, for example `门店为上海的销售额合计`. Operator-specific `args` also participate
75
75
  through each operator's `defaultName()`; period operators distinguish同比、环比 and other offsets.
@@ -78,7 +78,8 @@ An explicitly authored `name` is preserved unchanged.
78
78
  `entity_id` identifies one entity by `hierarchy.property` on hierarchy Schemas and by the unique
79
79
  `type: 'ID'` property on other Schemas. Normalization adds that identity filter unless the query
80
80
  already contains one, in which case the explicit query wins. The legacy value `placeholder` is
81
- preserved as entity context but never becomes a SQL filter. This also applies to relation queries
81
+ preserved as entity context but never becomes a SQL filter. String IDs and safe-integer IDs are
82
+ accepted and retain their original type. This also applies to relation queries
82
83
  shaped as `{ schema, query, entity_id }`. `representation` is presentation metadata for frontend
83
84
  consumers and does not change normalization, planning, or execution. See
84
85
  [Hierarchy plugin](docs/hierarchy-plugin.md) for Schema configuration, `$hierarchyLevel`, legacy
@@ -108,6 +109,8 @@ SQL string for diagnostics:
108
109
  ```ts
109
110
  interface ExecutedSql {
110
111
  type: 'semantic-resolution' | 'computation';
112
+ explain: string;
113
+ logicform: LogicformType;
111
114
  sql: string;
112
115
  parameters: readonly unknown[];
113
116
  displaySql: string;
@@ -115,7 +118,7 @@ interface ExecutedSql {
115
118
  ```
116
119
 
117
120
  `semantic-resolution` identifies supporting SQL used to resolve semantic input or output, such as
118
- latest-data-date lookup and object entity population. `computation` identifies SQL that calculates
121
+ time-watermark resolution and object entity population. `computation` identifies SQL that calculates
119
122
  the requested LogicForm result. `sqls` includes every physical SQL involved in the execution; an
120
123
  entry remains visible when its result is served by the query cache.
121
124
 
@@ -165,20 +168,20 @@ await Logicform.execute(logicform, {
165
168
 
166
169
  When `permissions` is omitted, execution remains unrestricted. When it is present, its Schema keys
167
170
  are the table allowlist. `rowPermissions` is always combined with the caller query using `AND`,
168
- including internal latest-data-date queries, related-table joins, and object population queries.
171
+ including internal time-watermark queries, related-table joins, and object population queries.
169
172
  `columnPermissions.whitelist` accepts property names or IDs and restricts caller projections,
170
173
  filters, grouping, operator inputs, and relation paths. A row policy may still use a non-whitelisted
171
174
  column as an internal filter. If an ID is not whitelisted, SemanticDB generates the executor-owned
172
175
  result-row `_id` instead of exposing the physical ID as that identity.
173
176
 
174
- ### Custom composite metrics
177
+ ### Component operators
175
178
 
176
- Pass legacy-compatible `genComponents`, `mergeComponents`, and `genMergeSQL` definitions through
177
- `ExecuteOptions.customFunctions`. JavaScript merge supports async callbacks; SQL merge compiles
178
- components into CTEs. `Logicform.genComponents()` expands the same definitions into an indicator
179
- tree without accessing a database. Cross-Schema components independently pass table, row, and
180
- column permissions. See [Custom composite metrics](docs/custom-functions.md) for the complete
181
- contract, merge-mode selection, and trusted function-string behavior.
179
+ Composite metrics are regular `OperatorDefinition` values with `kind: 'component'`. Their
180
+ `createComponent` hook can return query components merged through a CTE or JavaScript. Register
181
+ them in the same `OperatorRegistry` as scalar and aggregate operators. Operator names are free-form;
182
+ the `$` prefix is a convention used by built-in operators, not a requirement.
183
+
184
+ See [Register an operator](docs/register-operator.md) for the component contract.
182
185
 
183
186
  The root entry point accepts a `connections` array of `DatabaseConnection` items. Every item has a unique `id`; set `kind` to `mysql`,
184
187
  `doris`, `starrocks`, `clickhouse`, `snowflake`, `oracle`, or `postgresql`, then add that driver's
@@ -186,6 +189,10 @@ native connection fields directly on the item. Each Schema Mapping selects an it
186
189
  `connectionId`. SemanticDB lazily creates and reuses the matching internal provider. Call
187
190
  `await Logicform.close()` during application shutdown to close every connection pool and session.
188
191
 
192
+ MySQL-compatible providers default to 30 connections, at most 10 idle connections, a 60-second
193
+ idle timeout, and TCP keepalive. Native `mysql2` pool options on the connection item override these
194
+ defaults.
195
+
189
196
  ### PostgreSQL connection
190
197
 
191
198
  PostgreSQL uses the official `pg` pool and PostgreSQL-native `$1`, `$2` parameters:
@@ -306,7 +313,7 @@ comments, or parameter placeholders. Property UDFs do not support the legacy `fu
306
313
 
307
314
  ### Query cache
308
315
 
309
- All compiled provider queries, including the internal latest-data-date query, can share one
316
+ All compiled provider queries, including the internal time-watermark query, can share one
310
317
  caller-owned query cache. Redis is published from `semanticdb-v2/cache/redis`; cache identity
311
318
  includes namespace, provider, SQL, and parameters. Physical expiration belongs to each Schema
312
319
  mapping's `freshness` policy. See [Query cache and Redis](docs/query-cache.md).
@@ -442,7 +449,7 @@ npm run debug
442
449
  - `$and` and `$or`, HAVING, sorting, row-count and percentage pagination, and per-group `limitBy`
443
450
  - Query-level and output-column lineage
444
451
  - Multi-level scalar and array object relation paths, array groupby, and batched entity population
445
- - Nested `from` LogicForms compiled as parameterized derived tables
452
+ - Nested `from` LogicForm objects compiled as parameterized derived tables
446
453
 
447
454
  Exports and metadata persistence are intentionally deferred. Directly selected array-object
448
455
  properties are populated without expanding the root result rows.
@@ -1 +1 @@
1
- import{createClient as y}from"redis";import{queryCacheIdentityHash as d,sourceCacheIndexHash as f}from"./identity.js";import{deserializeQueryRows as w,serializeQueryRows as x}from"./serialization.js";const m=Number.MAX_SAFE_INTEGER;class u{#e;#t;#s;constructor(e,t={}){this.#e=e,this.#t=t.keyPrefix??"semanticdb:cache",this.#s=t.ownsClient??!1}#r(e){return`${this.#t}:query:${d(e)}`}#i(e,t){return`${this.#t}:source:${f(e,t)}`}async get(e){const t=await this.#e.get(this.#r(e));if(t!==null)return w(t)}async set(e,t,i){const s=this.#r(e),a=x(t),c=i.expiresAt?.getTime(),l=c??m,n=this.#e.multi();c===void 0?n.set(s,a):n.set(s,a,{PXAT:c});for(const h of new Set(i.sources)){const o=this.#i(e.namespace,h);n.zRemRangeByScore(o,0,Date.now()),n.zAdd(o,{score:l,value:s})}await n.exec()}async invalidateSource(e,t){const i=this.#i(e,t),s=await this.#e.zRange(i,0,-1);s.length>0&&await this.#e.del(s),await this.#e.del(i)}async close(){this.#s&&await this.#e.close()}}const C=async(r={})=>{const e=y(r.url?{url:r.url}:{});return e.on("error",()=>{}),await e.connect(),new u(e,{...r.keyPrefix?{keyPrefix:r.keyPrefix}:{},ownsClient:!0})};export{u as RedisQueryCache,C as createRedisQueryCache};
1
+ import{createClient as b}from"redis";import{createHash as g}from"node:crypto";const a=e=>e===void 0?{type:"undefined"}:typeof e=="bigint"?{type:"bigint",value:e.toString()}:typeof e=="number"&&!Number.isFinite(e)?{type:"number",value:String(e)}:e instanceof Date?{type:"date",value:e.toISOString()}:Array.isArray(e)?e.map(a):e&&typeof e=="object"?Object.fromEntries(Object.entries(e).sort(([t],[r])=>t.localeCompare(r)).map(([t,r])=>[t,a(r)])):e,d=e=>g("sha256").update(JSON.stringify(a(e))).digest("hex"),A=e=>d({namespace:e.namespace,provider:e.provider,sql:e.sql,parameters:e.parameters}),S=(e,t)=>d({namespace:e,source:t}),o=e=>e===void 0?{type:"undefined"}:typeof e=="bigint"?{type:"bigint",value:e.toString()}:typeof e=="number"&&!Number.isFinite(e)?{type:"number",value:String(e)}:e instanceof Date?{type:"date",value:e.toISOString()}:Array.isArray(e)?{type:"array",value:e.map(o)}:e&&typeof e=="object"?{type:"object",value:Object.entries(e).map(([t,r])=>[t,o(r)])}:e,y=e=>{if(e===null||typeof e!="object")return e;switch(e.type){case"undefined":return;case"bigint":return BigInt(e.value);case"number":return Number(e.value);case"date":return new Date(e.value);case"array":return e.value.map(y);case"object":return Object.fromEntries(e.value.map(([t,r])=>[t,y(r)]))}},w=e=>JSON.stringify(o(e)),x=e=>{const t=y(JSON.parse(e));if(!(!Array.isArray(t)||t.some(r=>!r||typeof r!="object"||Array.isArray(r))))return t},l=Number.MAX_SAFE_INTEGER;class p{#e;#t;#r;constructor(t,r={}){this.#e=t,this.#t=r.keyPrefix??"semanticdb:cache",this.#r=r.ownsClient??!1}#n(t){return`${this.#t}:query:${A(t)}`}#i(t,r){return`${this.#t}:source:${S(t,r)}`}async get(t){const r=await this.#e.get(this.#n(t));if(r!==null)return x(r)}async set(t,r,i){const n=this.#n(t),f=w(r),c=i.expiresAt?.getTime(),m=c??l,s=this.#e.multi();c===void 0?s.set(n,f):s.set(n,f,{PXAT:c});for(const h of new Set(i.sources)){const u=this.#i(t.namespace,h);s.zRemRangeByScore(u,0,Date.now()),s.zAdd(u,{score:m,value:n})}await s.exec()}async invalidateSource(t,r){const i=this.#i(t,r),n=await this.#e.zRange(i,0,-1);n.length>0&&await this.#e.del(n),await this.#e.del(i)}async close(){this.#r&&await this.#e.close()}}const j=async(e={})=>{const t=b(e.url?{url:e.url}:{});return t.on("error",()=>{}),await t.connect(),new p(t,{...e.keyPrefix?{keyPrefix:e.keyPrefix}:{},ownsClient:!0})};export{p as RedisQueryCache,j as createRedisQueryCache};
@@ -2,6 +2,6 @@
2
2
  export declare const CALENDAR_DATES_TABLE = "semanticdb_calendar_dates";
3
3
  export declare const CALENDAR_RELATIONS_TABLE = "semanticdb_calendar_relations";
4
4
  export declare const CALENDAR_SYSTEM_SCHEMA_IDS: {
5
- readonly dates: "__semanticdb_calendar_dates";
6
- readonly relations: "__semanticdb_calendar_relations";
5
+ readonly dates: "__sdb_calendar_dates";
6
+ readonly relations: "__sdb_calendar_relations";
7
7
  };
@@ -1,2 +1,2 @@
1
- export { assertNoLegacyLogicformFields, normalizeLegacyLogicform, splitLegacySchemas, } from './logicform';
1
+ export { assertNoLegacyLogicformFields, normalizeLegacyLogicform, } from './logicform';
2
2
  export { normalizeSchemas } from '../executor/compatibility';
@@ -1,13 +1,7 @@
1
1
  import type { LogicformType } from '../logicform-types';
2
2
  type SchemaRegistry = Readonly<Record<string, unknown>>;
3
3
  /** Converts a legacy LogicForm tree into the v2 wire shape without mutating input. */
4
- export declare const normalizeLegacyLogicform: (logicform: unknown) => LogicformType;
5
- /**
6
- * Converts the legacy `pred.schema` fan-out into v2 composition. The planner
7
- * intentionally rejects cross-schema PredItems, so this has to happen before
8
- * the v2 normalizer sees the tree.
9
- */
10
- export declare const splitLegacySchemas: (logicform: LogicformType, schemas?: SchemaRegistry) => LogicformType;
4
+ export declare const normalizeLegacyLogicform: (logicform: unknown, schemas?: SchemaRegistry) => LogicformType;
11
5
  /** Rejects legacy wire fields when a caller explicitly declares a v2 LogicForm. */
12
6
  export declare const assertNoLegacyLogicformFields: (logicform: unknown) => void;
13
7
  export {};
@@ -1,4 +1,4 @@
1
- import type { OperatorCteCalculation, OperatorGroupKeyShift } from '../operators/index';
1
+ import type { OperatorComponentCalculation, OperatorGroupKeyShift } from '../operators/index';
2
2
  import type { CoreComputeProvider } from '../physical/index';
3
3
  import type { LogicalPlan } from '../planner/index';
4
4
  import type { CompiledQuery } from './types';
@@ -9,4 +9,19 @@ export interface PreparedCteComponent {
9
9
  readonly groupKeyShifts?: readonly OperatorGroupKeyShift[];
10
10
  readonly joinKeys?: readonly string[];
11
11
  }
12
- export declare const compileCteCalculation: (calculation: OperatorCteCalculation, components: readonly PreparedCteComponent[], outputPlan: LogicalPlan, provider: CoreComputeProvider, operators: OperatorRegistry) => CompiledQuery;
12
+ /** A compiled top-level execution unit that can be joined into one SQL query. */
13
+ export interface PreparedCteQuery {
14
+ readonly plan: LogicalPlan;
15
+ readonly compiled: CompiledQuery;
16
+ /** Result projection names exposed by this execution unit (excluding groups). */
17
+ readonly outputs: readonly string[];
18
+ }
19
+ /**
20
+ * Combine independent SQL execution units into one statement.
21
+ *
22
+ * Component operators are compiled independently because their input ranges can
23
+ * differ (for example, current and previous periods). Keeping each unit as a
24
+ * CTE preserves those ranges while allowing the provider to execute one query.
25
+ */
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;
@@ -1,4 +1,5 @@
1
1
  export { compilePlan } from './compile-plan';
2
- export { compileCteCalculation } from './compile-cte';
2
+ export { compileCteCalculation, compileCteQueries } from './compile-cte';
3
+ export type { PreparedCteQuery } from './compile-cte';
3
4
  export { shortenSQL } from './shorten-sql';
4
5
  export type { CompiledQuery } from './types';
@@ -1,2 +1,2 @@
1
- /** Conservatively remove unused aliased columns from nested SELECT projections. */
1
+ /** Conservatively simplify nested SELECT projections and pass-through views. */
2
2
  export declare const shortenSQL: (sql: string) => string;
package/dist/errors.d.ts CHANGED
@@ -2,4 +2,6 @@ export declare class SemanticDBError extends Error {
2
2
  readonly code: string;
3
3
  readonly details?: Readonly<Record<string, unknown>> | undefined;
4
4
  constructor(code: string, message: string, details?: Readonly<Record<string, unknown>> | undefined);
5
+ /** Return the user-facing message for an execution locale. */
6
+ localizedMessage(locale?: string): string;
5
7
  }
@@ -1,3 +1,4 @@
1
+ import type { LogicformType } from '../logicform-types';
1
2
  import type { OperatorRegistry } from '../operators/index';
2
3
  import type { DataRow } from '../physical/index';
3
4
  import type { SchemaMappingRegistry } from '../schema-mappings/index';
@@ -20,7 +21,7 @@ interface FetchEntityOptions {
20
21
  readonly provider: CoreComputeProvider;
21
22
  readonly cache?: QueryCacheExecutionOptions;
22
23
  readonly signal?: AbortSignal;
23
- readonly onCompiled?: (compiled: CompiledQuery) => void;
24
+ readonly onCompiled?: (compiled: CompiledQuery, logicform: LogicformType) => void;
24
25
  }
25
26
  export declare const fetchEntities: (request: EntityFetchRequest, options: FetchEntityOptions) => Promise<DataRow[]>;
26
27
  export {};
@@ -1,4 +1,5 @@
1
1
  import type { DataRow } from '../physical/index';
2
2
  import type { RowIdentityPlan } from '../planner/index';
3
- export declare const groupRowIdentity: (row: DataRow, names: readonly string[]) => string;
3
+ export declare const identityPart: (value: unknown) => string;
4
+ export declare const groupRowIdentity: (row: DataRow, names: readonly string[], separator?: string, nullLabel?: string) => string;
4
5
  export declare const addRowIdentities: (rows: readonly DataRow[], identity: RowIdentityPlan) => DataRow[];
@@ -2,12 +2,11 @@ import type { 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';
5
- import type { SchemaMappingRegistry } from '../schema-mappings/index';
6
- import type { ResolvedSemanticSchema, SemanticSchemaDraft, SemanticTypeRegistry } from '../semantic-types/index';
7
- import type { LogicformType } from '../logicform-types';
5
+ import type { SchemaMappingDefinition, SchemaMappingRegistry } from '../schema-mappings/index';
6
+ import type { ResolvedSemanticSchema, SemanticSchemaDraft, SemanticTypeRegistry, TimeWatermarkPolicy } from '../semantic-types/index';
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
- import type { CustomFunctions } from '../custom-functions/index';
11
10
  import type { SemanticDBPlugin } from '../plugins/index';
12
11
  export type ExecuteProgressEvent = {
13
12
  readonly stage: 'started';
@@ -56,7 +55,6 @@ export type ExecuteProgressEvent = {
56
55
  export type ProgressCallback = (event: ExecuteProgressEvent) => void | Promise<void>;
57
56
  interface ExecuteBaseOptions {
58
57
  readonly schemas: Readonly<Record<string, SemanticSchemaDraft>>;
59
- readonly schemaMappings: SchemaMappingRegistry;
60
58
  readonly semanticTypes?: SemanticTypeRegistry;
61
59
  readonly operators?: OperatorRegistry;
62
60
  /** Caller-owned capability plugins appended to the built-in plugin set for this execution. */
@@ -65,22 +63,23 @@ interface ExecuteBaseOptions {
65
63
  readonly locale?: string;
66
64
  /** Table, row, and column permissions for this execution. */
67
65
  readonly permissions?: Permissions;
68
- /** Legacy-compatible dynamically supplied composite metric definitions. */
69
- readonly customFunctions?: CustomFunctions;
70
- /** Third argument passed to mergeComponents/genMergeSQL callbacks. */
71
- readonly customFunctionConfig?: Readonly<Record<string, unknown>>;
72
66
  /** Optional caller-owned cache shared across executions. */
73
67
  readonly cache?: QueryCacheExecutionOptions;
74
68
  readonly onProgress?: ProgressCallback;
75
69
  readonly signal?: AbortSignal;
70
+ /** Default time watermark policy; Schema and Property policies override it. */
71
+ readonly timeWatermark?: TimeWatermarkPolicy;
76
72
  }
77
73
  export interface ExecuteOptions extends ExecuteBaseOptions {
74
+ /** Physical mappings supplied as JSON definitions. */
75
+ readonly schemaMappings: readonly SchemaMappingDefinition[];
78
76
  /** Database connections addressable by SchemaMappingDefinition.connectionId. */
79
77
  readonly connections: readonly DatabaseConnection[];
80
78
  }
81
79
  /** Internal execution seam used by executor tests after a provider has been resolved. */
82
80
  export interface InternalExecuteOptions extends ExecuteBaseOptions {
83
81
  readonly provider: CoreComputeProvider;
82
+ readonly schemaMappings: SchemaMappingRegistry;
84
83
  /** Selected connection for public execution; omitted only by internal provider tests. */
85
84
  readonly connectionId?: string;
86
85
  }
@@ -88,7 +87,7 @@ export interface ExecuteSuccessResult {
88
87
  readonly result: DataRow[];
89
88
  /** Schema describing the computed result rows. */
90
89
  readonly schema: ResolvedSemanticSchema;
91
- readonly normedLogicform: LogicformType;
90
+ readonly normedLogicform: PublicLogicformType;
92
91
  readonly sqls: readonly ExecutedSql[];
93
92
  readonly lineage: QueryLineage;
94
93
  readonly provider: CoreComputeProvider['kind'];
@@ -98,7 +97,7 @@ export interface ExecuteFailureResult {
98
97
  readonly error: string;
99
98
  readonly result: readonly [];
100
99
  readonly schema?: ResolvedSemanticSchema;
101
- readonly normedLogicform: LogicformType;
100
+ readonly normedLogicform: PublicLogicformType;
102
101
  readonly sqls: readonly ExecutedSql[];
103
102
  readonly provider?: CoreComputeProvider['kind'];
104
103
  readonly lineage?: QueryLineage;
@@ -108,6 +107,10 @@ export type ExecutedSqlType = 'computation' | 'semantic-resolution';
108
107
  export interface ExecutedSql {
109
108
  /** Why this SQL participates in the LogicForm execution. */
110
109
  readonly type: ExecutedSqlType;
110
+ /** Human-readable, localized explanation of why this SQL is executed. */
111
+ readonly explain: string;
112
+ /** Normalized LogicForm represented by this SQL statement. */
113
+ readonly logicform: PublicLogicformType;
111
114
  /** Parameterized SQL used for provider execution and cache identity. */
112
115
  readonly sql: string;
113
116
  readonly parameters: SqlParameters;
package/dist/index.d.ts CHANGED
@@ -1,26 +1,24 @@
1
1
  export declare const Logicform: Readonly<{
2
2
  execute: (inputLogicform: import("./logicform-types").LogicformType, inputOptions: import(".").ExecuteOptions) => Promise<import(".").ExecuteResult>;
3
3
  close: () => Promise<void>;
4
- genComponents: (pred: import("./logicform-types").PredItemType, options: import(".").GenMetricComponentsOptions) => import(".").MetricComponentNode;
5
4
  }>;
6
5
  export { SemanticDBError } from './errors';
7
6
  export { builtinSemanticTypes, createSemanticTypeRegistry, resolveSchema, SemanticTypeRegistry, validateResolvedSchema, } from './semantic-types/index';
8
7
  export { builtinOperators, createOperatorRegistry, OperatorRegistry, } from './operators/index';
9
8
  export type { LegacySchemaPluginContext, SchemaMetadataPlugin, SemanticDBPlugin, } from './plugins/index';
10
- export { SchemaMappingRegistry, } from './schema-mappings/index';
11
- export type { AbsoluteDateValue, CompareOperator, CalendarDateValue, DateTimeValue, DateValue, ExpressionItemType, LogicformType, PeriodShiftTime, PredItemType, QueryLogicalOperand, RecursiveQueryType, RelationQueryType, QueryType, QueryValueType, QueryValueTypeWithCompareOperator, RelativeDateValue, RepresentationType, } from './logicform-types';
9
+ export { SchemaMappingRegistry, fromYiAskSchemaMapping, } from './schema-mappings/index';
10
+ export type { AbsoluteDateValue, CompareOperator, CalendarDateValue, DateTimeValue, DateValue, EntityIdType, ExpressionItemType, LogicformType, PublicLogicformType, PeriodShiftTime, PredItemType, QueryLogicalOperand, RecursiveQueryType, RelationQueryType, QueryType, QueryValueType, QueryValueTypeWithCompareOperator, RelativeDateValue, RepresentationType, } from './logicform-types';
12
11
  export { CALENDAR_DATES_TABLE, CALENDAR_RELATIONS_TABLE, CALENDAR_SYSTEM_SCHEMA_IDS, calendarSystemSchemas, ProviderCalendarRelationStore, resolveCalendarPeriod, resolveCalendarPeriodFromStore, selectCalendarDates, } from './calendar/index';
13
12
  export type { CalendarAlignment, CalendarComparison, CalendarDateRow, CalendarRelation, CalendarRelationRow, ResolvedCalendarPeriod, } from './calendar/index';
14
13
  export type { CalendarRelationStore } from './calendar/index';
15
- export type { PrimalType, PropertySqlDefinition, ResolvedSemanticProperty, ResolvedSemanticSchema, SemanticTypeNormalizeContext, SemanticPropertyDraft, SemanticSchemaDraft, SemanticTypeDefinition, SemanticTypeResultContext, SemanticTypeResultProperty, TemporalSemantics, TimeGranularity, } from './semantic-types/index';
14
+ export type { PrimalType, PropertySqlDefinition, ResolvedSemanticProperty, ResolvedSemanticSchema, SemanticTypeNormalizeContext, SemanticPropertyDraft, SemanticSchemaDraft, SemanticTypeDefinition, SemanticTypeResultContext, SemanticTypeResultProperty, TemporalSemantics, TimeGranularity, TimeWatermarkPolicy, } from './semantic-types/index';
16
15
  export type { HierarchyDefinition, HierarchyLevelDefinition, ResolvedHierarchyDefinition, } from './plugins/hierarchy/index';
17
16
  export type { DataRow, SqlParameters, DatabaseConnection, } from './physical/index';
18
- export type { OperatorDefinition, OperatorDefaultNameContext, OperatorComponentContext, OperatorCteCalculation, OperatorCteComponent, OperatorCteSqlContext, OperatorExecutionComponent, OperatorPlanInputContext, OperatorPlannedInput, OperatorGroupKeyShift, OperatorJavaScriptCalculation, OperatorQueryComponent, OperatorEvaluateContext, OperatorOutputPropertyContext, OperatorSqlCapabilities, OperatorSqlContext, ResultProperty, ResultPropertyTemporalMetadata, } from './operators/index';
19
- export type { SchemaMappingDefinition, SchemaMappingPredDefinition, SchemaMappingPredMatch, SourceFreshnessPolicy, } from './schema-mappings/index';
17
+ export type { OperatorDefinition, OperatorDefaultNameContext, OperatorComponentContext, OperatorComponentCalculation, OperatorComponentQuery, OperatorExecutionComponent, OperatorPlanInputContext, OperatorPlannedInput, OperatorGroupKeyShift, OperatorJavaScriptCalculation, OperatorQueryComponent, OperatorEvaluateContext, OperatorOutputPropertyContext, OperatorSqlCapabilities, OperatorSqlContext, ResultProperty, ResultPropertyTemporalMetadata, } from './operators/index';
18
+ export type { SchemaMappingDefinition, SchemaMappingItem, SchemaMappingPredDefinition, SchemaMappingPredMatch, SourceFreshnessPolicy, YiAskSchemaMappingItem, YiAskSchemaMappingRecord, } from './schema-mappings/index';
20
19
  export type { QueryCache, QueryCacheExecutionOptions, QueryCacheIdentity, QueryCacheWriteOptions, } from './cache/index';
21
20
  export type { ExecuteOptions, ExecuteFailureResult, ExecuteProgressEvent, ExecuteResult, ExecuteSuccessResult, ExecutedSql, ExecutedSqlType, PartialExecuteResult, ProgressCallback, } from './executor/index';
22
21
  export type { ColumnPermissions, Permissions, SchemaPermissions, } from './permissions/index';
23
- export type { CustomFunctionColumnProperty, CustomFunctionDefinition, CustomFunctionHelpers, CustomFunctionSqlContext, CustomFunctions, GenComponents, GenComponentsContext, GenMergeSQL, GenMetricComponentsOptions, MergeComponents, MetricComponentNode, } from './custom-functions/index';
24
22
  export type { CreateLogicalPlanOptions, LogicalPlan, QueryLineage, } from './planner/index';
25
23
  export { PlannerSemanticRegistry, createPlannerSemanticRegistry, } from './planner/index';
26
24
  export type { PlannerSemanticResolution, PlannerSemanticQueryContext, PlannerSemanticRule, PlannerSemanticRuleContext, } from './planner/index';
@@ -34,6 +34,8 @@ export interface CalendarDateValue {
34
34
  export type PeriodShiftTime = RelativeDateValue | AbsoluteDateValue;
35
35
  /** A date value before semantic-type normalization. */
36
36
  export type DateValue = string | RelativeDateValue | AbsoluteDateValue | CalendarDateValue;
37
+ /** Stable entity identity. Numeric IDs must be safe integers. */
38
+ export type EntityIdType = string | number;
37
39
  export type CompareOperator = '$eq' | '$gt' | '$gte' | '$lt' | '$lte' | '$ne' | '$in' | '$nin' | '$exists' | '$regex' | '$contains' | '$recursive' | '$and' | '$or';
38
40
  export interface RecursiveQueryType {
39
41
  readonly schema?: string;
@@ -50,7 +52,7 @@ export interface RelationQueryType {
50
52
  readonly schema: string;
51
53
  readonly query: QueryType;
52
54
  /** Stable entity identity. `placeholder` preserves context without adding an ID filter. */
53
- readonly entity_id?: string;
55
+ readonly entity_id?: EntityIdType;
54
56
  }
55
57
  export type QueryLogicalOperand = QueryValueType | QueryValueTypeWithCompareOperator;
56
58
  export type QueryValueTypeWithCompareOperator = Partial<{
@@ -80,16 +82,14 @@ export type QueryType = Record<string, QueryValueType | QueryValueTypeWithCompar
80
82
  };
81
83
  export interface ExpressionItemType {
82
84
  operator?: string;
83
- pred?: string | ExpressionItemType;
84
- /** Structural operands for multi-input operators. Operator options remain in `args`. */
85
- components?: ExpressionItemType[];
85
+ /** Operator input. Arrays represent ordered multi-input predicates. */
86
+ pred?: string | ExpressionItemType | (string | ExpressionItemType)[];
86
87
  name?: string;
87
88
  schema?: string;
88
89
  args?: Record<string, unknown>;
89
90
  }
90
91
  export interface PredItemType extends ExpressionItemType {
91
- pred?: string | PredItemType;
92
- components?: PredItemType[];
92
+ pred?: string | PredItemType | (string | PredItemType)[];
93
93
  query?: QueryType;
94
94
  }
95
95
  export type LogicformOutputTypeValue = 'url' | 'data' | 'export' | 'sql' | 'sqlComponents';
@@ -102,10 +102,10 @@ export interface LogicformType {
102
102
  version: string;
103
103
  /** Required for a physical leaf. Derived and composed nodes inherit their field space. */
104
104
  schema?: string;
105
- /** Complete child LogicForms whose result columns are combined by their shared row identity. */
106
- logicforms?: LogicformType[];
107
105
  query?: QueryType;
108
106
  preds?: PredItemType[];
107
+ /** Output/reference aliases for properties contributed by another Schema. */
108
+ propertyResolve?: Readonly<Record<string, Readonly<Record<string, string>>>>;
109
109
  groupby?: PredItemType[];
110
110
  sort?: Record<string, 1 | -1>;
111
111
  having?: QueryType;
@@ -115,11 +115,10 @@ export interface LogicformType {
115
115
  page?: number;
116
116
  representation?: RepresentationType;
117
117
  /** Stable entity identity. `placeholder` preserves context without adding an ID filter. */
118
- entity_id?: string;
118
+ entity_id?: EntityIdType;
119
119
  from?: LogicformType;
120
120
  currency?: string;
121
121
  }
122
+ /** Public normalized shape; composition is represented by Planner subplans. */
123
+ export type PublicLogicformType = LogicformType;
122
124
  export declare const isLogicform: (value: unknown) => value is LogicformType;
123
- export declare const isComposedLogicform: (value: LogicformType) => value is LogicformType & {
124
- readonly logicforms: LogicformType[];
125
- };
@@ -10,10 +10,10 @@ export interface NormalizeLogicformOptions {
10
10
  readonly locale?: string;
11
11
  readonly now?: Date;
12
12
  readonly resolveSchema?: (schemaId: string) => ResolvedSemanticSchema;
13
- readonly requestLatestDataDate?: (schema: ResolvedSemanticSchema, property: ResolvedSemanticProperty) => Promise<Date | undefined>;
13
+ readonly requestTimeWatermark?: (schema: ResolvedSemanticSchema, property: ResolvedSemanticProperty, requestedUpperBound: Date) => Promise<Date | undefined>;
14
14
  readonly resolveFromSchema?: (normalizedFrom: LogicformType, outerSchema: ResolvedSemanticSchema) => ResolvedSemanticSchema;
15
15
  readonly canProjectProperty?: (schema: ResolvedSemanticSchema, property: ResolvedSemanticProperty) => boolean;
16
16
  /** Internal recursion hook installed by normalizeLogicform. */
17
17
  readonly normalizeNestedLogicform?: (logicform: LogicformType) => Promise<LogicformType>;
18
18
  }
19
- export declare const resolveLogicformSchema: (logicform: LogicformType, currentSchema: ResolvedSemanticSchema, options: NormalizeLogicformOptions) => ResolvedSemanticSchema;
19
+ export declare const resolveFormSchema: (logicform: LogicformType, currentSchema: ResolvedSemanticSchema, options: NormalizeLogicformOptions) => ResolvedSemanticSchema;
@@ -0,0 +1,5 @@
1
+ import type { LogicformType } from '../logicform-types';
2
+ import type { ResolvedSemanticSchema } from '../semantic-types/index';
3
+ import type { NormalizeLogicformOptions } from './core';
4
+ /** Adds cross-Schema aliases after both legacy and v2 forms share normalization. */
5
+ export declare const normalizePropertyResolve: (logicform: LogicformType, rootSchema: ResolvedSemanticSchema, options: NormalizeLogicformOptions) => LogicformType;
@@ -0,0 +1,2 @@
1
+ import type { OperatorDefinition } from '../types';
2
+ export declare const constantOperator: OperatorDefinition;
@@ -0,0 +1,2 @@
1
+ import type { OperatorDefinition } from '../types';
2
+ export declare const periodValueOperator: OperatorDefinition;
@@ -0,0 +1,3 @@
1
+ import type { OperatorDefinition } from '../types';
2
+ export declare const leastOperator: OperatorDefinition;
3
+ export declare const greatestOperator: OperatorDefinition;
@@ -2,6 +2,6 @@ import type { SemanticDBPlugin } from '../plugins/index';
2
2
  import { OperatorRegistry } from './registry';
3
3
  export { OperatorRegistry } from './registry';
4
4
  export { bindTrustedSqlExpression } from './sql-expression';
5
- export type { OperatorDefinition, OperatorDefaultNameContext, OperatorComponentContext, OperatorCteCalculation, OperatorCteComponent, OperatorCteSqlContext, OperatorExecutionComponent, OperatorGroupKeyShift, OperatorJavaScriptCalculation, OperatorQueryComponent, OperatorEvaluateContext, OperatorOutputPropertyContext, OperatorObservationPolicy, OperatorObservationPolicyContext, OperatorNormalizePredContext, OperatorPlanExpressionContext, OperatorPeriodEvaluationContext, OperatorPlanInputContext, OperatorPlannedInput, OperatorRewriteLogicformContext, OperatorValidatePlanContext, OperatorSqlCapabilities, OperatorSqlContext, ResultProperty, ResultPropertyTemporalMetadata, } from './types';
5
+ 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
6
  export declare const builtinOperators: readonly import("./types").OperatorDefinition[];
7
7
  export declare const createOperatorRegistry: (plugins?: readonly SemanticDBPlugin[]) => OperatorRegistry;
@@ -10,6 +10,9 @@ export interface OperatorSqlCapabilities {
10
10
  concat(expressions: readonly string[]): string;
11
11
  substring(expression: string, start: number, length: number): string;
12
12
  dateBucket(expression: string, granularity: TimeGranularity): string;
13
+ dateShift(expression: string, granularity: TimeGranularity, offset: number): string;
14
+ /** Render a period boundary directly when the dialect has a concise native form. */
15
+ datePeriodBoundary?(expression: string, granularity: TimeGranularity, boundary: 'start' | 'end'): string;
13
16
  /** Bind a literal as a SQL parameter. */
14
17
  value(value: unknown): string;
15
18
  /** Compile a field-local LogicForm condition against an expression. */
@@ -20,7 +23,7 @@ export interface OperatorSqlContext {
20
23
  readonly sql: OperatorSqlCapabilities;
21
24
  /** SQL for the nested input expression, when this operator has one. */
22
25
  readonly expression?: string;
23
- /** SQL expressions produced by a multi-input operator's structural components. */
26
+ /** SQL expressions produced by a multi-input pred. */
24
27
  readonly expressions?: readonly string[];
25
28
  /** Quoted physical column for a leaf-property operator. */
26
29
  readonly column?: string;
@@ -76,8 +79,8 @@ export interface OperatorOutputPropertyContext {
76
79
  readonly property?: ResolvedSemanticProperty;
77
80
  /** Semantic metadata produced by a nested expression. */
78
81
  readonly inputProperty?: ResultProperty;
79
- /** Semantic metadata produced by structural components. */
80
- readonly componentProperties?: readonly ResultProperty[];
82
+ /** Semantic metadata produced by a multi-input pred. */
83
+ readonly inputProperties?: readonly ResultProperty[];
81
84
  /** Operator-specific LogicForm arguments. */
82
85
  readonly args: Readonly<Record<string, unknown>>;
83
86
  }
@@ -89,12 +92,12 @@ export interface OperatorPeriodEvaluationContext {
89
92
  readonly inputProperty?: ResolvedSemanticProperty;
90
93
  }
91
94
  export interface OperatorDefaultNameContext {
92
- /** Name produced by the direct pred, structural components, or localized row label. */
95
+ /** Name produced by the direct pred inputs or localized row label. */
93
96
  readonly operandName: string;
94
97
  /** Name of a direct or nested pred input. */
95
98
  readonly inputName?: string;
96
- /** Names of structural component inputs. */
97
- readonly componentNames: readonly string[];
99
+ /** Names of multi-input pred values. */
100
+ readonly inputNames: readonly string[];
98
101
  /** Operator-specific LogicForm arguments. */
99
102
  readonly args: Readonly<Record<string, unknown>>;
100
103
  /** Requested locale. Each operator owns its own localized default names. */
@@ -121,7 +124,7 @@ export interface OperatorPlanExpressionContext {
121
124
  readonly pred: PredItemType;
122
125
  readonly input?: Expression;
123
126
  readonly inputProperty?: ResultProperty;
124
- readonly components: readonly Expression[];
127
+ readonly inputs: readonly Expression[];
125
128
  readonly args: Readonly<Record<string, unknown>>;
126
129
  readonly resolveKey: (reference: string) => Expression;
127
130
  readonly getOperator: (name: string) => OperatorDefinition;
@@ -143,6 +146,8 @@ export interface OperatorValidatePlanContext {
143
146
  export interface OperatorRewriteLogicformContext {
144
147
  readonly logicform: LogicformType;
145
148
  readonly schema: ResolvedSemanticSchema;
149
+ /** Resolve operator metadata while rewriting nested expressions. */
150
+ readonly getOperator?: (name: string) => OperatorDefinition;
146
151
  }
147
152
  export interface OperatorComponentContext {
148
153
  /** Fully normalized LogicForm containing this top-level operator projection. */
@@ -173,31 +178,30 @@ export interface OperatorQueryComponent {
173
178
  /** SQL-side transformations that align this component's group keys with the base component. */
174
179
  readonly groupKeyShifts?: readonly OperatorGroupKeyShift[];
175
180
  }
176
- export interface OperatorCteSqlContext {
177
- readonly values: Readonly<Record<string, string>>;
178
- readonly quoteIdentifier: (identifier: string) => string;
179
- }
180
- export interface OperatorCteComponent {
181
+ export interface OperatorComponentQuery {
181
182
  readonly name: string;
182
- readonly component: OperatorQueryComponent;
183
+ readonly logicform: LogicformType;
184
+ readonly prepare?: boolean;
185
+ readonly mapResult?: (rows: readonly DataRow[]) => DataRow[];
186
+ readonly groupKeyShifts?: readonly OperatorGroupKeyShift[];
183
187
  /** Group output names used to join this component back to the first component. */
184
188
  readonly joinKeys?: readonly string[];
185
189
  }
186
- export interface OperatorCteCalculation {
187
- readonly kind: 'cte';
188
- readonly components: readonly OperatorCteComponent[];
190
+ export interface OperatorComponentCalculation {
191
+ readonly components: readonly OperatorComponentQuery[];
192
+ /** Provider-independent formula referring to component names. */
193
+ readonly expression: string;
189
194
  readonly outputName?: string;
190
- readonly toSQL: (context: OperatorCteSqlContext) => string;
191
195
  readonly exposeComponents?: boolean;
192
196
  }
193
197
  export interface OperatorJavaScriptCalculation {
194
198
  readonly kind: 'js';
195
- readonly components: readonly OperatorCteComponent[];
199
+ readonly components: readonly OperatorComponentQuery[];
196
200
  readonly outputName: string;
197
201
  readonly mergeRow: (values: DataRow) => unknown;
198
202
  readonly exposeComponents?: boolean;
199
203
  }
200
- export type OperatorExecutionComponent = OperatorQueryComponent | OperatorCteCalculation | OperatorJavaScriptCalculation;
204
+ export type OperatorExecutionComponent = OperatorQueryComponent | OperatorComponentCalculation | OperatorJavaScriptCalculation;
201
205
  /**
202
206
  * Extension contract for one LogicForm operator.
203
207
  *
@@ -207,7 +211,7 @@ export type OperatorExecutionComponent = OperatorQueryComponent | OperatorCteCal
207
211
  * `getOutputProperty` to describe the resulting one-column logical schema.
208
212
  */
209
213
  interface OperatorDefinitionBase {
210
- /** Public registry key, normally using the `$name` convention. */
214
+ /** Public registry key. Built-in operators commonly use a `$` prefix, but it is not required. */
211
215
  readonly name: string;
212
216
  /** Produce the normalized output name when the PredItem does not declare one. */
213
217
  readonly defaultName: (context: OperatorDefaultNameContext) => string;
@@ -227,7 +231,7 @@ interface OperatorDefinitionBase {
227
231
  readonly observationPolicy?: (context: OperatorObservationPolicyContext) => OperatorObservationPolicy | undefined;
228
232
  /** Validate this operator against the completed group key set. */
229
233
  readonly validatePlan?: (context: OperatorValidatePlanContext) => void;
230
- /** Expand high-level operator semantics into ordinary nested LogicForms before planning. */
234
+ /** Expand high-level operator semantics into ordinary nested LogicForm objects before planning. */
231
235
  readonly rewriteLogicform?: (context: OperatorRewriteLogicformContext) => LogicformType | undefined;
232
236
  /** Whether this operator requires one evaluation per time bucket. */
233
237
  readonly requiresPerPeriodEvaluation?: (context: OperatorPeriodEvaluationContext) => boolean;
@@ -30,6 +30,7 @@ export declare class ClickHouseProvider implements CoreComputeProvider {
30
30
  dateBucket(expression: string, level: string): string;
31
31
  dateShift(expression: string, granularity: string, offset: number): string;
32
32
  aggregateFunction(name: string, expression?: string): string;
33
+ stringify(expression: string): string;
33
34
  concat(expressions: readonly string[]): string;
34
35
  substring(expression: string, start: number, length: number): string;
35
36
  regex(expression: string, pattern: string, options?: string): string;
@@ -20,7 +20,9 @@ export declare abstract class MySQLProtocolProvider implements CoreComputeProvid
20
20
  displayQuery(sql: string, parameters: SqlParameters): string;
21
21
  dateBucket(expression: string, level: string): string;
22
22
  dateShift(expression: string, granularity: string, offset: number): string;
23
+ datePeriodBoundary(expression: string, granularity: string, boundary: 'start' | 'end'): string;
23
24
  aggregateFunction(name: string, expression?: string): string;
25
+ stringify(expression: string): string;
24
26
  concat(expressions: readonly string[]): string;
25
27
  substring(expression: string, start: number, length: number): string;
26
28
  regex(expression: string, pattern: string, options?: string): string;