@malloy-publisher/server 0.18.0 → 0.18.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/dist/app/api-doc.yaml +37 -6
- package/dist/app/assets/{EnvironmentPage-BYi5H87v.js → EnvironmentPage-CsFUI8IX.js} +1 -1
- package/dist/app/assets/{HomePage-DB-CSs0p.js → HomePage-B_FVtnN-.js} +1 -1
- package/dist/app/assets/{MainPage-2j-MpcYJ.js → MainPage-wFF9nPEr.js} +1 -1
- package/dist/app/assets/{ModelPage-BQE-ZC6E.js → ModelPage-CxenqDcz.js} +2 -2
- package/dist/app/assets/PackagePage-dcF6vrvw.js +1 -0
- package/dist/app/assets/PackageSplatRoute-CASBZk0k.js +2 -0
- package/dist/app/assets/{RenderedResult-QdYnecnr.es-PKDmuES7.js → RenderedResult--fYcsY1h.es-DzOt5Lwv.js} +3 -3
- package/dist/app/assets/{RouteError-7Fw_wYUy.js → RouteError-CUIolYwb.js} +1 -1
- package/dist/app/assets/{ThemeEditorPage-DmiRg7rU.js → ThemeEditorPage-DgU2YYq6.js} +1 -1
- package/dist/app/assets/{ToggleButtonGroup-BXVbLuei.js → ToggleButtonGroup-Dmr-hVlD.js} +1 -1
- package/dist/app/assets/{documentRoutes-DWIPC8nU.js → documentRoutes-Drv-WDwO.js} +1 -1
- package/dist/app/assets/{editPageMounted-BaGHeFZ5.js → editPageMounted-C5yJiIVi.js} +2 -2
- package/dist/app/assets/{index-CHfKShi-.js → index-BIoSdsU9.js} +1 -1
- package/dist/app/assets/{index-OQqQyWrE.js → index-BSyL0zds.js} +97 -97
- package/dist/app/assets/{index-BRdik0lA.js → index-Dtw4eTxH.js} +1 -1
- package/dist/app/assets/{index-APmAmrTn.js → index-DxF3kMLJ.js} +1 -1
- package/dist/app/assets/{index.es-DLFu6xFm.js → index.es-CX9m4CBD.js} +10 -10
- package/dist/app/assets/usePackageLinkNavigate-qNjcXPcY.js +1 -0
- package/dist/app/assets/{usePackageRoute-pIAy965Q.js → usePackageRoute-wJGaZEiY.js} +1 -1
- package/dist/app/index.html +1 -1
- package/dist/instrumentation.mjs +16 -7
- package/dist/package_load_worker.mjs +144 -43
- package/dist/runtime/publisher.colorScheme.spec.ts +167 -0
- package/dist/runtime/publisher.js +173 -3
- package/dist/runtime/publisher_embed.spec.ts +108 -0
- package/dist/server.mjs +1554 -554
- package/package.json +1 -1
- package/dist/app/assets/PackagePage-BMv6ojk4.js +0 -1
- package/dist/app/assets/PackageSplatRoute-BOAFRQKR.js +0 -2
- package/dist/app/assets/usePackageLinkNavigate-DTlEYsed.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{E as u,r as c}from"./index-BSyL0zds.js";import{w as e}from"./usePackageRoute-wJGaZEiY.js";function p(t,a,r){const s=u();return c.useCallback((o,i)=>s(e(o,t,a,r),i),[s,t,a,r])}export{p as u};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{C as f,a9 as p}from"./index-
|
|
1
|
+
import{C as f,a9 as p}from"./index-BSyL0zds.js";const $=/^(latest|[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?)$/,m="latest",l=e=>$.test(e),g=e=>{const n=e.indexOf("/"),o=n===-1?e:e.slice(0,n);if(l(o))return{segment:o,rest:n===-1?"":e.slice(n+1)}},h=e=>e===void 0||e===m?void 0:e,I=(e,n,o)=>`/${encodeURIComponent(e)}/${encodeURIComponent(n)}${o===void 0?"":`/${encodeURIComponent(o)}`}`,E=(e,n,o,t)=>{if(t===void 0)return e;const i=[`/${encodeURIComponent(n)}/${encodeURIComponent(o)}`,`/${n}/${o}`];for(const s of i){if(e!==s&&!e.startsWith(`${s}/`))continue;const r=e.slice(s.length).replace(/^\//,"");return`${I(n,o,t)}${r===""?"":`/${r}`}`}return e};function R(e={}){const n=f(),o=n.environmentName,t=n.packageName,i=n["*"],s=i===void 0?void 0:g(i),{versions:r,isPending:d,isError:v,refetch:u}=p(o??"",t??"",{enabled:e.always===!0||s!==void 0}),a=r.length>0,c=s&&a?s:void 0;return{environmentName:o,packageName:t,versionSegment:c?.segment,versionId:h(c?.segment),path:c?c.rest:i,versioned:a,deciding:s!==void 0&&d,undecided:s!==void 0&&v,retry:u,writable:!a&&!d&&!v}}export{m as L,I as p,R as u,h as v,E as w};
|
package/dist/app/index.html
CHANGED
|
@@ -16,7 +16,7 @@ SPDX-License-Identifier: MIT
|
|
|
16
16
|
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap"
|
|
17
17
|
/>
|
|
18
18
|
<title>Malloy Publisher</title>
|
|
19
|
-
<script type="module" crossorigin src="/assets/index-
|
|
19
|
+
<script type="module" crossorigin src="/assets/index-BSyL0zds.js"></script>
|
|
20
20
|
<link rel="stylesheet" crossorigin href="/assets/index-DUqldpo0.css">
|
|
21
21
|
</head>
|
|
22
22
|
<body>
|
package/dist/instrumentation.mjs
CHANGED
|
@@ -556,7 +556,7 @@ var init_launch = __esm(() => {
|
|
|
556
556
|
default: false,
|
|
557
557
|
kind: "launch",
|
|
558
558
|
description: "Wipe persisted storage and re-sync it from the config.",
|
|
559
|
-
notes: "Set to `true` (or pass `--init`) to **wipe persisted storage** (`publisher_data/`) and re-sync it from the config on boot. A first boot with empty storage loads the config automatically, so you only need this to reset state or pick up config changes. Also exposed as the `start:init` / `start:dev:init` scripts.",
|
|
559
|
+
notes: "Set to `true` (or pass `--init`) to **wipe persisted storage** (`publisher_data/`) and re-sync it from the config on boot. A first boot with empty storage loads the config automatically, so you only need this to reset state or pick up config changes. The search index (stored value reads, embeddings and LLM output) is kept, since each entry is reused only while what it was built from is unchanged; the rows of a package the config no longer lists are deleted. Also exposed as the `start:init` / `start:dev:init` scripts.",
|
|
560
560
|
shortFlags: ["--init"],
|
|
561
561
|
aliases: {
|
|
562
562
|
env: ["INITIALIZE_STORAGE"],
|
|
@@ -810,7 +810,7 @@ var init_provider_names = __esm(() => {
|
|
|
810
810
|
var EGRESS_PRESETS, DEFAULT_LLM_TIMEOUT_MS = 30000, DEFAULT_LLM_CONCURRENCY = 4, DEFAULT_LLM_MAX_CALLS_PER_SYNC = 300, DEFAULT_LLM_MAX_CALLS_PER_REQUEST = 20, DIMENSION_VALUE_DEFAULTS;
|
|
811
811
|
var init_defaults = __esm(() => {
|
|
812
812
|
EGRESS_PRESETS = ["default", "full"];
|
|
813
|
-
DIMENSION_VALUE_DEFAULTS = { enabled: true };
|
|
813
|
+
DIMENSION_VALUE_DEFAULTS = { enabled: true, givens: {} };
|
|
814
814
|
});
|
|
815
815
|
|
|
816
816
|
// src/settings/registry/retrieval.ts
|
|
@@ -825,7 +825,7 @@ var init_retrieval = __esm(() => {
|
|
|
825
825
|
key: "retrieval",
|
|
826
826
|
type: structured(),
|
|
827
827
|
kind: "structured",
|
|
828
|
-
description: "Semantic retrieval: indexing limits, the LLM, the embedding provider and
|
|
828
|
+
description: "Semantic retrieval: indexing limits, the LLM, the embedding provider and value search.",
|
|
829
829
|
aliases: { file: ["retrieval"] }
|
|
830
830
|
}),
|
|
831
831
|
setting({
|
|
@@ -926,9 +926,9 @@ var init_retrieval = __esm(() => {
|
|
|
926
926
|
setting({
|
|
927
927
|
key: "retrieval.egress.preset",
|
|
928
928
|
type: oneOf(EGRESS_PRESETS),
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
929
|
+
description: "No longer read: #(index) alone decides whether a dimension's values reach the embedding provider and LLM. Setting it logs a startup warning.",
|
|
930
|
+
notes: "Retired. An earlier release sent `#(index)` values to the embedding provider and the LLM only under `full`. Now the `#(index)` tag decides, as it does on a hosted index. To keep values on the machine, leave `EMBEDDING_API_KEY` unset, set `retrieval.fcj.valueEmbeddings` to `false` in the package's `publisher.json`, or set `retrieval.dimensionValues.enabled` to `false`. Access predicates (`#(access_filter)`, `#(authorize)`) never leave.",
|
|
931
|
+
defaultText: "_ignored_",
|
|
932
932
|
aliases: { file: ["retrieval.egress.preset"] }
|
|
933
933
|
}),
|
|
934
934
|
setting({
|
|
@@ -941,6 +941,15 @@ var init_retrieval = __esm(() => {
|
|
|
941
941
|
today: { file: "json-boolean" }
|
|
942
942
|
}
|
|
943
943
|
}),
|
|
944
|
+
setting({
|
|
945
|
+
key: "retrieval.dimensionValues.givens",
|
|
946
|
+
type: structured(),
|
|
947
|
+
kind: "structured",
|
|
948
|
+
description: "Local development: per package, the givens the value index reads with, so a source gated by `column = $GIVEN` is indexed for the listed values only.",
|
|
949
|
+
notes: 'An object of packages, each an object of givens, each one value or a list: `{ "<package>": { "REPORT_ID": [123, 456] } }`. Each `#(index)` dimension is read once per combination of the listed values (at most 50), through its gate. A source gated by `column = $GIVEN` is skipped unless its given is listed here. Never published with a package, and not a way to limit what hosted Credible indexes. See "Dimension value search" below.',
|
|
950
|
+
defaultText: "_unset_ (gated sources skipped)",
|
|
951
|
+
aliases: { file: ["retrieval.dimensionValues.givens"] }
|
|
952
|
+
}),
|
|
944
953
|
setting({
|
|
945
954
|
key: "retrieval.embedding.apiKey",
|
|
946
955
|
type: string(),
|
|
@@ -167076,7 +167085,7 @@ var init_telemetry = __esm(() => {
|
|
|
167076
167085
|
});
|
|
167077
167086
|
|
|
167078
167087
|
// package.json
|
|
167079
|
-
var version = "0.18.
|
|
167088
|
+
var version = "0.18.1";
|
|
167080
167089
|
var init_package = () => {};
|
|
167081
167090
|
|
|
167082
167091
|
// src/version.ts
|
|
@@ -979,7 +979,7 @@ var init_launch = __esm(() => {
|
|
|
979
979
|
default: false,
|
|
980
980
|
kind: "launch",
|
|
981
981
|
description: "Wipe persisted storage and re-sync it from the config.",
|
|
982
|
-
notes: "Set to `true` (or pass `--init`) to **wipe persisted storage** (`publisher_data/`) and re-sync it from the config on boot. A first boot with empty storage loads the config automatically, so you only need this to reset state or pick up config changes. Also exposed as the `start:init` / `start:dev:init` scripts.",
|
|
982
|
+
notes: "Set to `true` (or pass `--init`) to **wipe persisted storage** (`publisher_data/`) and re-sync it from the config on boot. A first boot with empty storage loads the config automatically, so you only need this to reset state or pick up config changes. The search index (stored value reads, embeddings and LLM output) is kept, since each entry is reused only while what it was built from is unchanged; the rows of a package the config no longer lists are deleted. Also exposed as the `start:init` / `start:dev:init` scripts.",
|
|
983
983
|
shortFlags: ["--init"],
|
|
984
984
|
aliases: {
|
|
985
985
|
env: ["INITIALIZE_STORAGE"],
|
|
@@ -1233,7 +1233,7 @@ var init_provider_names = __esm(() => {
|
|
|
1233
1233
|
var EGRESS_PRESETS, DEFAULT_LLM_TIMEOUT_MS = 30000, DEFAULT_LLM_CONCURRENCY = 4, DEFAULT_LLM_MAX_CALLS_PER_SYNC = 300, DEFAULT_LLM_MAX_CALLS_PER_REQUEST = 20, DIMENSION_VALUE_DEFAULTS;
|
|
1234
1234
|
var init_defaults = __esm(() => {
|
|
1235
1235
|
EGRESS_PRESETS = ["default", "full"];
|
|
1236
|
-
DIMENSION_VALUE_DEFAULTS = { enabled: true };
|
|
1236
|
+
DIMENSION_VALUE_DEFAULTS = { enabled: true, givens: {} };
|
|
1237
1237
|
});
|
|
1238
1238
|
|
|
1239
1239
|
// src/settings/registry/retrieval.ts
|
|
@@ -1248,7 +1248,7 @@ var init_retrieval = __esm(() => {
|
|
|
1248
1248
|
key: "retrieval",
|
|
1249
1249
|
type: structured(),
|
|
1250
1250
|
kind: "structured",
|
|
1251
|
-
description: "Semantic retrieval: indexing limits, the LLM, the embedding provider and
|
|
1251
|
+
description: "Semantic retrieval: indexing limits, the LLM, the embedding provider and value search.",
|
|
1252
1252
|
aliases: { file: ["retrieval"] }
|
|
1253
1253
|
}),
|
|
1254
1254
|
setting({
|
|
@@ -1349,9 +1349,9 @@ var init_retrieval = __esm(() => {
|
|
|
1349
1349
|
setting({
|
|
1350
1350
|
key: "retrieval.egress.preset",
|
|
1351
1351
|
type: oneOf(EGRESS_PRESETS),
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1352
|
+
description: "No longer read: #(index) alone decides whether a dimension's values reach the embedding provider and LLM. Setting it logs a startup warning.",
|
|
1353
|
+
notes: "Retired. An earlier release sent `#(index)` values to the embedding provider and the LLM only under `full`. Now the `#(index)` tag decides, as it does on a hosted index. To keep values on the machine, leave `EMBEDDING_API_KEY` unset, set `retrieval.fcj.valueEmbeddings` to `false` in the package's `publisher.json`, or set `retrieval.dimensionValues.enabled` to `false`. Access predicates (`#(access_filter)`, `#(authorize)`) never leave.",
|
|
1354
|
+
defaultText: "_ignored_",
|
|
1355
1355
|
aliases: { file: ["retrieval.egress.preset"] }
|
|
1356
1356
|
}),
|
|
1357
1357
|
setting({
|
|
@@ -1364,6 +1364,15 @@ var init_retrieval = __esm(() => {
|
|
|
1364
1364
|
today: { file: "json-boolean" }
|
|
1365
1365
|
}
|
|
1366
1366
|
}),
|
|
1367
|
+
setting({
|
|
1368
|
+
key: "retrieval.dimensionValues.givens",
|
|
1369
|
+
type: structured(),
|
|
1370
|
+
kind: "structured",
|
|
1371
|
+
description: "Local development: per package, the givens the value index reads with, so a source gated by `column = $GIVEN` is indexed for the listed values only.",
|
|
1372
|
+
notes: 'An object of packages, each an object of givens, each one value or a list: `{ "<package>": { "REPORT_ID": [123, 456] } }`. Each `#(index)` dimension is read once per combination of the listed values (at most 50), through its gate. A source gated by `column = $GIVEN` is skipped unless its given is listed here. Never published with a package, and not a way to limit what hosted Credible indexes. See "Dimension value search" below.',
|
|
1373
|
+
defaultText: "_unset_ (gated sources skipped)",
|
|
1374
|
+
aliases: { file: ["retrieval.dimensionValues.givens"] }
|
|
1375
|
+
}),
|
|
1367
1376
|
setting({
|
|
1368
1377
|
key: "retrieval.embedding.apiKey",
|
|
1369
1378
|
type: string(),
|
|
@@ -13357,13 +13366,15 @@ var init_errors2 = __esm(() => {
|
|
|
13357
13366
|
};
|
|
13358
13367
|
ManifestBindFailedError = class ManifestBindFailedError extends Error {
|
|
13359
13368
|
applied;
|
|
13369
|
+
problem;
|
|
13360
13370
|
get kind() {
|
|
13361
13371
|
return "manifest_bind_failed";
|
|
13362
13372
|
}
|
|
13363
|
-
constructor(manifestLocation, cause, applied) {
|
|
13373
|
+
constructor(manifestLocation, cause, applied, problem) {
|
|
13364
13374
|
const detail = cause instanceof Error ? cause.message : String(cause);
|
|
13365
13375
|
super(`The build manifest ${manifestLocation} could not be bound ` + `(${detail}), so it was not applied: the package serves what ` + `it served before.`, { cause });
|
|
13366
13376
|
this.applied = applied;
|
|
13377
|
+
this.problem = problem;
|
|
13367
13378
|
this.name = "ManifestBindFailedError";
|
|
13368
13379
|
}
|
|
13369
13380
|
};
|
|
@@ -13826,8 +13837,8 @@ var init_errors2 = __esm(() => {
|
|
|
13826
13837
|
connection_save: { status: 500, mcp: { advice: "internal" } },
|
|
13827
13838
|
write_rolled_back: { status: 500, mcp: { advice: "internal" } },
|
|
13828
13839
|
manifest_bind_failed: {
|
|
13829
|
-
status: 500,
|
|
13830
|
-
reason: "MANIFEST_BIND_FAILED",
|
|
13840
|
+
status: (error) => error.problem === "not_found" ? 400 : error.problem === "invalid" ? 422 : 500,
|
|
13841
|
+
reason: (error) => error.problem === "not_found" ? "MANIFEST_NOT_FOUND" : error.problem === "invalid" ? "MANIFEST_INVALID" : "MANIFEST_BIND_FAILED",
|
|
13831
13842
|
mcp: { advice: "internal" }
|
|
13832
13843
|
},
|
|
13833
13844
|
service_unavailable: BACK_PRESSURE,
|
|
@@ -31837,7 +31848,9 @@ function columnCompare(args, isString, collation, name) {
|
|
|
31837
31848
|
}
|
|
31838
31849
|
if (args.stackedOn !== undefined)
|
|
31839
31850
|
return args.stackedOn;
|
|
31840
|
-
|
|
31851
|
+
return liveCompare(args.live?.get(name));
|
|
31852
|
+
}
|
|
31853
|
+
function liveCompare(live) {
|
|
31841
31854
|
return live === "binary" ? "exact" : live === "deterministic" ? "equality" : "none";
|
|
31842
31855
|
}
|
|
31843
31856
|
function weakestStringCompare(upstreams) {
|
|
@@ -43114,7 +43127,7 @@ var init_package_retrieval_settings = __esm(() => {
|
|
|
43114
43127
|
questions: "auto",
|
|
43115
43128
|
docParts: "auto",
|
|
43116
43129
|
values: true,
|
|
43117
|
-
valueCap:
|
|
43130
|
+
valueCap: 5000,
|
|
43118
43131
|
valueEmbeddings: true,
|
|
43119
43132
|
judge: "auto",
|
|
43120
43133
|
contenderShare: 0,
|
|
@@ -45248,14 +45261,34 @@ function parseEmbedding(raw) {
|
|
|
45248
45261
|
documentPrefix: plainString(obj.documentPrefix, "retrieval.embedding.documentPrefix", `"documentPrefix": "search_document: "`) ?? ""
|
|
45249
45262
|
};
|
|
45250
45263
|
}
|
|
45251
|
-
function
|
|
45252
|
-
const
|
|
45253
|
-
|
|
45254
|
-
|
|
45255
|
-
|
|
45256
|
-
|
|
45264
|
+
function parseValueGivens(raw) {
|
|
45265
|
+
const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
45266
|
+
const isValue = (v) => typeof v === "string" || typeof v === "boolean" || typeof v === "number" && Number.isFinite(v);
|
|
45267
|
+
if (!isObject(raw)) {
|
|
45268
|
+
throw new Error(`Invalid retrieval.dimensionValues.givens: expected an object of packages, got ${describe2(raw)}. Fix: ${GIVENS_FIX}`);
|
|
45269
|
+
}
|
|
45270
|
+
const out = {};
|
|
45271
|
+
for (const [pkg, givens] of Object.entries(raw)) {
|
|
45272
|
+
const at = `retrieval.dimensionValues.givens.${pkg}`;
|
|
45273
|
+
if (!isObject(givens)) {
|
|
45274
|
+
throw new Error(`Invalid ${at}: expected an object of givens, got ${describe2(givens)}. Fix: ${GIVENS_FIX}`);
|
|
45275
|
+
}
|
|
45276
|
+
const parsed = {};
|
|
45277
|
+
let combinations = 1;
|
|
45278
|
+
for (const [name, value] of Object.entries(givens)) {
|
|
45279
|
+
const list = Array.isArray(value) ? value : [value];
|
|
45280
|
+
if (list.length === 0 || !list.every(isValue)) {
|
|
45281
|
+
throw new Error(`Invalid ${at}.${name}: expected a string, number or boolean, or a non-empty list of them, got ${describe2(value)}. Fix: ${GIVENS_FIX}`);
|
|
45282
|
+
}
|
|
45283
|
+
parsed[name] = [...new Set(list)];
|
|
45284
|
+
combinations *= parsed[name].length;
|
|
45285
|
+
}
|
|
45286
|
+
if (combinations > MAX_GIVEN_COMBINATIONS) {
|
|
45287
|
+
throw new Error(`Invalid ${at}: its lists make ${combinations} combinations, and each is one read per indexed dimension; at most ${MAX_GIVEN_COMBINATIONS}. Fix: list fewer values`);
|
|
45288
|
+
}
|
|
45289
|
+
out[pkg] = parsed;
|
|
45257
45290
|
}
|
|
45258
|
-
return
|
|
45291
|
+
return out;
|
|
45259
45292
|
}
|
|
45260
45293
|
function parseDimensionValues(raw) {
|
|
45261
45294
|
const fields = block(raw, "retrieval.dimensionValues", DIMENSION_VALUE_KEYS, `"dimensionValues": { "enabled": false }`);
|
|
@@ -45266,6 +45299,9 @@ function parseDimensionValues(raw) {
|
|
|
45266
45299
|
}
|
|
45267
45300
|
out.enabled = fields.enabled;
|
|
45268
45301
|
}
|
|
45302
|
+
if (fields.givens !== undefined && fields.givens !== null) {
|
|
45303
|
+
out.givens = parseValueGivens(fields.givens);
|
|
45304
|
+
}
|
|
45269
45305
|
return out;
|
|
45270
45306
|
}
|
|
45271
45307
|
function parseRetrievalConfig(raw) {
|
|
@@ -45292,17 +45328,16 @@ function parseRetrievalConfig(raw) {
|
|
|
45292
45328
|
if (embedding)
|
|
45293
45329
|
out.embedding = embedding;
|
|
45294
45330
|
}
|
|
45295
|
-
if (input.egress !== undefined
|
|
45296
|
-
|
|
45297
|
-
if (egress)
|
|
45298
|
-
out.egress = egress;
|
|
45299
|
-
}
|
|
45331
|
+
if (input.egress !== undefined)
|
|
45332
|
+
out.egressIgnored = true;
|
|
45300
45333
|
if (input.dimensionValues !== undefined && input.dimensionValues !== null) {
|
|
45301
45334
|
out.dimensionValues = parseDimensionValues(input.dimensionValues);
|
|
45302
45335
|
}
|
|
45303
45336
|
return out;
|
|
45304
45337
|
}
|
|
45305
45338
|
function setRetrievalConfig(config) {
|
|
45339
|
+
if (config?.egressIgnored)
|
|
45340
|
+
logger.warn(RETIRED_EGRESS_WARNING);
|
|
45306
45341
|
loaded = config;
|
|
45307
45342
|
}
|
|
45308
45343
|
function loadedRetrievalConfig() {
|
|
@@ -45311,14 +45346,12 @@ function loadedRetrievalConfig() {
|
|
|
45311
45346
|
function getDimensionValueSettings() {
|
|
45312
45347
|
return { ...DIMENSION_VALUE_DEFAULTS, ...loaded?.dimensionValues };
|
|
45313
45348
|
}
|
|
45314
|
-
|
|
45315
|
-
return loaded?.egress?.preset ?? "default";
|
|
45316
|
-
}
|
|
45317
|
-
var DIMENSION_VALUE_KEYS, loaded;
|
|
45349
|
+
var RETIRED_EGRESS_WARNING = "retrieval.egress is no longer read and is ignored. The values of #(index) dimensions are now sent to the configured embedding provider and LLM whenever one is configured. To keep them on this machine, set retrieval.dimensionValues.enabled to false in publisher.config.json. Leaving EMBEDDING_API_KEY unset, or setting retrieval.fcj.valueEmbeddings to false, only stops values being embedded: a configured LLM still sees them. Remove the egress block to silence this warning.", MAX_GIVEN_COMBINATIONS = 50, DIMENSION_VALUE_KEYS, GIVENS_FIX = `"givens": { "<package>": { "REPORT_ID": [123, 456] } }`, loaded;
|
|
45318
45350
|
var init_config = __esm(() => {
|
|
45351
|
+
init_logger();
|
|
45319
45352
|
init_types2();
|
|
45320
45353
|
init_defaults();
|
|
45321
|
-
DIMENSION_VALUE_KEYS = ["enabled"];
|
|
45354
|
+
DIMENSION_VALUE_KEYS = ["enabled", "givens"];
|
|
45322
45355
|
});
|
|
45323
45356
|
|
|
45324
45357
|
// src/config.ts
|
|
@@ -45547,7 +45580,7 @@ function assembleRetrieval(file) {
|
|
|
45547
45580
|
return { block: file, ignored };
|
|
45548
45581
|
}
|
|
45549
45582
|
const block = file ? structuredClone(file) : {};
|
|
45550
|
-
for (const leaf of REGISTRY.filter((entry) => entry.key.startsWith("retrieval.")
|
|
45583
|
+
for (const leaf of REGISTRY.filter((entry) => entry.key.startsWith("retrieval."))) {
|
|
45551
45584
|
const pathInBlock = leaf.key.split(".").slice(1);
|
|
45552
45585
|
const parent = nodeAt(block, pathInBlock.slice(0, -1));
|
|
45553
45586
|
const last = pathInBlock[pathInBlock.length - 1];
|
|
@@ -46645,6 +46678,13 @@ function gateRefusalReason(routes) {
|
|
|
46645
46678
|
}
|
|
46646
46679
|
|
|
46647
46680
|
// src/service/materialization/domain/compiled_build_plan.ts
|
|
46681
|
+
function stringCapabilityKey(sourceID, destination) {
|
|
46682
|
+
return JSON.stringify([sourceID, destination]);
|
|
46683
|
+
}
|
|
46684
|
+
function stringCapabilityKeyParts(key) {
|
|
46685
|
+
const [sourceID, destination] = JSON.parse(key);
|
|
46686
|
+
return { sourceID, destination };
|
|
46687
|
+
}
|
|
46648
46688
|
function* sourcesInBuildOrder(build, tables) {
|
|
46649
46689
|
for (const sourceID of build.order) {
|
|
46650
46690
|
const source = tables[sourceID]?.source;
|
|
@@ -50392,6 +50432,18 @@ function reachedUpstreams(root, modelDef, map) {
|
|
|
50392
50432
|
}
|
|
50393
50433
|
return out;
|
|
50394
50434
|
}
|
|
50435
|
+
function materializedUpstream(sourceID, map) {
|
|
50436
|
+
const node = map.node(sourceID);
|
|
50437
|
+
const def = node?.def;
|
|
50438
|
+
const notes = ownLevelNotes(def?.annotations);
|
|
50439
|
+
if (notesDeclarePersist(notes.filter((n) => routeOfNote(n.text) === "@"))) {
|
|
50440
|
+
return;
|
|
50441
|
+
}
|
|
50442
|
+
if (!notes.some((n) => routeOfNote(n.text) === "materialize")) {
|
|
50443
|
+
return;
|
|
50444
|
+
}
|
|
50445
|
+
return { name: node?.name ?? sourceID, dialect: def?.dialect };
|
|
50446
|
+
}
|
|
50395
50447
|
function storedElsewhereReason(upstreams) {
|
|
50396
50448
|
const stored = upstreams.find((u) => u.storage !== undefined);
|
|
50397
50449
|
return stored ? `its upstream '${stored.name}' is stored in the storage= destination ` + `'${stored.storage}', whose table a build in the warehouse cannot ` + `read, and a downstream is never built by recomputing its upstream ` + `from raw; it is ` + `answered live, over '${stored.name}''s table` : undefined;
|
|
@@ -55503,6 +55555,32 @@ function recordedCompare(names, contract) {
|
|
|
55503
55555
|
}
|
|
55504
55556
|
return "none";
|
|
55505
55557
|
}
|
|
55558
|
+
function unboundStringReadsRefusal(reads, unbound) {
|
|
55559
|
+
if ("refused" in reads)
|
|
55560
|
+
return;
|
|
55561
|
+
for (const read of reads.reads) {
|
|
55562
|
+
const upstream = read.upstream === undefined ? undefined : unbound.get(read.upstream);
|
|
55563
|
+
if (upstream === undefined)
|
|
55564
|
+
continue;
|
|
55565
|
+
const name = read.names[read.names.length - 1] ?? "?";
|
|
55566
|
+
const verb = read.need === "exact" ? "orders" : "groups or compares";
|
|
55567
|
+
const { capability } = upstream;
|
|
55568
|
+
if (capability === "unread") {
|
|
55569
|
+
return `it ${verb} '${name}' from '${upstream.name}', whose table is not ` + `bound yet and whose source's string comparison has not been ` + `read yet`;
|
|
55570
|
+
}
|
|
55571
|
+
const live = [...read.names].reverse().map((n) => capability.fields.get(n)).find((c) => c !== undefined);
|
|
55572
|
+
const compare = liveCompare(live);
|
|
55573
|
+
if (!MEETS[read.need].has(compare)) {
|
|
55574
|
+
return `it ${verb} '${name}' from '${upstream.name}', whose table is not ` + `bound yet and whose source compares it ` + `${compare === "none" ? "unlike byte order" : `by ${compare} only`}`;
|
|
55575
|
+
}
|
|
55576
|
+
}
|
|
55577
|
+
return;
|
|
55578
|
+
}
|
|
55579
|
+
function capabilityFingerprint(judged) {
|
|
55580
|
+
if (typeof judged === "string")
|
|
55581
|
+
return judged;
|
|
55582
|
+
return JSON.stringify([...judged.fields].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0));
|
|
55583
|
+
}
|
|
55506
55584
|
var MEETS;
|
|
55507
55585
|
var init_string_reads = __esm(() => {
|
|
55508
55586
|
init_column_contract();
|
|
@@ -56272,7 +56350,8 @@ function emptyBuildPlanParts() {
|
|
|
56272
56350
|
modelGateLines: noModelGateLines(),
|
|
56273
56351
|
persistedViews: {},
|
|
56274
56352
|
omittedSources: [],
|
|
56275
|
-
accessReads: []
|
|
56353
|
+
accessReads: [],
|
|
56354
|
+
stringCapabilityReads: {}
|
|
56276
56355
|
};
|
|
56277
56356
|
}
|
|
56278
56357
|
function mergeBuildPlanParts(into, from) {
|
|
@@ -56290,6 +56369,7 @@ function mergeBuildPlanParts(into, from) {
|
|
|
56290
56369
|
into.accessReads = [
|
|
56291
56370
|
...new Set([...into.accessReads, ...from.accessReads])
|
|
56292
56371
|
].sort();
|
|
56372
|
+
Object.assign(into.stringCapabilityReads, from.stringCapabilityReads);
|
|
56293
56373
|
}
|
|
56294
56374
|
function addAnnotationFinding(parts, finding) {
|
|
56295
56375
|
const key = (f) => [f.code, f.model ?? "", f.subject ?? "", f.message].join("\x00");
|
|
@@ -56483,7 +56563,10 @@ async function collectGeneratedRollups(parts, args) {
|
|
|
56483
56563
|
measures: plan.measures.map((m) => m.name)
|
|
56484
56564
|
},
|
|
56485
56565
|
stored: [storedBase.baseSourceID]
|
|
56486
|
-
}, plan.storage
|
|
56566
|
+
}, plan.storage, {
|
|
56567
|
+
modelDef: args.modelDef,
|
|
56568
|
+
judged: parts.stringCapabilityReads
|
|
56569
|
+
}) : undefined;
|
|
56487
56570
|
const overStored = provenRollupOverStored(source, plan, generated.overStoredBases.get(source.sourceID), parts.tables);
|
|
56488
56571
|
const unusableUpstream = storedBase && plan.storage !== undefined ? storedBaseDecline(args, source, plan, storedBase, plan.storage) : !storedBase && !overStored.overStoredBase ? rollupOverDefinition(args, plan) : undefined;
|
|
56489
56572
|
parts.tables[source.sourceID] = {
|
|
@@ -56510,7 +56593,7 @@ function provenRollupOverStored(source, plan, variant, tables) {
|
|
|
56510
56593
|
return {};
|
|
56511
56594
|
return overStoredProven(source, variant, base.source) ? { overStoredBase: variant } : {};
|
|
56512
56595
|
}
|
|
56513
|
-
async function planStringReads(ports, materializer, request, destination) {
|
|
56596
|
+
async function planStringReads(ports, materializer, request, destination, upstreams) {
|
|
56514
56597
|
if (!ports) {
|
|
56515
56598
|
return { refused: "this package reads no string a build compares" };
|
|
56516
56599
|
}
|
|
@@ -56523,14 +56606,30 @@ async function planStringReads(ports, materializer, request, destination) {
|
|
|
56523
56606
|
const unstored = unstoredReadRefusal(reads);
|
|
56524
56607
|
if (unstored !== undefined)
|
|
56525
56608
|
return { refused: unstored, unstored: true };
|
|
56526
|
-
if ("refused" in reads
|
|
56527
|
-
return reads;
|
|
56528
|
-
const contracts = new Map(request.stored.map((id) => [id, ports.boundContract(id, destination)]));
|
|
56529
|
-
if ([...contracts.values()].some((c) => c === undefined))
|
|
56609
|
+
if ("refused" in reads)
|
|
56530
56610
|
return reads;
|
|
56531
|
-
const
|
|
56611
|
+
const contracts = new Map(request.stored.map((id) => [id, ports.boundContract?.(id, destination)]));
|
|
56612
|
+
const why = ports.boundContract && [...contracts.values()].every((c) => c !== undefined) ? stringReadsRefusal(reads, contracts) : unboundStringReadsRefusal(reads, await unboundCapabilities(ports, reads, request.stored.filter((id) => contracts.get(id) === undefined), destination, upstreams));
|
|
56532
56613
|
return why === undefined ? reads : { refused: why };
|
|
56533
56614
|
}
|
|
56615
|
+
async function unboundCapabilities(ports, reads, unbound, destination, upstreams) {
|
|
56616
|
+
const out = new Map;
|
|
56617
|
+
if ("refused" in reads)
|
|
56618
|
+
return out;
|
|
56619
|
+
const map = SourceMap.of(upstreams.modelDef);
|
|
56620
|
+
for (const id of unbound) {
|
|
56621
|
+
if (!reads.reads.some((r) => r.upstream === id))
|
|
56622
|
+
continue;
|
|
56623
|
+
const upstream = materializedUpstream(id, map);
|
|
56624
|
+
if (upstream === undefined || capabilitiesOf(upstream.dialect).stringCollation !== "column") {
|
|
56625
|
+
continue;
|
|
56626
|
+
}
|
|
56627
|
+
const capability = ports.capability ? await ports.capability(id).catch(() => "unread") : "unread";
|
|
56628
|
+
upstreams.judged[stringCapabilityKey(id, destination)] = capabilityFingerprint(capability);
|
|
56629
|
+
out.set(id, { name: upstream.name, capability });
|
|
56630
|
+
}
|
|
56631
|
+
return out;
|
|
56632
|
+
}
|
|
56534
56633
|
function viewUnusableUpstream(generated, sourceID, proven) {
|
|
56535
56634
|
const unusable = generated.overStoredUnusable.get(sourceID);
|
|
56536
56635
|
if (unusable !== undefined)
|
|
@@ -56591,11 +56690,11 @@ function storedBaseDecline(args, source, plan, storedBase, destination) {
|
|
|
56591
56690
|
return `its model does not declare ${base}`;
|
|
56592
56691
|
return "declined" in text ? `${base} cannot be re-rooted on that table: ${text.declined}` : undefined;
|
|
56593
56692
|
}
|
|
56594
|
-
function inDestinationStringReads(args, stored, planned) {
|
|
56693
|
+
function inDestinationStringReads(args, stored, planned, upstreams) {
|
|
56595
56694
|
const run = planned.kind === "query" ? `run: ${quotedIdentifier(planned.queryName)}` : `run: ${quotedIdentifier(planned.sourceName)} -> ${quotedIdentifier(planned.viewName)}`;
|
|
56596
|
-
return planStringReads(args.stringReads, args.materializer, { run, stored: stored.upstreams.map((u) => u.sourceID) }, planned.storage);
|
|
56695
|
+
return planStringReads(args.stringReads, args.materializer, { run, stored: stored.upstreams.map((u) => u.sourceID) }, planned.storage, upstreams);
|
|
56597
56696
|
}
|
|
56598
|
-
async function chainedStringReads(source, modelDef, materializer, ports) {
|
|
56697
|
+
async function chainedStringReads(source, modelDef, materializer, ports, judged) {
|
|
56599
56698
|
const destination = declaredStorage(source)?.trim();
|
|
56600
56699
|
if (!destination)
|
|
56601
56700
|
return;
|
|
@@ -56607,7 +56706,7 @@ async function chainedStringReads(source, modelDef, materializer, ports) {
|
|
|
56607
56706
|
const stored = reachedUpstreams(def, modelDef, map).filter((u) => u.storage === destination && u.sourceID !== source.sourceID).map((u) => u.sourceID);
|
|
56608
56707
|
if (stored.length === 0)
|
|
56609
56708
|
return;
|
|
56610
|
-
const reads = await planStringReads(ports, materializer, { downstream: source.name, stored }, destination);
|
|
56709
|
+
const reads = await planStringReads(ports, materializer, { downstream: source.name, stored }, destination, { modelDef, judged });
|
|
56611
56710
|
if (!("refused" in reads) || !reads.unstored)
|
|
56612
56711
|
return reads;
|
|
56613
56712
|
const persisted = new Set(reachedUpstreams(def, modelDef, map).map((u) => u.sourceID));
|
|
@@ -56690,7 +56789,7 @@ async function collectGeneratedPersistedViews(parts, args) {
|
|
|
56690
56789
|
continue;
|
|
56691
56790
|
}
|
|
56692
56791
|
kept++;
|
|
56693
|
-
const stringReads = inDestination && "stored" in inDestination ? await inDestinationStringReads(args, inDestination.stored, query ?? plan) : undefined;
|
|
56792
|
+
const stringReads = inDestination && "stored" in inDestination ? await inDestinationStringReads(args, inDestination.stored, query ?? plan, { modelDef: authorDef, judged: parts.stringCapabilityReads }) : undefined;
|
|
56694
56793
|
const unusableUpstream = viewUnusableUpstream(generated, source.sourceID, overStoredBase !== undefined);
|
|
56695
56794
|
parts.tables[source.sourceID] = {
|
|
56696
56795
|
kind: "view",
|
|
@@ -56991,7 +57090,7 @@ async function planV1PersistSources(parts, planned, args) {
|
|
|
56991
57090
|
modelDef: modelDefOf(malloyModel),
|
|
56992
57091
|
deps: gateDepsFor(malloyModel, modelPath)
|
|
56993
57092
|
};
|
|
56994
|
-
const stringReads = declaringModelPath(sourceIDFileURL(sourceID), packagePath, modelPath) === modelPath ? await chainedStringReads(source, classificationCtx.modelDef, materializer, args.stringReads) : parts.tables[sourceID]?.stringReads;
|
|
57093
|
+
const stringReads = declaringModelPath(sourceIDFileURL(sourceID), packagePath, modelPath) === modelPath ? await chainedStringReads(source, classificationCtx.modelDef, materializer, args.stringReads, parts.stringCapabilityReads) : parts.tables[sourceID]?.stringReads;
|
|
56995
57094
|
const destination = declaredStorage(source)?.trim();
|
|
56996
57095
|
const map = SourceMap.of(classificationCtx.modelDef);
|
|
56997
57096
|
const query = map.node(sourceID)?.def?.query;
|
|
@@ -57353,6 +57452,7 @@ function derivePackagePlan(compiled, materializationConfig, counts = {}) {
|
|
|
57353
57452
|
materializePlans: materializePlansOf(compiled.tables),
|
|
57354
57453
|
asOfBuild,
|
|
57355
57454
|
accessReads: [...compiled.accessReads ?? []],
|
|
57455
|
+
...compiled.stringCapabilityReads && Object.keys(compiled.stringCapabilityReads).length > 0 ? { stringCapabilityReads: { ...compiled.stringCapabilityReads } } : {},
|
|
57356
57456
|
eligibilityRefused: { ...counts }
|
|
57357
57457
|
};
|
|
57358
57458
|
}
|
|
@@ -57653,6 +57753,7 @@ var init_build_plan = __esm(() => {
|
|
|
57653
57753
|
init_over_stored_proof();
|
|
57654
57754
|
init_downstream_upstreams();
|
|
57655
57755
|
init_string_reads();
|
|
57756
|
+
init_dialect();
|
|
57656
57757
|
init_column_contract();
|
|
57657
57758
|
init_source_map();
|
|
57658
57759
|
init_author_model();
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
/// <reference types="bun-types" />
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The runtime's half of the "publisher:color-scheme" contract
|
|
8
|
+
* (packages/sdk/src/utils/dataAppEmbed.ts): a framed page asks its host for
|
|
9
|
+
* the reader's mode, follows what the host says, and answers once the page
|
|
10
|
+
* says it drew it. Evaluated in a vm sandbox standing in for a framed window.
|
|
11
|
+
*/
|
|
12
|
+
import { describe, expect, it } from "bun:test";
|
|
13
|
+
import { readFileSync } from "fs";
|
|
14
|
+
import path from "path";
|
|
15
|
+
import vm from "vm";
|
|
16
|
+
|
|
17
|
+
const SOURCE = readFileSync(path.join(import.meta.dir, "publisher.js"), "utf8");
|
|
18
|
+
|
|
19
|
+
type Publisher = {
|
|
20
|
+
colorScheme: string | null;
|
|
21
|
+
onColorScheme: (fn: (m: string) => void) => () => void;
|
|
22
|
+
colorSchemeApplied: (m: string) => void;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function framedPage() {
|
|
26
|
+
const posted: { data: unknown; origin: string }[] = [];
|
|
27
|
+
const parent = {
|
|
28
|
+
postMessage: (data: unknown, origin: string) =>
|
|
29
|
+
posted.push({ data, origin }),
|
|
30
|
+
};
|
|
31
|
+
const handlers: ((e: unknown) => void)[] = [];
|
|
32
|
+
const sandbox: Record<string, unknown> = {
|
|
33
|
+
fetch: () => Promise.reject(new Error("no network")),
|
|
34
|
+
location: {
|
|
35
|
+
pathname: "/environments/e/packages/p/index.html",
|
|
36
|
+
origin: "https://data.example",
|
|
37
|
+
search: "",
|
|
38
|
+
},
|
|
39
|
+
console,
|
|
40
|
+
setInterval: () => 0,
|
|
41
|
+
setTimeout: () => 0,
|
|
42
|
+
parent,
|
|
43
|
+
// Enough of a document for the runtime's resize reporting, which runs in any frame.
|
|
44
|
+
document: {
|
|
45
|
+
readyState: "complete",
|
|
46
|
+
body: null,
|
|
47
|
+
documentElement: { scrollHeight: 0 },
|
|
48
|
+
addEventListener: () => {},
|
|
49
|
+
},
|
|
50
|
+
addEventListener: (type: string, fn: (e: unknown) => void) =>
|
|
51
|
+
type === "message" && handlers.push(fn),
|
|
52
|
+
};
|
|
53
|
+
sandbox.self = sandbox;
|
|
54
|
+
sandbox.top = parent;
|
|
55
|
+
sandbox.window = sandbox;
|
|
56
|
+
vm.runInContext(SOURCE, vm.createContext(sandbox), {
|
|
57
|
+
filename: "publisher.js",
|
|
58
|
+
});
|
|
59
|
+
const publisher = (sandbox.window as { Publisher: Publisher }).Publisher;
|
|
60
|
+
const send = (
|
|
61
|
+
data: unknown,
|
|
62
|
+
source: unknown = parent,
|
|
63
|
+
origin = "https://app.example",
|
|
64
|
+
) => handlers.forEach((h) => h({ data, source, origin }));
|
|
65
|
+
return { publisher, posted, send };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
describe("Publisher runtime color scheme", () => {
|
|
69
|
+
it("asks the host for the mode when the page starts", () => {
|
|
70
|
+
const { posted } = framedPage();
|
|
71
|
+
expect(posted.map((p) => p.data)).toContainEqual({
|
|
72
|
+
type: "publisher:color-scheme-request",
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("follows the host's mode and tells the page", () => {
|
|
77
|
+
const { publisher, send } = framedPage();
|
|
78
|
+
const seen: string[] = [];
|
|
79
|
+
publisher.onColorScheme((m) => seen.push(m));
|
|
80
|
+
send({ type: "publisher:color-scheme", mode: "dark" });
|
|
81
|
+
send({ type: "publisher:color-scheme", mode: "dark" });
|
|
82
|
+
send({ type: "publisher:color-scheme", mode: "light" });
|
|
83
|
+
expect(publisher.colorScheme).toBe("light");
|
|
84
|
+
expect(seen).toEqual(["dark", "light"]);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("ignores another window, an unknown mode and another message", () => {
|
|
88
|
+
const { publisher, send } = framedPage();
|
|
89
|
+
send(
|
|
90
|
+
{ type: "publisher:color-scheme", mode: "dark" },
|
|
91
|
+
{ not: "the parent" },
|
|
92
|
+
);
|
|
93
|
+
send({ type: "publisher:color-scheme", mode: "sepia" });
|
|
94
|
+
send({ type: "credible:color-scheme", mode: "dark" });
|
|
95
|
+
expect(publisher.colorScheme).toBe(null);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("answers the host, at its origin, once the page says it drew the mode", () => {
|
|
99
|
+
const { publisher, posted, send } = framedPage();
|
|
100
|
+
send({ type: "publisher:color-scheme", mode: "dark" });
|
|
101
|
+
publisher.colorSchemeApplied("dark");
|
|
102
|
+
expect(posted).toContainEqual({
|
|
103
|
+
data: { type: "publisher:color-scheme-applied", mode: "dark" },
|
|
104
|
+
origin: "https://app.example",
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("answers the same mode again when the host sends it again, so a host that reloaded the frame hears it", () => {
|
|
109
|
+
const { publisher, posted, send } = framedPage();
|
|
110
|
+
send({ type: "publisher:color-scheme", mode: "dark" });
|
|
111
|
+
publisher.colorSchemeApplied("dark");
|
|
112
|
+
posted.length = 0;
|
|
113
|
+
send({ type: "publisher:color-scheme", mode: "dark" });
|
|
114
|
+
expect(posted).toEqual([
|
|
115
|
+
{
|
|
116
|
+
data: { type: "publisher:color-scheme-applied", mode: "dark" },
|
|
117
|
+
origin: "https://app.example",
|
|
118
|
+
},
|
|
119
|
+
]);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("answers a repeated mode with the mode the page drew, when that differs", () => {
|
|
123
|
+
const { publisher, posted, send } = framedPage();
|
|
124
|
+
send({ type: "publisher:color-scheme", mode: "dark" });
|
|
125
|
+
publisher.colorSchemeApplied("light"); // a page fixed to light by its address
|
|
126
|
+
posted.length = 0;
|
|
127
|
+
send({ type: "publisher:color-scheme", mode: "dark" });
|
|
128
|
+
expect(posted).toEqual([
|
|
129
|
+
{
|
|
130
|
+
data: { type: "publisher:color-scheme-applied", mode: "light" },
|
|
131
|
+
origin: "https://app.example",
|
|
132
|
+
},
|
|
133
|
+
]);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("keeps a listener's error out of the page that adds it", () => {
|
|
137
|
+
const { publisher, send } = framedPage();
|
|
138
|
+
send({ type: "publisher:color-scheme", mode: "dark" });
|
|
139
|
+
expect(() =>
|
|
140
|
+
publisher.onColorScheme(() => {
|
|
141
|
+
throw new Error("listener");
|
|
142
|
+
}),
|
|
143
|
+
).not.toThrow();
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("tells the other listeners when one throws, and stops one that asks to stop", () => {
|
|
147
|
+
const { publisher, send } = framedPage();
|
|
148
|
+
const seen: string[] = [];
|
|
149
|
+
publisher.onColorScheme(() => {
|
|
150
|
+
throw new Error("listener");
|
|
151
|
+
});
|
|
152
|
+
const stop = publisher.onColorScheme((m) => seen.push(`stopped:${m}`));
|
|
153
|
+
publisher.onColorScheme((m) => seen.push(m));
|
|
154
|
+
send({ type: "publisher:color-scheme", mode: "dark" });
|
|
155
|
+
stop();
|
|
156
|
+
send({ type: "publisher:color-scheme", mode: "light" });
|
|
157
|
+
expect(seen).toEqual(["stopped:dark", "dark", "light"]);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("tells a listener added later the mode already known", () => {
|
|
161
|
+
const { publisher, send } = framedPage();
|
|
162
|
+
send({ type: "publisher:color-scheme", mode: "dark" });
|
|
163
|
+
const seen: string[] = [];
|
|
164
|
+
publisher.onColorScheme((m) => seen.push(m));
|
|
165
|
+
expect(seen).toEqual(["dark"]);
|
|
166
|
+
});
|
|
167
|
+
});
|