@true-sight/model-schema 1.1.0 → 1.2.0
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/dist/dsl/compile/compile-explore.js +7 -4
- package/dist/dsl/compile/compile-view.js +2 -0
- package/dist/dsl/expr/define-always-include.d.ts +6 -0
- package/dist/dsl/expr/define-always-include.js +6 -0
- package/dist/dsl/expr/field.d.ts +11 -8
- package/dist/dsl/expr/index.d.ts +2 -0
- package/dist/dsl/expr/index.js +3 -1
- package/dist/dsl/registry/view-registry.d.ts +2 -0
- package/dist/dsl/types/view-proxy.types.d.ts +4 -3
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/types/manifest.types.d.ts +2 -0
- package/dist/validate/semantic-rules.js +10 -3
- package/manifest.schema.json +4 -2
- package/package.json +1 -1
|
@@ -73,13 +73,13 @@ function resolveAlwaysInclude(ExploreClass, exploreName, views, scopedViewNames)
|
|
|
73
73
|
if (!Array.isArray(raw)) {
|
|
74
74
|
throw new compile_errors_js_1.AlwaysIncludeError(exploreName, 'callback must return Field[]');
|
|
75
75
|
}
|
|
76
|
-
const
|
|
76
|
+
const visibility = new Map();
|
|
77
77
|
for (const view of views) {
|
|
78
78
|
for (const dimension of view.dimensions) {
|
|
79
|
-
|
|
79
|
+
visibility.set(`${view.name}.${dimension.name}`, dimension.visible !== false);
|
|
80
80
|
}
|
|
81
81
|
for (const measurement of view.measurements) {
|
|
82
|
-
|
|
82
|
+
visibility.set(`${view.name}.${measurement.name}`, measurement.visible !== false);
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
const seen = new Set();
|
|
@@ -96,9 +96,12 @@ function resolveAlwaysInclude(ExploreClass, exploreName, views, scopedViewNames)
|
|
|
96
96
|
continue;
|
|
97
97
|
}
|
|
98
98
|
seen.add(ref);
|
|
99
|
-
if (!
|
|
99
|
+
if (!visibility.has(ref)) {
|
|
100
100
|
throw new compile_errors_js_1.AlwaysIncludeError(exploreName, `unknown field '${ref}'`);
|
|
101
101
|
}
|
|
102
|
+
if (visibility.get(ref) === false) {
|
|
103
|
+
throw new compile_errors_js_1.AlwaysIncludeError(exploreName, `field '${ref}' is not visible and cannot be alwaysInclude`);
|
|
104
|
+
}
|
|
102
105
|
names.push(ref);
|
|
103
106
|
}
|
|
104
107
|
return names.length > 0 ? names : undefined;
|
|
@@ -18,6 +18,7 @@ function compileView(ViewClass) {
|
|
|
18
18
|
label: entry.options.label,
|
|
19
19
|
type: entry.options.type,
|
|
20
20
|
expression: `${viewMeta.name}.${entry.propertyKey}`,
|
|
21
|
+
...(entry.options.visible === false ? { visible: false } : {}),
|
|
21
22
|
}));
|
|
22
23
|
const measurements = measureEntries.map((entry) => {
|
|
23
24
|
const raw = instance[entry.propertyKey];
|
|
@@ -28,6 +29,7 @@ function compileView(ViewClass) {
|
|
|
28
29
|
label: entry.options.label,
|
|
29
30
|
type: entry.options.type,
|
|
30
31
|
expression,
|
|
32
|
+
...(entry.options.visible === false ? { visible: false } : {}),
|
|
31
33
|
};
|
|
32
34
|
});
|
|
33
35
|
return {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AlwaysIncludeCallback } from '../types/join-scope.types.js';
|
|
2
|
+
import type { StrictViewProxy, ViewConstructor } from '../types/view-proxy.types.js';
|
|
3
|
+
import type { VisibleField } from './field.js';
|
|
4
|
+
export declare function defineAlwaysInclude<const Vs extends readonly ViewConstructor[]>(_views: Vs, fn: (...proxies: {
|
|
5
|
+
[I in keyof Vs]: Vs[I] extends ViewConstructor ? StrictViewProxy<Vs[I]> : never;
|
|
6
|
+
}) => VisibleField[]): AlwaysIncludeCallback;
|
package/dist/dsl/expr/field.d.ts
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import type { ManifestExpr, RefString } from '../../types/manifest-expr.types.js';
|
|
2
|
-
export declare class Field<T> {
|
|
2
|
+
export declare class Field<T, Visible extends boolean = true> {
|
|
3
3
|
readonly ref: RefString;
|
|
4
|
+
readonly __visible?: Visible;
|
|
4
5
|
constructor(viewName: string, fieldName: string);
|
|
5
|
-
eq(other: Field<unknown> | ManifestExpr): ManifestExpr;
|
|
6
|
-
neq(other: Field<unknown> | ManifestExpr): ManifestExpr;
|
|
7
|
-
gt(other: Field<unknown> | ManifestExpr): ManifestExpr;
|
|
8
|
-
gte(other: Field<unknown> | ManifestExpr): ManifestExpr;
|
|
9
|
-
lt(other: Field<unknown> | ManifestExpr): ManifestExpr;
|
|
10
|
-
lte(other: Field<unknown> | ManifestExpr): ManifestExpr;
|
|
6
|
+
eq(other: Field<unknown, boolean> | ManifestExpr): ManifestExpr;
|
|
7
|
+
neq(other: Field<unknown, boolean> | ManifestExpr): ManifestExpr;
|
|
8
|
+
gt(other: Field<unknown, boolean> | ManifestExpr): ManifestExpr;
|
|
9
|
+
gte(other: Field<unknown, boolean> | ManifestExpr): ManifestExpr;
|
|
10
|
+
lt(other: Field<unknown, boolean> | ManifestExpr): ManifestExpr;
|
|
11
|
+
lte(other: Field<unknown, boolean> | ManifestExpr): ManifestExpr;
|
|
11
12
|
and(other: ManifestExpr): ManifestExpr;
|
|
12
13
|
or(other: ManifestExpr): ManifestExpr;
|
|
13
14
|
not(): ManifestExpr;
|
|
14
15
|
}
|
|
15
|
-
export
|
|
16
|
+
export type VisibleField<T = unknown> = Field<T, true>;
|
|
17
|
+
export type HiddenField<T = unknown> = Field<T, false>;
|
|
18
|
+
export declare function field<T, Visible extends boolean = true>(viewName: string, fieldName: string): Field<T, Visible>;
|
package/dist/dsl/expr/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { Field, field } from './field.js';
|
|
2
|
+
export type { VisibleField, HiddenField } from './field.js';
|
|
3
|
+
export { defineAlwaysInclude } from './define-always-include.js';
|
|
2
4
|
export { count, max, min, sum } from './aggregates.js';
|
|
3
5
|
export { raw } from './raw.js';
|
|
4
6
|
export { joinScope, isJoinScopeTagged } from './join-scope.js';
|
package/dist/dsl/expr/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isJoinScopeTagged = exports.joinScope = exports.raw = exports.sum = exports.min = exports.max = exports.count = exports.field = exports.Field = void 0;
|
|
3
|
+
exports.isJoinScopeTagged = exports.joinScope = exports.raw = exports.sum = exports.min = exports.max = exports.count = exports.defineAlwaysInclude = exports.field = exports.Field = void 0;
|
|
4
4
|
var field_js_1 = require("./field.js");
|
|
5
5
|
Object.defineProperty(exports, "Field", { enumerable: true, get: function () { return field_js_1.Field; } });
|
|
6
6
|
Object.defineProperty(exports, "field", { enumerable: true, get: function () { return field_js_1.field; } });
|
|
7
|
+
var define_always_include_js_1 = require("./define-always-include.js");
|
|
8
|
+
Object.defineProperty(exports, "defineAlwaysInclude", { enumerable: true, get: function () { return define_always_include_js_1.defineAlwaysInclude; } });
|
|
7
9
|
var aggregates_js_1 = require("./aggregates.js");
|
|
8
10
|
Object.defineProperty(exports, "count", { enumerable: true, get: function () { return aggregates_js_1.count; } });
|
|
9
11
|
Object.defineProperty(exports, "max", { enumerable: true, get: function () { return aggregates_js_1.max; } });
|
|
@@ -8,11 +8,13 @@ export type DimensionOptions = {
|
|
|
8
8
|
groupLabel: string;
|
|
9
9
|
label: string;
|
|
10
10
|
type: DimensionType;
|
|
11
|
+
visible?: boolean;
|
|
11
12
|
};
|
|
12
13
|
export type MeasureOptions = {
|
|
13
14
|
groupLabel: string;
|
|
14
15
|
label: string;
|
|
15
16
|
type: AggregateType;
|
|
17
|
+
visible?: boolean;
|
|
16
18
|
};
|
|
17
19
|
export type DimensionEntry = {
|
|
18
20
|
propertyKey: string;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { Field } from '../expr/field.js';
|
|
2
2
|
export type ViewConstructor = new (...args: unknown[]) => object;
|
|
3
3
|
export type DimensionKeys<V extends ViewConstructor> = {
|
|
4
|
-
[K in keyof InstanceType<V>]: InstanceType<V>[K] extends Field<infer
|
|
4
|
+
[K in keyof InstanceType<V>]: InstanceType<V>[K] extends Field<infer _T, infer _V> ? K : never;
|
|
5
5
|
}[keyof InstanceType<V>];
|
|
6
|
-
export type
|
|
6
|
+
export type StrictViewProxy<V extends ViewConstructor> = {
|
|
7
7
|
[K in DimensionKeys<V>]: InstanceType<V>[K];
|
|
8
|
-
}
|
|
8
|
+
};
|
|
9
|
+
export type ViewProxy<V extends ViewConstructor> = StrictViewProxy<V> & {
|
|
9
10
|
[key: string]: Field<unknown>;
|
|
10
11
|
};
|
|
11
12
|
export interface ViewBrand {
|
package/dist/index.d.ts
CHANGED
|
@@ -4,10 +4,11 @@ export { isJoinPair, isManifestExprObject, isRefString, REF_STRING_PATTERN, } fr
|
|
|
4
4
|
export type { AggregateType, DimensionDefinition, DimensionType, Explore as ManifestExplore, ExploreJoin, JoinRelationship, JoinType, MeasurementDefinition, Model as ManifestModel, ModelManifest, ViewDefinition, } from './types/manifest.types.js';
|
|
5
5
|
export type { ManifestValidationError, ValidationResult, } from './validate/validation-result.js';
|
|
6
6
|
export { validateManifest } from './validate/validate-manifest.js';
|
|
7
|
-
export { Field, field, count, sum, min, max, raw, joinScope, isJoinScopeTagged } from './dsl/expr/index.js';
|
|
7
|
+
export { Field, field, count, sum, min, max, raw, joinScope, isJoinScopeTagged, defineAlwaysInclude } from './dsl/expr/index.js';
|
|
8
|
+
export type { VisibleField, HiddenField } from './dsl/expr/index.js';
|
|
8
9
|
export type { JoinScopeCallback, JoinScopeSqlOn, JoinScopeTagged, AlwaysIncludeCallback } from './dsl/types/join-scope.types.js';
|
|
9
10
|
export { View, Dimension, Measure, Explore, Join, Model, AlwaysInclude } from './dsl/decorators/index.js';
|
|
10
|
-
export type { ViewProxy, ViewConstructor } from './dsl/types/view-proxy.types.js';
|
|
11
|
+
export type { ViewProxy, ViewConstructor, StrictViewProxy } from './dsl/types/view-proxy.types.js';
|
|
11
12
|
export type { ViewNameMap, ViewProxyByName, } from './dsl/types/view-name-map.types.js';
|
|
12
13
|
export { compileView, compileExplore, compileModel, compileModels } from './dsl/compile/index.js';
|
|
13
14
|
export { MissingMetadataError, InvalidMeasureError, JoinScopeError, DuplicateNameError, AlwaysIncludeError, } from './dsl/errors/compile-errors.js';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AlwaysIncludeError = exports.DuplicateNameError = exports.JoinScopeError = exports.InvalidMeasureError = exports.MissingMetadataError = exports.compileModels = exports.compileModel = exports.compileExplore = exports.compileView = exports.AlwaysInclude = exports.Model = exports.Join = exports.Explore = exports.Measure = exports.Dimension = exports.View = exports.isJoinScopeTagged = exports.joinScope = exports.raw = exports.max = exports.min = exports.sum = exports.count = exports.field = exports.Field = exports.validateManifest = exports.REF_STRING_PATTERN = exports.isRefString = exports.isManifestExprObject = exports.isJoinPair = exports.SCHEMA_VERSION = void 0;
|
|
3
|
+
exports.AlwaysIncludeError = exports.DuplicateNameError = exports.JoinScopeError = exports.InvalidMeasureError = exports.MissingMetadataError = exports.compileModels = exports.compileModel = exports.compileExplore = exports.compileView = exports.AlwaysInclude = exports.Model = exports.Join = exports.Explore = exports.Measure = exports.Dimension = exports.View = exports.defineAlwaysInclude = exports.isJoinScopeTagged = exports.joinScope = exports.raw = exports.max = exports.min = exports.sum = exports.count = exports.field = exports.Field = exports.validateManifest = exports.REF_STRING_PATTERN = exports.isRefString = exports.isManifestExprObject = exports.isJoinPair = exports.SCHEMA_VERSION = void 0;
|
|
4
4
|
var constants_js_1 = require("./constants.js");
|
|
5
5
|
Object.defineProperty(exports, "SCHEMA_VERSION", { enumerable: true, get: function () { return constants_js_1.SCHEMA_VERSION; } });
|
|
6
6
|
var manifest_expr_types_js_1 = require("./types/manifest-expr.types.js");
|
|
@@ -20,6 +20,7 @@ Object.defineProperty(exports, "max", { enumerable: true, get: function () { ret
|
|
|
20
20
|
Object.defineProperty(exports, "raw", { enumerable: true, get: function () { return index_js_1.raw; } });
|
|
21
21
|
Object.defineProperty(exports, "joinScope", { enumerable: true, get: function () { return index_js_1.joinScope; } });
|
|
22
22
|
Object.defineProperty(exports, "isJoinScopeTagged", { enumerable: true, get: function () { return index_js_1.isJoinScopeTagged; } });
|
|
23
|
+
Object.defineProperty(exports, "defineAlwaysInclude", { enumerable: true, get: function () { return index_js_1.defineAlwaysInclude; } });
|
|
23
24
|
var index_js_2 = require("./dsl/decorators/index.js");
|
|
24
25
|
Object.defineProperty(exports, "View", { enumerable: true, get: function () { return index_js_2.View; } });
|
|
25
26
|
Object.defineProperty(exports, "Dimension", { enumerable: true, get: function () { return index_js_2.Dimension; } });
|
|
@@ -16,6 +16,7 @@ export interface DimensionDefinition {
|
|
|
16
16
|
label: string;
|
|
17
17
|
type: DimensionType;
|
|
18
18
|
expression: ManifestExpr;
|
|
19
|
+
visible?: boolean;
|
|
19
20
|
}
|
|
20
21
|
export interface MeasurementDefinition {
|
|
21
22
|
groupLabel: string;
|
|
@@ -23,6 +24,7 @@ export interface MeasurementDefinition {
|
|
|
23
24
|
label: string;
|
|
24
25
|
type: AggregateType;
|
|
25
26
|
expression: ManifestExpr;
|
|
27
|
+
visible?: boolean;
|
|
26
28
|
}
|
|
27
29
|
export interface ViewDefinition {
|
|
28
30
|
name: string;
|
|
@@ -44,13 +44,13 @@ function collectSemanticErrors(manifest) {
|
|
|
44
44
|
message: `from view "${explore.from}" is not in explore views`,
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
|
-
const qualifiedFields = new
|
|
47
|
+
const qualifiedFields = new Map();
|
|
48
48
|
for (const view of explore.views) {
|
|
49
49
|
for (const dimension of view.dimensions) {
|
|
50
|
-
qualifiedFields.
|
|
50
|
+
qualifiedFields.set(`${view.name}.${dimension.name}`, dimension.visible !== false);
|
|
51
51
|
}
|
|
52
52
|
for (const measurement of view.measurements) {
|
|
53
|
-
qualifiedFields.
|
|
53
|
+
qualifiedFields.set(`${view.name}.${measurement.name}`, measurement.visible !== false);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
(explore.alwaysInclude ?? []).forEach((name, index) => {
|
|
@@ -67,6 +67,13 @@ function collectSemanticErrors(manifest) {
|
|
|
67
67
|
path,
|
|
68
68
|
message: `alwaysInclude name "${name}" is not a dimension or measurement on this explore`,
|
|
69
69
|
});
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (qualifiedFields.get(name) === false) {
|
|
73
|
+
errors.push({
|
|
74
|
+
path,
|
|
75
|
+
message: `alwaysInclude name "${name}" is not visible`,
|
|
76
|
+
});
|
|
70
77
|
}
|
|
71
78
|
});
|
|
72
79
|
explore.joins.forEach((join, joinIndex) => {
|
package/manifest.schema.json
CHANGED
|
@@ -119,7 +119,8 @@
|
|
|
119
119
|
"name": { "type": "string", "minLength": 1 },
|
|
120
120
|
"label": { "type": "string" },
|
|
121
121
|
"type": { "$ref": "#/definitions/DimensionType" },
|
|
122
|
-
"expression": { "$ref": "#/definitions/ManifestExpr" }
|
|
122
|
+
"expression": { "$ref": "#/definitions/ManifestExpr" },
|
|
123
|
+
"visible": { "type": "boolean" }
|
|
123
124
|
}
|
|
124
125
|
},
|
|
125
126
|
"MeasurementDefinition": {
|
|
@@ -131,7 +132,8 @@
|
|
|
131
132
|
"name": { "type": "string", "minLength": 1 },
|
|
132
133
|
"label": { "type": "string" },
|
|
133
134
|
"type": { "$ref": "#/definitions/AggregateType" },
|
|
134
|
-
"expression": { "$ref": "#/definitions/ManifestExpr" }
|
|
135
|
+
"expression": { "$ref": "#/definitions/ManifestExpr" },
|
|
136
|
+
"visible": { "type": "boolean" }
|
|
135
137
|
}
|
|
136
138
|
},
|
|
137
139
|
"ViewDefinition": {
|