houdini 2.0.0-next.0 → 2.0.0-next.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.
@@ -64947,20 +64947,21 @@ var CacheInternal = class {
64947
64947
  } else if (Array.isArray(value) && // make typescript happy
64948
64948
  (typeof previousValue === "undefined" || previousValue === null || Array.isArray(previousValue))) {
64949
64949
  let oldIDs = [...previousValue || []];
64950
- const emptyEdges = !updates ? [] : oldIDs.map((id) => {
64951
- if (!id) {
64952
- return "";
64953
- }
64954
- const { value: cursorField } = this.storage.get(id, "cursor");
64955
- if (cursorField) {
64956
- return "";
64957
- }
64958
- const { value: node } = this.storage.get(id, "node");
64959
- if (!node) {
64960
- return "";
64961
- }
64962
- return node;
64963
- });
64950
+ if (updates?.includes("append") || updates?.includes("prepend")) {
64951
+ oldIDs = oldIDs.filter((id) => {
64952
+ for (const layer2 of this.storage.data) {
64953
+ for (const operation of Object.values(layer2.operations)) {
64954
+ if (operation.fields?.[key])
64955
+ for (const listOperation of operation.fields[key]) {
64956
+ if ("id" in listOperation && listOperation.id === id) {
64957
+ return false;
64958
+ }
64959
+ }
64960
+ }
64961
+ }
64962
+ return true;
64963
+ });
64964
+ }
64964
64965
  let linkedIDs = [];
64965
64966
  const { newIDs, nestedIDs } = this.extractNestedListIDs({
64966
64967
  value,
@@ -64979,39 +64980,45 @@ var CacheInternal = class {
64979
64980
  layer.writeLink(parent2, key, linkedIDs);
64980
64981
  };
64981
64982
  if (applyUpdates && updates) {
64982
- if (key === "edges") {
64983
- const newNodeIDs = [];
64984
- for (const id of newIDs) {
64983
+ const filterIDs = (keep, insert) => {
64984
+ const existingIDs = /* @__PURE__ */ new Set();
64985
+ for (const id of keep) {
64985
64986
  if (!id) {
64986
64987
  continue;
64987
64988
  }
64988
64989
  const { value: node } = this.storage.get(id, "node");
64989
- if (typeof node !== "string") {
64990
+ if (!node) {
64990
64991
  continue;
64991
64992
  }
64992
- if (!node || !this.storage.get(node, "__typename")) {
64993
+ const nodeID = this.storage.get(node, "id");
64994
+ if (!nodeID) {
64993
64995
  continue;
64994
64996
  }
64995
- newNodeIDs.push(node);
64997
+ existingIDs.add(nodeID.value);
64996
64998
  }
64997
- oldIDs = oldIDs.filter((id) => {
64999
+ return insert.filter((id) => {
64998
65000
  if (!id) {
64999
65001
  return true;
65000
65002
  }
65001
- const { value: value2 } = this.storage.get(id, "node");
65002
- const node = value2;
65003
- if (newNodeIDs.includes(node) && emptyEdges.includes(node)) {
65004
- return false;
65003
+ const { value: node } = this.storage.get(id, "node");
65004
+ if (!node) {
65005
+ return true;
65005
65006
  }
65006
- return true;
65007
+ const nodeID = this.storage.get(node, "id");
65008
+ if (!nodeID) {
65009
+ return true;
65010
+ }
65011
+ return !existingIDs.has(nodeID.value);
65007
65012
  });
65008
- }
65013
+ };
65009
65014
  for (const update of applyUpdates) {
65010
65015
  if (update !== "replace" && !updates.includes(update)) {
65011
65016
  continue;
65012
65017
  }
65013
65018
  if (update === "prepend") {
65014
- linkedIDs = newIDs.concat(oldIDs);
65019
+ linkedIDs = newIDs.concat(
65020
+ filterIDs(newIDs, oldIDs)
65021
+ );
65015
65022
  if (layer?.optimistic) {
65016
65023
  action = () => {
65017
65024
  for (const id of newIDs) {
@@ -65022,7 +65029,7 @@ var CacheInternal = class {
65022
65029
  };
65023
65030
  }
65024
65031
  } else if (update === "append") {
65025
- linkedIDs = oldIDs.concat(newIDs);
65032
+ linkedIDs = filterIDs(newIDs, oldIDs).concat(newIDs);
65026
65033
  if (layer?.optimistic) {
65027
65034
  action = () => {
65028
65035
  for (const id of newIDs) {
@@ -65633,6 +65640,7 @@ var Config = class {
65633
65640
  routesDir;
65634
65641
  schemaPollInterval;
65635
65642
  schemaPollTimeout;
65643
+ schemaPollWriteToDisk = false;
65636
65644
  schemaPollHeaders;
65637
65645
  pluginMode = false;
65638
65646
  plugins = [];
@@ -65709,6 +65717,7 @@ var Config = class {
65709
65717
  this.routesDir = join(this.projectRoot, "src", "routes");
65710
65718
  this.schemaPollInterval = watchSchema?.interval === void 0 ? 2e3 : watchSchema.interval;
65711
65719
  this.schemaPollTimeout = watchSchema?.timeout ?? 3e4;
65720
+ this.schemaPollWriteToDisk = watchSchema?.writePolledSchema ?? true;
65712
65721
  this.schemaPollHeaders = watchSchema?.headers ?? {};
65713
65722
  this.rootDir = join(this.projectRoot, this.runtimeDir);
65714
65723
  this.persistedQueriesPath = persistedQueriesPath ?? join(this.rootDir, "persisted_queries.json");
@@ -65741,11 +65750,17 @@ var Config = class {
65741
65750
  const include = [`src/**/*{${extensions.join(",")}}`];
65742
65751
  for (const plugin2 of this.plugins) {
65743
65752
  const runtimeDir = this.pluginRuntimeSource(plugin2);
65744
- if (!runtimeDir) {
65753
+ const staticDir = this.pluginStaticRuntimeSource(plugin2);
65754
+ if (!runtimeDir && !staticDir) {
65745
65755
  continue;
65746
65756
  }
65747
- const includePath = relative(this.projectRoot, runtimeDir);
65748
- include.push(`${includePath}/**/*{${extensions.join(",")}}`);
65757
+ for (const dir of [runtimeDir, staticDir]) {
65758
+ if (!dir) {
65759
+ continue;
65760
+ }
65761
+ const includePath = relative(this.projectRoot, dir);
65762
+ include.push(`${includePath}/**/*{${extensions.join(",")}}`);
65763
+ }
65749
65764
  }
65750
65765
  return include;
65751
65766
  }
@@ -65799,6 +65814,15 @@ var Config = class {
65799
65814
  typeof plugin2.includeRuntime === "string" ? plugin2.includeRuntime : plugin2.includeRuntime?.[this.module]
65800
65815
  );
65801
65816
  }
65817
+ pluginStaticRuntimeSource(plugin2) {
65818
+ if (!plugin2.staticRuntime) {
65819
+ return null;
65820
+ }
65821
+ return join(
65822
+ dirname(plugin2.filepath),
65823
+ typeof plugin2.staticRuntime === "string" ? plugin2.staticRuntime : plugin2.staticRuntime?.[this.module]
65824
+ );
65825
+ }
65802
65826
  async sourceFiles() {
65803
65827
  return [
65804
65828
  ...new Set(
@@ -65995,6 +66019,9 @@ var Config = class {
65995
66019
  pluginRuntimeDirectory(name) {
65996
66020
  return join(this.pluginDirectory(name), "runtime");
65997
66021
  }
66022
+ pluginStaticRuntimeDirectory(name) {
66023
+ return join(this.pluginDirectory(name), "static");
66024
+ }
65998
66025
  get pluginRootDirectory() {
65999
66026
  return houdini_mode.is_testing ? "../../../" : join(this.rootDir, "plugins");
66000
66027
  }
@@ -70699,6 +70726,11 @@ async function writeIndexFile2(config, docs) {
70699
70726
  module: relative2(config.pluginRuntimeDirectory(plugin2.name))
70700
70727
  });
70701
70728
  }
70729
+ if (plugin2.staticRuntime) {
70730
+ body += exportStar({
70731
+ module: relative2(config.pluginStaticRuntimeDirectory(plugin2.name))
70732
+ });
70733
+ }
70702
70734
  }
70703
70735
  await fs_exports.writeFile(path_exports.join(config.rootDir, "index.js"), body);
70704
70736
  }
@@ -72468,7 +72468,7 @@ function fixResponseChunkedTransferBadEnding(request, errorCallback) {
72468
72468
  }
72469
72469
 
72470
72470
  // src/lib/introspection.ts
72471
- async function pullSchema(url, fetchTimeout, schemaPath, headers, skipWriting) {
72471
+ async function pullSchema(url, fetchTimeout, schemaPath, headers, writeToDisk = true) {
72472
72472
  let content = "";
72473
72473
  try {
72474
72474
  const fetchWithTimeout = (url2, timeoutMs, options) => {
@@ -72506,8 +72506,15 @@ async function pullSchema(url, fetchTimeout, schemaPath, headers, skipWriting) {
72506
72506
  } else {
72507
72507
  fileData = JSON.stringify(jsonSchema);
72508
72508
  }
72509
- if (!skipWriting) {
72510
- await writeFile(schemaPath, fileData);
72509
+ if (writeToDisk) {
72510
+ try {
72511
+ await writeFile(schemaPath, fileData);
72512
+ } catch (e2) {
72513
+ console.warn(
72514
+ `\u26A0\uFE0F Couldn't write your pulled schema to disk: ${e2.message}
72515
+ If this is expected, please set watchSchema.writePolledSchema to false in your config file.`
72516
+ );
72517
+ }
72511
72518
  }
72512
72519
  return fileData;
72513
72520
  } catch (e2) {
@@ -74990,20 +74997,21 @@ var CacheInternal = class {
74990
74997
  } else if (Array.isArray(value) && // make typescript happy
74991
74998
  (typeof previousValue === "undefined" || previousValue === null || Array.isArray(previousValue))) {
74992
74999
  let oldIDs = [...previousValue || []];
74993
- const emptyEdges = !updates ? [] : oldIDs.map((id) => {
74994
- if (!id) {
74995
- return "";
74996
- }
74997
- const { value: cursorField } = this.storage.get(id, "cursor");
74998
- if (cursorField) {
74999
- return "";
75000
- }
75001
- const { value: node } = this.storage.get(id, "node");
75002
- if (!node) {
75003
- return "";
75004
- }
75005
- return node;
75006
- });
75000
+ if (updates?.includes("append") || updates?.includes("prepend")) {
75001
+ oldIDs = oldIDs.filter((id) => {
75002
+ for (const layer2 of this.storage.data) {
75003
+ for (const operation of Object.values(layer2.operations)) {
75004
+ if (operation.fields?.[key])
75005
+ for (const listOperation of operation.fields[key]) {
75006
+ if ("id" in listOperation && listOperation.id === id) {
75007
+ return false;
75008
+ }
75009
+ }
75010
+ }
75011
+ }
75012
+ return true;
75013
+ });
75014
+ }
75007
75015
  let linkedIDs = [];
75008
75016
  const { newIDs, nestedIDs } = this.extractNestedListIDs({
75009
75017
  value,
@@ -75022,39 +75030,45 @@ var CacheInternal = class {
75022
75030
  layer.writeLink(parent2, key, linkedIDs);
75023
75031
  };
75024
75032
  if (applyUpdates && updates) {
75025
- if (key === "edges") {
75026
- const newNodeIDs = [];
75027
- for (const id of newIDs) {
75033
+ const filterIDs = (keep, insert) => {
75034
+ const existingIDs = /* @__PURE__ */ new Set();
75035
+ for (const id of keep) {
75028
75036
  if (!id) {
75029
75037
  continue;
75030
75038
  }
75031
75039
  const { value: node } = this.storage.get(id, "node");
75032
- if (typeof node !== "string") {
75040
+ if (!node) {
75033
75041
  continue;
75034
75042
  }
75035
- if (!node || !this.storage.get(node, "__typename")) {
75043
+ const nodeID = this.storage.get(node, "id");
75044
+ if (!nodeID) {
75036
75045
  continue;
75037
75046
  }
75038
- newNodeIDs.push(node);
75047
+ existingIDs.add(nodeID.value);
75039
75048
  }
75040
- oldIDs = oldIDs.filter((id) => {
75049
+ return insert.filter((id) => {
75041
75050
  if (!id) {
75042
75051
  return true;
75043
75052
  }
75044
- const { value: value2 } = this.storage.get(id, "node");
75045
- const node = value2;
75046
- if (newNodeIDs.includes(node) && emptyEdges.includes(node)) {
75047
- return false;
75053
+ const { value: node } = this.storage.get(id, "node");
75054
+ if (!node) {
75055
+ return true;
75048
75056
  }
75049
- return true;
75057
+ const nodeID = this.storage.get(node, "id");
75058
+ if (!nodeID) {
75059
+ return true;
75060
+ }
75061
+ return !existingIDs.has(nodeID.value);
75050
75062
  });
75051
- }
75063
+ };
75052
75064
  for (const update of applyUpdates) {
75053
75065
  if (update !== "replace" && !updates.includes(update)) {
75054
75066
  continue;
75055
75067
  }
75056
75068
  if (update === "prepend") {
75057
- linkedIDs = newIDs.concat(oldIDs);
75069
+ linkedIDs = newIDs.concat(
75070
+ filterIDs(newIDs, oldIDs)
75071
+ );
75058
75072
  if (layer?.optimistic) {
75059
75073
  action = () => {
75060
75074
  for (const id of newIDs) {
@@ -75065,7 +75079,7 @@ var CacheInternal = class {
75065
75079
  };
75066
75080
  }
75067
75081
  } else if (update === "append") {
75068
- linkedIDs = oldIDs.concat(newIDs);
75082
+ linkedIDs = filterIDs(newIDs, oldIDs).concat(newIDs);
75069
75083
  if (layer?.optimistic) {
75070
75084
  action = () => {
75071
75085
  for (const id of newIDs) {
@@ -75734,6 +75748,7 @@ var Config = class {
75734
75748
  routesDir;
75735
75749
  schemaPollInterval;
75736
75750
  schemaPollTimeout;
75751
+ schemaPollWriteToDisk = false;
75737
75752
  schemaPollHeaders;
75738
75753
  pluginMode = false;
75739
75754
  plugins = [];
@@ -75810,6 +75825,7 @@ var Config = class {
75810
75825
  this.routesDir = join2(this.projectRoot, "src", "routes");
75811
75826
  this.schemaPollInterval = watchSchema?.interval === void 0 ? 2e3 : watchSchema.interval;
75812
75827
  this.schemaPollTimeout = watchSchema?.timeout ?? 3e4;
75828
+ this.schemaPollWriteToDisk = watchSchema?.writePolledSchema ?? true;
75813
75829
  this.schemaPollHeaders = watchSchema?.headers ?? {};
75814
75830
  this.rootDir = join2(this.projectRoot, this.runtimeDir);
75815
75831
  this.persistedQueriesPath = persistedQueriesPath ?? join2(this.rootDir, "persisted_queries.json");
@@ -75842,11 +75858,17 @@ var Config = class {
75842
75858
  const include = [`src/**/*{${extensions.join(",")}}`];
75843
75859
  for (const plugin2 of this.plugins) {
75844
75860
  const runtimeDir = this.pluginRuntimeSource(plugin2);
75845
- if (!runtimeDir) {
75861
+ const staticDir = this.pluginStaticRuntimeSource(plugin2);
75862
+ if (!runtimeDir && !staticDir) {
75846
75863
  continue;
75847
75864
  }
75848
- const includePath = relative(this.projectRoot, runtimeDir);
75849
- include.push(`${includePath}/**/*{${extensions.join(",")}}`);
75865
+ for (const dir of [runtimeDir, staticDir]) {
75866
+ if (!dir) {
75867
+ continue;
75868
+ }
75869
+ const includePath = relative(this.projectRoot, dir);
75870
+ include.push(`${includePath}/**/*{${extensions.join(",")}}`);
75871
+ }
75850
75872
  }
75851
75873
  return include;
75852
75874
  }
@@ -75900,6 +75922,15 @@ var Config = class {
75900
75922
  typeof plugin2.includeRuntime === "string" ? plugin2.includeRuntime : plugin2.includeRuntime?.[this.module]
75901
75923
  );
75902
75924
  }
75925
+ pluginStaticRuntimeSource(plugin2) {
75926
+ if (!plugin2.staticRuntime) {
75927
+ return null;
75928
+ }
75929
+ return join2(
75930
+ dirname(plugin2.filepath),
75931
+ typeof plugin2.staticRuntime === "string" ? plugin2.staticRuntime : plugin2.staticRuntime?.[this.module]
75932
+ );
75933
+ }
75903
75934
  async sourceFiles() {
75904
75935
  return [
75905
75936
  ...new Set(
@@ -76096,6 +76127,9 @@ var Config = class {
76096
76127
  pluginRuntimeDirectory(name) {
76097
76128
  return join2(this.pluginDirectory(name), "runtime");
76098
76129
  }
76130
+ pluginStaticRuntimeDirectory(name) {
76131
+ return join2(this.pluginDirectory(name), "static");
76132
+ }
76099
76133
  get pluginRootDirectory() {
76100
76134
  return houdini_mode.is_testing ? "../../../" : join2(this.rootDir, "plugins");
76101
76135
  }
@@ -76473,17 +76507,20 @@ async function getConfig({
76473
76507
  if (!_config.localSchema && _config.schemaPath && !_config.schema) {
76474
76508
  let schemaOk = true;
76475
76509
  if (apiURL) {
76476
- if (glob2.hasMagic(_config.schemaPath)) {
76510
+ if (glob2.hasMagic(_config.schemaPath) && _config.schemaPollWriteToDisk) {
76477
76511
  console.log(
76478
76512
  `\u26A0\uFE0F Your houdini configuration contains an apiUrl and a path pointing to multiple files.
76479
- This will prevent your schema from being pulled.`
76513
+ This will prevent your schema from being written to disk. If this is expected, please set the writePolledSchema value to false.`
76480
76514
  );
76515
+ _config.schemaPollWriteToDisk = false;
76481
76516
  } else if (!await readFile(_config.schemaPath)) {
76482
76517
  console.log("\u231B Pulling schema from api");
76483
76518
  schemaOk = await pullSchema(
76484
76519
  apiURL,
76485
76520
  _config.schemaPollTimeout,
76486
- _config.schemaPath
76521
+ _config.schemaPath,
76522
+ {},
76523
+ _config.schemaPollWriteToDisk
76487
76524
  ) !== null;
76488
76525
  }
76489
76526
  }
@@ -79817,6 +79854,50 @@ function moduleStatments(config2) {
79817
79854
  exportStarStatement
79818
79855
  };
79819
79856
  }
79857
+ async function generateStaticRuntimes({ config: config2 }) {
79858
+ if (houdini_mode.is_testing) {
79859
+ return;
79860
+ }
79861
+ const { importStatement, exportDefaultStatement, exportStarStatement } = moduleStatments(config2);
79862
+ await Promise.all(
79863
+ config2.plugins.filter((plugin2) => plugin2.staticRuntime).map(async (plugin2) => {
79864
+ const runtime_path = config2.pluginStaticRuntimeSource(plugin2);
79865
+ if (!runtime_path) {
79866
+ return;
79867
+ }
79868
+ try {
79869
+ await stat(runtime_path);
79870
+ } catch {
79871
+ throw new HoudiniError({
79872
+ message: "Cannot find runtime to generate for " + plugin2.name,
79873
+ description: "Maybe it was bundled?"
79874
+ });
79875
+ }
79876
+ const pluginDir = config2.pluginStaticRuntimeDirectory(plugin2.name);
79877
+ let transformMap = plugin2.transformRuntime ?? {};
79878
+ if (transformMap && typeof transformMap === "function") {
79879
+ transformMap = transformMap([], { config: config2 });
79880
+ }
79881
+ await mkdirp(pluginDir);
79882
+ await recursiveCopy(
79883
+ runtime_path,
79884
+ pluginDir,
79885
+ Object.fromEntries(
79886
+ Object.entries(transformMap).map(([key, value]) => [
79887
+ join2(runtime_path, key),
79888
+ (content) => value({
79889
+ config: config2,
79890
+ content,
79891
+ importStatement,
79892
+ exportDefaultStatement,
79893
+ exportStarStatement
79894
+ })
79895
+ ])
79896
+ )
79897
+ );
79898
+ })
79899
+ );
79900
+ }
79820
79901
  async function generatePluginRuntimes({
79821
79902
  config: config2,
79822
79903
  docs
@@ -81418,6 +81499,11 @@ async function writeIndexFile2(config2, docs) {
81418
81499
  module: relative2(config2.pluginRuntimeDirectory(plugin2.name))
81419
81500
  });
81420
81501
  }
81502
+ if (plugin2.staticRuntime) {
81503
+ body += exportStar({
81504
+ module: relative2(config2.pluginStaticRuntimeDirectory(plugin2.name))
81505
+ });
81506
+ }
81421
81507
  }
81422
81508
  await fs_exports.writeFile(path_exports.join(config2.rootDir, "index.js"), body);
81423
81509
  }
@@ -85335,6 +85421,7 @@ async function componentFields2(config2, docs) {
85335
85421
 
85336
85422
  // src/codegen/index.ts
85337
85423
  async function compile(config2) {
85424
+ await generateStaticRuntimes({ config: config2 });
85338
85425
  const documents = await collectDocuments(config2);
85339
85426
  return await runPipeline2(config2, documents);
85340
85427
  }
@@ -85946,7 +86033,8 @@ function watch_remote_schema(opts = {}) {
85946
86033
  apiURL,
85947
86034
  config2.schemaPollTimeout,
85948
86035
  config2.schemaPath ?? path_exports.resolve(process.cwd(), "schema.json"),
85949
- await config2.pullHeaders()
86036
+ await config2.pullHeaders(),
86037
+ config2.schemaPollWriteToDisk
85950
86038
  );
85951
86039
  nbPullError = schemaState ? 0 : nbPullError + 1;
85952
86040
  } catch (e2) {