Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(schema-compiler): add meta property for cube definition #7327

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions docs/pages/reference/data-model/cube.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,33 @@ cubes:

</CodeTabs>

### meta

Custom metadata. Can be used to pass any information to the frontend.

<CodeTabs>

```javascript
cube(`orders`, {
sql_table: `orders`,
title: `Product Orders`,
meta: {
any: `value`,
}
});
```

```yaml
cubes:
- name: orders
sql_table: orders
title: Product Orders
meta:
any: value
```

</CodeTabs>

### extends

You can extend cubes in order to reuse all declared members of a cube. In the
Expand Down
23 changes: 23 additions & 0 deletions docs/pages/reference/data-model/view.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,29 @@ views:

</CodeTabs>

### meta

Custom metadata. Can be used to pass any information to the frontend.

<CodeTabs>

```javascript
view(`active_users`, {
meta: {
any: "value",
}
});
```

```yaml
views:
- name: active_users
meta:
any: value
```

</CodeTabs>

### `cubes`

Use `cubes` parameter in view to include exposed cubes in bulk. You can build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class CubeToMetaTransformer {
public: isCubeVisible,
description: cube.description,
connectedComponent: this.joinGraph.connectedComponents()[cube.name],
meta: cube.meta,
measures: R.compose(
R.map((nameToMetric) => ({
...this.measureConfig(cube.name, cubeTitle, nameToMetric),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ const baseSchema = {
rewriteQueries: Joi.boolean().strict(),
shown: Joi.boolean().strict(),
public: Joi.boolean().strict(),
meta: Joi.any(),
joins: Joi.object().pattern(identifierRegex, Joi.object().keys({
sql: Joi.func().required(),
relationship: Joi.any().valid(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ export class YamlCompiler {
return this.extractProgramBodyIfNeeded(ast);
} else if (typeof obj === 'boolean') {
return t.booleanLiteral(obj);
} else if (typeof obj === 'number') {
return t.numericLiteral(obj);
} else if (obj === null && propertyPath.includes('meta')) {
return t.nullLiteral();
}

if (typeof obj === 'object' && obj !== null) {
Expand Down
32 changes: 32 additions & 0 deletions packages/cubejs-schema-compiler/test/unit/yaml-schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,36 @@ describe('Yaml Schema Testing', () => {
expect(e.message).toContain('name isn\'t defined for dimension: ');
}
});

it('accepts cube meta', async () => {
const { compiler } = prepareYamlCompiler(
`
cubes:
- name: Users
sql: SELECT * FROM e2e.users
meta:
scalars:
example_string: "foo"
example_integer: 1
example_float: 1.0
example_boolean: true
example_null: null
sequence:
- 1
- 2
- 3
mixed_sequence:
- 1
- "foo"
- 3
dimensions:
- name: id
sql: id
type: number
primaryKey: true
`
);

await compiler.compile();
});
});
Loading