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 @@
|
|
|
1
|
+
const r=(e,{property:t,requestEntity:n})=>!t.ref||e===void 0||e===null||typeof e=="object"&&!Array.isArray(e)?e:n(t.ref,e),c={name:"object",primalType:"object",hydrateResult:r};export{r as hydrateObjectResult,c as objectSemanticType};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e={name:"order",primalType:"number"};export{e as orderSemanticType};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e={name:"percentage",primalType:"number"};export{e as percentageSemanticType};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const t={name:"start_date",primalType:"date"};export{t as startDateSemanticType};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const n={name:"string",primalType:"string"};export{n as stringSemanticType};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e={name:"timestamp",primalType:"date"};export{e as timestampSemanticType};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SemanticTypeRegistry } from './registry';
|
|
2
|
+
export { builtinSemanticTypes } from './builtins/index';
|
|
3
|
+
export { SemanticTypeRegistry } from './registry';
|
|
4
|
+
export { resolveSchema } from './resolve-schema';
|
|
5
|
+
export { validateResolvedSchema } from './validate-resolved-schema';
|
|
6
|
+
export { normalizePrimalQuery } from './primal-types/index';
|
|
7
|
+
export type { ComparableCategoryDefinition, PropertySqlDefinition, PrimalType, ResolvedSemanticProperty, ResolvedSemanticSchema, LegacySemanticSchemaMetadata, ResolvedSemanticSchemaMetadata, SemanticSchemaMetadata, SemanticTypeNormalizeContext, SemanticPeriodEvaluationContext, SemanticTypeResultContext, SemanticTypeResultProperty, SemanticPropertyDraft, SemanticSchemaDraft, SemanticTypeDefinition, TimeGranularity, TemporalSemantics, } from './types';
|
|
8
|
+
export type { HierarchyDefinition, HierarchyLevelDefinition, ResolvedHierarchyDefinition, } from '../plugins/hierarchy/index';
|
|
9
|
+
export declare const createSemanticTypeRegistry: () => SemanticTypeRegistry;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{builtinSemanticTypes as e}from"./builtins/index.js";import{SemanticTypeRegistry as t}from"./registry.js";import"./primal-types/date.js";const i=()=>new t(e);export{t as SemanticTypeRegistry,e as builtinSemanticTypes,i as createSemanticTypeRegistry};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import o from"dayjs";import b from"dayjs/plugin/customParseFormat.js";import A from"dayjs/plugin/isoWeek.js";import k from"dayjs/plugin/quarterOfYear.js";import{SemanticDBError as p}from"../../errors.js";import{isLogicform as O}from"../../logicform-types.js";o.extend(b),o.extend(A),o.extend(k);const U="YYYY-MM-DD HH:mm:ss",h=new Set(["YTD","QTD","MTD","WTD","DTD"]),q=new Set(["$eq","$gt","$gte","$lt","$lte","$in","$nin","$and","$or"]),$=["second","minute","hour","day","week","month","quarter","year"],a=t=>Object.prototype.toString.call(t)==="[object Object]",D=t=>!a(t)||"$gte"in t||"$gt"in t||"$lte"in t||"$lt"in t||"$or"in t||"$ne"in t?!1:typeof t.granularity=="string"&&$.includes(t.granularity)&&typeof t.offset=="number"||$.some(r=>r in t),c=t=>o(t).format(U),P=(t,r)=>$.find(n=>n in t||r!==void 0),E=(t,r,n)=>r==="month"?t.month(n-1):r==="day"?t.date(n):r==="week"?t.isoWeek(n):r==="quarter"?t.quarter(n):t.set(r,n),l=(t,r)=>{const n=typeof t.granularity=="string"?t.granularity:void 0,e=n?{[n]:t.offset}:void 0,i=n??P(t,void 0)??"day";let s=o(r).millisecond(0);for(const f of[...$].reverse()){const d=t[f];typeof d=="number"&&(s=E(s,f,d));const m=e?.[f];typeof m=="number"&&m!==0&&(s=s.add(m,f))}const y=i==="week"?"isoWeek":i;return{$gte:c(s.startOf(y)),$lte:c(s.endOf(y))}},R=(t,r)=>{const n=o(r),i={DTD:()=>n.startOf("day"),WTD:()=>n.startOf("isoWeek"),MTD:()=>n.startOf("month"),QTD:()=>n.startOf("quarter"),YTD:()=>n.startOf("year")}[t];return{$gte:c(i()),$lte:c(n.endOf("day"))}},w=async(t,r)=>{const n=o(String(t.$lte)),e=o(r.now).endOf("day");if(!n.isAfter(e))return t;const s=await r.requestLatestDataDate()??r.now,y=r.property.granularity??"day",f=y==="week"?"isoWeek":y,d=o(s).endOf(f),m=d.isBefore(n)?d:n;return{...t,$lte:c(m)}},u=async(t,r)=>O(t)?t:t instanceof Date||typeof t=="string"&&o(t).isValid()?c(t):typeof t=="string"&&h.has(t)?w(R(t,r.now),r):D(t)?w(l(t,r.now),r):t,T=async(t,r,n)=>{if(t==="$and"||t==="$or")return Array.isArray(r)?Promise.all(r.map(i=>g(i,n))):r;if(Array.isArray(r))return Promise.all(r.map(i=>u(i,n)));const e=await u(r,n);return t==="$eq"&&a(e)&&"$gte"in e&&"$lte"in e?e:t==="$gte"||t==="$gt"?a(e)&&"$gte"in e?e.$gte:e:(t==="$lte"||t==="$lt")&&a(e)&&"$lte"in e?e.$lte:e},g=async(t,r)=>{if(O(t))return t;if(Array.isArray(t))return Promise.all(t.map(i=>g(i,r)));if(!a(t))return u(t,r);if("$options"in t)throw new p("UNSUPPORTED_QUERY_OPERATOR","$options is a LogicForm 1.x field; use args.options in LogicForm 2.0");if("$offset"in t)throw new p("UNSUPPORTED_DATE_VALUE","The legacy {$offset: ...} date form is not supported; use { granularity, offset }");if(("granularity"in t||"offset"in t)&&(!D(t)||!Number.isInteger(t.offset)))throw new p("INVALID_DATE_VALUE","Relative date values require one granularity and an integer offset");if(D(t))return w(l(t,r.now),r);const n=Object.entries(t);if(n.length===1&&n[0]?.[0]==="$eq"){const i=await T("$eq",n[0][1],r);if(a(i)&&"$gte"in i&&"$lte"in i)return i}const e={};for(const[i,s]of n)e[i]=q.has(i)?await T(i,s,r):await g(s,r);return e};export{g as normalizeDateQuery};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{normalizeDateQuery as t}from"./date.js";const i=(r,e)=>e.property.primal_type==="date"?t(r,e):r;export{i as normalizePrimalQuery};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ResolvedSemanticProperty, ResolvedSemanticSchema, SemanticTypeDefinition } from './types';
|
|
2
|
+
import type { LogicformType, PredItemType } from '../logicform-types';
|
|
3
|
+
export declare class SemanticTypeRegistry {
|
|
4
|
+
#private;
|
|
5
|
+
constructor(definitions?: readonly SemanticTypeDefinition[]);
|
|
6
|
+
register(definition: SemanticTypeDefinition): this;
|
|
7
|
+
get(name: string): SemanticTypeDefinition;
|
|
8
|
+
requiresPerPeriodEvaluation(context: {
|
|
9
|
+
readonly logicform: LogicformType;
|
|
10
|
+
readonly pred: PredItemType;
|
|
11
|
+
readonly schema: ResolvedSemanticSchema;
|
|
12
|
+
readonly property?: ResolvedSemanticProperty;
|
|
13
|
+
}): boolean;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{SemanticDBError as t}from"../errors.js";class s{#e=new Map;constructor(e=[]){for(const r of e)this.register(r)}register(e){if(!e.name)throw new t("INVALID_SEMANTIC_TYPE","Semantic type name must not be empty");if(this.#e.has(e.name))throw new t("SEMANTIC_TYPE_ALREADY_REGISTERED",`Semantic type is already registered: ${e.name}`,{type:e.name});return this.#e.set(e.name,e),this}get(e){const r=this.#e.get(e);if(!r)throw new t("SEMANTIC_TYPE_NOT_FOUND",`Semantic type is not registered: ${e}`,{type:e});return r}requiresPerPeriodEvaluation(e){return e.property?this.get(e.property.type).requiresPerPeriodEvaluation?.({...e,property:e.property})??!1:!1}}export{s as SemanticTypeRegistry};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SemanticDBPlugin } from '../plugins/index';
|
|
2
|
+
import type { SemanticTypeRegistry } from './registry';
|
|
3
|
+
import type { ResolvedSemanticSchema, SemanticSchemaDraft } from './types';
|
|
4
|
+
export declare const resolveSchema: (schema: SemanticSchemaDraft, registry: SemanticTypeRegistry, externalPlugins?: readonly SemanticDBPlugin[]) => ResolvedSemanticSchema;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{SemanticDBError as i}from"../errors.js";import{resolvePlugins as f}from"../plugins/index.js";import{validateResolvedSchema as y}from"./validate-resolved-schema.js";const c=new Set(["hour","day","week","month","quarter","year"]),A=(e,l)=>{if("_id"in e||"_sid"in e)throw new i("LEGACY_PROPERTY_ID_NOT_ALLOWED",`Property ${e.name} must use id instead of _id; _sid is not supported`,{property:e.name});if("sid"in e)throw new i("PROPERTY_SID_NOT_ALLOWED",`Property ${e.name} must not declare sid`,{property:e.name});const m=e;if(m.is_comparable!==void 0||m.comparable_order!==void 0)throw new i("LEGACY_COMPARABLE_NOT_ALLOWED",`Property ${e.name} must use comparable instead of is_comparable/comparable_order`,{property:e.name});if(e.udf!==void 0){const r=e.udf;if(typeof r!="object"||r===null||Array.isArray(r))throw new i("INVALID_PROPERTY_UDF",`Property ${e.name} udf must be an object containing only sql`,{property:e.name});const n=r,o=Object.keys(n).filter(d=>d!=="sql");if(o.length>0)throw new i("UNSUPPORTED_PROPERTY_UDF",`Property ${e.name} udf only supports sql`,{property:e.name,unsupportedKeys:o});if(typeof n.sql!="string"||n.sql.trim().length===0)throw new i("INVALID_PROPERTY_UDF",`Property ${e.name} udf.sql must be a non-empty string`,{property:e.name})}const s=l.get(e.type);if(e.primal_type!==void 0&&e.primal_type!==s.primalType)throw new i("PRIMAL_TYPE_MISMATCH",`Property ${e.name} declares primal_type ${e.primal_type}, but ${e.type} requires ${s.primalType}`,{property:e.name,type:e.type,declared:e.primal_type,expected:s.primalType});if(e.isArray!==void 0&&typeof e.isArray!="boolean")throw new i("INVALID_IS_ARRAY",`Property ${e.name} isArray must be a boolean`,{property:e.name,isArray:e.isArray});if("is_observation"in e)throw new i("LEGACY_TEMPORAL_SEMANTICS_NOT_ALLOWED",`Property ${e.name} must use Schema temporalSemantics; is_observation is not supported`,{property:e.name});if(e.comparable!==void 0){const r=e.comparable;if(typeof r!="object"||r===null||Array.isArray(r))throw new i("INVALID_COMPARABLE_CATEGORY",`Property ${e.name} comparable must contain values and direction`);const n=r;if(Object.keys(n).some(o=>o!=="values"&&o!=="direction")||!Array.isArray(n.values)||n.values.length===0||n.values.some(o=>typeof o!="string")||new Set(n.values).size!==n.values.length||n.direction!==1&&n.direction!==-1)throw new i("INVALID_COMPARABLE_CATEGORY",`Property ${e.name} comparable requires unique string values and direction 1 or -1`,{property:e.name,comparable:r});if(e.type!=="category"||e.isArray===!0)throw new i("COMPARABLE_CATEGORY_REQUIRED",`Property ${e.name} comparable is only supported by scalar category properties`,{property:e.name,type:e.type})}const t={...e,id:e.id??e.name,primal_type:s.primalType,isArray:e.isArray??!1,is_dynamic:e.udf?.sql!==void 0,...s.primalType==="date"?{granularity:e.granularity??"day"}:{}};if(s.primalType==="object"){if(typeof t.ref!="string"||t.ref.length===0)throw new i("PROPERTY_REF_REQUIRED",`Object property ${t.name} must declare ref`,{property:t.name,type:t.type})}else if(t.ref!==void 0)throw new i("PROPERTY_REF_NOT_ALLOWED",`Property ${t.name} cannot declare ref unless its primal_type is object`,{property:t.name,type:t.type});if(s.primalType==="date"){if(t.granularity!==void 0&&!c.has(t.granularity))throw new i("INVALID_GRANULARITY",`Property ${t.name} has unsupported granularity: ${t.granularity}`,{property:t.name,granularity:t.granularity})}else if(t.granularity!==void 0)throw new i("GRANULARITY_NOT_ALLOWED",`Property ${t.name} cannot declare granularity unless its primal_type is date`,{property:t.name,type:t.type});return s.validateProperty?.(t),t},P=(e,l,m=[])=>{const s=f(m);if("_id"in e||"_sid"in e)throw new i("LEGACY_SCHEMA_ID_NOT_ALLOWED","Schema must use id instead of _id; _sid is not supported");if("sid"in e)throw new i("SCHEMA_SID_NOT_ALLOWED","Schema must not declare sid");if("is_snapshot"in e||"is_observation"in e)throw new i("LEGACY_TEMPORAL_SEMANTICS_NOT_ALLOWED","Schema must use temporalSemantics instead of is_snapshot/is_observation",{schemaId:e.id});const t=e.temporalSemantics??"normal";if(t!=="normal"&&t!=="snapshot")throw new i("INVALID_TEMPORAL_SEMANTICS","Schema temporalSemantics must be normal or snapshot",{schemaId:e.id,temporalSemantics:t});const r=t;if(!e.id)throw new i("INVALID_SCHEMA_ID","Schema id must not be empty");let n=e.properties.map(a=>A(a,l));if(e.type==="entity"&&!n.some(({type:a})=>a==="timestamp")&&n.some(({type:a})=>a==="start_date")&&n.some(({type:a})=>a==="end_date")&&!n.some(({name:a})=>a==="\u65E5\u671F")){const a=n.find(({type:u})=>u==="start_date");a&&(n=[...n,{id:"__chatbi__timestamp__placeholder__",name:"\u65E5\u671F",type:"timestamp",primal_type:"date",isArray:!1,is_dynamic:!0,is_supplementary:!0,udf:{sql:a.id}}])}y(n,{temporalSemantics:r,schemaId:e.id});const o=s.flatMap(a=>a.schemaMetadata?[a.schemaMetadata]:[]);let d={};for(const a of o)d={...d,...a.resolve(e,n)};const _=e.parentProperty===void 0?void 0:n.find(({id:a,name:u})=>a===e.parentProperty||u===e.parentProperty);if(e.parentProperty!==void 0&&!_)throw new i("RECURSIVE_PARENT_PROPERTY_REQUIRED",`Schema parentProperty does not exist: ${e.parentProperty}`,{schemaId:e.id,property:e.parentProperty});const p=new Set(s.flatMap(a=>[...a.schemaMetadata?.keys??[],...a.legacySchemaKeys??[]]));return{...Object.fromEntries(Object.entries(e).filter(([a])=>a!=="parentProperty"&&!p.has(a))),temporalSemantics:r,properties:n,...d,..._?{parentProperty:_.name}:{}}};export{P as resolveSchema};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { PropertyTypeDraft, SchemaTypeDraft } from 'semanticdb-core';
|
|
2
|
+
import type { LogicformType, PredItemType } from '../logicform-types';
|
|
3
|
+
export type PrimalType = 'string' | 'number' | 'boolean' | 'date' | 'object';
|
|
4
|
+
export type TimeGranularity = 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year';
|
|
5
|
+
export type TemporalSemantics = 'normal' | 'snapshot';
|
|
6
|
+
export interface PropertySqlDefinition {
|
|
7
|
+
readonly sql: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ComparableCategoryDefinition {
|
|
10
|
+
readonly values: readonly string[];
|
|
11
|
+
readonly direction: 1 | -1;
|
|
12
|
+
}
|
|
13
|
+
/** Extension point for plugin-owned Schema draft metadata. */
|
|
14
|
+
export interface SemanticSchemaMetadata {
|
|
15
|
+
}
|
|
16
|
+
/** Extension point for plugin-owned resolved Schema metadata. */
|
|
17
|
+
export interface ResolvedSemanticSchemaMetadata {
|
|
18
|
+
}
|
|
19
|
+
/** Extension point for legacy plugin metadata removed from the canonical Schema shape. */
|
|
20
|
+
export interface LegacySemanticSchemaMetadata {
|
|
21
|
+
}
|
|
22
|
+
export interface SemanticPropertyDraft extends Omit<PropertyTypeDraft, '_id' | '_sid' | 'id' | 'sid' | 'type' | 'primal_type' | 'isArray' | 'granularity' | 'is_observation' | 'is_snapshot' | 'temporalSemantics' | 'is_dynamic' | 'udf' | 'is_comparable' | 'comparable_order'> {
|
|
23
|
+
readonly id?: string;
|
|
24
|
+
readonly type: string;
|
|
25
|
+
readonly primal_type?: PrimalType;
|
|
26
|
+
readonly isArray?: boolean;
|
|
27
|
+
readonly granularity?: TimeGranularity;
|
|
28
|
+
/** Derived during schema resolution from whether the property has udf.sql. */
|
|
29
|
+
readonly is_dynamic?: boolean;
|
|
30
|
+
readonly udf?: PropertySqlDefinition;
|
|
31
|
+
readonly comparable?: ComparableCategoryDefinition;
|
|
32
|
+
}
|
|
33
|
+
export interface ResolvedSemanticProperty extends Omit<SemanticPropertyDraft, 'id' | 'primal_type' | 'isArray' | 'is_dynamic'> {
|
|
34
|
+
readonly id: string;
|
|
35
|
+
readonly primal_type: PrimalType;
|
|
36
|
+
readonly isArray: boolean;
|
|
37
|
+
readonly is_dynamic?: boolean;
|
|
38
|
+
}
|
|
39
|
+
export interface SemanticSchemaDraft extends Omit<SchemaTypeDraft, '_id' | 'id' | 'sid' | 'properties' | 'db' | 'from' | 'fromSQL' | 'projections' | keyof SemanticSchemaMetadata | keyof LegacySemanticSchemaMetadata>, SemanticSchemaMetadata {
|
|
40
|
+
readonly [key: string]: unknown;
|
|
41
|
+
readonly id: string;
|
|
42
|
+
readonly properties: readonly SemanticPropertyDraft[];
|
|
43
|
+
readonly temporalSemantics?: TemporalSemantics;
|
|
44
|
+
/** Property that stores the parent node id for recursive tree queries. */
|
|
45
|
+
readonly parentProperty?: string;
|
|
46
|
+
}
|
|
47
|
+
export interface ResolvedSemanticSchema extends Omit<SchemaTypeDraft, '_id' | 'id' | 'sid' | 'properties' | 'db' | 'from' | 'fromSQL' | 'projections' | keyof SemanticSchemaMetadata | keyof LegacySemanticSchemaMetadata>, ResolvedSemanticSchemaMetadata {
|
|
48
|
+
readonly [key: string]: unknown;
|
|
49
|
+
readonly id: string;
|
|
50
|
+
readonly properties: readonly ResolvedSemanticProperty[];
|
|
51
|
+
readonly temporalSemantics?: TemporalSemantics;
|
|
52
|
+
/** Canonical logical name of the parent Property used by recursive tree queries. */
|
|
53
|
+
readonly parentProperty?: string;
|
|
54
|
+
}
|
|
55
|
+
export interface SemanticTypeNormalizeContext {
|
|
56
|
+
readonly schema: ResolvedSemanticSchema;
|
|
57
|
+
readonly property: ResolvedSemanticProperty;
|
|
58
|
+
readonly now: Date;
|
|
59
|
+
readonly requestLatestDataDate: () => Promise<Date | undefined>;
|
|
60
|
+
}
|
|
61
|
+
/** Context used when deciding whether a value must be evaluated per time period. */
|
|
62
|
+
export interface SemanticPeriodEvaluationContext {
|
|
63
|
+
readonly logicform: LogicformType;
|
|
64
|
+
readonly pred: PredItemType;
|
|
65
|
+
readonly schema: ResolvedSemanticSchema;
|
|
66
|
+
readonly property: ResolvedSemanticProperty;
|
|
67
|
+
}
|
|
68
|
+
export interface SemanticTypeResultProperty {
|
|
69
|
+
readonly name: string;
|
|
70
|
+
readonly type: string;
|
|
71
|
+
readonly primal_type: PrimalType;
|
|
72
|
+
readonly isArray: boolean;
|
|
73
|
+
readonly ref?: string;
|
|
74
|
+
readonly comparable?: ComparableCategoryDefinition;
|
|
75
|
+
}
|
|
76
|
+
export interface SemanticTypeResultContext {
|
|
77
|
+
readonly property: SemanticTypeResultProperty;
|
|
78
|
+
/** Batch-aware entity lookup supplied by the executor's Result Hydrator. */
|
|
79
|
+
readonly requestEntity: (schemaId: string, id: unknown) => Promise<unknown>;
|
|
80
|
+
}
|
|
81
|
+
export interface SemanticTypeDefinition {
|
|
82
|
+
readonly name: string;
|
|
83
|
+
readonly primalType: PrimalType;
|
|
84
|
+
readonly validateProperty?: (property: ResolvedSemanticProperty) => void;
|
|
85
|
+
/** Whether this semantic property requires one evaluation per time bucket. */
|
|
86
|
+
readonly requiresPerPeriodEvaluation?: (context: SemanticPeriodEvaluationContext) => boolean;
|
|
87
|
+
/** Hydrate a physical result value before it is exposed by ExecuteResult. */
|
|
88
|
+
readonly hydrateResult?: (value: unknown, context: SemanticTypeResultContext) => unknown;
|
|
89
|
+
readonly normalizeQuery?: (value: unknown, context: SemanticTypeNormalizeContext) => unknown;
|
|
90
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ResolvedSemanticProperty, TemporalSemantics } from './types';
|
|
2
|
+
/** Validates invariants that require the complete set of resolved Properties. */
|
|
3
|
+
export declare const validateResolvedSchema: (properties: readonly ResolvedSemanticProperty[], options?: {
|
|
4
|
+
readonly temporalSemantics?: TemporalSemantics;
|
|
5
|
+
readonly schemaId?: string;
|
|
6
|
+
}) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{SemanticDBError as a}from"../errors.js";const m=o=>{const r=new Set,t=new Set;for(const e of o){if(!e.name)throw new a("INVALID_PROPERTY_NAME","Property name must not be empty");if(!e.id)throw new a("INVALID_PROPERTY_ID",`Property ${e.name} physical id must not be empty`);if(r.has(e.name))throw new a("DUPLICATE_PROPERTY_NAME",`Duplicate property name: ${e.name}`,{property:e.name});if(t.has(e.id))throw new a("DUPLICATE_PROPERTY_ID",`Duplicate property physical id: ${e.id}`,{propertyId:e.id});r.add(e.name),t.add(e.id)}},n=(o,r={})=>{m(o);const t=o.filter(({type:e})=>e==="timestamp");if(t.length>1)throw new a("MULTIPLE_TIMESTAMP_PROPERTIES","A Schema can declare at most one timestamp Property",{properties:t.map(({name:e})=>e)});if(r.temporalSemantics==="snapshot"&&t.length===0)throw new a("SNAPSHOT_TIMESTAMP_REQUIRED","A snapshot Schema must declare exactly one timestamp Property",{schemaId:r.schemaId})};export{n as validateResolvedSchema};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const clone: <T>(value: T) => T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const o=e=>structuredClone(e);export{o as clone};
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "semanticdb-v2",
|
|
3
|
+
"version": "2.0.0-alpha.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./cache/redis": {
|
|
13
|
+
"types": "./dist/cache/redis-query-cache.d.ts",
|
|
14
|
+
"import": "./dist/cache/redis-query-cache.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
|
|
22
|
+
"build:types": "tsc -p tsconfig.build.json",
|
|
23
|
+
"build:rollup": "rollup -c",
|
|
24
|
+
"build": "npm run clean && npm run build:types && npm run build:rollup",
|
|
25
|
+
"typecheck": "tsc --noEmit",
|
|
26
|
+
"debug": "vite-node debug/debug.ts",
|
|
27
|
+
"test": "vitest run --coverage",
|
|
28
|
+
"lint": "eslint .",
|
|
29
|
+
"check": "npm run lint && npm run typecheck && npm test && npm run build"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@clickhouse/client": "^1.11.2",
|
|
33
|
+
"dayjs": "^1.11.21",
|
|
34
|
+
"mysql2": "^3.14.4",
|
|
35
|
+
"oracledb": "^6.10.0",
|
|
36
|
+
"pg": "^8.23.0",
|
|
37
|
+
"redis": "^5.10.0",
|
|
38
|
+
"snowflake-sdk": "^2.4.3"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"semanticdb-core": "^1.1.57"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@eslint/js": "^9.32.0",
|
|
45
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
46
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
47
|
+
"@rollup/rollup-darwin-arm64": "^4.62.4",
|
|
48
|
+
"@types/node": "^22.17.0",
|
|
49
|
+
"@types/oracledb": "^6.10.4",
|
|
50
|
+
"@types/pg": "^8.21.0",
|
|
51
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
52
|
+
"dotenv": "^17.4.2",
|
|
53
|
+
"esbuild": "^0.28.1",
|
|
54
|
+
"eslint": "^9.32.0",
|
|
55
|
+
"rollup": "^4.62.4",
|
|
56
|
+
"semanticdb-core": "^1.1.57",
|
|
57
|
+
"tslib": "^2.8.1",
|
|
58
|
+
"typescript": "^5.9.2",
|
|
59
|
+
"typescript-eslint": "^8.38.0",
|
|
60
|
+
"vitest": "^3.2.4"
|
|
61
|
+
}
|
|
62
|
+
}
|