@microsoft/rayfin-semantic-model-pack 1.0.0 → 2.0.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/CHANGELOG +8 -0
- package/README.md +34 -10
- package/kit/hooks/use-query-factory-target.spec.ts +191 -0
- package/kit/hooks/use-query-factory-target.ts +123 -0
- package/{skills/analytics/kit → kit}/hooks/use-semantic-model-query.spec.ts +59 -23
- package/{skills/analytics/kit → kit}/hooks/use-semantic-model-query.ts +30 -54
- package/kit/lib/query-factory.spec.ts +97 -0
- package/kit/lib/query-factory.ts +68 -0
- package/kit/lib/semantic-model-errors.spec.ts +131 -0
- package/kit/lib/semantic-model-errors.ts +110 -0
- package/kit/lib/to-data-table.spec.ts +444 -0
- package/kit/lib/to-data-table.ts +221 -0
- package/pack.json +141 -0
- package/package.json +3 -1
- package/skills/analytics/SKILL.md +126 -421
- package/skills/dax-authoring/SKILL.md +99 -34
- package/skills/query-design/SKILL.md +22 -29
- package/skills/query-design/references/anti-patterns.md +13 -11
- package/skills/query-design/references/format-strings.md +6 -12
- package/skills/query-design/references/multi-grain-patterns.md +121 -108
- package/skills/schema-discovery/SKILL.md +197 -368
- package/skills/schema-discovery/references/discovery-queries.md +6 -8
- package/skills/visual-interactivity/SKILL.md +68 -0
- package/skills/visual-interactivity/references/advanced-query-shapes.md +155 -0
- package/skills/visual-interactivity/references/filter-aware-grid-totals.md +101 -0
- package/skills/visual-interactivity/references/highlight-queries.md +88 -0
- package/skills/visual-interactivity/references/interaction-manager.md +127 -0
- package/skills/visual-interactivity/references/native-selections.md +20 -0
- package/skills/visual-interactivity/references/query-factories.md +169 -0
- package/skills/analytics/kit/lib/connectors.ts +0 -94
- package/skills/analytics/kit/scripts/rayfin-connector.mjs +0 -265
- package/skills/analytics/kit/scripts/rayfin-connector.test.mjs +0 -243
- package/skills/analytics/kit/scripts/schema-sql-batch.test.mjs +0 -2097
- package/skills/analytics/kit/scripts/schema-sql-cli.test.mjs +0 -488
- package/skills/analytics/kit/scripts/schema-sql.mjs +0 -2650
- package/skills/analytics/kit/scripts/schema-sql.test.mjs +0 -1387
- package/skills/analytics/kit/scripts/schema.mjs +0 -166
- package/skills/analytics/kit/scripts/schema.test.mjs +0 -271
- package/skills/analytics/pack.json +0 -49
- package/skills/query-design/references/filter-strategy.md +0 -68
- package/skills/query-design/references/highlight-queries.md +0 -122
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
//-----------------------------------------------------------------------
|
|
2
|
-
// <copyright company="Microsoft Corporation">
|
|
3
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
-
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
5
|
-
// </copyright>
|
|
6
|
-
//-----------------------------------------------------------------------
|
|
7
|
-
|
|
8
|
-
import assert from 'node:assert/strict';
|
|
9
|
-
import { EventEmitter } from 'node:events';
|
|
10
|
-
import {
|
|
11
|
-
existsSync,
|
|
12
|
-
mkdtempSync,
|
|
13
|
-
readdirSync,
|
|
14
|
-
readFileSync,
|
|
15
|
-
rmSync,
|
|
16
|
-
writeFileSync,
|
|
17
|
-
} from 'node:fs';
|
|
18
|
-
import { tmpdir } from 'node:os';
|
|
19
|
-
import { join, relative } from 'node:path';
|
|
20
|
-
import test from 'node:test';
|
|
21
|
-
|
|
22
|
-
import {
|
|
23
|
-
invokeConnector,
|
|
24
|
-
listConfiguredConnectors,
|
|
25
|
-
rayfinErrorMessage,
|
|
26
|
-
resolveRayfinCliEntry,
|
|
27
|
-
} from './rayfin-connector.mjs';
|
|
28
|
-
|
|
29
|
-
function fakeChild(onStart) {
|
|
30
|
-
const child = new EventEmitter();
|
|
31
|
-
child.stdout = new EventEmitter();
|
|
32
|
-
child.stderr = new EventEmitter();
|
|
33
|
-
queueMicrotask(() => onStart(child));
|
|
34
|
-
return child;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
test('rayfinErrorMessage extracts only error envelopes', () => {
|
|
38
|
-
assert.equal(
|
|
39
|
-
rayfinErrorMessage({
|
|
40
|
-
status: 'error',
|
|
41
|
-
error: { message: 'Access denied' },
|
|
42
|
-
}),
|
|
43
|
-
'Access denied'
|
|
44
|
-
);
|
|
45
|
-
assert.equal(
|
|
46
|
-
rayfinErrorMessage({ status: 'ok', output: { ignored: true } }),
|
|
47
|
-
null
|
|
48
|
-
);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test('resolveRayfinCliEntry reads the extensionless package bin', () => {
|
|
52
|
-
const packagePath = join(
|
|
53
|
-
'C:',
|
|
54
|
-
'app',
|
|
55
|
-
'node_modules',
|
|
56
|
-
'@microsoft',
|
|
57
|
-
'rayfin-cli',
|
|
58
|
-
'package.json'
|
|
59
|
-
);
|
|
60
|
-
const createRequireImpl = () => ({
|
|
61
|
-
resolve(specifier) {
|
|
62
|
-
assert.equal(specifier, '@microsoft/rayfin-cli/package.json');
|
|
63
|
-
return packagePath;
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
const entry = resolveRayfinCliEntry({
|
|
67
|
-
createRequireImpl,
|
|
68
|
-
readFileSyncImpl: () => JSON.stringify({ bin: { rayfin: 'scripts/main' } }),
|
|
69
|
-
});
|
|
70
|
-
assert.equal(
|
|
71
|
-
entry,
|
|
72
|
-
join(
|
|
73
|
-
'C:',
|
|
74
|
-
'app',
|
|
75
|
-
'node_modules',
|
|
76
|
-
'@microsoft',
|
|
77
|
-
'rayfin-cli',
|
|
78
|
-
'scripts',
|
|
79
|
-
'main'
|
|
80
|
-
)
|
|
81
|
-
);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test('connector list treats empty stdout as a resolution error', async () => {
|
|
85
|
-
const result = await listConfiguredConnectors({
|
|
86
|
-
cliEntry: 'rayfin-entry',
|
|
87
|
-
spawnImpl: (_command, args) =>
|
|
88
|
-
fakeChild((child) => {
|
|
89
|
-
assert.deepEqual(args.slice(1), ['connector', 'list', '--json']);
|
|
90
|
-
child.emit('close', 0, null);
|
|
91
|
-
}),
|
|
92
|
-
});
|
|
93
|
-
assert.equal(result.ok, false);
|
|
94
|
-
assert.match(result.error, /did not return a JSON array/i);
|
|
95
|
-
assert.match(result.error, /app root/i);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
test('connector list accepts a valid project with no connectors', async () => {
|
|
99
|
-
const result = await listConfiguredConnectors({
|
|
100
|
-
cliEntry: 'rayfin-entry',
|
|
101
|
-
spawnImpl: () =>
|
|
102
|
-
fakeChild((child) => {
|
|
103
|
-
child.stdout.emit('data', '[]\n');
|
|
104
|
-
child.emit('close', 0, null);
|
|
105
|
-
}),
|
|
106
|
-
});
|
|
107
|
-
assert.deepEqual(result.connectors, []);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
test('invokeConnector spawns Node directly and reads the full spilled result', async () => {
|
|
111
|
-
const cwd = mkdtempSync(join(tmpdir(), 'rayfin-project-'));
|
|
112
|
-
const fullRows = Array.from({ length: 120 }, (_, index) => [
|
|
113
|
-
index,
|
|
114
|
-
'x'.repeat(100),
|
|
115
|
-
]);
|
|
116
|
-
const fullOutput = {
|
|
117
|
-
status: 'success',
|
|
118
|
-
table: {
|
|
119
|
-
columns: [{ name: '[Id]' }, { name: '[Value]' }],
|
|
120
|
-
rows: fullRows,
|
|
121
|
-
},
|
|
122
|
-
};
|
|
123
|
-
assert.ok(
|
|
124
|
-
Buffer.byteLength(JSON.stringify(fullOutput), 'utf8') > 8 * 1024,
|
|
125
|
-
"the fixture must exceed Rayfin's default inline threshold"
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
let payloadPath;
|
|
129
|
-
let outputPath;
|
|
130
|
-
let command;
|
|
131
|
-
let payload;
|
|
132
|
-
const spawnImpl = (receivedCommand, args, options) => {
|
|
133
|
-
command = receivedCommand;
|
|
134
|
-
assert.equal(options.cwd, cwd);
|
|
135
|
-
assert.equal(options.shell, false);
|
|
136
|
-
assert.equal(args[0], 'rayfin-entry');
|
|
137
|
-
payloadPath = args[args.indexOf('--file') + 1];
|
|
138
|
-
outputPath = args[args.indexOf('--output-file') + 1];
|
|
139
|
-
assert.ok(!relative(cwd, payloadPath).startsWith('..'));
|
|
140
|
-
assert.ok(!relative(cwd, outputPath).startsWith('..'));
|
|
141
|
-
payload = JSON.parse(readFileSync(payloadPath, 'utf8'));
|
|
142
|
-
|
|
143
|
-
return fakeChild((child) => {
|
|
144
|
-
writeFileSync(outputPath, JSON.stringify(fullOutput), 'utf8');
|
|
145
|
-
child.stdout.emit(
|
|
146
|
-
'data',
|
|
147
|
-
JSON.stringify({
|
|
148
|
-
status: 'ok',
|
|
149
|
-
output: {
|
|
150
|
-
...fullOutput,
|
|
151
|
-
table: {
|
|
152
|
-
...fullOutput.table,
|
|
153
|
-
rows: fullRows.slice(0, 20),
|
|
154
|
-
},
|
|
155
|
-
},
|
|
156
|
-
outputFile: outputPath,
|
|
157
|
-
outputBytes: Buffer.byteLength(JSON.stringify(fullOutput)),
|
|
158
|
-
outputTruncated: true,
|
|
159
|
-
previewItems: 20,
|
|
160
|
-
})
|
|
161
|
-
);
|
|
162
|
-
child.emit('close', 0, null);
|
|
163
|
-
});
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
try {
|
|
167
|
-
const result = await invokeConnector({
|
|
168
|
-
connector: 'sales',
|
|
169
|
-
query: 'EVALUATE INFO.VIEW.COLUMNS()',
|
|
170
|
-
cwd,
|
|
171
|
-
cliEntry: 'rayfin-entry',
|
|
172
|
-
spawnImpl,
|
|
173
|
-
});
|
|
174
|
-
assert.equal(command, process.execPath);
|
|
175
|
-
assert.equal(result.ok, true);
|
|
176
|
-
assert.equal(result.outputTruncated, true);
|
|
177
|
-
assert.equal(result.output.table.rows.length, 120);
|
|
178
|
-
assert.equal(
|
|
179
|
-
result.output.table.rows[119][0],
|
|
180
|
-
119,
|
|
181
|
-
'the full file must win over the 20-row stdout preview'
|
|
182
|
-
);
|
|
183
|
-
assert.deepEqual(payload, {
|
|
184
|
-
query: 'EVALUATE INFO.VIEW.COLUMNS()',
|
|
185
|
-
});
|
|
186
|
-
assert.equal(existsSync(payloadPath), false);
|
|
187
|
-
assert.equal(existsSync(outputPath), false);
|
|
188
|
-
} finally {
|
|
189
|
-
rmSync(cwd, { recursive: true, force: true });
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
test('invokeConnector refuses an unverified output file', async () => {
|
|
194
|
-
const cwd = mkdtempSync(join(tmpdir(), 'rayfin-project-'));
|
|
195
|
-
try {
|
|
196
|
-
const result = await invokeConnector({
|
|
197
|
-
connector: 'sales',
|
|
198
|
-
query: 'EVALUATE INFO.VIEW.TABLES()',
|
|
199
|
-
cwd,
|
|
200
|
-
cliEntry: 'rayfin-entry',
|
|
201
|
-
spawnImpl: () =>
|
|
202
|
-
fakeChild((child) => {
|
|
203
|
-
child.stdout.emit(
|
|
204
|
-
'data',
|
|
205
|
-
JSON.stringify({
|
|
206
|
-
status: 'ok',
|
|
207
|
-
output: { preview: true },
|
|
208
|
-
outputFile: join(cwd, 'wrong.json'),
|
|
209
|
-
outputTruncated: true,
|
|
210
|
-
})
|
|
211
|
-
);
|
|
212
|
-
child.emit('close', 0, null);
|
|
213
|
-
}),
|
|
214
|
-
});
|
|
215
|
-
assert.equal(result.ok, false);
|
|
216
|
-
assert.match(result.error, /Refusing to trust/i);
|
|
217
|
-
} finally {
|
|
218
|
-
rmSync(cwd, { recursive: true, force: true });
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
test('invokeConnector cleans its directory when payload serialization fails', async () => {
|
|
223
|
-
const cwd = mkdtempSync(join(tmpdir(), 'rayfin-project-'));
|
|
224
|
-
try {
|
|
225
|
-
await assert.rejects(
|
|
226
|
-
invokeConnector({
|
|
227
|
-
connector: 'sales',
|
|
228
|
-
query: 1n,
|
|
229
|
-
cwd,
|
|
230
|
-
cliEntry: 'rayfin-entry',
|
|
231
|
-
}),
|
|
232
|
-
/BigInt/
|
|
233
|
-
);
|
|
234
|
-
assert.deepEqual(
|
|
235
|
-
readdirSync(cwd).filter((name) =>
|
|
236
|
-
name.startsWith('.rayfin-schema-query-')
|
|
237
|
-
),
|
|
238
|
-
[]
|
|
239
|
-
);
|
|
240
|
-
} finally {
|
|
241
|
-
rmSync(cwd, { recursive: true, force: true });
|
|
242
|
-
}
|
|
243
|
-
});
|