houdini 2.0.0-next.31 → 2.0.0-next.33

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/build/cmd/init.js CHANGED
@@ -472,7 +472,7 @@ async function packageJSON(targetPath, frameworkInfo) {
472
472
  }
473
473
  packageJSON2.devDependencies = {
474
474
  ...packageJSON2.devDependencies,
475
- houdini: "^2.0.0-next.31"
475
+ houdini: "^2.0.0-next.33"
476
476
  };
477
477
  if (frameworkInfo.framework === "svelte" || frameworkInfo.framework === "kit") {
478
478
  packageJSON2.devDependencies = {
@@ -41,6 +41,8 @@ export type CompilerProxy = {
41
41
  }) => Promise<Record<string, any> | null>;
42
42
  database_path: string;
43
43
  run_pipeline: (options: RunPipelineOptions) => Promise<Record<PipelineHook, Record<string, any>>>;
44
+ /** Serializes concurrent pipeline runs (HMR vs schema watcher) via a promise chain. */
45
+ pipeline_lock: <T>(fn: () => Promise<T>) => Promise<T>;
44
46
  };
45
47
  export declare function plugin_db_key(name: string): string;
46
48
  export declare function codegen_setup(config: Config, mode: string, db: Db, db_file: string): Promise<CompilerProxy>;
@@ -50,8 +50,8 @@ process.exit(0);}
50
50
  `
51
51
  );
52
52
  import * as conventions from "../router/conventions.js";
53
- import { openDb } from "./db.js";
54
53
  import { create_schema, write_config } from "./database.js";
54
+ import { openDb } from "./db.js";
55
55
  import { format_hook_error } from "./error.js";
56
56
  import * as fs from "./fs.js";
57
57
  import { Logger } from "./logger.js";
@@ -88,8 +88,8 @@ function plugin_db_key(name) {
88
88
  return name.replace(/\./g, "_").replace(/\//g, "__");
89
89
  }
90
90
  async function codegen_setup(config, mode, db, db_file) {
91
- let _db = db;
92
- const logger = new Logger(config.config_file.logLevel ?? LogLevel.Summary);
91
+ const _db = db;
92
+ const logger = new Logger(config.config_file.logLevel ?? LogLevel.ShortSummary);
93
93
  await fs.mkdirpSync(conventions.houdini_root(config));
94
94
  const rawTransport = config.config_file.pluginTransport ?? "websocket";
95
95
  const resolvedTransport = rawTransport.startsWith("env:") ? process.env[rawTransport.slice("env:".length)] ?? "websocket" : rawTransport;
@@ -170,14 +170,15 @@ async function codegen_setup(config, mode, db, db_file) {
170
170
  };
171
171
  spec_results[name] = spec;
172
172
  _db.run(
173
- `INSERT OR IGNORE INTO plugins (name, hooks, port, plugin_order, include_runtime, config_module, client_plugins)
174
- VALUES (?, ?, ?, ?, ?, ?, ?)`,
173
+ `INSERT OR IGNORE INTO plugins (name, hooks, port, plugin_order, include_runtime, include_static_runtime, config_module, client_plugins)
174
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
175
175
  [
176
176
  spec.name,
177
177
  JSON.stringify([...spec.hooks]),
178
178
  spec.port,
179
179
  spec.order,
180
180
  msg.includeRuntime ?? null,
181
+ msg.includeStaticRuntime ?? null,
181
182
  msg.configModule ?? null,
182
183
  msg.clientPlugins ?? null
183
184
  ]
