@malloy-publisher/server 0.18.1 → 0.18.2

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.
@@ -167085,7 +167085,7 @@ var init_telemetry = __esm(() => {
167085
167085
  });
167086
167086
 
167087
167087
  // package.json
167088
- var version = "0.18.1";
167088
+ var version = "0.18.2";
167089
167089
  var init_package = () => {};
167090
167090
 
167091
167091
  // src/version.ts
@@ -35854,21 +35854,33 @@ function fieldPathsIn(e, out = [], depth = 0) {
35854
35854
  }
35855
35855
 
35856
35856
  // src/service/materialization/serve/stored_upstream.ts
35857
+ function querySourceIDs(modelDef) {
35858
+ if (modelDef === null || typeof modelDef !== "object")
35859
+ return new Map;
35860
+ let out = querySourcesMemo.get(modelDef);
35861
+ if (out)
35862
+ return out;
35863
+ out = new Map;
35864
+ const contents = modelDef.contents ?? {};
35865
+ for (const c of Object.values(contents)) {
35866
+ const d = c;
35867
+ if (typeof d?.sourceID !== "string" || d.query === undefined)
35868
+ continue;
35869
+ const q = JSON.stringify(d.query);
35870
+ out.set(q, [...out.get(q) ?? [], d.sourceID]);
35871
+ }
35872
+ querySourcesMemo.set(modelDef, out);
35873
+ return out;
35874
+ }
35857
35875
  function storedUpstreamResolver(modelDef, stored) {
35858
35876
  let byID;
35859
- let byQuery;
35860
35877
  const index = () => {
35861
35878
  byID = new Map;
35862
- byQuery = new Map;
35863
35879
  const contents = modelDef?.contents ?? {};
35864
35880
  for (const c of Object.values(contents)) {
35865
35881
  const d = c;
35866
- if (typeof d?.sourceID !== "string")
35867
- continue;
35868
- byID.set(d.sourceID, d);
35869
- if (stored.has(d.sourceID) && d.query !== undefined) {
35870
- byQuery.set(JSON.stringify(d.query), d.sourceID);
35871
- }
35882
+ if (typeof d?.sourceID === "string")
35883
+ byID.set(d.sourceID, d);
35872
35884
  }
35873
35885
  };
35874
35886
  return (owner) => {
@@ -35880,7 +35892,7 @@ function storedUpstreamResolver(modelDef, stored) {
35880
35892
  if (byID === undefined)
35881
35893
  index();
35882
35894
  if (at.query !== undefined) {
35883
- const id = byQuery.get(JSON.stringify(at.query));
35895
+ const id = (querySourceIDs(modelDef).get(JSON.stringify(at.query)) ?? []).findLast((x) => stored.has(x));
35884
35896
  if (id !== undefined)
35885
35897
  return id;
35886
35898
  }
@@ -35893,6 +35905,10 @@ function storedUpstreamResolver(modelDef, stored) {
35893
35905
  return;
35894
35906
  };
35895
35907
  }
35908
+ var querySourcesMemo;
35909
+ var init_stored_upstream = __esm(() => {
35910
+ querySourcesMemo = new WeakMap;
35911
+ });
35896
35912
 
35897
35913
  // src/service/materialization/serve/gate_reads.ts
35898
35914
  function gateIdentifiers(exprs) {
@@ -36203,22 +36219,7 @@ class GateReadWalk {
36203
36219
  if (s?.query === undefined)
36204
36220
  return false;
36205
36221
  const query = JSON.stringify(s.query);
36206
- return this.storedQueries().has(query);
36207
- }
36208
- storedQueriesMemo;
36209
- storedQueries() {
36210
- if (this.storedQueriesMemo)
36211
- return this.storedQueriesMemo;
36212
- const out = new Set;
36213
- const contents = this.modelDef?.contents ?? {};
36214
- for (const c of Object.values(contents)) {
36215
- const d = c;
36216
- if (typeof d?.sourceID === "string" && this.stored.has(d.sourceID) && d.query !== undefined) {
36217
- out.add(JSON.stringify(d.query));
36218
- }
36219
- }
36220
- this.storedQueriesMemo = out;
36221
- return out;
36222
+ return (querySourceIDs(this.modelDef).get(query) ?? []).some((id) => this.stored.has(id));
36222
36223
  }
36223
36224
  tooDeep() {
36224
36225
  return ++this.steps > 4096;
@@ -36929,6 +36930,7 @@ var init_gate_reads = __esm(() => {
36929
36930
  init_prepared_query();
36930
36931
  init_malloy_lexer_core();
36931
36932
  init_query_text();
36933
+ init_stored_upstream();
36932
36934
  GATE_KEYWORDS = new Set([
36933
36935
  "and",
36934
36936
  "or",
@@ -37995,6 +37997,7 @@ var RANGE_OPERATORS, EQUALITY_OPERATORS, ORDERING_FUNCTIONS, EQUALITY_FUNCTIONS,
37995
37997
  var init_result_reads = __esm(() => {
37996
37998
  init_prepared_query();
37997
37999
  init_dialect();
38000
+ init_stored_upstream();
37998
38001
  RANGE_OPERATORS = new Set([">", "<", ">=", "<="]);
37999
38002
  EQUALITY_OPERATORS = new Set(["=", "!=", "like", "!like"]);
38000
38003
  ORDERING_FUNCTIONS = new Set([
package/dist/server.mjs CHANGED
@@ -139288,6 +139288,26 @@ var init_composite_row_filter = __esm(() => {
139288
139288
  init_authorize_routes();
139289
139289
  });
139290
139290
 
139291
+ // src/service/event_loop_yield.ts
139292
+ function yieldToEventLoop() {
139293
+ return new Promise((resolve) => setImmediate(resolve));
139294
+ }
139295
+ function createEventLoopYielder() {
139296
+ let since = performance.now();
139297
+ return {
139298
+ async maybeYield() {
139299
+ if (performance.now() - since < budgetMs)
139300
+ return;
139301
+ await yieldToEventLoop();
139302
+ since = performance.now();
139303
+ }
139304
+ };
139305
+ }
139306
+ var DEFAULT_BUDGET_MS = 10, budgetMs;
139307
+ var init_event_loop_yield = __esm(() => {
139308
+ budgetMs = DEFAULT_BUDGET_MS;
139309
+ });
139310
+
139291
139311
  // src/service/materialization/serve/gate_paths.ts
139292
139312
  function fieldPathsIn(e, out = [], depth = 0) {
139293
139313
  if (depth > 64 || e === null || typeof e !== "object")
@@ -139307,21 +139327,33 @@ function fieldPathsIn(e, out = [], depth = 0) {
139307
139327
  }
139308
139328
 
139309
139329
  // src/service/materialization/serve/stored_upstream.ts
139330
+ function querySourceIDs(modelDef) {
139331
+ if (modelDef === null || typeof modelDef !== "object")
139332
+ return new Map;
139333
+ let out = querySourcesMemo.get(modelDef);
139334
+ if (out)
139335
+ return out;
139336
+ out = new Map;
139337
+ const contents = modelDef.contents ?? {};
139338
+ for (const c of Object.values(contents)) {
139339
+ const d = c;
139340
+ if (typeof d?.sourceID !== "string" || d.query === undefined)
139341
+ continue;
139342
+ const q = JSON.stringify(d.query);
139343
+ out.set(q, [...out.get(q) ?? [], d.sourceID]);
139344
+ }
139345
+ querySourcesMemo.set(modelDef, out);
139346
+ return out;
139347
+ }
139310
139348
  function storedUpstreamResolver(modelDef, stored) {
139311
139349
  let byID;
139312
- let byQuery;
139313
139350
  const index = () => {
139314
139351
  byID = new Map;
139315
- byQuery = new Map;
139316
139352
  const contents = modelDef?.contents ?? {};
139317
139353
  for (const c of Object.values(contents)) {
139318
139354
  const d = c;
139319
- if (typeof d?.sourceID !== "string")
139320
- continue;
139321
- byID.set(d.sourceID, d);
139322
- if (stored.has(d.sourceID) && d.query !== undefined) {
139323
- byQuery.set(JSON.stringify(d.query), d.sourceID);
139324
- }
139355
+ if (typeof d?.sourceID === "string")
139356
+ byID.set(d.sourceID, d);
139325
139357
  }
139326
139358
  };
139327
139359
  return (owner) => {
@@ -139333,7 +139365,7 @@ function storedUpstreamResolver(modelDef, stored) {
139333
139365
  if (byID === undefined)
139334
139366
  index();
139335
139367
  if (at.query !== undefined) {
139336
- const id = byQuery.get(JSON.stringify(at.query));
139368
+ const id = (querySourceIDs(modelDef).get(JSON.stringify(at.query)) ?? []).findLast((x) => stored.has(x));
139337
139369
  if (id !== undefined)
139338
139370
  return id;
139339
139371
  }
@@ -139346,6 +139378,10 @@ function storedUpstreamResolver(modelDef, stored) {
139346
139378
  return;
139347
139379
  };
139348
139380
  }
139381
+ var querySourcesMemo;
139382
+ var init_stored_upstream = __esm(() => {
139383
+ querySourcesMemo = new WeakMap;
139384
+ });
139349
139385
 
139350
139386
  // src/service/materialization/serve/gate_reads.ts
139351
139387
  function gateIdentifiers(exprs) {
@@ -139656,22 +139692,7 @@ class GateReadWalk {
139656
139692
  if (s?.query === undefined)
139657
139693
  return false;
139658
139694
  const query = JSON.stringify(s.query);
139659
- return this.storedQueries().has(query);
139660
- }
139661
- storedQueriesMemo;
139662
- storedQueries() {
139663
- if (this.storedQueriesMemo)
139664
- return this.storedQueriesMemo;
139665
- const out = new Set;
139666
- const contents = this.modelDef?.contents ?? {};
139667
- for (const c of Object.values(contents)) {
139668
- const d = c;
139669
- if (typeof d?.sourceID === "string" && this.stored.has(d.sourceID) && d.query !== undefined) {
139670
- out.add(JSON.stringify(d.query));
139671
- }
139672
- }
139673
- this.storedQueriesMemo = out;
139674
- return out;
139695
+ return (querySourceIDs(this.modelDef).get(query) ?? []).some((id) => this.stored.has(id));
139675
139696
  }
139676
139697
  tooDeep() {
139677
139698
  return ++this.steps > 4096;
@@ -140382,6 +140403,7 @@ var init_gate_reads = __esm(() => {
140382
140403
  init_prepared_query();
140383
140404
  init_malloy_lexer_core();
140384
140405
  init_query_text();
140406
+ init_stored_upstream();
140385
140407
  GATE_KEYWORDS = new Set([
140386
140408
  "and",
140387
140409
  "or",
@@ -140453,8 +140475,15 @@ function readsKey(name, stored, rerooted) {
140453
140475
  function readsNothing(r) {
140454
140476
  return r !== undefined && !r.unresolved && !r.scoped && !r.gated && r.columns.length === 0 && r.names.size === 0 && r.entryPaths.length === 0;
140455
140477
  }
140456
- function recordScopeFacts(runtime, args) {
140478
+ function disjoint(a, b) {
140479
+ for (const id of a)
140480
+ if (b.has(id))
140481
+ return false;
140482
+ return true;
140483
+ }
140484
+ async function recordScopeFacts(runtime, args) {
140457
140485
  const { modelDef, snapshot, lane } = args;
140486
+ const yielder = createEventLoopYielder();
140458
140487
  const flags = new Map;
140459
140488
  const reads = new Map;
140460
140489
  const empty = new Set;
@@ -140472,6 +140501,7 @@ function recordScopeFacts(runtime, args) {
140472
140501
  addSet(b.sourceIDs ?? []);
140473
140502
  }
140474
140503
  for (const name of Object.keys(modelDef.contents ?? {})) {
140504
+ await yielder.maybeYield();
140475
140505
  const struct = resolveStructRefSource(name, modelDef);
140476
140506
  if (struct === undefined)
140477
140507
  continue;
@@ -140479,22 +140509,33 @@ function recordScopeFacts(runtime, args) {
140479
140509
  carriesGate: carriesAGate(struct),
140480
140510
  compositeRowFilter: compositeOf(struct, modelDef)
140481
140511
  });
140482
- const none = gateReadsOfSource(struct, modelDef, empty, empty);
140512
+ const askedStored = new AskedSet;
140513
+ const askedRerooted = new AskedSet;
140514
+ const none = gateReadsOfSource(struct, modelDef, askedStored, askedRerooted);
140483
140515
  if (readsNothing(none)) {
140484
140516
  reads.set(readsKey(name), none);
140485
140517
  continue;
140486
140518
  }
140487
140519
  reads.set(readsKey(name, empty, empty), none);
140520
+ const readsOver = (set, rerooted) => {
140521
+ if (disjoint(set, askedStored.asked) && disjoint(rerooted, askedRerooted.asked)) {
140522
+ walks.reused++;
140523
+ return none;
140524
+ }
140525
+ walks.walked++;
140526
+ return gateReadsOfSource(struct, modelDef, set, rerooted);
140527
+ };
140488
140528
  for (const set of storedSets) {
140489
140529
  for (const rerooted of lane ? [empty, lane.rerooted] : [empty]) {
140490
140530
  const key = readsKey(name, set, rerooted);
140491
140531
  if (!reads.has(key)) {
140492
- reads.set(key, gateReadsOfSource(struct, modelDef, set, rerooted));
140532
+ reads.set(key, readsOver(set, rerooted));
140533
+ await yielder.maybeYield();
140493
140534
  }
140494
140535
  }
140495
140536
  }
140496
140537
  if (lane) {
140497
- reads.set(readsKey(name, lane.stored, lane.rerooted), gateReadsOfSource(struct, modelDef, lane.stored, lane.rerooted));
140538
+ reads.set(readsKey(name, lane.stored, lane.rerooted), readsOver(lane.stored, lane.rerooted));
140498
140539
  }
140499
140540
  }
140500
140541
  recorded3.set(runtime, {
@@ -140568,13 +140609,22 @@ function carriesAGate(node, seen = new WeakSet, depth = 0) {
140568
140609
  }
140569
140610
  return Object.values(record).some((v) => carriesAGate(v, seen, depth + 1));
140570
140611
  }
140571
- var recorded3, tablesMemo, MAX_GATE_WALK_DEPTH = 200;
140612
+ var recorded3, AskedSet, walks, tablesMemo, MAX_GATE_WALK_DEPTH = 200;
140572
140613
  var init_scope_facts = __esm(() => {
140573
140614
  init_authorize();
140574
140615
  init_composite_row_filter();
140616
+ init_event_loop_yield();
140575
140617
  init_prepared_query();
140576
140618
  init_gate_reads();
140577
140619
  recorded3 = new WeakMap;
140620
+ AskedSet = class AskedSet extends Set {
140621
+ asked = new Set;
140622
+ has(value) {
140623
+ this.asked.add(value);
140624
+ return super.has(value);
140625
+ }
140626
+ };
140627
+ walks = { walked: 0, reused: 0 };
140578
140628
  tablesMemo = new WeakMap;
140579
140629
  });
140580
140630
 
@@ -158077,7 +158127,7 @@ var init_generated_files = __esm(() => {
158077
158127
  });
158078
158128
 
158079
158129
  // package.json
158080
- var version = "0.18.1";
158130
+ var version = "0.18.2";
158081
158131
  var init_package = () => {};
158082
158132
 
158083
158133
  // src/version.ts
@@ -163478,26 +163528,6 @@ var init_build_plan = __esm(() => {
163478
163528
  };
163479
163529
  });
163480
163530
 
163481
- // src/service/event_loop_yield.ts
163482
- function yieldToEventLoop() {
163483
- return new Promise((resolve) => setImmediate(resolve));
163484
- }
163485
- function createEventLoopYielder() {
163486
- let since = performance.now();
163487
- return {
163488
- async maybeYield() {
163489
- if (performance.now() - since < budgetMs)
163490
- return;
163491
- await yieldToEventLoop();
163492
- since = performance.now();
163493
- }
163494
- };
163495
- }
163496
- var DEFAULT_BUDGET_MS = 10, budgetMs;
163497
- var init_event_loop_yield = __esm(() => {
163498
- budgetMs = DEFAULT_BUDGET_MS;
163499
- });
163500
-
163501
163531
  // src/data_styles.ts
163502
163532
  function compileDataStyles(styles) {
163503
163533
  try {
@@ -169673,15 +169703,15 @@ var init_served_copy_checks = __esm(() => {
169673
169703
 
169674
169704
  // src/service/materialization/serve/query_walks.ts
169675
169705
  function reportQueryWalk(site) {
169676
- walks.set(site, (walks.get(site) ?? 0) + 1);
169706
+ walks2.set(site, (walks2.get(site) ?? 0) + 1);
169677
169707
  observer?.queryWalk(site);
169678
169708
  }
169679
169709
  function observeAdmission(o) {
169680
169710
  observer = o;
169681
169711
  }
169682
- var observer, walks;
169712
+ var observer, walks2;
169683
169713
  var init_query_walks = __esm(() => {
169684
- walks = new Map;
169714
+ walks2 = new Map;
169685
169715
  });
169686
169716
 
169687
169717
  // src/service/materialization/serve/result_reads.ts
@@ -170393,6 +170423,7 @@ var RANGE_OPERATORS, EQUALITY_OPERATORS, ORDERING_FUNCTIONS, EQUALITY_FUNCTIONS,
170393
170423
  var init_result_reads = __esm(() => {
170394
170424
  init_prepared_query();
170395
170425
  init_dialect();
170426
+ init_stored_upstream();
170396
170427
  RANGE_OPERATORS = new Set([">", "<", ">=", "<="]);
170397
170428
  EQUALITY_OPERATORS = new Set(["=", "!=", "like", "!like"]);
170398
170429
  ORDERING_FUNCTIONS = new Set([
@@ -183717,7 +183748,7 @@ class PackageMaterialization {
183717
183748
  }
183718
183749
  if (next.bindings.length > 0 || Object.keys(next.entries).length > 0) {
183719
183750
  for (const model of this.owner.models().values()) {
183720
- model.recordScopeFactsOver(next);
183751
+ await model.recordScopeFactsOver(next);
183721
183752
  }
183722
183753
  }
183723
183754
  } finally {
@@ -184331,10 +184362,17 @@ class PackageMaterialization {
184331
184362
  if (bindings === this.publishedBindings && !models)
184332
184363
  return;
184333
184364
  this.publishedBindings = bindings;
184334
- for (const model of this.owner.models().values()) {
184365
+ const targets = [...this.owner.models().values()];
184366
+ for (const model of targets)
184335
184367
  this.setServedCopyContextOn(model);
184336
- model.prepareServedCopy();
184337
- }
184368
+ const run = this.commitChain.then(async () => {
184369
+ if (this.disposed)
184370
+ return;
184371
+ await Promise.all(targets.map((model) => model.prepareServedCopy()));
184372
+ });
184373
+ this.commitChain = run.catch(() => {
184374
+ return;
184375
+ });
184338
184376
  this.bindTypeFindings(bindings);
184339
184377
  this.scheduleLapse();
184340
184378
  }
@@ -381792,7 +381830,7 @@ var init_model = __esm(() => {
381792
381830
  await this.refreshStringCapabilities();
381793
381831
  const snapshot = this.servingSnapshot();
381794
381832
  await this.prepareServedCopyOver(snapshot);
381795
- this.recordScopeFactsOver(snapshot);
381833
+ await this.recordScopeFactsOver(snapshot);
381796
381834
  }
381797
381835
  stringCapabilityRuntime() {
381798
381836
  return this.modelMaterializer?.runtime;
@@ -381819,7 +381857,7 @@ var init_model = __esm(() => {
381819
381857
  });
381820
381858
  }
381821
381859
  }
381822
- recordScopeFactsOver(snapshot = this.servingSnapshot()) {
381860
+ async recordScopeFactsOver(snapshot = this.servingSnapshot()) {
381823
381861
  const lane = this.servedCopyEnabled() ? this.servedCopy.scopeLane() : undefined;
381824
381862
  const runtime = this.modelMaterializer?.runtime;
381825
381863
  const modelDef = this.modelDef;
@@ -381828,7 +381866,7 @@ var init_model = __esm(() => {
381828
381866
  return;
381829
381867
  }
381830
381868
  try {
381831
- record(runtime, {
381869
+ await record(runtime, {
381832
381870
  modelDef,
381833
381871
  snapshot,
381834
381872
  ...lane ? { lane } : {}
package/package.json CHANGED
@@ -19,7 +19,7 @@
19
19
  "snowflake"
20
20
  ],
21
21
  "homepage": "https://docs.malloydata.dev/documentation/user_guides/publishing/mcp_agents",
22
- "version": "0.18.1",
22
+ "version": "0.18.2",
23
23
  "main": "dist/server.mjs",
24
24
  "bin": {
25
25
  "malloy-publisher": "dist/server.mjs"