semanticdb-v2 2.0.0-alpha.1
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 +448 -0
- package/dist/cache/expiry.d.ts +5 -0
- package/dist/cache/expiry.js +1 -0
- package/dist/cache/identity.d.ts +3 -0
- package/dist/cache/identity.js +1 -0
- package/dist/cache/index.d.ts +3 -0
- package/dist/cache/redis-query-cache.d.ts +37 -0
- package/dist/cache/redis-query-cache.js +1 -0
- package/dist/cache/serialization.d.ts +3 -0
- package/dist/cache/serialization.js +1 -0
- package/dist/cache/types.d.ts +27 -0
- package/dist/calendar/constants.d.ts +7 -0
- package/dist/calendar/constants.js +1 -0
- package/dist/calendar/index.d.ts +6 -0
- package/dist/calendar/provider-relation-store.d.ts +9 -0
- package/dist/calendar/provider-relation-store.js +1 -0
- package/dist/calendar/resolver.d.ts +10 -0
- package/dist/calendar/resolver.js +1 -0
- package/dist/calendar/system-schemas.d.ts +3 -0
- package/dist/calendar/system-schemas.js +1 -0
- package/dist/calendar/types.d.ts +31 -0
- package/dist/compatibility/index.d.ts +2 -0
- package/dist/compatibility/logicform.d.ts +13 -0
- package/dist/compatibility/logicform.js +1 -0
- package/dist/compiler/compile-cte.d.ts +12 -0
- package/dist/compiler/compile-cte.js +1 -0
- package/dist/compiler/compile-plan.d.ts +5 -0
- package/dist/compiler/compile-plan.js +1 -0
- package/dist/compiler/index.d.ts +4 -0
- package/dist/compiler/shorten-sql.d.ts +2 -0
- package/dist/compiler/shorten-sql.js +2 -0
- package/dist/compiler/types.d.ts +5 -0
- package/dist/custom-functions/custom-functions.d.ts +6 -0
- package/dist/custom-functions/custom-functions.js +1 -0
- package/dist/custom-functions/index.d.ts +3 -0
- package/dist/custom-functions/operator-adapter.d.ts +12 -0
- package/dist/custom-functions/operator-adapter.js +1 -0
- package/dist/custom-functions/types.d.ts +62 -0
- package/dist/errors.d.ts +5 -0
- package/dist/errors.js +1 -0
- package/dist/executor/compatibility.d.ts +6 -0
- package/dist/executor/compatibility.js +1 -0
- package/dist/executor/components.d.ts +9 -0
- package/dist/executor/components.js +1 -0
- package/dist/executor/connection-registry.d.ts +12 -0
- package/dist/executor/connection-registry.js +1 -0
- package/dist/executor/evaluate.d.ts +4 -0
- package/dist/executor/evaluate.js +1 -0
- package/dist/executor/execute-query.d.ts +13 -0
- package/dist/executor/execute-query.js +1 -0
- package/dist/executor/execute.d.ts +4 -0
- package/dist/executor/execute.js +1 -0
- package/dist/executor/fetch-entities.d.ts +26 -0
- package/dist/executor/fetch-entities.js +1 -0
- package/dist/executor/index.d.ts +3 -0
- package/dist/executor/result-hydrator/entity-loader.d.ts +6 -0
- package/dist/executor/result-hydrator/entity-loader.js +1 -0
- package/dist/executor/result-hydrator/format-values.d.ts +4 -0
- package/dist/executor/result-hydrator/format-values.js +1 -0
- package/dist/executor/result-hydrator/hydrate-result.d.ts +4 -0
- package/dist/executor/result-hydrator/hydrate-result.js +1 -0
- package/dist/executor/result-hydrator/index.d.ts +2 -0
- package/dist/executor/result-hydrator/missing-entity.d.ts +3 -0
- package/dist/executor/result-hydrator/missing-entity.js +1 -0
- package/dist/executor/result-hydrator/populate-entities.d.ts +3 -0
- package/dist/executor/result-hydrator/populate-entities.js +1 -0
- package/dist/executor/result-hydrator/types.d.ts +14 -0
- package/dist/executor/row-identity.d.ts +4 -0
- package/dist/executor/row-identity.js +1 -0
- package/dist/executor/types.d.ts +118 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +1 -0
- package/dist/logicform-types.d.ts +125 -0
- package/dist/logicform-types.js +1 -0
- package/dist/normalizer/core.d.ts +19 -0
- package/dist/normalizer/core.js +1 -0
- package/dist/normalizer/default-pred-name.d.ts +6 -0
- package/dist/normalizer/default-pred-name.js +1 -0
- package/dist/normalizer/entity-id.d.ts +4 -0
- package/dist/normalizer/entity-id.js +1 -0
- package/dist/normalizer/groupby.d.ts +4 -0
- package/dist/normalizer/groupby.js +1 -0
- package/dist/normalizer/index.d.ts +3 -0
- package/dist/normalizer/normalize-logicform.d.ts +4 -0
- package/dist/normalizer/normalize-logicform.js +1 -0
- package/dist/normalizer/pagination.d.ts +2 -0
- package/dist/normalizer/pagination.js +1 -0
- package/dist/normalizer/pred-query-name.d.ts +1 -0
- package/dist/normalizer/pred-query-name.js +1 -0
- package/dist/normalizer/preds.d.ts +4 -0
- package/dist/normalizer/preds.js +1 -0
- package/dist/normalizer/query.d.ts +5 -0
- package/dist/normalizer/query.js +1 -0
- package/dist/normalizer/version.d.ts +3 -0
- package/dist/normalizer/version.js +1 -0
- package/dist/operators/builtins/abs.d.ts +2 -0
- package/dist/operators/builtins/abs.js +1 -0
- package/dist/operators/builtins/accumulate.d.ts +2 -0
- package/dist/operators/builtins/accumulate.js +1 -0
- package/dist/operators/builtins/add.d.ts +2 -0
- package/dist/operators/builtins/add.js +1 -0
- package/dist/operators/builtins/arithmetic.d.ts +3 -0
- package/dist/operators/builtins/arithmetic.js +1 -0
- package/dist/operators/builtins/average-per-period.d.ts +2 -0
- package/dist/operators/builtins/average-per-period.js +1 -0
- package/dist/operators/builtins/avg.d.ts +2 -0
- package/dist/operators/builtins/avg.js +1 -0
- package/dist/operators/builtins/case.d.ts +2 -0
- package/dist/operators/builtins/case.js +1 -0
- package/dist/operators/builtins/concat.d.ts +2 -0
- package/dist/operators/builtins/concat.js +1 -0
- package/dist/operators/builtins/count-distinct.d.ts +2 -0
- package/dist/operators/builtins/count-distinct.js +1 -0
- package/dist/operators/builtins/count.d.ts +2 -0
- package/dist/operators/builtins/count.js +1 -0
- package/dist/operators/builtins/date-bucket.d.ts +2 -0
- package/dist/operators/builtins/date-bucket.js +1 -0
- package/dist/operators/builtins/divide.d.ts +2 -0
- package/dist/operators/builtins/divide.js +1 -0
- package/dist/operators/builtins/index.d.ts +2 -0
- package/dist/operators/builtins/index.js +1 -0
- package/dist/operators/builtins/max.d.ts +2 -0
- package/dist/operators/builtins/max.js +1 -0
- package/dist/operators/builtins/min.d.ts +2 -0
- package/dist/operators/builtins/min.js +1 -0
- package/dist/operators/builtins/multiply.d.ts +2 -0
- package/dist/operators/builtins/multiply.js +1 -0
- package/dist/operators/builtins/newly.d.ts +2 -0
- package/dist/operators/builtins/newly.js +1 -0
- package/dist/operators/builtins/period-boundary.d.ts +2 -0
- package/dist/operators/builtins/period-boundary.js +1 -0
- package/dist/operators/builtins/period-difference.d.ts +2 -0
- package/dist/operators/builtins/period-difference.js +1 -0
- package/dist/operators/builtins/period-growth.d.ts +2 -0
- package/dist/operators/builtins/period-growth.js +1 -0
- package/dist/operators/builtins/period-name.d.ts +1 -0
- package/dist/operators/builtins/period-name.js +1 -0
- package/dist/operators/builtins/period-shift.d.ts +6 -0
- package/dist/operators/builtins/period-shift.js +1 -0
- package/dist/operators/builtins/rank.d.ts +2 -0
- package/dist/operators/builtins/rank.js +1 -0
- package/dist/operators/builtins/row-number.d.ts +2 -0
- package/dist/operators/builtins/row-number.js +1 -0
- package/dist/operators/builtins/share-of-total.d.ts +2 -0
- package/dist/operators/builtins/share-of-total.js +1 -0
- package/dist/operators/builtins/sql.d.ts +3 -0
- package/dist/operators/builtins/sql.js +1 -0
- package/dist/operators/builtins/substring.d.ts +2 -0
- package/dist/operators/builtins/substring.js +1 -0
- package/dist/operators/builtins/subtract.d.ts +2 -0
- package/dist/operators/builtins/subtract.js +1 -0
- package/dist/operators/builtins/sum.d.ts +2 -0
- package/dist/operators/builtins/sum.js +1 -0
- package/dist/operators/builtins/time-range.d.ts +13 -0
- package/dist/operators/builtins/time-range.js +1 -0
- package/dist/operators/groupby.d.ts +3 -0
- package/dist/operators/groupby.js +1 -0
- package/dist/operators/index.d.ts +7 -0
- package/dist/operators/index.js +1 -0
- package/dist/operators/registry.d.ts +10 -0
- package/dist/operators/registry.js +1 -0
- package/dist/operators/sql-expression.d.ts +1 -0
- package/dist/operators/sql-expression.js +1 -0
- package/dist/operators/types.d.ts +277 -0
- package/dist/permissions/index.d.ts +3 -0
- package/dist/permissions/permissions.d.ts +10 -0
- package/dist/permissions/permissions.js +1 -0
- package/dist/permissions/types.d.ts +12 -0
- package/dist/physical/clickhouse-provider.d.ts +44 -0
- package/dist/physical/clickhouse-provider.js +1 -0
- package/dist/physical/connection.d.ts +32 -0
- package/dist/physical/connection.js +1 -0
- package/dist/physical/display-query.d.ts +4 -0
- package/dist/physical/display-query.js +1 -0
- package/dist/physical/doris-provider.d.ts +9 -0
- package/dist/physical/doris-provider.js +1 -0
- package/dist/physical/index.d.ts +18 -0
- package/dist/physical/mysql-compatible-sql.d.ts +6 -0
- package/dist/physical/mysql-compatible-sql.js +1 -0
- package/dist/physical/mysql-protocol-provider.d.ts +34 -0
- package/dist/physical/mysql-protocol-provider.js +1 -0
- package/dist/physical/mysql-provider.d.ts +8 -0
- package/dist/physical/mysql-provider.js +1 -0
- package/dist/physical/oracle-provider.d.ts +53 -0
- package/dist/physical/oracle-provider.js +1 -0
- package/dist/physical/postgresql-provider.d.ts +37 -0
- package/dist/physical/postgresql-provider.js +1 -0
- package/dist/physical/provider.d.ts +40 -0
- package/dist/physical/snowflake-provider.d.ts +45 -0
- package/dist/physical/snowflake-provider.js +1 -0
- package/dist/physical/starrocks-provider.d.ts +9 -0
- package/dist/physical/starrocks-provider.js +1 -0
- package/dist/planner/build-lineage.d.ts +5 -0
- package/dist/planner/build-lineage.js +1 -0
- package/dist/planner/create-logical-plan.d.ts +15 -0
- package/dist/planner/create-logical-plan.js +1 -0
- package/dist/planner/index.d.ts +7 -0
- package/dist/planner/select-schema-mapping.d.ts +14 -0
- package/dist/planner/select-schema-mapping.js +1 -0
- package/dist/planner/semantics/index.d.ts +5 -0
- package/dist/planner/semantics/lifecycle/classification.d.ts +7 -0
- package/dist/planner/semantics/lifecycle/classification.js +1 -0
- package/dist/planner/semantics/lifecycle/index.d.ts +3 -0
- package/dist/planner/semantics/lifecycle/query-policy.d.ts +3 -0
- package/dist/planner/semantics/lifecycle/query-policy.js +1 -0
- package/dist/planner/semantics/lifecycle/rule.d.ts +2 -0
- package/dist/planner/semantics/lifecycle/rule.js +1 -0
- package/dist/planner/semantics/observation/classification.d.ts +3 -0
- package/dist/planner/semantics/observation/classification.js +1 -0
- package/dist/planner/semantics/observation/index.d.ts +4 -0
- package/dist/planner/semantics/observation/operator-policy.d.ts +11 -0
- package/dist/planner/semantics/observation/operator-policy.js +1 -0
- package/dist/planner/semantics/observation/rule.d.ts +2 -0
- package/dist/planner/semantics/observation/rule.js +1 -0
- package/dist/planner/semantics/observation/types.d.ts +3 -0
- package/dist/planner/semantics/registry-defaults.d.ts +2 -0
- package/dist/planner/semantics/registry-defaults.js +1 -0
- package/dist/planner/semantics/registry.d.ts +32 -0
- package/dist/planner/semantics/registry.js +1 -0
- package/dist/planner/types.d.ts +202 -0
- package/dist/planner/types.js +1 -0
- package/dist/plugins/hierarchy/compatibility.d.ts +2 -0
- package/dist/plugins/hierarchy/compatibility.js +1 -0
- package/dist/plugins/hierarchy/entity-identity.d.ts +2 -0
- package/dist/plugins/hierarchy/entity-identity.js +1 -0
- package/dist/plugins/hierarchy/index.d.ts +3 -0
- package/dist/plugins/hierarchy/index.js +1 -0
- package/dist/plugins/hierarchy/operator.d.ts +2 -0
- package/dist/plugins/hierarchy/operator.js +1 -0
- package/dist/plugins/hierarchy/resolve-schema.d.ts +2 -0
- package/dist/plugins/hierarchy/resolve-schema.js +1 -0
- package/dist/plugins/hierarchy/types.d.ts +28 -0
- package/dist/plugins/index.d.ts +5 -0
- package/dist/plugins/index.js +1 -0
- package/dist/plugins/types.d.ts +20 -0
- package/dist/schema/entity-identity.d.ts +5 -0
- package/dist/schema/entity-identity.js +1 -0
- package/dist/schema/index.d.ts +4 -0
- package/dist/schema/resolve-property-path.d.ts +15 -0
- package/dist/schema/resolve-property-path.js +1 -0
- package/dist/schema/schema-registry.d.ts +4 -0
- package/dist/schema/schema-registry.js +1 -0
- package/dist/schema-mappings/freshness.d.ts +7 -0
- package/dist/schema-mappings/freshness.js +1 -0
- package/dist/schema-mappings/index.d.ts +4 -0
- package/dist/schema-mappings/registry.d.ts +9 -0
- package/dist/schema-mappings/registry.js +1 -0
- package/dist/schema-mappings/types.d.ts +46 -0
- package/dist/semantic-types/builtins/boolean.d.ts +2 -0
- package/dist/semantic-types/builtins/boolean.js +1 -0
- package/dist/semantic-types/builtins/category.d.ts +2 -0
- package/dist/semantic-types/builtins/category.js +1 -0
- package/dist/semantic-types/builtins/currency.d.ts +2 -0
- package/dist/semantic-types/builtins/currency.js +1 -0
- package/dist/semantic-types/builtins/date.d.ts +2 -0
- package/dist/semantic-types/builtins/date.js +1 -0
- package/dist/semantic-types/builtins/duration.d.ts +2 -0
- package/dist/semantic-types/builtins/duration.js +1 -0
- package/dist/semantic-types/builtins/end-date.d.ts +2 -0
- package/dist/semantic-types/builtins/end-date.js +1 -0
- package/dist/semantic-types/builtins/entity.d.ts +2 -0
- package/dist/semantic-types/builtins/entity.js +1 -0
- package/dist/semantic-types/builtins/file.d.ts +2 -0
- package/dist/semantic-types/builtins/file.js +1 -0
- package/dist/semantic-types/builtins/human-name.d.ts +2 -0
- package/dist/semantic-types/builtins/human-name.js +1 -0
- package/dist/semantic-types/builtins/id.d.ts +2 -0
- package/dist/semantic-types/builtins/id.js +1 -0
- package/dist/semantic-types/builtins/image.d.ts +2 -0
- package/dist/semantic-types/builtins/image.js +1 -0
- package/dist/semantic-types/builtins/index.d.ts +2 -0
- package/dist/semantic-types/builtins/index.js +1 -0
- package/dist/semantic-types/builtins/int.d.ts +2 -0
- package/dist/semantic-types/builtins/int.js +1 -0
- package/dist/semantic-types/builtins/name.d.ts +2 -0
- package/dist/semantic-types/builtins/name.js +1 -0
- package/dist/semantic-types/builtins/number.d.ts +2 -0
- package/dist/semantic-types/builtins/number.js +1 -0
- package/dist/semantic-types/builtins/object.d.ts +3 -0
- package/dist/semantic-types/builtins/object.js +1 -0
- package/dist/semantic-types/builtins/order.d.ts +2 -0
- package/dist/semantic-types/builtins/order.js +1 -0
- package/dist/semantic-types/builtins/percentage.d.ts +2 -0
- package/dist/semantic-types/builtins/percentage.js +1 -0
- package/dist/semantic-types/builtins/start-date.d.ts +2 -0
- package/dist/semantic-types/builtins/start-date.js +1 -0
- package/dist/semantic-types/builtins/string.d.ts +2 -0
- package/dist/semantic-types/builtins/string.js +1 -0
- package/dist/semantic-types/builtins/timestamp.d.ts +2 -0
- package/dist/semantic-types/builtins/timestamp.js +1 -0
- package/dist/semantic-types/index.d.ts +9 -0
- package/dist/semantic-types/index.js +1 -0
- package/dist/semantic-types/primal-types/date.d.ts +2 -0
- package/dist/semantic-types/primal-types/date.js +1 -0
- package/dist/semantic-types/primal-types/index.d.ts +2 -0
- package/dist/semantic-types/primal-types/index.js +1 -0
- package/dist/semantic-types/registry.d.ts +14 -0
- package/dist/semantic-types/registry.js +1 -0
- package/dist/semantic-types/resolve-schema.d.ts +4 -0
- package/dist/semantic-types/resolve-schema.js +1 -0
- package/dist/semantic-types/types.d.ts +90 -0
- package/dist/semantic-types/validate-resolved-schema.d.ts +6 -0
- package/dist/semantic-types/validate-resolved-schema.js +1 -0
- package/dist/utils/clone.d.ts +1 -0
- package/dist/utils/clone.js +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { PredItemType } from '../../logicform-types';
|
|
2
|
+
import type { LogicformType, QueryType } from '../../logicform-types';
|
|
3
|
+
import type { ResolvedSemanticProperty, ResolvedSemanticSchema } from '../../semantic-types/index';
|
|
4
|
+
import type { OperatorDefinition, ResultProperty } from '../../operators/index';
|
|
5
|
+
export interface PlannerSemanticRuleContext {
|
|
6
|
+
readonly pred: PredItemType;
|
|
7
|
+
readonly schema: ResolvedSemanticSchema;
|
|
8
|
+
readonly sourceProperty?: ResolvedSemanticProperty;
|
|
9
|
+
readonly outputProperty: ResultProperty;
|
|
10
|
+
readonly operator?: OperatorDefinition;
|
|
11
|
+
}
|
|
12
|
+
export interface PlannerSemanticQueryContext {
|
|
13
|
+
readonly logicform: LogicformType;
|
|
14
|
+
readonly schema: ResolvedSemanticSchema;
|
|
15
|
+
readonly query?: QueryType;
|
|
16
|
+
}
|
|
17
|
+
export interface PlannerSemanticResolution {
|
|
18
|
+
readonly outputProperty?: ResultProperty;
|
|
19
|
+
}
|
|
20
|
+
export interface PlannerSemanticRule {
|
|
21
|
+
readonly name: string;
|
|
22
|
+
readonly resolveProjection?: (context: PlannerSemanticRuleContext) => PlannerSemanticResolution | undefined;
|
|
23
|
+
readonly resolveQuery?: (context: PlannerSemanticQueryContext) => QueryType | undefined;
|
|
24
|
+
}
|
|
25
|
+
export declare class PlannerSemanticRegistry {
|
|
26
|
+
#private;
|
|
27
|
+
constructor(rules?: readonly PlannerSemanticRule[]);
|
|
28
|
+
register(rule: PlannerSemanticRule): this;
|
|
29
|
+
resolveProjection(context: PlannerSemanticRuleContext): ResultProperty;
|
|
30
|
+
resolveQuery(context: PlannerSemanticQueryContext): QueryType | undefined;
|
|
31
|
+
rules(): readonly PlannerSemanticRule[];
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{SemanticDBError as s}from"../../errors.js";class o{#e=new Map;constructor(e=[]){for(const r of e)this.register(r)}register(e){if(!e.name)throw new s("INVALID_SEMANTIC_RULE","Semantic rule name must not be empty");if(this.#e.has(e.name))throw new s("SEMANTIC_RULE_ALREADY_REGISTERED",`Semantic rule is already registered: ${e.name}`,{rule:e.name});return this.#e.set(e.name,e),this}resolveProjection(e){return[...this.#e.values()].reduce((r,t)=>t.resolveProjection?.({...e,outputProperty:r})?.outputProperty??r,e.outputProperty)}resolveQuery(e){return[...this.#e.values()].reduce((r,t)=>t.resolveQuery?.({...e,...r?{query:r}:{}})??r,e.query)}rules(){return[...this.#e.values()]}}export{o as PlannerSemanticRegistry};
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import type { CoreComputeProvider } from '../physical/index';
|
|
2
|
+
import type { ResultProperty } from '../operators/index';
|
|
3
|
+
import type { ComparableCategoryDefinition, TimeGranularity } from '../semantic-types/index';
|
|
4
|
+
export interface FieldReferencePlan {
|
|
5
|
+
readonly schemaId: string;
|
|
6
|
+
readonly property: string;
|
|
7
|
+
/** Stable logical Schema Property ID; column may come from a selected Mapping. */
|
|
8
|
+
readonly propertyId?: string;
|
|
9
|
+
readonly column: string;
|
|
10
|
+
readonly qualifier: string;
|
|
11
|
+
readonly sql?: string;
|
|
12
|
+
readonly timestampColumn?: string;
|
|
13
|
+
readonly isArray?: boolean;
|
|
14
|
+
readonly comparable?: ComparableCategoryDefinition;
|
|
15
|
+
}
|
|
16
|
+
export interface LogicalQuerySubquery {
|
|
17
|
+
readonly kind: 'logicform-subquery';
|
|
18
|
+
readonly plan: LogicalPlan;
|
|
19
|
+
}
|
|
20
|
+
export interface LogicalRecursiveQuery {
|
|
21
|
+
readonly kind: 'recursive-query';
|
|
22
|
+
readonly schemaId: string;
|
|
23
|
+
readonly source: string;
|
|
24
|
+
readonly sourceSql?: string;
|
|
25
|
+
readonly idColumn: string;
|
|
26
|
+
readonly parentColumn: string;
|
|
27
|
+
readonly roots: readonly unknown[];
|
|
28
|
+
readonly includeSelf: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface LogicalOrdinalQuery {
|
|
31
|
+
readonly kind: 'ordinal-query';
|
|
32
|
+
readonly comparable: ComparableCategoryDefinition;
|
|
33
|
+
readonly condition: unknown;
|
|
34
|
+
}
|
|
35
|
+
export declare const isLogicalQuerySubquery: (value: unknown) => value is LogicalQuerySubquery;
|
|
36
|
+
export declare const isLogicalRecursiveQuery: (value: unknown) => value is LogicalRecursiveQuery;
|
|
37
|
+
export declare const isLogicalOrdinalQuery: (value: unknown) => value is LogicalOrdinalQuery;
|
|
38
|
+
export type Expression = {
|
|
39
|
+
readonly kind: 'array-element';
|
|
40
|
+
readonly schemaId: string;
|
|
41
|
+
readonly property: string;
|
|
42
|
+
readonly expansionPath: string;
|
|
43
|
+
} | {
|
|
44
|
+
readonly kind: 'column';
|
|
45
|
+
readonly schemaId?: string;
|
|
46
|
+
readonly property: string;
|
|
47
|
+
readonly propertyId?: string;
|
|
48
|
+
readonly column: string;
|
|
49
|
+
readonly qualifier?: string;
|
|
50
|
+
} | {
|
|
51
|
+
readonly kind: 'property-sql';
|
|
52
|
+
readonly schemaId: string;
|
|
53
|
+
readonly property: string;
|
|
54
|
+
readonly propertyId: string;
|
|
55
|
+
readonly sql: string;
|
|
56
|
+
readonly qualifier?: string;
|
|
57
|
+
readonly timestampColumn?: string;
|
|
58
|
+
} | {
|
|
59
|
+
readonly kind: 'operator';
|
|
60
|
+
readonly operator: string;
|
|
61
|
+
readonly property?: string;
|
|
62
|
+
readonly column?: string;
|
|
63
|
+
readonly qualifier?: string;
|
|
64
|
+
readonly schemaId?: string;
|
|
65
|
+
readonly input?: Expression;
|
|
66
|
+
readonly components?: readonly Expression[];
|
|
67
|
+
readonly args: Readonly<Record<string, unknown>>;
|
|
68
|
+
readonly query?: Readonly<Record<string, unknown>>;
|
|
69
|
+
} | {
|
|
70
|
+
readonly kind: 'window';
|
|
71
|
+
readonly function: 'rank' | 'rowNumber';
|
|
72
|
+
readonly input: Expression;
|
|
73
|
+
readonly partitionBy: readonly Expression[];
|
|
74
|
+
readonly direction: 'ASC' | 'DESC';
|
|
75
|
+
} | {
|
|
76
|
+
readonly kind: 'cumulative';
|
|
77
|
+
readonly function: 'sum' | 'min' | 'max';
|
|
78
|
+
readonly input: Expression;
|
|
79
|
+
readonly partitionBy: readonly Expression[];
|
|
80
|
+
readonly orderBy: readonly {
|
|
81
|
+
readonly expression: Expression;
|
|
82
|
+
readonly direction: 'ASC' | 'DESC';
|
|
83
|
+
}[];
|
|
84
|
+
} | {
|
|
85
|
+
readonly kind: 'ordinal-encode';
|
|
86
|
+
readonly input: Expression;
|
|
87
|
+
readonly comparable: ComparableCategoryDefinition;
|
|
88
|
+
} | {
|
|
89
|
+
readonly kind: 'ordinal-decode';
|
|
90
|
+
readonly input: Expression;
|
|
91
|
+
readonly comparable: ComparableCategoryDefinition;
|
|
92
|
+
};
|
|
93
|
+
export interface ProjectionPlan {
|
|
94
|
+
readonly name: string;
|
|
95
|
+
readonly expression: Expression;
|
|
96
|
+
}
|
|
97
|
+
export interface OrderPlan {
|
|
98
|
+
readonly name: string;
|
|
99
|
+
readonly direction: 'ASC' | 'DESC';
|
|
100
|
+
readonly comparable?: ComparableCategoryDefinition;
|
|
101
|
+
readonly expression?: Expression;
|
|
102
|
+
}
|
|
103
|
+
export interface JoinPlan {
|
|
104
|
+
readonly kind: 'left';
|
|
105
|
+
readonly path: string;
|
|
106
|
+
readonly sourceAlias: string;
|
|
107
|
+
readonly sourceColumn: string;
|
|
108
|
+
readonly sourceSql?: string;
|
|
109
|
+
readonly sourceTimestampColumn?: string;
|
|
110
|
+
readonly sourceTimestampGranularity?: TimeGranularity;
|
|
111
|
+
readonly targetSchemaId: string;
|
|
112
|
+
readonly targetSource: string;
|
|
113
|
+
readonly targetSourceSql?: string;
|
|
114
|
+
readonly targetAlias: string;
|
|
115
|
+
readonly targetColumn: string;
|
|
116
|
+
readonly targetSql?: string;
|
|
117
|
+
readonly targetTimestampColumn?: string;
|
|
118
|
+
readonly targetTimestampGranularity?: TimeGranularity;
|
|
119
|
+
readonly sourceArrayExpansionPath?: string;
|
|
120
|
+
}
|
|
121
|
+
export interface ArrayExpansionPlan {
|
|
122
|
+
readonly path: string;
|
|
123
|
+
readonly sourceAlias: string;
|
|
124
|
+
readonly sourceColumn: string;
|
|
125
|
+
readonly sourceSql?: string;
|
|
126
|
+
readonly sourceTimestampColumn?: string;
|
|
127
|
+
readonly alias: string;
|
|
128
|
+
}
|
|
129
|
+
export type PaginationPlan = {
|
|
130
|
+
readonly kind: 'rows';
|
|
131
|
+
readonly page: number;
|
|
132
|
+
readonly pageSize: number;
|
|
133
|
+
} | {
|
|
134
|
+
readonly kind: 'ratio';
|
|
135
|
+
readonly page: number;
|
|
136
|
+
readonly ratio: number;
|
|
137
|
+
};
|
|
138
|
+
export interface GroupLimitPlan {
|
|
139
|
+
readonly count: number;
|
|
140
|
+
readonly partitionBy: readonly string[];
|
|
141
|
+
readonly orderBy: readonly OrderPlan[];
|
|
142
|
+
}
|
|
143
|
+
export type RowIdentityPlan = {
|
|
144
|
+
readonly kind: 'group';
|
|
145
|
+
readonly names: readonly string[];
|
|
146
|
+
} | {
|
|
147
|
+
readonly kind: 'property';
|
|
148
|
+
readonly column: string;
|
|
149
|
+
readonly internalName: string;
|
|
150
|
+
} | {
|
|
151
|
+
readonly kind: 'generated';
|
|
152
|
+
} | {
|
|
153
|
+
readonly kind: 'singleton';
|
|
154
|
+
};
|
|
155
|
+
export interface LogicalPlan {
|
|
156
|
+
readonly schemaId: string;
|
|
157
|
+
readonly source: string;
|
|
158
|
+
/** Trusted derived-table SQL supplied by the selected physical mapping. */
|
|
159
|
+
readonly sourceSql?: string;
|
|
160
|
+
/** Physical mapping selected by the Planner for this logical Schema. */
|
|
161
|
+
readonly mappingId?: string;
|
|
162
|
+
/** Child relations combined by their compatible group identity. */
|
|
163
|
+
readonly composition?: readonly LogicalPlan[];
|
|
164
|
+
/** Optional query plan compiled as the derived-table source of this plan. */
|
|
165
|
+
readonly sourcePlan?: LogicalPlan;
|
|
166
|
+
readonly sourceAlias?: string;
|
|
167
|
+
readonly fields: Readonly<Record<string, string>>;
|
|
168
|
+
readonly fieldReferences?: Readonly<Record<string, FieldReferencePlan>>;
|
|
169
|
+
readonly joins?: readonly JoinPlan[];
|
|
170
|
+
readonly arrayExpansions?: readonly ArrayExpansionPlan[];
|
|
171
|
+
readonly projections: readonly ProjectionPlan[];
|
|
172
|
+
readonly columnProperties?: readonly ResultProperty[];
|
|
173
|
+
readonly groupBy: readonly ProjectionPlan[];
|
|
174
|
+
readonly query?: Readonly<Record<string, unknown>>;
|
|
175
|
+
readonly having?: Readonly<Record<string, unknown>>;
|
|
176
|
+
readonly orderBy: readonly OrderPlan[];
|
|
177
|
+
readonly pagination?: PaginationPlan;
|
|
178
|
+
readonly groupLimit?: GroupLimitPlan;
|
|
179
|
+
/** Strategy used by the executor to add the system-owned `_id` to each result row. */
|
|
180
|
+
readonly rowIdentity: RowIdentityPlan;
|
|
181
|
+
}
|
|
182
|
+
export interface LineageColumnSource {
|
|
183
|
+
readonly schemaId: string;
|
|
184
|
+
readonly propertyId: string;
|
|
185
|
+
readonly propertyName: string;
|
|
186
|
+
readonly physicalColumn: string;
|
|
187
|
+
}
|
|
188
|
+
export interface LineageOutput {
|
|
189
|
+
readonly name: string;
|
|
190
|
+
readonly sources: readonly LineageColumnSource[];
|
|
191
|
+
readonly transformations: readonly string[];
|
|
192
|
+
}
|
|
193
|
+
export interface QueryLineage {
|
|
194
|
+
readonly source: {
|
|
195
|
+
readonly schemaId: string;
|
|
196
|
+
readonly schemaName: string;
|
|
197
|
+
readonly physicalTable: string;
|
|
198
|
+
readonly provider: CoreComputeProvider['kind'];
|
|
199
|
+
};
|
|
200
|
+
readonly outputs: readonly LineageOutput[];
|
|
201
|
+
readonly filters: readonly LineageColumnSource[];
|
|
202
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const o=r=>typeof r=="object"&&r!==null&&!Array.isArray(r)&&r.kind==="logicform-subquery"&&typeof r.plan=="object"&&r.plan!==null,i=r=>typeof r=="object"&&r!==null&&!Array.isArray(r)&&r.kind==="recursive-query",y=r=>typeof r=="object"&&r!==null&&!Array.isArray(r)&&r.kind==="ordinal-query";export{y as isLogicalOrdinalQuery,o as isLogicalQuerySubquery,i as isLogicalRecursiveQuery};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{SemanticDBError as h}from"../../errors.js";const s=({source:o,properties:y})=>{const t=o.hierarchy;if(!Array.isArray(t))return t===void 0?{}:{hierarchy:t};let n=o.hierarchy_property;if(typeof n!="string"||n.length===0){const r=y.filter(({type:c})=>c==="ID");if(r.length!==1)throw new h("LEGACY_HIERARCHY_ID_PROPERTY_REQUIRED","Legacy Schema hierarchy without hierarchy_property must contain exactly one ID property",{idPropertyCount:r.length});const e=r[0];n=e?.id??e?.name}const i=t.map(r=>{if(typeof r!="object"||r===null||Array.isArray(r))return;const e=r;if(!(typeof e.name!="string"||!Number.isInteger(e.code_length)))return{name:e.name,...Array.isArray(e.syno)?{synonyms:e.syno}:{},codeLength:e.code_length}});if(i.some(r=>r===void 0))return{};const a=t[0];return{hierarchy:{property:n,storage:a?.use_full_length===!0?"zero-padded":"compact",levels:i}}};export{s as normalizeLegacyHierarchy};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{SemanticDBError as o}from"../../errors.js";const i=r=>{if(!r.hierarchy)return;const e=r.properties.find(({name:t})=>t===r.hierarchy?.property);if(!e)throw new o("HIERARCHY_PROPERTY_NOT_FOUND",`Schema hierarchy.property does not exist: ${r.hierarchy.property}`,{schemaId:r.id,property:r.hierarchy.property});return e};export{i as resolveHierarchyEntityFilterProperty};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{normalizeLegacyHierarchy as r}from"./compatibility.js";import{resolveHierarchyEntityFilterProperty as e}from"./entity-identity.js";import{hierarchyLevelOperator as a}from"./operator.js";import{hierarchySchemaMetadata as t}from"./resolve-schema.js";const o=Object.freeze({name:"hierarchy",schemaMetadata:t,legacySchemaKeys:["hierarchy_property"],normalizeLegacySchema:r,resolveEntityFilterProperty:e,operators:[a]});export{o as hierarchyPlugin};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{SemanticDBError as i}from"../../errors.js";import{resolvePropertyPath as y}from"../../schema/resolve-property-path.js";const d=(n,t,o)=>{const e=y(n,t,o);if(e.property.primal_type!=="object")return{schema:e.schema,reference:e.canonicalName,relation:!1};if(e.property.isArray)throw new i("ARRAY_HIERARCHY_RELATION_UNSUPPORTED",`$hierarchyLevel cannot group an array relation: ${e.canonicalName}`);if(!e.property.ref||!o)throw new i("SCHEMA_RESOLVER_REQUIRED",`$hierarchyLevel requires a Schema resolver for relation ${e.canonicalName}`);return{schema:o(e.property.ref),reference:e.canonicalName,relation:!0}},f={name:"$hierarchyLevel",defaultName:({operandName:n,args:t,locale:o})=>{const e=typeof t.level=="string"?t.level:"";return o.toLowerCase().startsWith("en")?`${n}${e?` ${e}`:""} level`:`${n}${e}\u5C42\u7EA7`},kind:"scalar",planInput({reference:n,args:t,schema:o,resolveSchema:e}){const h=Object.keys(t).filter(a=>a!=="level");if(h.length>0||typeof t.level!="string"||t.level.length===0)throw new i("INVALID_HIERARCHY_LEVEL_ARGS","$hierarchyLevel args must contain exactly one non-empty level string",{unsupportedArgs:h});const r=d(o,n,e),c=r.schema.hierarchy;if(!c)throw new i("SCHEMA_HIERARCHY_REQUIRED",`Schema ${r.schema.id} does not declare hierarchy`,{schemaId:r.schema.id});const l=r.schema.properties.find(({name:a})=>a===c.property);if(!l)throw new i("HIERARCHY_PROPERTY_NOT_FOUND",`Schema hierarchy.property does not exist: ${c.property}`);if(!r.relation&&l.name!==y(o,n,e).property.name)throw new i("HIERARCHY_PROPERTY_REQUIRED",`$hierarchyLevel pred must be an object relation or hierarchy property ${l.name}`);let s=0;const p=c.levels.find(a=>(s+=a.codeLength,a.name===t.level||a.synonyms?.includes(t.level)));if(!p)throw new i("HIERARCHY_LEVEL_NOT_FOUND",`Schema ${r.schema.id} does not declare hierarchy level: ${t.level}`,{schemaId:r.schema.id,level:t.level});const R=c.levels.reduce((a,u)=>a+u.codeLength,0),m=r.schema.properties.filter(({type:a})=>a==="ID");return{reference:r.relation&&m.length===1&&m[0]?.name===l.name?r.reference:r.relation?`${r.reference}_${l.name}`:r.reference,args:{level:p.name,codeLength:s,totalLength:R,storage:c.storage}}},toSQL({expression:n,args:t,sql:o}){if(!n)throw new Error("$hierarchyLevel requires a hierarchy pred");const e=t.codeLength,h=t.totalLength,r=t.storage;if(!Number.isInteger(e)||!Number.isInteger(h)||Number(e)<=0||Number(h)<Number(e)||r!=="compact"&&r!=="zero-padded")throw new i("INVALID_HIERARCHY_LEVEL_PLAN","$hierarchyLevel must be resolved by the planner before SQL compilation");const c=o.substring(n,1,Number(e)),l=Number(h)-Number(e);return r==="zero-padded"&&l>0?o.concat([c,o.value("0".repeat(l))]):c},getOutputProperty({name:n}){return{name:n,type:"string",primal_type:"string",isArray:!1}}};export{f as hierarchyLevelOperator};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{SemanticDBError as r}from"../../errors.js";const H={keys:["hierarchy"],resolve(m,R){if("hierarchy_property"in m)throw new r("LEGACY_HIERARCHY_PROPERTY_NOT_ALLOWED","Schema hierarchy must declare hierarchy.property instead of hierarchy_property");const s=m.hierarchy;if(s===void 0)return{};if(typeof s!="object"||s===null||Array.isArray(s))throw new r("INVALID_HIERARCHY","Schema hierarchy must be an object containing property, levels, and optional storage");const n=s,l=Object.keys(n).filter(o=>o!=="property"&&o!=="storage"&&o!=="levels");if(l.length>0)throw new r("UNSUPPORTED_HIERARCHY_FIELD","Schema hierarchy only supports property, storage, and levels",{unsupportedKeys:l});if(typeof n.property!="string"||n.property.length===0)throw new r("HIERARCHY_PROPERTY_REQUIRED","Schema hierarchy.property must be a non-empty property name or id");const a=R.find(o=>o.name===n.property||o.id===n.property);if(!a)throw new r("HIERARCHY_PROPERTY_NOT_FOUND",`Schema hierarchy.property does not exist: ${n.property}`,{property:n.property});if(a.primal_type!=="string")throw new r("INVALID_HIERARCHY_PROPERTY",`Hierarchy property ${a.name} must have primal_type string`,{property:a.name,primal_type:a.primal_type});const y=n.storage??"compact";if(y!=="compact"&&y!=="zero-padded")throw new r("INVALID_HIERARCHY_STORAGE","Schema hierarchy.storage must be compact or zero-padded");if(!Array.isArray(n.levels)||n.levels.length===0)throw new r("HIERARCHY_LEVELS_REQUIRED","Schema hierarchy.levels must be a non-empty array");const h=new Set,p=new Set,_=n.levels.map((o,i)=>{if(typeof o!="object"||o===null||Array.isArray(o))throw new r("INVALID_HIERARCHY_LEVEL",`Hierarchy level ${i} must be an object`);const e=o,E=Object.keys(e).filter(t=>t!=="name"&&t!=="synonyms"&&t!=="codeLength");if(E.length>0)throw new r("UNSUPPORTED_HIERARCHY_LEVEL_FIELD",`Hierarchy level ${i} only supports name, synonyms, and codeLength`,{unsupportedKeys:E});if(typeof e.name!="string"||e.name.length===0)throw new r("INVALID_HIERARCHY_LEVEL",`Hierarchy level ${i} name must not be empty`);if(h.has(e.name)||p.has(e.name))throw new r("DUPLICATE_HIERARCHY_LEVEL",`Duplicate hierarchy level name: ${e.name}`);if(!Number.isInteger(e.codeLength)||Number(e.codeLength)<=0)throw new r("INVALID_HIERARCHY_CODE_LENGTH",`Hierarchy level ${e.name} codeLength must be a positive integer`);if(e.synonyms!==void 0&&(!Array.isArray(e.synonyms)||e.synonyms.some(t=>typeof t!="string"||t.length===0)))throw new r("INVALID_HIERARCHY_SYNONYMS",`Hierarchy level ${e.name} synonyms must contain only non-empty strings`);const c=e.synonyms??[];for(const t of c){if(t===e.name||h.has(t)||p.has(t))throw new r("DUPLICATE_HIERARCHY_LEVEL",`Duplicate hierarchy level alias: ${t}`);p.add(t)}return h.add(e.name),{name:e.name,...c.length>0?{synonyms:[...c]}:{},codeLength:Number(e.codeLength)}});return{hierarchy:{property:a.name,storage:y,levels:_}}}};export{H as hierarchySchemaMetadata};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface HierarchyLevelDefinition {
|
|
2
|
+
readonly name: string;
|
|
3
|
+
readonly synonyms?: readonly string[];
|
|
4
|
+
readonly codeLength: number;
|
|
5
|
+
}
|
|
6
|
+
export interface HierarchyDefinition {
|
|
7
|
+
/** Property that physically stores the complete hierarchy code. */
|
|
8
|
+
readonly property: string;
|
|
9
|
+
/** Compact codes stop at their level; zero-padded codes fill remaining segments with zeroes. */
|
|
10
|
+
readonly storage?: 'compact' | 'zero-padded';
|
|
11
|
+
readonly levels: readonly HierarchyLevelDefinition[];
|
|
12
|
+
}
|
|
13
|
+
export interface ResolvedHierarchyDefinition extends Omit<HierarchyDefinition, 'storage'> {
|
|
14
|
+
/** Canonical logical property name. */
|
|
15
|
+
readonly property: string;
|
|
16
|
+
readonly storage: 'compact' | 'zero-padded';
|
|
17
|
+
}
|
|
18
|
+
declare module '../../semantic-types/types' {
|
|
19
|
+
interface SemanticSchemaMetadata {
|
|
20
|
+
readonly hierarchy?: HierarchyDefinition;
|
|
21
|
+
}
|
|
22
|
+
interface ResolvedSemanticSchemaMetadata {
|
|
23
|
+
readonly hierarchy?: ResolvedHierarchyDefinition;
|
|
24
|
+
}
|
|
25
|
+
interface LegacySemanticSchemaMetadata {
|
|
26
|
+
readonly hierarchy_property?: unknown;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SemanticDBPlugin } from './types';
|
|
2
|
+
export type { LegacySchemaPluginContext, SchemaMetadataPlugin, SemanticDBPlugin } from './types';
|
|
3
|
+
/** Built-in capabilities are composed here; feature implementations live in their own folders. */
|
|
4
|
+
export declare const builtinPlugins: readonly SemanticDBPlugin[];
|
|
5
|
+
export declare const resolvePlugins: (plugins?: readonly SemanticDBPlugin[]) => readonly SemanticDBPlugin[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{hierarchyPlugin as l}from"./hierarchy/index.js";import{SemanticDBError as n}from"../errors.js";const i=Object.freeze([l]),E=(m=[])=>{const t=[...i,...m],r=new Set,o=new Set,s=new Set;for(const e of t){if(!e.name)throw new n("INVALID_PLUGIN","Plugin name must not be empty");if(r.has(e.name))throw new n("PLUGIN_ALREADY_REGISTERED",`Plugin is already registered: ${e.name}`,{plugin:e.name});r.add(e.name);for(const a of[...e.schemaMetadata?.keys??[],...e.legacySchemaKeys??[]]){if(!a)throw new n("INVALID_PLUGIN_METADATA_KEY","Plugin metadata key must not be empty");if(o.has(a))throw new n("PLUGIN_METADATA_KEY_ALREADY_REGISTERED",`Plugin Schema metadata key is already registered: ${a}`,{key:a,plugin:e.name});o.add(a)}for(const a of e.operators??[]){if(s.has(a.name))throw new n("PLUGIN_OPERATOR_ALREADY_REGISTERED",`Plugin Operator is already registered: ${a.name}`,{operator:a.name,plugin:e.name});s.add(a.name)}}return Object.freeze(t)};export{i as builtinPlugins,E as resolvePlugins};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { OperatorDefinition } from '../operators/types';
|
|
2
|
+
import type { ResolvedSemanticProperty, ResolvedSemanticSchema, SemanticSchemaDraft } from '../semantic-types/types';
|
|
3
|
+
export interface SchemaMetadataPlugin {
|
|
4
|
+
readonly keys: readonly string[];
|
|
5
|
+
readonly resolve: (schema: SemanticSchemaDraft, properties: readonly ResolvedSemanticProperty[]) => Readonly<Record<string, unknown>>;
|
|
6
|
+
}
|
|
7
|
+
export interface LegacySchemaPluginContext {
|
|
8
|
+
readonly source: Readonly<Record<string, unknown>>;
|
|
9
|
+
readonly properties: readonly SemanticSchemaDraft['properties'][number][];
|
|
10
|
+
}
|
|
11
|
+
export interface SemanticDBPlugin {
|
|
12
|
+
/** Stable name used for diagnostics and duplicate detection. */
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly schemaMetadata?: SchemaMetadataPlugin;
|
|
15
|
+
/** Legacy-only Schema fields removed after normalizeLegacySchema runs. */
|
|
16
|
+
readonly legacySchemaKeys?: readonly string[];
|
|
17
|
+
readonly normalizeLegacySchema?: (context: LegacySchemaPluginContext) => Readonly<Record<string, unknown>>;
|
|
18
|
+
readonly resolveEntityFilterProperty?: (schema: ResolvedSemanticSchema) => ResolvedSemanticProperty | undefined;
|
|
19
|
+
readonly operators?: readonly OperatorDefinition[];
|
|
20
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SemanticDBPlugin } from '../plugins/index';
|
|
2
|
+
import type { ResolvedSemanticProperty, ResolvedSemanticSchema } from '../semantic-types/index';
|
|
3
|
+
export declare const isConcreteEntityId: (value: unknown) => value is string;
|
|
4
|
+
export declare const resolveEntityIdProperty: (schema: ResolvedSemanticSchema) => ResolvedSemanticProperty;
|
|
5
|
+
export declare const resolveEntityFilterProperty: (schema: ResolvedSemanticSchema, plugins?: readonly SemanticDBPlugin[]) => ResolvedSemanticProperty;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{SemanticDBError as i}from"../errors.js";import{resolvePlugins as p}from"../plugins/index.js";const s=t=>typeof t=="string"&&t.length>0&&t!=="placeholder",n=t=>{const r=t.properties.filter(({type:e})=>e==="ID");if(r.length!==1)throw new i("ENTITY_ID_PROPERTY_REQUIRED",`Schema ${t.id} must contain exactly one ID property to use entity_id`,{schemaId:t.id,idPropertyCount:r.length});return r[0]},l=(t,r=[])=>{for(const e of p(r)){const o=e.resolveEntityFilterProperty?.(t);if(o)return o}return n(t)};export{s as isConcreteEntityId,l as resolveEntityFilterProperty,n as resolveEntityIdProperty};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { buildFieldMap, getProperty, getSchema, } from './schema-registry';
|
|
2
|
+
export { resolvePropertyPath } from './resolve-property-path';
|
|
3
|
+
export { isConcreteEntityId, resolveEntityFilterProperty, resolveEntityIdProperty, } from './entity-identity';
|
|
4
|
+
export type { ResolvedPropertyPath, ResolvedRelationSegment, ResolvedSchemaLookup, } from './resolve-property-path';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ResolvedSemanticProperty, ResolvedSemanticSchema } from '../semantic-types/index';
|
|
2
|
+
export type ResolvedSchemaLookup = (schemaId: string) => ResolvedSemanticSchema;
|
|
3
|
+
export interface ResolvedRelationSegment {
|
|
4
|
+
readonly sourceSchema: ResolvedSemanticSchema;
|
|
5
|
+
readonly property: ResolvedSemanticProperty;
|
|
6
|
+
readonly targetSchema: ResolvedSemanticSchema;
|
|
7
|
+
}
|
|
8
|
+
export interface ResolvedPropertyPath {
|
|
9
|
+
readonly canonicalName: string;
|
|
10
|
+
readonly canonicalId: string;
|
|
11
|
+
readonly schema: ResolvedSemanticSchema;
|
|
12
|
+
readonly property: ResolvedSemanticProperty;
|
|
13
|
+
readonly relations: readonly ResolvedRelationSegment[];
|
|
14
|
+
}
|
|
15
|
+
export declare const resolvePropertyPath: (rootSchema: ResolvedSemanticSchema, reference: string, resolveSchema?: ResolvedSchemaLookup) => ResolvedPropertyPath;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{SemanticDBError as o}from"../errors.js";const p=(a,n)=>a.properties.some(i=>i!==n&&i.id===n.name)?n.id:n.name,l=(a,n)=>a.properties.flatMap(i=>[...n.startsWith(`${i.id}_`)?[{property:i,prefix:i.id}]:[],...i.name!==i.id&&n.startsWith(`${i.name}_`)?[{property:i,prefix:i.name}]:[]]).sort((i,s)=>s.prefix.length-i.prefix.length||(s.prefix===s.property.id?1:0)-(i.prefix===i.property.id?1:0)),c=(a,n,i)=>{const s=a.properties.find(t=>t.id===n)??a.properties.find(t=>t.name===n);if(s)return{canonicalName:p(a,s),canonicalId:s.id,schema:a,property:s,relations:[]};for(const{property:t,prefix:d}of l(a,n)){if(t.primal_type!=="object"||!t.ref)continue;if(!i)throw new o("SCHEMA_RESOLVER_REQUIRED",`Resolving property path ${n} requires a Schema resolver`);const e=i(t.ref),r=c(e,n.slice(d.length+1),i);return{canonicalName:`${p(a,t)}_${r.canonicalName}`,canonicalId:`${t.id}_${r.canonicalId}`,schema:r.schema,property:r.property,relations:[{sourceSchema:a,property:t,targetSchema:e},...r.relations]}}throw new o("PROPERTY_NOT_FOUND",`Property path not found in ${a.id}: ${n}`,{schemaId:a.id,property:n})};export{c as resolvePropertyPath};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ResolvedSemanticProperty, ResolvedSemanticSchema, SemanticSchemaDraft } from '../semantic-types/index';
|
|
2
|
+
export declare const getSchema: (schemaId: string, schemas: Readonly<Record<string, SemanticSchemaDraft>>) => SemanticSchemaDraft;
|
|
3
|
+
export declare const getProperty: (schema: ResolvedSemanticSchema, nameOrId: string) => ResolvedSemanticProperty;
|
|
4
|
+
export declare const buildFieldMap: (schema: ResolvedSemanticSchema) => Readonly<Record<string, string>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{SemanticDBError as r}from"../errors.js";const o=(t,e)=>{const i=e[t];if(!i)throw new r("SCHEMA_NOT_FOUND",`Schema not found: ${t}`,{schemaId:t});if("_id"in i||"_sid"in i)throw new r("LEGACY_SCHEMA_ID_NOT_ALLOWED","Schema must use id instead of _id; _sid is not supported",{schemaId:t});if("sid"in i)throw new r("SCHEMA_SID_NOT_ALLOWED","Schema must not declare sid",{schemaId:t});if(i.id!==t)throw new r("SCHEMA_ID_MISMATCH",`Schema registry key ${t} does not match schema.id ${i.id}`,{registryKey:t,schemaId:i.id});return i},d=(t,e)=>{const i=t.properties.find(n=>n.id===e)??t.properties.find(n=>n.name===e);if(!i)throw new r("PROPERTY_NOT_FOUND",`Property not found in ${t.id}: ${e}`,{schemaId:t.id,property:e});return i},s=t=>{const e=t.properties.flatMap(i=>[[i.name,i.id],[i.id,i.id]]);return Object.freeze(Object.fromEntries(e))};export{s as buildFieldMap,d as getProperty,o as getSchema};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SchemaMappingDefinition } from './types';
|
|
2
|
+
export declare const parseDailyExpireAt: (value: string) => {
|
|
3
|
+
readonly hour: number;
|
|
4
|
+
readonly minute: number;
|
|
5
|
+
readonly second: number;
|
|
6
|
+
} | undefined;
|
|
7
|
+
export declare const validateSourceFreshness: (definition: SchemaMappingDefinition) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{SemanticDBError as n}from"../errors.js";const m=/^(\d{2}):(\d{2})(?::(\d{2}))?$/,o=t=>{const e=m.exec(t);if(!e)return;const r=Number(e[1]),s=Number(e[2]),i=Number(e[3]??0);if(!(r>23||s>59||i>59))return{hour:r,minute:s,second:i}},c=t=>{const e=t.freshness;if(e){if(e.mode==="ttl"){if(!Number.isInteger(e.ttlSeconds)||e.ttlSeconds<=0)throw new n("INVALID_SOURCE_FRESHNESS","TTL freshness requires a positive integer ttlSeconds");return}if(e.mode==="daily"){if(!o(e.expireAt))throw new n("INVALID_SOURCE_FRESHNESS","Daily freshness expireAt must use HH:mm or HH:mm:ss");if(e.timeZone)try{new Intl.DateTimeFormat("en-US",{timeZone:e.timeZone}).format()}catch{throw new n("INVALID_SOURCE_FRESHNESS",`Invalid freshness timeZone: ${e.timeZone}`)}}}};export{o as parseDailyExpireAt,c as validateSourceFreshness};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SchemaMappingDefinition } from './types';
|
|
2
|
+
export declare class SchemaMappingRegistry {
|
|
3
|
+
#private;
|
|
4
|
+
constructor(definitions?: readonly SchemaMappingDefinition[]);
|
|
5
|
+
register(definition: SchemaMappingDefinition): this;
|
|
6
|
+
get(schemaId: string): SchemaMappingDefinition;
|
|
7
|
+
list(schemaId: string): readonly SchemaMappingDefinition[];
|
|
8
|
+
findSource(schemaId: string, source: string): SchemaMappingDefinition | undefined;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{SemanticDBError as s}from"../errors.js";import{validateSourceFreshness as m}from"./freshness.js";class o{#e=new Map;constructor(e=[]){for(const r of e)this.register(r)}register(e){if(!e.schemaId)throw new s("INVALID_SCHEMA_MAPPING","Schema mapping schemaId must not be empty");if(!e.source)throw new s("INVALID_SCHEMA_MAPPING","Schema mapping source must not be empty");if(e.sourceSql!==void 0&&e.sourceSql.trim().length===0)throw new s("INVALID_SCHEMA_MAPPING","Schema mapping sourceSql must not be empty");if(e.id!==void 0&&!e.id)throw new s("INVALID_SCHEMA_MAPPING","Schema mapping id must not be empty");if(e.connectionId.trim().length===0)throw new s("INVALID_SCHEMA_MAPPING","Schema mapping connectionId must not be empty");if(e.priority!==void 0&&!Number.isFinite(e.priority))throw new s("INVALID_SCHEMA_MAPPING","Schema mapping priority must be finite");for(const t of e.predMappings??[])if(!t.match.operator||!t.match.pred||!t.column)throw new s("INVALID_SCHEMA_MAPPING","Schema mapping PredItem matches require operator, pred, and column");m(e);const r=this.#e.get(e.schemaId)??[],p=e.id??e.source;if(r.some(t=>(t.id??t.source)===p||t.source===e.source))throw new s("SCHEMA_MAPPING_ALREADY_REGISTERED",`Schema mapping is already registered: ${e.schemaId}:${p}`,{schemaId:e.schemaId,mappingId:p});return this.#e.set(e.schemaId,[...r,e]),this}get(e){const r=this.list(e);if(r.length===1)return r[0];const p=r.filter(t=>t.predMappings===void 0&&t.properties===void 0);if(p.length===1)return p[0];throw new s("SCHEMA_MAPPING_AMBIGUOUS",`Schema ${e} has multiple mappings and requires LogicForm-based selection`,{schemaId:e,mappingIds:r.map(t=>t.id??t.source)})}list(e){const r=this.#e.get(e);if(!r||r.length===0)throw new s("SCHEMA_MAPPING_NOT_FOUND",`Schema mapping is not registered: ${e}`,{schemaId:e});return r}findSource(e,r){return this.#e.get(e)?.find(p=>p.source===r)}}export{o as SchemaMappingRegistry};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { QueryType } from '../logicform-types';
|
|
2
|
+
export type SourceFreshnessPolicy = {
|
|
3
|
+
readonly mode: 'ttl';
|
|
4
|
+
readonly ttlSeconds: number;
|
|
5
|
+
} | {
|
|
6
|
+
readonly mode: 'daily';
|
|
7
|
+
readonly expireAt: string;
|
|
8
|
+
readonly timeZone?: string;
|
|
9
|
+
} | {
|
|
10
|
+
readonly mode: 'manual';
|
|
11
|
+
};
|
|
12
|
+
export interface SchemaMappingPredMatch {
|
|
13
|
+
/** Defaults to the owning mapping's Schema. */
|
|
14
|
+
readonly schema?: string;
|
|
15
|
+
readonly operator: string;
|
|
16
|
+
readonly pred: string;
|
|
17
|
+
/** Required conjunctive conditions across the LogicForm and PredItem queries. */
|
|
18
|
+
readonly query?: QueryType;
|
|
19
|
+
}
|
|
20
|
+
export interface SchemaMappingPredDefinition {
|
|
21
|
+
readonly match: SchemaMappingPredMatch;
|
|
22
|
+
/** Physical column used as the matched PredItem's operator input. */
|
|
23
|
+
readonly column: string;
|
|
24
|
+
}
|
|
25
|
+
export interface SchemaMappingDefinition {
|
|
26
|
+
/** Stable identity when a Schema has multiple physical mappings. */
|
|
27
|
+
readonly id?: string;
|
|
28
|
+
readonly schemaId: string;
|
|
29
|
+
/** Database connection used by this physical mapping. */
|
|
30
|
+
readonly connectionId: string;
|
|
31
|
+
/** Stable physical source identity used by connection routing, lineage, and cache invalidation. */
|
|
32
|
+
readonly source: string;
|
|
33
|
+
/** Optional trusted query compiled as a derived-table source instead of reading source directly. */
|
|
34
|
+
readonly sourceSql?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Supported logical properties and their physical columns. Missing means all
|
|
37
|
+
* Schema properties keep their configured physical IDs.
|
|
38
|
+
*/
|
|
39
|
+
readonly properties?: Readonly<Record<string, string>>;
|
|
40
|
+
/** PredItem patterns implemented by physical measure columns in this source. */
|
|
41
|
+
readonly predMappings?: readonly SchemaMappingPredDefinition[];
|
|
42
|
+
/** Higher values win when multiple candidates cover the same LogicForm. */
|
|
43
|
+
readonly priority?: number;
|
|
44
|
+
/** Missing means queries depending on this physical source are not cached. */
|
|
45
|
+
readonly freshness?: SourceFreshnessPolicy;
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const o={name:"boolean",primalType:"boolean",hydrateResult(e){return typeof e=="number"?e===1:e}};export{o as booleanSemanticType};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e={name:"category",primalType:"string"};export{e as categorySemanticType};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e={name:"currency",primalType:"number"};export{e as currencySemanticType};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e={name:"date",primalType:"date"};export{e as dateSemanticType};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e={name:"duration",primalType:"number"};export{e as durationSemanticType};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e={name:"end_date",primalType:"date"};export{e as endDateSemanticType};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{hydrateObjectResult as t}from"./object.js";const e={name:"entity",primalType:"object",hydrateResult:t};export{e as entitySemanticType};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e={name:"file",primalType:"string"};export{e as fileSemanticType};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const a={name:"humanName",primalType:"string"};export{a as humanNameSemanticType};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e={name:"ID",primalType:"string"};export{e as idSemanticType};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e={name:"image",primalType:"string"};export{e as imageSemanticType};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{booleanSemanticType as m}from"./boolean.js";import{categorySemanticType as e}from"./category.js";import{currencySemanticType as t}from"./currency.js";import{dateSemanticType as r}from"./date.js";import{durationSemanticType as i}from"./duration.js";import{endDateSemanticType as o}from"./end-date.js";import{entitySemanticType as p}from"./entity.js";import{fileSemanticType as a}from"./file.js";import{humanNameSemanticType as n}from"./human-name.js";import{idSemanticType as c}from"./id.js";import{imageSemanticType as y}from"./image.js";import{intSemanticType as f}from"./int.js";import{nameSemanticType as S}from"./name.js";import{numberSemanticType as T}from"./number.js";import{objectSemanticType as b}from"./object.js";import{orderSemanticType as d}from"./order.js";import{percentageSemanticType as s}from"./percentage.js";import{startDateSemanticType as u}from"./start-date.js";import{stringSemanticType as g}from"./string.js";import{timestampSemanticType as l}from"./timestamp.js";const j=Object.freeze([c,g,S,n,e,y,a,T,f,t,s,i,d,m,l,r,u,o,p,b]);export{j as builtinSemanticTypes};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e={name:"int",primalType:"number"};export{e as intSemanticType};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e={name:"name",primalType:"string"};export{e as nameSemanticType};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e={name:"number",primalType:"number"};export{e as numberSemanticType};
|