@@ -451,10 +452,21 @@ async function codegen_setup(config, mode, db, db_file) {
451
452
  await trigger_hook("Config");
452
453
  await trigger_hook("AfterLoad");
453
454
  await trigger_hook("Schema");
455
+ let pipelineQueue = Promise.resolve();
454
456
  return {
455
457
  database_path: db_file,
456
458
  trigger_hook,
457
459
  run_pipeline: (options) => run_pipeline(trigger_hook, options),
460
+ pipeline_lock: (fn) => {
461
+ const result = pipelineQueue.then(fn);
462
+ pipelineQueue = result.then(
463
+ () => {
464
+ },
465
+ () => {
466
+ }
467
+ );
468
+ return result;
469
+ },
458
470
  close: async () => {
459
471
  for (const [name, ws] of wsConnections.entries()) {
460
472
  try {
@@ -2,5 +2,5 @@ import type { PluginSpec } from './codegen.js';
2
2
  import type { Db } from './db.js';
3
3
  import type { Config } from './config.js';
4
4
  import { Logger } from './logger.js';
5
- export declare const create_schema = "\nCREATE TABLE IF NOT EXISTS plugins (\n name TEXT NOT NULL PRIMARY KEY UNIQUE,\n port INTEGER NOT NULL,\n hooks JSON NOT NULL,\n plugin_order TEXT CHECK (plugin_order IS NULL OR plugin_order IN ('before', 'after', 'core')),\n include_runtime TEXT,\n include_static_runtime TEXT,\n config JSON,\n\t config_module TEXT,\n\t\tclient_plugins JSON\n);\n\n-- Watch Schema Config\nCREATE TABLE IF NOT EXISTS watch_schema_config (\n url TEXT NOT NULL,\n headers JSON,\n interval INTEGER,\n timeout INTEGER\n);\n\n-- Router Config\nCREATE TABLE IF NOT EXISTS router_config (\n api_endpoint TEXT,\n redirect TEXT UNIQUE,\n session_keys TEXT NOT NULL UNIQUE,\n url TEXT,\n mutation TEXT UNIQUE\n);\n\n-- Runtime Scalar Definition\nCREATE TABLE IF NOT EXISTS runtime_scalar_definitions (\n name TEXT NOT NULL PRIMARY KEY UNIQUE,\n type TEXT NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS component_fields (\n\tid INTEGER PRIMARY KEY AUTOINCREMENT,\n\tdocument INTEGER NOT NULL,\n type TEXT,\n\tprop TEXT,\n field TEXT,\n\tinline BOOLEAN default false,\n type_field TEXT,\n fragment TEXT,\n\tUNIQUE (document),\n\tFOREIGN KEY (document) REFERENCES raw_documents(id) ON DELETE CASCADE\n);\n\n-- Static Config (main config table)\nCREATE TABLE IF NOT EXISTS config (\n include JSON NOT NULL,\n exclude JSON NOT NULL,\n schema_path TEXT NOT NULL,\n definitions_path TEXT,\n cache_buffer_size INTEGER,\n default_cache_policy TEXT,\n default_partial BOOLEAN,\n default_lifetime INTEGER,\n default_list_position TEXT CHECK (default_list_position IN ('APPEND', 'PREPEND')),\n default_list_target TEXT CHECK (default_list_target IN ('ALL', 'NULL')),\n default_paginate_mode TEXT CHECK (default_paginate_mode IN ('Infinite', 'SinglePage')),\n suppress_pagination_deduplication BOOLEAN,\n log_level TEXT CHECK (log_level IN ('QUIET', 'FULL', 'SUMMARY', 'SHORT_SUMMARY')),\n default_fragment_masking BOOLEAN,\n default_keys JSON,\n persisted_queries_path TEXT NOT NULL,\n project_root TEXT,\n runtime_dir TEXT,\n\t\tpath TEXT\n);\n\nCREATE TABLE IF NOT EXISTS scalar_config (\n name TEXT NOT NULL PRIMARY KEY UNIQUE,\n type TEXT NOT NULL,\n\tinput_types JSON,\n\tmodule TEXT,\n\tdefault_import BOOLEAN\n);\n\n-- Types configuration\nCREATE TABLE IF NOT EXISTS type_configs (\n name TEXT NOT NULL,\n keys JSON NOT NULL,\n\tresolve_query TEXT\n);\n\n-- A table of original document contents (to be populated by plugins)\nCREATE TABLE IF NOT EXISTS raw_documents (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n offset_line INTEGER,\n offset_column INTEGER,\n filepath TEXT NOT NULL,\n content TEXT NOT NULL,\n current_task TEXT,\n loaded_with TEXT\n);\n\n-----------------------------------------------------------\n-- Schema Definition Tables\n-----------------------------------------------------------\n\nCREATE TABLE IF NOT EXISTS types (\n name TEXT NOT NULL PRIMARY KEY UNIQUE,\n kind TEXT NOT NULL CHECK (kind IN ('OBJECT', 'INTERFACE', 'UNION', 'ENUM', 'SCALAR', 'INPUT')),\n operation TEXT,\n\tdescription TEXT,\n\tinternal BOOLEAN default false,\n\tbuilt_in BOOLEAN default false\n);\n\nCREATE TABLE IF NOT EXISTS type_fields (\n id TEXT PRIMARY KEY, -- will be something like User.name so we don't have to look up the generated id\n parent TEXT NOT NULL, -- will be User\n name TEXT NOT NULL,\n type TEXT NOT NULL,\n\t type_modifiers TEXT,\n default_value TEXT,\n description TEXT,\n\t internal BOOLEAN default false,\n document INT,\n\n FOREIGN KEY (document) REFERENCES raw_documents(id) ON DELETE CASCADE,\n FOREIGN KEY (parent) REFERENCES types(name) ON DELETE CASCADE,\n FOREIGN KEY (type) REFERENCES types(name) ON DELETE CASCADE,\n UNIQUE (parent, name)\n);\n\nCREATE TABLE IF NOT EXISTS type_field_arguments (\n id TEXT PRIMARY KEY,\n field TEXT NOT NULL,\n name TEXT NOT NULL,\n type TEXT NOT NULL,\n type_modifiers TEXT,\n default_value TEXT,\n FOREIGN KEY (field) REFERENCES type_fields(id) ON DELETE CASCADE,\n UNIQUE (field, name)\n);\n\n\nCREATE TABLE IF NOT EXISTS enum_values (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n parent TEXT NOT NULL,\n value TEXT NOT NULL,\n description TEXT,\n FOREIGN KEY (parent) REFERENCES types(name) ON DELETE CASCADE,\n UNIQUE (parent, value)\n);\n\nCREATE TABLE IF NOT EXISTS possible_types (\n type TEXT NOT NULL,\n member TEXT NOT NULL,\n FOREIGN KEY (type) REFERENCES types(name) ON DELETE CASCADE,\n FOREIGN KEY (member) REFERENCES types(name) ON DELETE CASCADE,\n PRIMARY KEY (type, member)\n);\n\nCREATE TABLE IF NOT EXISTS directives (\n name TEXT NOT NULL UNIQUE PRIMARY KEY,\n\tinternal BOOLEAN default false,\n visible BOOLEAN default true,\n repeatable BOOLEAN default false,\n\tdescription TEXT\n);\n\nCREATE TABLE IF NOT EXISTS directive_arguments (\n parent TEXT NOT NULL,\n name TEXT NOT NULL,\n type TEXT NOT NULL,\n\ttype_modifiers TEXT,\n default_value TEXT,\n FOREIGN KEY (parent) REFERENCES directives(name),\n PRIMARY KEY (parent, name),\n UNIQUE (parent, name)\n);\n\nCREATE TABLE IF NOT EXISTS directive_locations (\n directive TEXT NOT NULL,\n location TEXT NOT NULL CHECK (location IN ('QUERY', 'MUTATION', 'SUBSCRIPTION', 'FIELD', 'FRAGMENT_DEFINITION', 'FRAGMENT_SPREAD', 'INLINE_FRAGMENT', 'SCHEMA', 'SCALAR', 'OBJECT', 'FIELD_DEFINITION', 'ARGUMENT_DEFINITION', 'INTERFACE', 'UNION', 'ENUM', 'ENUM_VALUE', 'INPUT_OBJECT', 'INPUT_FIELD_DEFINITION')),\n FOREIGN KEY (directive) REFERENCES directives(name),\n PRIMARY KEY (directive, location)\n);\n\nCREATE TABLE IF NOT EXISTS document_variable_directives (\n\tid INTEGER PRIMARY KEY AUTOINCREMENT,\n\tparent INTEGER NOT NULL,\n\tdirective TEXT NOT NULL,\n row INTEGER NOT NULL,\n column INTEGER NOT NULL,\n\tFOREIGN KEY (parent) REFERENCES document_variables(id) ON DELETE CASCADE,\n\tFOREIGN KEY (directive) REFERENCES directives(name) ON DELETE CASCADE\n);\n\nCREATE TABLE IF NOT EXISTS document_variable_directive_arguments (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n parent INTEGER NOT NULL,\n name TEXT NOT NULL,\n value INTEGER NOT NULL,\n\n FOREIGN KEY (value) REFERENCES argument_values(id) ON DELETE CASCADE,\n FOREIGN KEY (parent) REFERENCES document_variable_directives(id) ON DELETE CASCADE\n);\n\n-----------------------------------------------------------\n-- Document Tables\n-----------------------------------------------------------\n\nCREATE TABLE IF NOT EXISTS document_variables (\n \tid INTEGER PRIMARY KEY AUTOINCREMENT,\n document TEXT NOT NULL,\n name TEXT NOT NULL,\n type TEXT NOT NULL,\n type_modifiers TEXT,\n default_value INT,\n row INTEGER NOT NULL,\n column INTEGER NOT NULL,\n\n FOREIGN KEY (default_value) REFERENCES argument_values(id) ON DELETE CASCADE,\n FOREIGN KEY (document) REFERENCES documents(id) ON DELETE CASCADE,\n UNIQUE (document, name)\n);\n\n-- this is pulled out separately from operations and fragments so foreign keys can be used\nCREATE TABLE IF NOT EXISTS documents (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n name TEXT NOT NULL,\n kind TEXT NOT NULL CHECK (kind IN ('query', 'mutation', 'subscription', 'fragment')),\n raw_document INTEGER,\n type_condition TEXT,\n hash TEXT,\n printed TEXT,\n\t\tinternal boolean default false,\n\t\tvisible boolean default true,\n\t\tprocessed boolean default false,\n FOREIGN KEY (type_condition) REFERENCES types(name) ON DELETE CASCADE,\n FOREIGN KEY (raw_document) REFERENCES raw_documents(id) ON DELETE CASCADE\n);\n\nCREATE TABLE IF NOT EXISTS selections (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n field_name TEXT NOT NULL,\n\tkind TEXT NOT NULL CHECK (kind IN ('field', 'fragment', 'inline_fragment')),\n alias TEXT,\n type TEXT, -- should be something like User.Avatar\n fragment_ref TEXT, -- used when fragment arguments cause a hash to be inlined (removing the ability to track what the original fragment is)\n\t\tfragment_args JSON -- used to store the arguments that are used when fragment variables are expanded\n);\n\nCREATE TABLE IF NOT EXISTS selection_directives (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n selection_id INTEGER NOT NULL,\n directive TEXT NOT NULL,\n row INTEGER NOT NULL,\n column INTEGER NOT NULL,\n FOREIGN KEY (selection_id) REFERENCES selections(id) ON DELETE CASCADE,\n FOREIGN KEY (directive) REFERENCES directives(name) ON DELETE CASCADE\n);\n\nCREATE TABLE IF NOT EXISTS selection_directive_arguments (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n parent INTEGER NOT NULL,\n name TEXT NOT NULL,\n value INTEGER NOT NULL,\n document INTEGER NOT NULL,\n\n FOREIGN KEY (value) REFERENCES argument_values(id) ON DELETE CASCADE,\n FOREIGN KEY (parent) REFERENCES selection_directives(id) ON DELETE CASCADE,\n FOREIGN KEY (document) REFERENCES documents(id) ON DELETE CASCADE\n);\n\nCREATE TABLE IF NOT EXISTS document_directives (\n\tid INTEGER PRIMARY KEY AUTOINCREMENT,\n\tdocument int NOT NULL,\n\tdirective TEXT NOT NULL,\n\trow INTEGER NOT NULL,\n\tcolumn INTEGER NOT NULL,\n\tFOREIGN KEY (document) REFERENCES documents(id) ON DELETE CASCADE,\n\tFOREIGN KEY (directive) REFERENCES directives(name) ON DELETE CASCADE\n);\n\nCREATE TABLE IF NOT EXISTS document_directive_arguments (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n parent INTEGER NOT NULL,\n name TEXT NOT NULL,\n value INTEGER NOT NULL,\n\n FOREIGN KEY (value) REFERENCES argument_values(id) ON DELETE CASCADE,\n FOREIGN KEY (parent) REFERENCES document_directives(id) ON DELETE CASCADE\n);\n\nCREATE TABLE IF NOT EXISTS selection_refs (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n parent_id INTEGER,\n child_id INTEGER NOT NULL,\n path_index INTEGER NOT NULL,\n document INTEGER NOT NULL,\n\trow INTEGER NOT NULL,\n\tcolumn INTEGER NOT NULL,\n\tinternal BOOLEAN NOT NULL DEFAULT false,\n FOREIGN KEY (parent_id) REFERENCES selections(id) ON DELETE CASCADE,\n FOREIGN KEY (child_id) REFERENCES selections(id) ON DELETE CASCADE,\n FOREIGN KEY (document) REFERENCES documents(id) ON DELETE CASCADE\n);\n\nCREATE TABLE IF NOT EXISTS selection_arguments (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n selection_id INTEGER NOT NULL,\n document INTEGER NOT NULL,\n name TEXT NOT NULL,\n value INTEGER NOT NULL,\n row INTEGER NOT NULL,\n column INTEGER NOT NULL,\n field_argument TEXT NOT NULL,\n\n FOREIGN KEY (value) REFERENCES argument_values(id) ON DELETE CASCADE,\n FOREIGN KEY (selection_id) REFERENCES selections(id) ON DELETE CASCADE,\n FOREIGN KEY (document) REFERENCES documents(id) ON DELETE CASCADE\n);\n\n\nCREATE TABLE IF NOT EXISTS argument_values (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n kind TEXT NOT NULL CHECK (kind IN ('Variable', 'Int', 'Float', 'String', 'Block', 'Boolean', 'Null', 'Enum', 'List', 'Object')),\n raw TEXT NOT NULL,\n row INTEGER NOT NULL,\n column INTEGER NOT NULL,\n expected_type TEXT NOT NULL,\n expected_type_modifiers TEXT,\n document INTEGER NOT NULL,\n\n FOREIGN KEY (document) REFERENCES documents(id) ON DELETE CASCADE\n);\n\nCREATE TABLE IF NOT EXISTS argument_value_children (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n name TEXT,\n parent INTEGER NOT NULL,\n value INTEGER NOT NULL,\n row INTEGER NOT NULL,\n column INTEGER NOT NULL,\n document INTEGER NOT NULL,\n\n FOREIGN KEY (document) REFERENCES documents(id) ON DELETE CASCADE,\n FOREIGN KEY (parent) REFERENCES argument_values(id) ON DELETE CASCADE,\n FOREIGN KEY (value) REFERENCES argument_values(id) ON DELETE CASCADE\n);\n\nCREATE TABLE IF NOT EXISTS discovered_lists (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n name TEXT,\n node_type TEXT NOT NULL,\n edge_type TEXT,\n connection_type TEXT NOT NULL,\n node INTEGER NOT NULL,\n page_size INTEGER NOT NULL,\n document INTEGER NOT NULL,\n mode TEXT NOT NULL,\n embedded BOOLEAN NOT NULL,\n target_type TEXT NOT NULL,\n connection BOOLEAN default false,\n list_field INTEGER NOT NULL,\n paginate TEXT,\n supports_forward BOOLEAN default false,\n supports_backward BOOLEAN default false,\n cursor_type TEXT,\n\n FOREIGN KEY (list_field) REFERENCES selections(id) ON DELETE CASCADE,\n\t FOREIGN KEY (node) REFERENCES selections(id) ON DELETE CASCADE,\n FOREIGN KEY (node_type) REFERENCES types(name) ON DELETE CASCADE,\n FOREIGN KEY (document) REFERENCES documents(id) ON DELETE CASCADE\n);\n\nCREATE TABLE IF NOT EXISTS document_dependencies (\n document INTEGER NOT NULL,\n depends_on TEXT NOT NULL,\n\n FOREIGN KEY (document) REFERENCES documents(id) ON DELETE CASCADE,\n UNIQUE (document, depends_on)\n);\n\n-----------------------------------------------------------\n-- Indices\n-----------------------------------------------------------\n\n-- component_fields\nCREATE INDEX IF NOT EXISTS idx_component_fields_type_fields ON component_fields(type_field);\n\n-- discovered_lists\nCREATE INDEX IF NOT EXISTS idx_discovered_lists_document ON discovered_lists(document);\nCREATE INDEX IF NOT EXISTS idx_discovered_lists_node ON discovered_lists(node);\nCREATE INDEX IF NOT EXISTS idx_discovered_lists_list_field ON discovered_lists(list_field);\n-- note: no index on discovered_lists(connection) \u2014 boolean column, ~2 distinct values\n\n-- types\nCREATE INDEX IF NOT EXISTS idx_types_kind_operation ON types(kind, operation);\n-- note: no index on types(name) \u2014 covered by PRIMARY KEY UNIQUE\n\n-- documents\nCREATE INDEX IF NOT EXISTS idx_documents_kind ON documents(kind);\nCREATE INDEX IF NOT EXISTS idx_documents_type_condition ON documents(type_condition);\nCREATE INDEX IF NOT EXISTS idx_documents_raw_document ON documents(raw_document);\nCREATE INDEX IF NOT EXISTS idx_documents_name_kind ON documents(name, kind);\n\n-- raw_documents\nCREATE INDEX IF NOT EXISTS idx_raw_documents_current_task ON raw_documents(current_task);\n\n-- selections\nCREATE INDEX IF NOT EXISTS idx_selections_type ON selections(type);\nCREATE INDEX IF NOT EXISTS idx_selections_alias ON selections(alias);\nCREATE INDEX IF NOT EXISTS idx_selections_field_name_kind ON selections(field_name, kind);\n\n-- selection_refs: composite covers document-only lookups, so no separate single-column index needed\nCREATE INDEX IF NOT EXISTS idx_selection_refs_parent_id ON selection_refs(parent_id);\n\nCREATE INDEX IF NOT EXISTS idx_selection_refs_child_id ON selection_refs(child_id);\nCREATE INDEX IF NOT EXISTS idx_selection_refs_document_parent_id ON selection_refs(document, parent_id);\n\n-- selection_directives / selection_directive_arguments / selection_arguments\nCREATE INDEX IF NOT EXISTS idx_selection_directives_selection ON selection_directives(selection_id);\nCREATE INDEX IF NOT EXISTS idx_selection_directives_directive ON selection_directives(directive);\nCREATE INDEX IF NOT EXISTS idx_selection_directive_arguments_parent_name ON selection_directive_arguments(parent, name);\n-- note: no index on selection_directive_arguments(parent) alone \u2014 covered by (parent,name) composite\nCREATE INDEX IF NOT EXISTS idx_selection_directive_arguments_value ON selection_directive_arguments(value);\n-- document FK on selection_directive_arguments and selection_arguments: used in WHERE/JOIN in CollectDocuments\nCREATE INDEX IF NOT EXISTS idx_selection_directive_arguments_document ON selection_directive_arguments(document);\nCREATE INDEX IF NOT EXISTS idx_selection_arguments_document ON selection_arguments(document);\nCREATE INDEX IF NOT EXISTS idx_selection_arguments_selection ON selection_arguments(selection_id);\nCREATE INDEX IF NOT EXISTS idx_selection_arguments_value ON selection_arguments(value);\n\n-- type_fields / type_field_arguments\n-- note: no index on type_fields(id) or type_field_arguments(id) \u2014 covered by their TEXT PRIMARY KEYs\nCREATE INDEX IF NOT EXISTS idx_type_fields_parent ON type_fields(parent);\nCREATE INDEX IF NOT EXISTS idx_type_fields_name ON type_fields(name);\nCREATE INDEX IF NOT EXISTS idx_type_configs_name ON type_configs(name);\n\n-- possible_types\n-- note: no index on possible_types(type) \u2014 covered by PRIMARY KEY(type,member) leading column\nCREATE INDEX IF NOT EXISTS idx_possible_types_member ON possible_types(member);\n\n-- type_fields: type and document FK columns have no implicit index\nCREATE INDEX IF NOT EXISTS idx_type_fields_type ON type_fields(type);\nCREATE INDEX IF NOT EXISTS idx_type_fields_document ON type_fields(document);\n\n-- enum_values\n-- note: no index on enum_values(parent) or (parent,value) \u2014 both covered by UNIQUE(parent,value)\n\n-- document_directives / document_directive_arguments\nCREATE INDEX IF NOT EXISTS idx_document_directives_document ON document_directives(document);\nCREATE INDEX IF NOT EXISTS idx_document_directives_directive ON document_directives(directive);\nCREATE INDEX IF NOT EXISTS idx_document_directive_arguments_parent_name ON document_directive_arguments(parent, name);\n-- note: no index on document_directive_arguments(parent) alone \u2014 covered by (parent,name) composite\nCREATE INDEX IF NOT EXISTS idx_document_directive_arguments_value on document_directive_arguments(value);\n\n-- document_variables\n-- note: no index on document_variables(document,name) \u2014 covered by UNIQUE(document,name)\n-- default_value FK is used as a JOIN column in validate and fragmentArguments transforms\nCREATE INDEX IF NOT EXISTS idx_document_variables_default_value ON document_variables(default_value);\nCREATE INDEX IF NOT EXISTS idx_document_variables_document_id ON document_variables(document, id);\nCREATE INDEX IF NOT EXISTS idx_document_variables_document_type_modifiers_default ON document_variables(document, type_modifiers, default_value);\n\n-- document_variable_directives / document_variable_directive_arguments\nCREATE INDEX IF NOT EXISTS idx_document_variable_directives_parent ON document_variable_directives(parent);\nCREATE INDEX IF NOT EXISTS idx_document_variable_directives_directive ON document_variable_directives(directive);\nCREATE INDEX IF NOT EXISTS idx_document_variable_directive_arguments_parent ON document_variable_directive_arguments(parent);\n\n-- document_dependencies\n-- note: no index on document_dependencies(document) \u2014 covered by UNIQUE(document,depends_on) leading column\nCREATE INDEX IF NOT EXISTS idx_document_dependency_depends_on on document_dependencies(depends_on);\n\n-- argument_values: composite (document,id) covers document-only lookups\n-- note: no separate index on argument_values(document) alone\nCREATE INDEX IF NOT EXISTS idx_argument_values_kind_raw ON argument_values(kind, raw);\nCREATE INDEX IF NOT EXISTS idx_argument_values_document_id ON argument_values(document, id);\nCREATE INDEX IF NOT EXISTS idx_argument_values_expected_type_document ON argument_values(expected_type, document);\n\n-- argument_value_children: composite (parent,value) covers parent-only lookups\n-- note: no separate index on argument_value_children(parent) alone\nCREATE INDEX IF NOT EXISTS idx_argument_value_children_parent_value ON argument_value_children(parent, value);\nCREATE INDEX IF NOT EXISTS idx_argument_value_children_value ON argument_value_children(value);\n-- document FK: large table; index needed for efficient CASCADE DELETE from documents\nCREATE INDEX IF NOT EXISTS idx_argument_value_children_document ON argument_value_children(document);\n";
5
+ export declare const create_schema = "\nCREATE TABLE IF NOT EXISTS plugins (\n name TEXT NOT NULL PRIMARY KEY UNIQUE,\n port INTEGER NOT NULL,\n hooks JSON NOT NULL,\n plugin_order TEXT CHECK (plugin_order IS NULL OR plugin_order IN ('before', 'after', 'core')),\n include_runtime TEXT,\n include_static_runtime TEXT,\n config JSON,\n\t config_module TEXT,\n\t\tclient_plugins JSON\n);\n\n-- Watch Schema Config\nCREATE TABLE IF NOT EXISTS watch_schema_config (\n url TEXT NOT NULL,\n headers JSON,\n interval INTEGER,\n timeout INTEGER\n);\n\n-- Router Config\nCREATE TABLE IF NOT EXISTS router_config (\n api_endpoint TEXT,\n redirect TEXT UNIQUE,\n session_keys TEXT NOT NULL UNIQUE,\n url TEXT,\n mutation TEXT UNIQUE\n);\n\n-- Runtime Scalar Definition\nCREATE TABLE IF NOT EXISTS runtime_scalar_definitions (\n name TEXT NOT NULL PRIMARY KEY UNIQUE,\n type TEXT NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS component_fields (\n\tid INTEGER PRIMARY KEY AUTOINCREMENT,\n\tdocument INTEGER NOT NULL,\n type TEXT,\n\tprop TEXT,\n field TEXT,\n\tinline BOOLEAN default false,\n type_field TEXT,\n fragment TEXT,\n\tUNIQUE (document),\n\tFOREIGN KEY (document) REFERENCES raw_documents(id) ON DELETE CASCADE\n);\n\n-- Static Config (main config table)\nCREATE TABLE IF NOT EXISTS config (\n include JSON NOT NULL,\n exclude JSON NOT NULL,\n schema_path TEXT NOT NULL,\n definitions_path TEXT,\n cache_buffer_size INTEGER,\n default_cache_policy TEXT,\n default_partial BOOLEAN,\n default_lifetime INTEGER,\n default_list_position TEXT CHECK (default_list_position IN ('APPEND', 'PREPEND')),\n default_list_target TEXT CHECK (default_list_target IN ('ALL', 'NULL')),\n default_paginate_mode TEXT CHECK (default_paginate_mode IN ('Infinite', 'SinglePage')),\n suppress_pagination_deduplication BOOLEAN,\n log_level TEXT CHECK (log_level IN ('QUIET', 'FULL', 'SUMMARY', 'SHORT_SUMMARY')),\n default_fragment_masking BOOLEAN,\n default_keys JSON,\n persisted_queries_path TEXT NOT NULL,\n project_root TEXT,\n runtime_dir TEXT,\n\t\tpath TEXT\n);\n\nCREATE TABLE IF NOT EXISTS scalar_config (\n name TEXT NOT NULL PRIMARY KEY UNIQUE,\n type TEXT NOT NULL,\n\tinput_types JSON,\n\tmodule TEXT,\n\tdefault_import BOOLEAN\n);\n\n-- Types configuration\nCREATE TABLE IF NOT EXISTS type_configs (\n name TEXT NOT NULL,\n keys JSON NOT NULL,\n\tresolve_query TEXT\n);\n\n-- A table of original document contents (to be populated by plugins)\nCREATE TABLE IF NOT EXISTS raw_documents (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n offset_line INTEGER,\n offset_column INTEGER,\n filepath TEXT NOT NULL,\n content TEXT NOT NULL,\n current_task TEXT,\n loaded_with TEXT\n);\n\n-----------------------------------------------------------\n-- Schema Definition Tables\n-----------------------------------------------------------\n\nCREATE TABLE IF NOT EXISTS types (\n name TEXT NOT NULL PRIMARY KEY UNIQUE,\n kind TEXT NOT NULL CHECK (kind IN ('OBJECT', 'INTERFACE', 'UNION', 'ENUM', 'SCALAR', 'INPUT')),\n operation TEXT,\n\tdescription TEXT,\n\tinternal BOOLEAN default false,\n\tbuilt_in BOOLEAN default false\n);\n\nCREATE TABLE IF NOT EXISTS type_fields (\n id TEXT PRIMARY KEY, -- will be something like User.name so we don't have to look up the generated id\n parent TEXT NOT NULL, -- will be User\n name TEXT NOT NULL,\n type TEXT NOT NULL,\n\t type_modifiers TEXT,\n default_value TEXT,\n description TEXT,\n\t internal BOOLEAN default false,\n document INT,\n\n FOREIGN KEY (document) REFERENCES raw_documents(id) ON DELETE CASCADE,\n FOREIGN KEY (parent) REFERENCES types(name) ON DELETE CASCADE,\n FOREIGN KEY (type) REFERENCES types(name) ON DELETE CASCADE,\n UNIQUE (parent, name)\n);\n\nCREATE TABLE IF NOT EXISTS type_field_arguments (\n id TEXT PRIMARY KEY,\n field TEXT NOT NULL,\n name TEXT NOT NULL,\n type TEXT NOT NULL,\n type_modifiers TEXT,\n default_value TEXT,\n FOREIGN KEY (field) REFERENCES type_fields(id) ON DELETE CASCADE,\n UNIQUE (field, name)\n);\n\n\nCREATE TABLE IF NOT EXISTS enum_values (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n parent TEXT NOT NULL,\n value TEXT NOT NULL,\n description TEXT,\n FOREIGN KEY (parent) REFERENCES types(name) ON DELETE CASCADE,\n UNIQUE (parent, value)\n);\n\nCREATE TABLE IF NOT EXISTS possible_types (\n type TEXT NOT NULL,\n member TEXT NOT NULL,\n FOREIGN KEY (type) REFERENCES types(name) ON DELETE CASCADE,\n FOREIGN KEY (member) REFERENCES types(name) ON DELETE CASCADE,\n PRIMARY KEY (type, member)\n);\n\nCREATE TABLE IF NOT EXISTS directives (\n name TEXT NOT NULL UNIQUE PRIMARY KEY,\n\tinternal BOOLEAN default false,\n visible BOOLEAN default true,\n repeatable BOOLEAN default false,\n\tdescription TEXT\n);\n\nCREATE TABLE IF NOT EXISTS directive_arguments (\n parent TEXT NOT NULL,\n name TEXT NOT NULL,\n type TEXT NOT NULL,\n\ttype_modifiers TEXT,\n default_value TEXT,\n FOREIGN KEY (parent) REFERENCES directives(name),\n PRIMARY KEY (parent, name),\n UNIQUE (parent, name)\n);\n\nCREATE TABLE IF NOT EXISTS directive_locations (\n directive TEXT NOT NULL,\n location TEXT NOT NULL CHECK (location IN ('QUERY', 'MUTATION', 'SUBSCRIPTION', 'FIELD', 'FRAGMENT_DEFINITION', 'FRAGMENT_SPREAD', 'INLINE_FRAGMENT', 'SCHEMA', 'SCALAR', 'OBJECT', 'FIELD_DEFINITION', 'ARGUMENT_DEFINITION', 'INTERFACE', 'UNION', 'ENUM', 'ENUM_VALUE', 'INPUT_OBJECT', 'INPUT_FIELD_DEFINITION')),\n FOREIGN KEY (directive) REFERENCES directives(name),\n PRIMARY KEY (directive, location)\n);\n\nCREATE TABLE IF NOT EXISTS document_variable_directives (\n\tid INTEGER PRIMARY KEY AUTOINCREMENT,\n\tparent INTEGER NOT NULL,\n\tdirective TEXT NOT NULL,\n row INTEGER NOT NULL,\n column INTEGER NOT NULL,\n\tFOREIGN KEY (parent) REFERENCES document_variables(id) ON DELETE CASCADE,\n\tFOREIGN KEY (directive) REFERENCES directives(name) ON DELETE CASCADE\n);\n\nCREATE TABLE IF NOT EXISTS document_variable_directive_arguments (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n parent INTEGER NOT NULL,\n name TEXT NOT NULL,\n value INTEGER NOT NULL,\n\n FOREIGN KEY (value) REFERENCES argument_values(id) ON DELETE CASCADE,\n FOREIGN KEY (parent) REFERENCES document_variable_directives(id) ON DELETE CASCADE\n);\n\n-----------------------------------------------------------\n-- Document Tables\n-----------------------------------------------------------\n\nCREATE TABLE IF NOT EXISTS document_variables (\n \tid INTEGER PRIMARY KEY AUTOINCREMENT,\n document TEXT NOT NULL,\n name TEXT NOT NULL,\n type TEXT NOT NULL,\n type_modifiers TEXT,\n default_value INT,\n row INTEGER NOT NULL,\n column INTEGER NOT NULL,\n\n FOREIGN KEY (default_value) REFERENCES argument_values(id) ON DELETE CASCADE,\n FOREIGN KEY (document) REFERENCES documents(id) ON DELETE CASCADE,\n UNIQUE (document, name)\n);\n\n-- this is pulled out separately from operations and fragments so foreign keys can be used\nCREATE TABLE IF NOT EXISTS documents (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n name TEXT NOT NULL,\n kind TEXT NOT NULL CHECK (kind IN ('query', 'mutation', 'subscription', 'fragment')),\n raw_document INTEGER,\n type_condition TEXT,\n hash TEXT,\n printed TEXT,\n\t\tinternal boolean default false,\n\t\tvisible boolean default true,\n\t\tprocessed boolean default false,\n FOREIGN KEY (type_condition) REFERENCES types(name) ON DELETE CASCADE,\n FOREIGN KEY (raw_document) REFERENCES raw_documents(id) ON DELETE CASCADE\n);\n\nCREATE TABLE IF NOT EXISTS selections (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n field_name TEXT NOT NULL,\n\tkind TEXT NOT NULL CHECK (kind IN ('field', 'fragment', 'inline_fragment')),\n alias TEXT,\n type TEXT, -- should be something like User.Avatar\n fragment_ref TEXT, -- used when fragment arguments cause a hash to be inlined (removing the ability to track what the original fragment is)\n\t\tfragment_args JSON -- used to store the arguments that are used when fragment variables are expanded\n);\n\nCREATE TABLE IF NOT EXISTS selection_directives (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n selection_id INTEGER NOT NULL,\n directive TEXT NOT NULL,\n row INTEGER NOT NULL,\n column INTEGER NOT NULL,\n FOREIGN KEY (selection_id) REFERENCES selections(id) ON DELETE CASCADE,\n FOREIGN KEY (directive) REFERENCES directives(name) ON DELETE CASCADE\n);\n\nCREATE TABLE IF NOT EXISTS selection_directive_arguments (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n parent INTEGER NOT NULL,\n name TEXT NOT NULL,\n value INTEGER NOT NULL,\n document INTEGER NOT NULL,\n\n FOREIGN KEY (value) REFERENCES argument_values(id) ON DELETE CASCADE,\n FOREIGN KEY (parent) REFERENCES selection_directives(id) ON DELETE CASCADE,\n FOREIGN KEY (document) REFERENCES documents(id) ON DELETE CASCADE\n);\n\nCREATE TABLE IF NOT EXISTS document_directives (\n\tid INTEGER PRIMARY KEY AUTOINCREMENT,\n\tdocument int NOT NULL,\n\tdirective TEXT NOT NULL,\n\trow INTEGER NOT NULL,\n\tcolumn INTEGER NOT NULL,\n\tFOREIGN KEY (document) REFERENCES documents(id) ON DELETE CASCADE,\n\tFOREIGN KEY (directive) REFERENCES directives(name) ON DELETE CASCADE\n);\n\nCREATE TABLE IF NOT EXISTS document_directive_arguments (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n parent INTEGER NOT NULL,\n name TEXT NOT NULL,\n value INTEGER NOT NULL,\n\n FOREIGN KEY (value) REFERENCES argument_values(id) ON DELETE CASCADE,\n FOREIGN KEY (parent) REFERENCES document_directives(id) ON DELETE CASCADE\n);\n\nCREATE TABLE IF NOT EXISTS selection_refs (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n parent_id INTEGER,\n child_id INTEGER NOT NULL,\n path_index INTEGER NOT NULL,\n document INTEGER NOT NULL,\n\trow INTEGER NOT NULL,\n\tcolumn INTEGER NOT NULL,\n\tinternal BOOLEAN NOT NULL DEFAULT false,\n FOREIGN KEY (parent_id) REFERENCES selections(id) ON DELETE CASCADE,\n FOREIGN KEY (child_id) REFERENCES selections(id) ON DELETE CASCADE,\n FOREIGN KEY (document) REFERENCES documents(id) ON DELETE CASCADE\n);\n\nCREATE TABLE IF NOT EXISTS selection_arguments (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n selection_id INTEGER NOT NULL,\n document INTEGER NOT NULL,\n name TEXT NOT NULL,\n value INTEGER NOT NULL,\n row INTEGER NOT NULL,\n column INTEGER NOT NULL,\n field_argument TEXT NOT NULL,\n\n FOREIGN KEY (value) REFERENCES argument_values(id) ON DELETE CASCADE,\n FOREIGN KEY (selection_id) REFERENCES selections(id) ON DELETE CASCADE,\n FOREIGN KEY (document) REFERENCES documents(id) ON DELETE CASCADE\n);\n\n\nCREATE TABLE IF NOT EXISTS argument_values (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n kind TEXT NOT NULL CHECK (kind IN ('Variable', 'Int', 'Float', 'String', 'Block', 'Boolean', 'Null', 'Enum', 'List', 'Object')),\n raw TEXT NOT NULL,\n row INTEGER NOT NULL,\n column INTEGER NOT NULL,\n expected_type TEXT NOT NULL,\n expected_type_modifiers TEXT,\n document INTEGER NOT NULL,\n\n FOREIGN KEY (document) REFERENCES documents(id) ON DELETE CASCADE\n);\n\nCREATE TABLE IF NOT EXISTS argument_value_children (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n name TEXT,\n parent INTEGER NOT NULL,\n value INTEGER NOT NULL,\n row INTEGER NOT NULL,\n column INTEGER NOT NULL,\n document INTEGER NOT NULL,\n\n FOREIGN KEY (document) REFERENCES documents(id) ON DELETE CASCADE,\n FOREIGN KEY (parent) REFERENCES argument_values(id) ON DELETE CASCADE,\n FOREIGN KEY (value) REFERENCES argument_values(id) ON DELETE CASCADE\n);\n\nCREATE TABLE IF NOT EXISTS discovered_lists (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n name TEXT,\n node_type TEXT NOT NULL,\n edge_type TEXT,\n connection_type TEXT NOT NULL,\n node INTEGER NOT NULL,\n page_size INTEGER NOT NULL,\n document INTEGER NOT NULL,\n mode TEXT NOT NULL,\n embedded BOOLEAN NOT NULL,\n target_type TEXT NOT NULL,\n connection BOOLEAN default false,\n list_field INTEGER NOT NULL,\n paginate TEXT,\n supports_forward BOOLEAN default false,\n supports_backward BOOLEAN default false,\n cursor_type TEXT,\n\n FOREIGN KEY (list_field) REFERENCES selections(id) ON DELETE CASCADE,\n\t FOREIGN KEY (node) REFERENCES selections(id) ON DELETE CASCADE,\n FOREIGN KEY (node_type) REFERENCES types(name) ON DELETE CASCADE,\n FOREIGN KEY (document) REFERENCES documents(id) ON DELETE CASCADE\n);\n\nCREATE TABLE IF NOT EXISTS document_dependencies (\n document INTEGER NOT NULL,\n depends_on TEXT NOT NULL,\n\n FOREIGN KEY (document) REFERENCES documents(id) ON DELETE CASCADE,\n UNIQUE (document, depends_on)\n);\n\n-----------------------------------------------------------\n-- Indices\n-----------------------------------------------------------\n\n-- component_fields\nCREATE INDEX IF NOT EXISTS idx_component_fields_type_fields ON component_fields(type_field);\n\n-- discovered_lists\nCREATE INDEX IF NOT EXISTS idx_discovered_lists_document ON discovered_lists(document);\nCREATE INDEX IF NOT EXISTS idx_discovered_lists_node ON discovered_lists(node);\nCREATE INDEX IF NOT EXISTS idx_discovered_lists_list_field ON discovered_lists(list_field);\n-- note: no index on discovered_lists(connection) \u2014 boolean column, ~2 distinct values\n\n-- types\nCREATE INDEX IF NOT EXISTS idx_types_kind_operation ON types(kind, operation);\n-- note: no index on types(name) \u2014 covered by PRIMARY KEY UNIQUE\n\n-- documents\nCREATE INDEX IF NOT EXISTS idx_documents_kind ON documents(kind);\nCREATE INDEX IF NOT EXISTS idx_documents_type_condition ON documents(type_condition);\nCREATE INDEX IF NOT EXISTS idx_documents_raw_document ON documents(raw_document);\nCREATE INDEX IF NOT EXISTS idx_documents_name_kind ON documents(name, kind);\n\n-- raw_documents\nCREATE INDEX IF NOT EXISTS idx_raw_documents_current_task ON raw_documents(current_task);\nCREATE INDEX IF NOT EXISTS idx_raw_documents_filepath ON raw_documents(filepath);\n\n-- selections\nCREATE INDEX IF NOT EXISTS idx_selections_type ON selections(type);\nCREATE INDEX IF NOT EXISTS idx_selections_alias ON selections(alias);\nCREATE INDEX IF NOT EXISTS idx_selections_field_name_kind ON selections(field_name, kind);\n\n-- selection_refs: composite covers document-only lookups, so no separate single-column index needed\nCREATE INDEX IF NOT EXISTS idx_selection_refs_parent_id ON selection_refs(parent_id);\n\nCREATE INDEX IF NOT EXISTS idx_selection_refs_child_id ON selection_refs(child_id);\nCREATE INDEX IF NOT EXISTS idx_selection_refs_document_parent_id ON selection_refs(document, parent_id);\n\n-- selection_directives / selection_directive_arguments / selection_arguments\nCREATE INDEX IF NOT EXISTS idx_selection_directives_selection ON selection_directives(selection_id);\nCREATE INDEX IF NOT EXISTS idx_selection_directives_directive ON selection_directives(directive);\nCREATE INDEX IF NOT EXISTS idx_selection_directive_arguments_parent_name ON selection_directive_arguments(parent, name);\n-- note: no index on selection_directive_arguments(parent) alone \u2014 covered by (parent,name) composite\nCREATE INDEX IF NOT EXISTS idx_selection_directive_arguments_value ON selection_directive_arguments(value);\n-- document FK on selection_directive_arguments and selection_arguments: used in WHERE/JOIN in CollectDocuments\nCREATE INDEX IF NOT EXISTS idx_selection_directive_arguments_document ON selection_directive_arguments(document);\nCREATE INDEX IF NOT EXISTS idx_selection_arguments_document ON selection_arguments(document);\nCREATE INDEX IF NOT EXISTS idx_selection_arguments_selection ON selection_arguments(selection_id);\nCREATE INDEX IF NOT EXISTS idx_selection_arguments_value ON selection_arguments(value);\n\n-- type_fields / type_field_arguments\n-- note: no index on type_fields(id) or type_field_arguments(id) \u2014 covered by their TEXT PRIMARY KEYs\nCREATE INDEX IF NOT EXISTS idx_type_fields_parent ON type_fields(parent);\nCREATE INDEX IF NOT EXISTS idx_type_fields_name ON type_fields(name);\nCREATE INDEX IF NOT EXISTS idx_type_configs_name ON type_configs(name);\n\n-- possible_types\n-- note: no index on possible_types(type) \u2014 covered by PRIMARY KEY(type,member) leading column\nCREATE INDEX IF NOT EXISTS idx_possible_types_member ON possible_types(member);\n\n-- type_fields: type and document FK columns have no implicit index\nCREATE INDEX IF NOT EXISTS idx_type_fields_type ON type_fields(type);\nCREATE INDEX IF NOT EXISTS idx_type_fields_document ON type_fields(document);\n\n-- enum_values\n-- note: no index on enum_values(parent) or (parent,value) \u2014 both covered by UNIQUE(parent,value)\n\n-- document_directives / document_directive_arguments\nCREATE INDEX IF NOT EXISTS idx_document_directives_document ON document_directives(document);\nCREATE INDEX IF NOT EXISTS idx_document_directives_directive ON document_directives(directive);\nCREATE INDEX IF NOT EXISTS idx_document_directive_arguments_parent_name ON document_directive_arguments(parent, name);\n-- note: no index on document_directive_arguments(parent) alone \u2014 covered by (parent,name) composite\nCREATE INDEX IF NOT EXISTS idx_document_directive_arguments_value on document_directive_arguments(value);\n\n-- document_variables\n-- note: no index on document_variables(document,name) \u2014 covered by UNIQUE(document,name)\n-- default_value FK is used as a JOIN column in validate and fragmentArguments transforms\nCREATE INDEX IF NOT EXISTS idx_document_variables_default_value ON document_variables(default_value);\nCREATE INDEX IF NOT EXISTS idx_document_variables_document_id ON document_variables(document, id);\nCREATE INDEX IF NOT EXISTS idx_document_variables_document_type_modifiers_default ON document_variables(document, type_modifiers, default_value);\n\n-- document_variable_directives / document_variable_directive_arguments\nCREATE INDEX IF NOT EXISTS idx_document_variable_directives_parent ON document_variable_directives(parent);\nCREATE INDEX IF NOT EXISTS idx_document_variable_directives_directive ON document_variable_directives(directive);\nCREATE INDEX IF NOT EXISTS idx_document_variable_directive_arguments_parent ON document_variable_directive_arguments(parent);\n\n-- document_dependencies\n-- note: no index on document_dependencies(document) \u2014 covered by UNIQUE(document,depends_on) leading column\nCREATE INDEX IF NOT EXISTS idx_document_dependency_depends_on on document_dependencies(depends_on);\n\n-- argument_values: composite (document,id) covers document-only lookups\n-- note: no separate index on argument_values(document) alone\nCREATE INDEX IF NOT EXISTS idx_argument_values_kind_raw ON argument_values(kind, raw);\nCREATE INDEX IF NOT EXISTS idx_argument_values_document_id ON argument_values(document, id);\nCREATE INDEX IF NOT EXISTS idx_argument_values_expected_type_document ON argument_values(expected_type, document);\n\n-- argument_value_children: composite (parent,value) covers parent-only lookups\n-- note: no separate index on argument_value_children(parent) alone\nCREATE INDEX IF NOT EXISTS idx_argument_value_children_parent_value ON argument_value_children(parent, value);\nCREATE INDEX IF NOT EXISTS idx_argument_value_children_value ON argument_value_children(value);\n-- document FK: large table; index needed for efficient CASCADE DELETE from documents\nCREATE INDEX IF NOT EXISTS idx_argument_value_children_document ON argument_value_children(document);\n";
6
6
  export declare function write_config(db: Db, config: Config, invoke_hook: (plugin: string, hook: string, args: Record<string, any>) => Promise<Record<string, any>>, plugins: Array<PluginSpec>, mode: string, logger?: Logger): Promise<void>;
@@ -407,6 +407,7 @@ CREATE INDEX IF NOT EXISTS idx_documents_name_kind ON documents(name, kind);
407
407
 
408
408
  -- raw_documents
409
409
  CREATE INDEX IF NOT EXISTS idx_raw_documents_current_task ON raw_documents(current_task);
410
+ CREATE INDEX IF NOT EXISTS idx_raw_documents_filepath ON raw_documents(filepath);
410
411
 
411
412
  -- selections
412
413
  CREATE INDEX IF NOT EXISTS idx_selections_type ON selections(type);
@@ -10,45 +10,49 @@ async function plugin_path(plugin_name, config_path, preferWasm = false) {
10
10
  }
11
11
  return { executable, directory: path.dirname(executable) };
12
12
  }
13
+ if (process.versions.pnp) {
14
+ const { findPnpApi } = require("node:module");
15
+ const pnp = findPnpApi(config_path);
16
+ return pnp.resolveRequest(plugin_name, config_path, {
17
+ conditions: /* @__PURE__ */ new Set(["import"])
18
+ });
19
+ }
20
+ let plugin_dir;
13
21
  try {
14
- if (process.versions.pnp) {
15
- const { findPnpApi } = require("node:module");
16
- const pnp = findPnpApi(config_path);
17
- return pnp.resolveRequest(plugin_name, config_path, {
18
- conditions: /* @__PURE__ */ new Set(["import"])
19
- });
20
- }
21
- const plugin_dir = find_module(plugin_name, config_path);
22
- const package_json_src = await fs.readFile(path.join(plugin_dir, "package.json"));
23
- if (!package_json_src) {
24
- throw new Error("There is no package.json.");
25
- }
26
- const package_json = JSON.parse(package_json_src);
27
- if (!package_json.bin) {
28
- throw new Error("There is no bin defined.");
29
- }
30
- const bin_value = typeof package_json.bin === "string" ? package_json.bin : Object.values(package_json.bin)[0];
31
- const native_bin = path.join(plugin_dir, bin_value);
32
- if (preferWasm) {
33
- try {
34
- const wasm_dir = find_module(`${plugin_name}-wasm`, config_path);
35
- return {
36
- executable: path.join(wasm_dir, "bin", `${plugin_name}.wasm`),
37
- directory: plugin_dir
38
- };
39
- } catch {
40
- }
41
- }
42
- return {
43
- executable: native_bin,
44
- directory: plugin_dir
45
- };
22
+ plugin_dir = find_module(plugin_name, config_path);
46
23
  } catch (e) {
47
- const err = new Error(
48
- `Could not find plugin: ${plugin_name}. Are you sure its installed? If so, please open a ticket on GitHub. ${e}`
24
+ throw new Error(
25
+ `Could not find plugin: ${plugin_name}. Are you sure it's installed? If so, please open a ticket on GitHub. ${e}`
49
26
  );
50
- throw err;
51
27
  }
28
+ const package_json_src = await fs.readFile(path.join(plugin_dir, "package.json"));
29
+ if (!package_json_src) {
30
+ throw new Error(
31
+ `Found package '${plugin_name}' but could not read its package.json at ${plugin_dir}.`
32
+ );
33
+ }
34
+ const package_json = JSON.parse(package_json_src);
35
+ if (!package_json.bin) {
36
+ throw new Error(
37
+ `Found package '${plugin_name}' but it has no bin field in its package.json. Houdini plugins are executables \u2014 add a "bin" entry pointing to the plugin's entry point. If this is a local monorepo package, this is the most likely cause.`
38
+ );
39
+ }
40
+ const bin_value = typeof package_json.bin === "string" ? package_json.bin : Object.values(package_json.bin)[0];
41
+ const native_bin = path.join(plugin_dir, bin_value);
42
+ if (preferWasm) {
43
+ try {
44
+ const wasm_dir = find_module(`${plugin_name}-wasm`, config_path);
45
+ return {
46
+ executable: path.join(wasm_dir, "bin", `${plugin_name}.wasm`),
47
+ directory: plugin_dir
48
+ };
49
+ } catch {
50
+ }
51
+ }
52
+ return {
53
+ executable: native_bin,
54
+ directory: plugin_dir
55
+ };
52
56
  }
53
57
  function find_module(pkg, config_path) {
54
58
  try {
@@ -1,6 +1,6 @@
1
1
  import { type Db } from '../lib/db.js';
2
2
  export type { Db } from '../lib/db.js';
3
- export type PipelineHook = 'config' | 'afterLoad' | 'schema' | 'extractDocuments' | 'afterExtract' | 'beforeValidate' | 'validate' | 'afterValidate' | 'beforeGenerate' | 'generateDocuments' | 'generateRuntime' | 'afterGenerate';
3
+ export type PipelineHook = 'config' | 'afterLoad' | 'schema' | 'extractDocuments' | 'afterExtract' | 'beforeValidate' | 'validate' | 'afterValidate' | 'beforeGenerate' | 'generateDocuments' | 'generateRuntime' | 'afterGenerate' | 'environment' | 'indexFile';
4
4
  export type PluginContext = {
5
5
  taskId: string;
6
6
  pluginDirectory: string;
@@ -9,12 +9,16 @@ export type PluginContext = {
9
9
  parallel?: boolean;
10
10
  }): Promise<Record<string, any>>;
11
11
  };
12
- export type HookHandler = (ctx: PluginContext, payload: Record<string, any>) => Promise<Record<string, any> | undefined> | Record<string, any> | undefined;
12
+ export type TransformFn = (source: string, content: string) => Promise<string> | string;
13
+ export type HookHandler = (ctx: PluginContext, payload: Record<string, any>) => Promise<Record<string, any> | string[] | string | undefined> | Record<string, any> | string[] | string | undefined;
13
14
  export type NodePluginConfig = {
14
15
  name: string;
15
16
  order: 'before' | 'after' | 'core';
16
17
  hooks: Partial<Record<PipelineHook, HookHandler>>;
17
18
  includeRuntime?: string;
19
+ staticRuntime?: string;
20
+ transformRuntime?: TransformFn;
21
+ transformStaticRuntime?: TransformFn;
18
22
  configModule?: string;
19
23
  clientPlugins?: Record<string, any>;
20
24
  };
@@ -1,7 +1,9 @@
1
+ import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
1
2
  import http from "node:http";
3
+ import { dirname, join } from "node:path";
2
4
  import { createInterface } from "node:readline";
3
- import { openDb } from "../lib/db.js";
4
5
  import { WebSocketServer } from "ws";
6
+ import { openDb } from "../lib/db.js";
5
7
  class PluginError extends Error {
6
8
  detail;
7
9
  locations;
@@ -22,14 +24,17 @@ function plugin(config) {
22
24
  }
23
25
  }
24
26
  async function runStdio(config, databasePath, pluginKey) {
27
+ const resolvedName = pluginKey || config.name;
25
28
  const { pending, invokeCounter, rl } = makeStdioChannel();
29
+ const wireHooks = registeredHookNames(config).map(toWireName);
26
30
  const reg = {
27
31
  type: "register",
28
- name: pluginKey || config.name,
29
- hooks: hookKeys(config).map(toWireName),
32
+ name: resolvedName,
33
+ hooks: wireHooks,
30
34
  order: config.order
31
35
  };
32
36
  if (config.includeRuntime !== void 0) reg.includeRuntime = config.includeRuntime;
37
+ if (config.staticRuntime !== void 0) reg.includeStaticRuntime = config.staticRuntime;
33
38
  if (config.configModule !== void 0) reg.configModule = config.configModule;
34
39
  if (config.clientPlugins !== void 0) reg.clientPlugins = JSON.stringify(config.clientPlugins);
35
40
  stdioWrite(reg);
@@ -49,7 +54,7 @@ async function runStdio(config, databasePath, pluginKey) {
49
54
  db: db2,
50
55
  invokeHook: makeInvokeHook(pending, invokeCounter, msg.taskId ?? "")
51
56
  };
52
- await dispatch(config, msg, ctx, (response) => stdioWrite(response));
57
+ await dispatch(config, resolvedName, msg, ctx, (response) => stdioWrite(response));
53
58
  } else if (msg.type === "invoke_result") {
54
59
  resolveInvoke(pending, msg);
55
60
  }
@@ -69,8 +74,9 @@ async function runWebSocket(config, databasePath, pluginKey) {
69
74
  process.stderr.write("node plugin: --database path is required in websocket mode\n");
70
75
  process.exit(1);
71
76
  }
77
+ const resolvedName = pluginKey || config.name;
72
78
  const db = await openDb(databasePath);
73
- const wireHooks = hookKeys(config).map(toWireName);
79
+ const wireHooks = registeredHookNames(config).map(toWireName);
74
80
  const wsInvokeHook = () => {
75
81
  throw new Error("invokeHook is not supported in websocket transport");
76
82
  };
@@ -98,7 +104,7 @@ async function runWebSocket(config, databasePath, pluginKey) {
98
104
  db,
99
105
  invokeHook: wsInvokeHook
100
106
  };
101
- await dispatch(config, msg, ctx, (response) => {
107
+ await dispatch(config, resolvedName, msg, ctx, (response) => {
102
108
  if (response.error) {
103
109
  res.writeHead(500, { "Content-Type": "application/json" });
104
110
  res.end(JSON.stringify(response.error));
@@ -134,7 +140,13 @@ async function runWebSocket(config, databasePath, pluginKey) {
134
140
  db,
135
141
  invokeHook: wsInvokeHook
136
142
  };
137
- await dispatch(config, msg, ctx, (response) => ws.send(JSON.stringify(response)));
143
+ await dispatch(
144
+ config,
145
+ resolvedName,
146
+ msg,
147
+ ctx,
148
+ (response) => ws.send(JSON.stringify(response))
149
+ );
138
150
  });
139
151
  ws.on("close", () => {
140
152
  db.close();
@@ -150,14 +162,15 @@ async function runWebSocket(config, databasePath, pluginKey) {
150
162
  server.listen(0, () => {
151
163
  const port = server.address().port;
152
164
  db.run(
153
- `INSERT INTO plugins (name, hooks, port, plugin_order, include_runtime, config_module, client_plugins)
154
- VALUES (?, ?, ?, ?, ?, ?, ?)`,
165
+ `INSERT INTO plugins (name, hooks, port, plugin_order, include_runtime, include_static_runtime, config_module, client_plugins)
166
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
155
167
  [
156
- pluginKey || config.name,
168
+ resolvedName,
157
169
  JSON.stringify(wireHooks),
158
170
  port,
159
171
  config.order,
160
172
  config.includeRuntime ?? null,
173
+ config.staticRuntime ?? null,
161
174
  config.configModule ?? null,
162
175
  config.clientPlugins ? JSON.stringify(config.clientPlugins) : null
163
176
  ]
@@ -167,6 +180,153 @@ async function runWebSocket(config, databasePath, pluginKey) {
167
180
  process.on("SIGINT", () => shutdown(db, server));
168
181
  process.on("SIGTERM", () => shutdown(db, server));
169
182
  }
183
+ async function dispatch(config, pluginName, msg, ctx, send) {
184
+ const normalized = msg.hook.toLowerCase();
185
+ const payload = msg.payload ?? {};
186
+ try {
187
+ let result;
188
+ switch (normalized) {
189
+ case "config": {
190
+ const handler = config.hooks.config;
191
+ result = handler ? await handler(ctx, payload) : void 0;
192
+ break;
193
+ }
194
+ case "afterload": {
195
+ result = await dispatchAfterLoad(config, pluginName, ctx, payload);
196
+ break;
197
+ }
198
+ case "generateruntime": {
199
+ result = await dispatchGenerateRuntime(config, pluginName, ctx, payload);
200
+ break;
201
+ }
202
+ case "indexfile": {
203
+ await dispatchIndexFile(config, pluginName, ctx, payload);
204
+ result = void 0;
205
+ break;
206
+ }
207
+ default: {
208
+ const hookKey = Object.keys(config.hooks).find(
209
+ (k) => k.toLowerCase() === normalized
210
+ );
211
+ const handler = hookKey ? config.hooks[hookKey] : void 0;
212
+ if (!handler) {
213
+ send({
214
+ id: msg.id,
215
+ type: "response",
216
+ error: { message: `no handler for hook ${msg.hook}` }
217
+ });
218
+ return;
219
+ }
220
+ result = await handler(ctx, payload);
221
+ }
222
+ }
223
+ send({ id: msg.id, type: "response", result: result ?? {} });
224
+ } catch (err) {
225
+ send({ id: msg.id, type: "response", error: serializeError(err) });
226
+ }
227
+ }
228
+ async function dispatchAfterLoad(config, pluginName, ctx, payload) {
229
+ if (config.hooks.config) {
230
+ const defaults = await config.hooks.config(ctx, payload);
231
+ if (defaults !== void 0) {
232
+ ctx.db.run("UPDATE plugins SET config = $config WHERE name = $name", {
233
+ $config: JSON.stringify(defaults),
234
+ $name: pluginName
235
+ });
236
+ }
237
+ }
238
+ if (config.staticRuntime) {
239
+ const { projectRoot, runtimeDir } = readProjectConfig(ctx.db);
240
+ const src = join(ctx.pluginDirectory, config.staticRuntime);
241
+ const dst = pluginStaticRuntimeDir(projectRoot, runtimeDir, pluginName);
242
+ await recursiveCopy(src, dst, config.transformStaticRuntime);
243
+ }
244
+ if (config.hooks.afterLoad) {
245
+ return await config.hooks.afterLoad(ctx, payload);
246
+ }
247
+ return void 0;
248
+ }
249
+ async function dispatchGenerateRuntime(config, pluginName, ctx, payload) {
250
+ const paths = [];
251
+ if (config.includeRuntime !== void 0) {
252
+ const { projectRoot, runtimeDir } = readProjectConfig(ctx.db);
253
+ const src = join(ctx.pluginDirectory, config.includeRuntime);
254
+ const dst = pluginRuntimeDir(projectRoot, runtimeDir, pluginName);
255
+ const copied = await recursiveCopy(src, dst, config.transformRuntime);
256
+ paths.push(...copied);
257
+ }
258
+ if (config.hooks.generateRuntime) {
259
+ const result = await config.hooks.generateRuntime(ctx, payload);
260
+ if (Array.isArray(result)) {
261
+ paths.push(...result);
262
+ }
263
+ }
264
+ return paths;
265
+ }
266
+ async function dispatchIndexFile(config, pluginName, ctx, payload) {
267
+ if (!config.hooks.indexFile) return;
268
+ const { projectRoot, runtimeDir } = readProjectConfig(ctx.db);
269
+ const targetPath = join(projectRoot, runtimeDir, "index.ts");
270
+ const content = await config.hooks.indexFile(ctx, { ...payload, filepath: targetPath });
271
+ if (typeof content === "string" && content) {
272
+ const existing = existsSync(targetPath) ? readFileSync(targetPath, "utf8") : "";
273
+ mkdirSync(dirname(targetPath), { recursive: true });
274
+ writeFileSync(targetPath, existing + "\n" + content, "utf8");
275
+ }
276
+ }
277
+ function readProjectConfig(db) {
278
+ const row = db.get(
279
+ "SELECT project_root, runtime_dir FROM config LIMIT 1"
280
+ );
281
+ return { projectRoot: row?.project_root ?? "", runtimeDir: row?.runtime_dir ?? "" };
282
+ }
283
+ function pluginRuntimeDir(projectRoot, runtimeDir, name) {
284
+ if (name === "houdini-core") {
285
+ return join(projectRoot, runtimeDir, "runtime");
286
+ }
287
+ return join(projectRoot, runtimeDir, "plugins", name, "runtime");
288
+ }
289
+ function pluginStaticRuntimeDir(projectRoot, runtimeDir, name) {
290
+ return join(projectRoot, runtimeDir, "plugins", name, "static");
291
+ }
292
+ async function recursiveCopy(src, dst, transform) {
293
+ const written = [];
294
+ if (!existsSync(src)) return written;
295
+ const walk = async (srcDir, dstDir) => {
296
+ mkdirSync(dstDir, { recursive: true });
297
+ for (const entry of readdirSync(srcDir)) {
298
+ const srcPath = join(srcDir, entry);
299
+ const dstPath = join(dstDir, entry);
300
+ if (statSync(srcPath).isDirectory()) {
301
+ await walk(srcPath, dstPath);
302
+ } else {
303
+ let content = readFileSync(srcPath, "utf8");
304
+ if (transform) content = await transform(srcPath, content);
305
+ mkdirSync(dirname(dstPath), { recursive: true });
306
+ writeFileSync(dstPath, content, "utf8");
307
+ written.push(dstPath);
308
+ }
309
+ }
310
+ };
311
+ await walk(src, dst);
312
+ return written;
313
+ }
314
+ function registeredHookNames(config) {
315
+ const names = /* @__PURE__ */ new Set();
316
+ names.add("config");
317
+ if (config.staticRuntime || config.hooks.afterLoad || config.hooks.config) {
318
+ names.add("afterLoad");
319
+ }
320
+ if (config.includeRuntime !== void 0 || config.hooks.generateRuntime || config.configModule !== void 0) {
321
+ names.add("generateRuntime");
322
+ }
323
+ for (const key of Object.keys(config.hooks)) {
324
+ if (typeof config.hooks[key] === "function") {
325
+ names.add(key);
326
+ }
327
+ }
328
+ return Array.from(names);
329
+ }
170
330
  function makeStdioChannel() {
171
331
  const pending = /* @__PURE__ */ new Map();
172
332
  const invokeCounter = { value: 0 };
@@ -206,32 +366,6 @@ function shutdown(db, server) {
206
366
  server.close();
207
367
  process.exit(0);
208
368
  }
209
- async function dispatch(config, msg, ctx, send) {
210
- const normalizedHook = msg.hook.toLowerCase();
211
- const hookKey = Object.keys(config.hooks).find(
212
- (k) => k.toLowerCase() === normalizedHook
213
- );
214
- const handler = hookKey ? config.hooks[hookKey] : void 0;
215
- if (!handler) {
216
- send({
217
- id: msg.id,
218
- type: "response",
219
- error: { message: `no handler for hook ${msg.hook}` }
220
- });
221
- return;
222
- }
223
- try {
224
- const result = await handler(ctx, msg.payload ?? {});
225
- send({ id: msg.id, type: "response", result: result ?? {} });
226
- } catch (err) {
227
- send({ id: msg.id, type: "response", error: serializeError(err) });
228
- }
229
- }
230
- function hookKeys(config) {
231
- return Object.keys(config.hooks).filter(
232
- (k) => typeof config.hooks[k] === "function"
233
- );
234
- }
235
369
  function parseArgs() {
236
370
  const argv = process.argv;
237
371
  let transport = "websocket";
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "houdini",
3
- "version": "2.0.0-next.31",
3
+ "version": "2.0.0-next.33",
4
4
  "description": "The disappearing GraphQL clients",
5
5
  "keywords": [
6
6
  "typescript",
@@ -54,9 +54,11 @@ export declare class Cache {
54
54
  hydrate(...args: Parameters<InMemoryStorage['hydrate']>): void;
55
55
  clearLayer(layerID: Layer['id']): void;
56
56
  reset(): void;
57
+ getEpoch(): number;
57
58
  }
58
59
  declare class CacheInternal {
59
60
  disabled: boolean;
61
+ epoch: number;
60
62
  _config?: ConfigFile;
61
63
  storage: InMemoryStorage;
62
64
  subscriptions: InMemorySubscriptions;
@@ -203,10 +203,16 @@ class Cache {
203
203
  this._internal_unstable.storage.reset();
204
204
  this.#notifySubscribers(subSpecs);
205
205
  }
206
+ // returns the current notification generation; fragment references carry this value
207
+ // so hooks can detect which epoch of data they were rendered with
208
+ getEpoch() {
209
+ return this._internal_unstable.epoch;
210
+ }
206
211
  #notifySubscribers(subs) {
207
212
  if (subs.length === 0) {
208
213
  return;
209
214
  }
215
+ this._internal_unstable.epoch++;
210
216
  const notified = [];
211
217
  for (const spec of subs) {
212
218
  if (!notified.includes(spec.set)) {
@@ -226,6 +232,9 @@ class Cache {
226
232
  class CacheInternal {
227
233
  // for server-side requests we need to be able to flag the cache as disabled so we dont write to it
228
234
  disabled = false;
235
+ // monotonically increasing counter incremented on every cache notification flush;
236
+ // threaded into fragment references so hooks know which generation of data they hold
237
+ epoch = 0;
229
238
  _config;
230
239
  storage;
231
240
  subscriptions;
@@ -331,9 +340,7 @@ class CacheInternal {
331
340
  }
332
341
  }
333
342
  }
334
- if (updates && applyUpdates?.includes("prepend") && ["endCursor", "hasNextPage"].includes(key)) {
335
- newValue = previousValue;
336
- } else if (updates && applyUpdates?.includes("append") && ["startCursor", "hasPreviousPage"].includes(key)) {
343
+ if (updates && applyUpdates?.some((op) => !updates.includes(op))) {
337
344
  newValue = previousValue;
338
345
  }
339
346
  const valueChanged = !deepEquals(newValue, previousValue);
@@ -149,8 +149,12 @@ class InMemorySubscriptions {
149
149
  keyRaw,
150
150
  selection: innerSelection,
151
151
  list,
152
- filters
152
+ filters,
153
+ visible
153
154
  } = selection;
155
+ if (!visible) {
156
+ continue;
157
+ }
154
158
  const key = evaluateKey(keyRaw, variables);
155
159
  const fieldSelection = innerSelection ? getFieldsForType(innerSelection, parentType, false) : void 0;
156
160
  this.addFieldSubscription({