houdini 1.5.3 → 1.5.5
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-cjs/index.js +420 -546
- package/build/cmd-esm/index.js +270 -396
- package/build/codegen/generators/runtime/index.d.ts +2 -7
- package/build/codegen/generators/runtime/pluginRuntime.d.ts +8 -1
- package/build/codegen-cjs/index.js +389 -389
- package/build/codegen-esm/index.js +239 -239
- package/build/lib/router/conventions.d.ts +1 -1
- package/build/lib/router/manifest.d.ts +1 -1
- package/build/lib/typescript.d.ts +1 -1
- package/build/lib-cjs/index.js +666 -664
- package/build/lib-esm/index.js +666 -664
- package/build/test-cjs/index.js +398 -398
- package/build/test-esm/index.js +248 -248
- package/build/vite/imports.d.ts +2 -2
- package/build/vite-cjs/index.js +588 -587
- package/build/vite-esm/index.js +463 -462
- package/package.json +1 -1
package/build/lib-esm/index.js
CHANGED
|
@@ -59797,7 +59797,7 @@ function mergeSchemas(config) {
|
|
|
59797
59797
|
|
|
59798
59798
|
// src/lib/config.ts
|
|
59799
59799
|
var import_minimatch8 = __toESM(require_minimatch(), 1);
|
|
59800
|
-
import * as
|
|
59800
|
+
import * as graphql5 from "graphql";
|
|
59801
59801
|
import { fileURLToPath as fileURLToPath3, pathToFileURL } from "node:url";
|
|
59802
59802
|
|
|
59803
59803
|
// src/runtime/imports/config.ts
|
|
@@ -67210,43 +67210,43 @@ __export(conventions_exports, {
|
|
|
67210
67210
|
vite_render_path: () => vite_render_path
|
|
67211
67211
|
});
|
|
67212
67212
|
function router_path(config) {
|
|
67213
|
-
return
|
|
67213
|
+
return join2(base_dir(config), "Router.jsx");
|
|
67214
67214
|
}
|
|
67215
67215
|
function page_entry_path(config, id, base) {
|
|
67216
|
-
return
|
|
67216
|
+
return join2(page_entries_dir(config, base), `${id}.jsx`);
|
|
67217
67217
|
}
|
|
67218
67218
|
function server_adapter_path(config, base) {
|
|
67219
|
-
return
|
|
67219
|
+
return join2(units_dir(config, base), "render", "server.js");
|
|
67220
67220
|
}
|
|
67221
67221
|
function adapter_config_path(config, base) {
|
|
67222
|
-
return
|
|
67222
|
+
return join2(units_dir(config, base), "render", "config.js");
|
|
67223
67223
|
}
|
|
67224
67224
|
function vite_render_path(config, base) {
|
|
67225
|
-
return
|
|
67225
|
+
return join2(units_dir(config, base), "render", "vite.js");
|
|
67226
67226
|
}
|
|
67227
67227
|
function app_component_path(config, base) {
|
|
67228
|
-
return
|
|
67228
|
+
return join2(units_dir(config, base), "render", "App.jsx");
|
|
67229
67229
|
}
|
|
67230
67230
|
function page_unit_path(config, id, base) {
|
|
67231
|
-
return
|
|
67231
|
+
return join2(page_units_dir(config, base), `${id}.jsx`);
|
|
67232
67232
|
}
|
|
67233
67233
|
function layout_unit_path(config, id, base) {
|
|
67234
|
-
return
|
|
67234
|
+
return join2(layout_units_dir(config, base), `${id}.jsx`);
|
|
67235
67235
|
}
|
|
67236
67236
|
function componentField_unit_path(config, id, base) {
|
|
67237
|
-
return
|
|
67237
|
+
return join2(units_dir(config, base), "componentFields", `wrapper_${id}.jsx`);
|
|
67238
67238
|
}
|
|
67239
67239
|
function fallback_unit_path(config, which, id, base) {
|
|
67240
|
-
return
|
|
67240
|
+
return join2(fallbacks_units_dir(config, which, base), `${id}.jsx`);
|
|
67241
67241
|
}
|
|
67242
67242
|
async function read_pageQuery(base) {
|
|
67243
|
-
const target =
|
|
67244
|
-
return [target, await
|
|
67243
|
+
const target = join2(base, "+page.gql");
|
|
67244
|
+
return [target, await readFile(target)];
|
|
67245
67245
|
}
|
|
67246
67246
|
async function read_pageView(base) {
|
|
67247
67247
|
for (const name of ["+page.tsx", "+page.jsx"]) {
|
|
67248
|
-
let target =
|
|
67249
|
-
let result = await
|
|
67248
|
+
let target = join2(base, name);
|
|
67249
|
+
let result = await readFile(target);
|
|
67250
67250
|
if (result) {
|
|
67251
67251
|
return [target, result];
|
|
67252
67252
|
}
|
|
@@ -67254,13 +67254,13 @@ async function read_pageView(base) {
|
|
|
67254
67254
|
return [null, null];
|
|
67255
67255
|
}
|
|
67256
67256
|
async function read_layoutQuery(base) {
|
|
67257
|
-
const target =
|
|
67258
|
-
return [target, await
|
|
67257
|
+
const target = join2(base, "+layout.gql");
|
|
67258
|
+
return [target, await readFile(target)];
|
|
67259
67259
|
}
|
|
67260
67260
|
async function read_layoutView(base) {
|
|
67261
67261
|
for (const name of ["+layout.tsx", "+layout.jsx"]) {
|
|
67262
|
-
let target =
|
|
67263
|
-
let result = await
|
|
67262
|
+
let target = join2(base, name);
|
|
67263
|
+
let result = await readFile(target);
|
|
67264
67264
|
if (result) {
|
|
67265
67265
|
return [target, result];
|
|
67266
67266
|
}
|
|
@@ -67268,10 +67268,10 @@ async function read_layoutView(base) {
|
|
|
67268
67268
|
return [null, null];
|
|
67269
67269
|
}
|
|
67270
67270
|
function temp_dir(config, key) {
|
|
67271
|
-
return
|
|
67271
|
+
return join2(config.rootDir, "temp", key);
|
|
67272
67272
|
}
|
|
67273
67273
|
function router_index_path(config) {
|
|
67274
|
-
return
|
|
67274
|
+
return join2(config.routesDir, "..", "+index.jsx");
|
|
67275
67275
|
}
|
|
67276
67276
|
function is_layout(path4) {
|
|
67277
67277
|
return path4.endsWith("+layout.tsx") || path4.endsWith("+layout.jsx");
|
|
@@ -67294,190 +67294,591 @@ function page_id(path4) {
|
|
|
67294
67294
|
return copy;
|
|
67295
67295
|
}
|
|
67296
67296
|
function page_entries_dir(config, base) {
|
|
67297
|
-
return
|
|
67297
|
+
return join2(units_dir(config, base), "entries");
|
|
67298
67298
|
}
|
|
67299
67299
|
function page_units_dir(config, base) {
|
|
67300
|
-
return
|
|
67300
|
+
return join2(units_dir(config, base), "pages");
|
|
67301
67301
|
}
|
|
67302
67302
|
function layout_units_dir(config, base) {
|
|
67303
|
-
return
|
|
67303
|
+
return join2(units_dir(config, base), "layouts");
|
|
67304
67304
|
}
|
|
67305
67305
|
function fallbacks_units_dir(config, which, base) {
|
|
67306
|
-
return
|
|
67306
|
+
return join2(units_dir(config, base), "fallbacks", which);
|
|
67307
67307
|
}
|
|
67308
67308
|
function units_dir(config, base = base_dir(config)) {
|
|
67309
|
-
return
|
|
67309
|
+
return join2(base, "units");
|
|
67310
67310
|
}
|
|
67311
67311
|
function base_dir(config) {
|
|
67312
67312
|
return config.pluginDirectory("houdini-react");
|
|
67313
67313
|
}
|
|
67314
67314
|
function serialized_manifest_path(config, base = base_dir(config)) {
|
|
67315
|
-
return
|
|
67315
|
+
return join2(base, "manifest.json");
|
|
67316
67316
|
}
|
|
67317
67317
|
|
|
67318
67318
|
// src/lib/router/manifest.ts
|
|
67319
67319
|
var t2 = __toESM(require_lib5(), 1);
|
|
67320
|
-
import * as
|
|
67321
|
-
|
|
67322
|
-
|
|
67323
|
-
|
|
67324
|
-
|
|
67325
|
-
|
|
67326
|
-
|
|
67327
|
-
|
|
67328
|
-
|
|
67329
|
-
|
|
67330
|
-
|
|
67331
|
-
layout_queries: {},
|
|
67332
|
-
artifacts: [],
|
|
67333
|
-
local_schema: false,
|
|
67334
|
-
local_yoga: false
|
|
67335
|
-
},
|
|
67336
|
-
queries: [],
|
|
67337
|
-
layouts: [],
|
|
67338
|
-
variables: {}
|
|
67339
|
-
});
|
|
67340
|
-
if (args.includeArtifacts) {
|
|
67341
|
-
try {
|
|
67342
|
-
for (const artifactPath of await fs_exports.readdir(args.config.artifactDirectory)) {
|
|
67343
|
-
if (!artifactPath.endsWith(".js") || artifactPath === "index.js") {
|
|
67344
|
-
continue;
|
|
67345
|
-
}
|
|
67346
|
-
manifest.artifacts.push(artifactPath.substring(0, artifactPath.length - 3));
|
|
67347
|
-
}
|
|
67348
|
-
} catch {
|
|
67320
|
+
import * as graphql3 from "graphql";
|
|
67321
|
+
|
|
67322
|
+
// src/runtime/router/match.ts
|
|
67323
|
+
var param_pattern = /^(\[)?(\.\.\.)?(\w+)(?:=(\w+))?(\])?$/;
|
|
67324
|
+
function find_match(config, manifest, current, allowNull = true) {
|
|
67325
|
+
let match2 = null;
|
|
67326
|
+
let matchVariables = null;
|
|
67327
|
+
for (const page of Object.values(manifest.pages)) {
|
|
67328
|
+
const urlMatch = current.match(page.pattern);
|
|
67329
|
+
if (!urlMatch) {
|
|
67330
|
+
continue;
|
|
67349
67331
|
}
|
|
67332
|
+
match2 = page;
|
|
67333
|
+
matchVariables = exec(urlMatch, page.params) || {};
|
|
67334
|
+
break;
|
|
67350
67335
|
}
|
|
67351
|
-
|
|
67352
|
-
|
|
67353
|
-
|
|
67354
|
-
|
|
67355
|
-
|
|
67356
|
-
|
|
67357
|
-
|
|
67358
|
-
|
|
67336
|
+
if (!match2 && !allowNull) {
|
|
67337
|
+
throw new Error("404");
|
|
67338
|
+
}
|
|
67339
|
+
let variables = {
|
|
67340
|
+
...matchVariables
|
|
67341
|
+
};
|
|
67342
|
+
for (const document of Object.values(match2?.documents ?? {})) {
|
|
67343
|
+
for (const [variable, { type }] of Object.entries(document.variables)) {
|
|
67344
|
+
if (matchVariables?.[variable]) {
|
|
67345
|
+
variables[variable] = parseScalar(config, type, matchVariables[variable]);
|
|
67359
67346
|
}
|
|
67360
67347
|
}
|
|
67361
|
-
} catch {
|
|
67362
67348
|
}
|
|
67363
|
-
return
|
|
67349
|
+
return [match2, variables];
|
|
67364
67350
|
}
|
|
67365
|
-
|
|
67366
|
-
const
|
|
67367
|
-
|
|
67368
|
-
|
|
67369
|
-
|
|
67370
|
-
|
|
67371
|
-
|
|
67372
|
-
|
|
67373
|
-
|
|
67374
|
-
|
|
67375
|
-
|
|
67376
|
-
|
|
67377
|
-
|
|
67378
|
-
|
|
67379
|
-
|
|
67380
|
-
|
|
67381
|
-
|
|
67382
|
-
|
|
67383
|
-
|
|
67384
|
-
|
|
67385
|
-
|
|
67386
|
-
|
|
67387
|
-
|
|
67388
|
-
|
|
67389
|
-
|
|
67390
|
-
|
|
67391
|
-
|
|
67392
|
-
type: "layout",
|
|
67393
|
-
contents: layoutQueryContents,
|
|
67394
|
-
variables
|
|
67395
|
-
});
|
|
67396
|
-
newLayoutQueries = [...args.queries, layoutQuery.name];
|
|
67397
|
-
}
|
|
67398
|
-
if (layoutViewContents) {
|
|
67399
|
-
layout = await add_view({
|
|
67400
|
-
url: args.url,
|
|
67401
|
-
path: layoutViewPath,
|
|
67402
|
-
project: args.project,
|
|
67403
|
-
type: "layout",
|
|
67404
|
-
contents: layoutViewContents,
|
|
67405
|
-
layouts: args.layouts,
|
|
67406
|
-
queries: newLayoutQueries,
|
|
67407
|
-
config: args.config,
|
|
67408
|
-
variables
|
|
67409
|
-
});
|
|
67410
|
-
newLayouts = [...args.layouts, page_id(layout.url)];
|
|
67411
|
-
}
|
|
67412
|
-
if (pageQueryContents) {
|
|
67413
|
-
pageQuery = await add_query({
|
|
67414
|
-
path: pageQueryPath,
|
|
67415
|
-
config: args.config,
|
|
67416
|
-
url: args.url,
|
|
67417
|
-
project: args.project,
|
|
67418
|
-
type: "page",
|
|
67419
|
-
contents: pageQueryContents,
|
|
67420
|
-
variables
|
|
67421
|
-
});
|
|
67422
|
-
}
|
|
67423
|
-
if (pageViewContents) {
|
|
67424
|
-
await add_view({
|
|
67425
|
-
path: pageViewPath,
|
|
67426
|
-
url: args.url.substring(0, args.url.length - 1) || "/",
|
|
67427
|
-
project: args.project,
|
|
67428
|
-
type: "page",
|
|
67429
|
-
contents: pageViewContents,
|
|
67430
|
-
layouts: newLayouts,
|
|
67431
|
-
queries: pageQuery ? [...newLayoutQueries, pageQuery.name] : newLayoutQueries,
|
|
67432
|
-
config: args.config,
|
|
67433
|
-
variables
|
|
67434
|
-
});
|
|
67435
|
-
}
|
|
67436
|
-
await Promise.all(
|
|
67437
|
-
directory_contents.map((dir) => {
|
|
67438
|
-
if (!dir.isDirectory()) {
|
|
67351
|
+
function parse_page_pattern(id) {
|
|
67352
|
+
const params = [];
|
|
67353
|
+
const pattern = id === "/" ? /^\/$/ : new RegExp(
|
|
67354
|
+
`^${get_route_segments(id).map((segment) => {
|
|
67355
|
+
const rest_match = /^\[\.\.\.(\w+)(?:=(\w+))?\]$/.exec(segment);
|
|
67356
|
+
if (rest_match) {
|
|
67357
|
+
params.push({
|
|
67358
|
+
name: rest_match[1],
|
|
67359
|
+
matcher: rest_match[2],
|
|
67360
|
+
optional: false,
|
|
67361
|
+
rest: true,
|
|
67362
|
+
chained: true
|
|
67363
|
+
});
|
|
67364
|
+
return "(?:/(.*))?";
|
|
67365
|
+
}
|
|
67366
|
+
const optional_match = /^\[\[(\w+)(?:=(\w+))?\]\]$/.exec(segment);
|
|
67367
|
+
if (optional_match) {
|
|
67368
|
+
params.push({
|
|
67369
|
+
name: optional_match[1],
|
|
67370
|
+
matcher: optional_match[2],
|
|
67371
|
+
optional: true,
|
|
67372
|
+
rest: false,
|
|
67373
|
+
chained: true
|
|
67374
|
+
});
|
|
67375
|
+
return "(?:/([^/]+))?";
|
|
67376
|
+
}
|
|
67377
|
+
if (!segment) {
|
|
67439
67378
|
return;
|
|
67440
67379
|
}
|
|
67441
|
-
|
|
67442
|
-
|
|
67443
|
-
|
|
67444
|
-
|
|
67445
|
-
|
|
67446
|
-
|
|
67447
|
-
|
|
67448
|
-
|
|
67449
|
-
|
|
67380
|
+
const parts = segment.split(/\[(.+?)\](?!\])/);
|
|
67381
|
+
const result = parts.map((content, i2) => {
|
|
67382
|
+
if (i2 % 2) {
|
|
67383
|
+
if (content.startsWith("x+")) {
|
|
67384
|
+
return escape3(
|
|
67385
|
+
String.fromCharCode(parseInt(content.slice(2), 16))
|
|
67386
|
+
);
|
|
67387
|
+
}
|
|
67388
|
+
if (content.startsWith("u+")) {
|
|
67389
|
+
return escape3(
|
|
67390
|
+
String.fromCharCode(
|
|
67391
|
+
...content.slice(2).split("-").map((code) => parseInt(code, 16))
|
|
67392
|
+
)
|
|
67393
|
+
);
|
|
67394
|
+
}
|
|
67395
|
+
const match2 = param_pattern.exec(content);
|
|
67396
|
+
if (!match2) {
|
|
67397
|
+
throw new Error(
|
|
67398
|
+
`Invalid param: ${content}. Params and matcher names can only have underscores and alphanumeric characters.`
|
|
67399
|
+
);
|
|
67400
|
+
}
|
|
67401
|
+
const [, is_optional, is_rest, name, matcher] = match2;
|
|
67402
|
+
params.push({
|
|
67403
|
+
name,
|
|
67404
|
+
matcher,
|
|
67405
|
+
optional: !!is_optional,
|
|
67406
|
+
rest: !!is_rest,
|
|
67407
|
+
chained: is_rest ? i2 === 1 && parts[0] === "" : false
|
|
67408
|
+
});
|
|
67409
|
+
return is_rest ? "(.*?)" : is_optional ? "([^/]*)?" : "([^/]+?)";
|
|
67410
|
+
}
|
|
67411
|
+
return escape3(content);
|
|
67412
|
+
}).join("");
|
|
67413
|
+
return "/" + result;
|
|
67414
|
+
}).join("")}/?$`
|
|
67450
67415
|
);
|
|
67451
|
-
return
|
|
67416
|
+
return { pattern, params, page_id: id };
|
|
67452
67417
|
}
|
|
67453
|
-
|
|
67454
|
-
|
|
67455
|
-
|
|
67456
|
-
|
|
67457
|
-
|
|
67458
|
-
|
|
67459
|
-
|
|
67460
|
-
|
|
67418
|
+
function affects_path(segment) {
|
|
67419
|
+
return !/^\([^)]+\)$/.test(segment);
|
|
67420
|
+
}
|
|
67421
|
+
function get_route_segments(route) {
|
|
67422
|
+
return route.slice(1).split("/").filter(affects_path);
|
|
67423
|
+
}
|
|
67424
|
+
function exec(match2, params) {
|
|
67425
|
+
const result = {};
|
|
67426
|
+
const values = match2.slice(1);
|
|
67427
|
+
let buffered = "";
|
|
67428
|
+
for (let i2 = 0; i2 < (params || []).length; i2 += 1) {
|
|
67429
|
+
const param = params[i2];
|
|
67430
|
+
let value = values[i2];
|
|
67431
|
+
if (param.chained && param.rest && buffered) {
|
|
67432
|
+
value = value ? buffered + "/" + value : buffered;
|
|
67433
|
+
}
|
|
67434
|
+
buffered = "";
|
|
67435
|
+
if (value === void 0) {
|
|
67436
|
+
if (param.rest)
|
|
67437
|
+
result[param.name] = "";
|
|
67438
|
+
} else {
|
|
67439
|
+
result[param.name] = decodeURIComponent(value);
|
|
67440
|
+
}
|
|
67461
67441
|
}
|
|
67462
|
-
|
|
67463
|
-
|
|
67464
|
-
|
|
67465
|
-
|
|
67466
|
-
|
|
67467
|
-
|
|
67468
|
-
|
|
67469
|
-
|
|
67470
|
-
|
|
67471
|
-
|
|
67472
|
-
|
|
67473
|
-
|
|
67474
|
-
|
|
67475
|
-
)
|
|
67476
|
-
}
|
|
67477
|
-
|
|
67442
|
+
if (buffered)
|
|
67443
|
+
return;
|
|
67444
|
+
return result;
|
|
67445
|
+
}
|
|
67446
|
+
function escape3(str) {
|
|
67447
|
+
return str.normalize().replace(/[[\]]/g, "\\$&").replace(/%/g, "%25").replace(/\//g, "%2[Ff]").replace(/\?/g, "%3[Ff]").replace(/#/g, "%23").replace(/[.*+?^${}()|\\]/g, "\\$&");
|
|
67448
|
+
}
|
|
67449
|
+
|
|
67450
|
+
// src/lib/graphql.ts
|
|
67451
|
+
import * as graphql2 from "graphql";
|
|
67452
|
+
import crypto2 from "node:crypto";
|
|
67453
|
+
function getRootType(type) {
|
|
67454
|
+
if (graphql2.isNonNullType(type)) {
|
|
67455
|
+
return getRootType(type.ofType);
|
|
67456
|
+
}
|
|
67457
|
+
if (graphql2.isListType(type)) {
|
|
67458
|
+
return getRootType(type.ofType);
|
|
67459
|
+
}
|
|
67460
|
+
return type;
|
|
67461
|
+
}
|
|
67462
|
+
function processComponentFieldDirective(directive) {
|
|
67463
|
+
let field;
|
|
67464
|
+
let exportValue;
|
|
67465
|
+
let prop;
|
|
67466
|
+
let raw;
|
|
67467
|
+
for (const arg of directive.arguments ?? []) {
|
|
67468
|
+
if (arg.name.value === "field" && arg.value.kind === "StringValue") {
|
|
67469
|
+
field = arg.value.value;
|
|
67470
|
+
} else if (arg.name.value === "export" && arg.value.kind === "StringValue") {
|
|
67471
|
+
exportValue = arg.value.value;
|
|
67472
|
+
} else if (arg.name.value === "prop" && arg.value.kind === "StringValue") {
|
|
67473
|
+
prop = arg.value.value;
|
|
67474
|
+
} else if (arg.name.value === "raw" && arg.value.kind === "StringValue") {
|
|
67475
|
+
raw = arg.value.value;
|
|
67476
|
+
}
|
|
67477
|
+
}
|
|
67478
|
+
const missing = [];
|
|
67479
|
+
if (!field) {
|
|
67480
|
+
missing.push("field");
|
|
67481
|
+
}
|
|
67482
|
+
if (!prop) {
|
|
67483
|
+
missing.push("prop");
|
|
67484
|
+
}
|
|
67485
|
+
if (missing.length > 0) {
|
|
67486
|
+
throw new Error(`missing arguments to @componentField: ${missing.join(", ")}`);
|
|
67487
|
+
}
|
|
67488
|
+
return {
|
|
67489
|
+
prop,
|
|
67490
|
+
field,
|
|
67491
|
+
raw,
|
|
67492
|
+
export: exportValue
|
|
67493
|
+
};
|
|
67494
|
+
}
|
|
67495
|
+
function hashOriginal({ document }) {
|
|
67496
|
+
return hashDocument(document.originalString);
|
|
67497
|
+
}
|
|
67498
|
+
function hashRaw({ document }) {
|
|
67499
|
+
return hashDocument(document.artifact?.raw);
|
|
67500
|
+
}
|
|
67501
|
+
function hashDocument(str) {
|
|
67502
|
+
return crypto2.createHash("sha256").update(str || "").digest("hex");
|
|
67503
|
+
}
|
|
67504
|
+
function parentField(ancestors) {
|
|
67505
|
+
return walkParentField([...ancestors].sort(() => -1));
|
|
67506
|
+
}
|
|
67507
|
+
function walkParentField(ancestors) {
|
|
67508
|
+
let head = ancestors.shift();
|
|
67509
|
+
if (Array.isArray(head) || head.kind === "SelectionSet") {
|
|
67510
|
+
return walkParentField(ancestors);
|
|
67511
|
+
}
|
|
67512
|
+
return head;
|
|
67513
|
+
}
|
|
67514
|
+
function parentTypeFromAncestors(schema, filepath, ancestors) {
|
|
67515
|
+
const parents = [...ancestors];
|
|
67516
|
+
parents.reverse();
|
|
67517
|
+
return walkAncestors(schema, filepath, parents);
|
|
67518
|
+
}
|
|
67519
|
+
function walkAncestors(schema, filepath, ancestors) {
|
|
67520
|
+
let head = ancestors.shift();
|
|
67521
|
+
if (Array.isArray(head)) {
|
|
67522
|
+
return walkAncestors(schema, filepath, ancestors);
|
|
67523
|
+
}
|
|
67524
|
+
if (!head) {
|
|
67525
|
+
throw new HoudiniError({ filepath, message: "Could not figure out type of field" });
|
|
67526
|
+
}
|
|
67527
|
+
if (head.kind === "OperationDefinition") {
|
|
67528
|
+
const operationType = {
|
|
67529
|
+
query: schema.getQueryType(),
|
|
67530
|
+
mutation: schema.getMutationType(),
|
|
67531
|
+
subscription: schema.getSubscriptionType()
|
|
67532
|
+
}[head.operation];
|
|
67533
|
+
if (!operationType) {
|
|
67534
|
+
throw new HoudiniError({ filepath, message: "Could not find operation type" });
|
|
67535
|
+
}
|
|
67536
|
+
return operationType;
|
|
67537
|
+
}
|
|
67538
|
+
if (head.kind === "FragmentDefinition") {
|
|
67539
|
+
const result = schema.getType(head.typeCondition.name.value);
|
|
67540
|
+
if (!result) {
|
|
67541
|
+
throw new HoudiniError({
|
|
67542
|
+
filepath,
|
|
67543
|
+
message: `Could not find definition for ${head.typeCondition.name.value} in the schema`
|
|
67544
|
+
});
|
|
67545
|
+
}
|
|
67546
|
+
return result;
|
|
67547
|
+
}
|
|
67548
|
+
if (head.kind === "FragmentSpread") {
|
|
67549
|
+
throw new Error("How the hell did this happen?");
|
|
67550
|
+
}
|
|
67551
|
+
const parent = walkAncestors(schema, filepath, ancestors);
|
|
67552
|
+
if (head.kind === "InlineFragment") {
|
|
67553
|
+
if (!head.typeCondition) {
|
|
67554
|
+
return parent;
|
|
67555
|
+
}
|
|
67556
|
+
const wrapper = schema.getType(head.typeCondition.name.value);
|
|
67557
|
+
if (!wrapper) {
|
|
67558
|
+
throw new HoudiniError({
|
|
67559
|
+
filepath,
|
|
67560
|
+
message: "Could not find type with name: " + head.typeCondition.name.value
|
|
67561
|
+
});
|
|
67562
|
+
}
|
|
67563
|
+
return wrapper;
|
|
67564
|
+
}
|
|
67565
|
+
if (head.kind === "SelectionSet") {
|
|
67566
|
+
return parent;
|
|
67567
|
+
}
|
|
67568
|
+
const field = parent.getFields()[head.name.value];
|
|
67569
|
+
if (!field) {
|
|
67570
|
+
throw new HoudiniError({
|
|
67571
|
+
filepath,
|
|
67572
|
+
message: `Could not find definition of ${head.name.value} in ${parent.toString()}`
|
|
67573
|
+
});
|
|
67574
|
+
}
|
|
67575
|
+
return getRootType(field.type);
|
|
67576
|
+
}
|
|
67577
|
+
function definitionFromAncestors(ancestors) {
|
|
67578
|
+
let parents = [...ancestors];
|
|
67579
|
+
parents.shift();
|
|
67580
|
+
let definition = parents.shift();
|
|
67581
|
+
while (Array.isArray(definition) && definition) {
|
|
67582
|
+
definition = parents.shift();
|
|
67583
|
+
}
|
|
67584
|
+
return { parents, definition };
|
|
67585
|
+
}
|
|
67586
|
+
function formatErrors(e2, afterError) {
|
|
67587
|
+
const errors = Array.isArray(e2) ? e2 : [e2];
|
|
67588
|
+
for (const error of errors) {
|
|
67589
|
+
if ("filepath" in error && error.filepath) {
|
|
67590
|
+
const relative2 = relative(process.cwd(), error.filepath);
|
|
67591
|
+
console.error(`\u274C Encountered error in ${relative2}`);
|
|
67592
|
+
if (error.message) {
|
|
67593
|
+
console.error(error.message);
|
|
67594
|
+
}
|
|
67595
|
+
} else {
|
|
67596
|
+
console.error(`\u274C ${error.message}`);
|
|
67597
|
+
if ("description" in error && error.description) {
|
|
67598
|
+
console.error(`${error.description}`);
|
|
67599
|
+
}
|
|
67600
|
+
}
|
|
67601
|
+
afterError?.(e2);
|
|
67602
|
+
}
|
|
67603
|
+
}
|
|
67604
|
+
function operation_requires_variables(operation) {
|
|
67605
|
+
return Boolean(
|
|
67606
|
+
operation.variableDefinitions && operation.variableDefinitions?.find(
|
|
67607
|
+
(defn) => defn.type.kind === "NonNullType" && !defn.defaultValue
|
|
67608
|
+
)
|
|
67609
|
+
);
|
|
67610
|
+
}
|
|
67611
|
+
function unwrapType(config, type, wrappers = [], convertRuntimeScalars) {
|
|
67612
|
+
if (type.kind === "NonNullType") {
|
|
67613
|
+
return unwrapType(config, type.type, [TypeWrapper.NonNull, ...wrappers]);
|
|
67614
|
+
}
|
|
67615
|
+
if (type instanceof graphql2.GraphQLNonNull) {
|
|
67616
|
+
return unwrapType(config, type.ofType, [TypeWrapper.NonNull, ...wrappers]);
|
|
67617
|
+
}
|
|
67618
|
+
if (wrappers[0] !== TypeWrapper.NonNull) {
|
|
67619
|
+
wrappers.unshift(TypeWrapper.Nullable);
|
|
67620
|
+
}
|
|
67621
|
+
if (type.kind === "ListType") {
|
|
67622
|
+
return unwrapType(config, type.type, [TypeWrapper.List, ...wrappers]);
|
|
67623
|
+
}
|
|
67624
|
+
if (type instanceof graphql2.GraphQLList) {
|
|
67625
|
+
return unwrapType(config, type.ofType, [TypeWrapper.List, ...wrappers]);
|
|
67626
|
+
}
|
|
67627
|
+
if (convertRuntimeScalars && config.configFile.features?.runtimeScalars?.[type.name.value]) {
|
|
67628
|
+
type = config.schema.getType(
|
|
67629
|
+
config.configFile.features?.runtimeScalars?.[type.name.value].type
|
|
67630
|
+
);
|
|
67631
|
+
}
|
|
67632
|
+
const namedType = config.schema.getType(type.name.value || type.name);
|
|
67633
|
+
if (!namedType) {
|
|
67634
|
+
throw new Error("Unknown type: " + type.name.value || type.name);
|
|
67635
|
+
}
|
|
67636
|
+
return { type: namedType, wrappers };
|
|
67637
|
+
}
|
|
67638
|
+
function wrapType({
|
|
67639
|
+
type,
|
|
67640
|
+
wrappers
|
|
67641
|
+
}) {
|
|
67642
|
+
const head = wrappers[0];
|
|
67643
|
+
const tail = wrappers.slice(1);
|
|
67644
|
+
let kind = graphql2.Kind.NAMED_TYPE;
|
|
67645
|
+
if (head === TypeWrapper.List) {
|
|
67646
|
+
kind = graphql2.Kind.LIST_TYPE;
|
|
67647
|
+
} else if (head === TypeWrapper.NonNull) {
|
|
67648
|
+
kind = graphql2.Kind.NON_NULL_TYPE;
|
|
67649
|
+
}
|
|
67650
|
+
if (kind === "NamedType") {
|
|
67651
|
+
return {
|
|
67652
|
+
kind,
|
|
67653
|
+
name: {
|
|
67654
|
+
kind: graphql2.Kind.NAME,
|
|
67655
|
+
value: type.name
|
|
67656
|
+
}
|
|
67657
|
+
};
|
|
67658
|
+
}
|
|
67659
|
+
return {
|
|
67660
|
+
kind,
|
|
67661
|
+
type: wrapType({ type, wrappers: tail })
|
|
67662
|
+
};
|
|
67663
|
+
}
|
|
67664
|
+
var TypeWrapper = /* @__PURE__ */ ((TypeWrapper2) => {
|
|
67665
|
+
TypeWrapper2["Nullable"] = "Nullable";
|
|
67666
|
+
TypeWrapper2["List"] = "List";
|
|
67667
|
+
TypeWrapper2["NonNull"] = "NonNull";
|
|
67668
|
+
return TypeWrapper2;
|
|
67669
|
+
})(TypeWrapper || {});
|
|
67670
|
+
|
|
67671
|
+
// src/lib/parse.ts
|
|
67672
|
+
var import_parser = __toESM(require_lib6(), 1);
|
|
67673
|
+
var import_recast = __toESM(require_main2(), 1);
|
|
67674
|
+
|
|
67675
|
+
// src/lib/deepMerge.ts
|
|
67676
|
+
var import_deepmerge = __toESM(require_cjs(), 1);
|
|
67677
|
+
function deepMerge2(filepath, ...targets) {
|
|
67678
|
+
try {
|
|
67679
|
+
if (targets.length === 1) {
|
|
67680
|
+
return targets[0];
|
|
67681
|
+
} else if (targets.length === 2) {
|
|
67682
|
+
return (0, import_deepmerge.default)(targets[0], targets[1], {
|
|
67683
|
+
arrayMerge: (source, update) => [...new Set(source.concat(update))]
|
|
67684
|
+
});
|
|
67685
|
+
}
|
|
67686
|
+
return deepMerge2(filepath, targets[0], deepMerge2(filepath, ...targets.slice(1)));
|
|
67687
|
+
} catch (e2) {
|
|
67688
|
+
throw new HoudiniError({
|
|
67689
|
+
filepath,
|
|
67690
|
+
message: "could not merge: " + JSON.stringify(targets, null, 4),
|
|
67691
|
+
description: e2.message
|
|
67692
|
+
});
|
|
67693
|
+
}
|
|
67694
|
+
}
|
|
67695
|
+
|
|
67696
|
+
// src/lib/parse.ts
|
|
67697
|
+
function parseJS(str, config) {
|
|
67698
|
+
const defaultConfig = {
|
|
67699
|
+
plugins: [
|
|
67700
|
+
"typescript",
|
|
67701
|
+
"importAssertions",
|
|
67702
|
+
"decorators-legacy",
|
|
67703
|
+
"explicitResourceManagement"
|
|
67704
|
+
],
|
|
67705
|
+
sourceType: "module"
|
|
67706
|
+
};
|
|
67707
|
+
return (0, import_parser.parse)(str || "", config ? deepMerge2("", defaultConfig, config) : defaultConfig).program;
|
|
67708
|
+
}
|
|
67709
|
+
function parseJSON(str) {
|
|
67710
|
+
str = str.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, (m2, g) => g ? "" : m2);
|
|
67711
|
+
return JSON.parse(str);
|
|
67712
|
+
}
|
|
67713
|
+
async function printJS(script, options) {
|
|
67714
|
+
if (options?.pretty) {
|
|
67715
|
+
return (0, import_recast.prettyPrint)(script, options);
|
|
67716
|
+
} else {
|
|
67717
|
+
return (0, import_recast.print)(script, options);
|
|
67718
|
+
}
|
|
67719
|
+
}
|
|
67720
|
+
|
|
67721
|
+
// src/lib/router/manifest.ts
|
|
67722
|
+
async function load_manifest(args) {
|
|
67723
|
+
const manifest = await walk_routes({
|
|
67724
|
+
config: args.config,
|
|
67725
|
+
url: "/",
|
|
67726
|
+
filepath: args.config.routesDir,
|
|
67727
|
+
project: {
|
|
67728
|
+
component_fields: {},
|
|
67729
|
+
pages: {},
|
|
67730
|
+
layouts: {},
|
|
67731
|
+
page_queries: {},
|
|
67732
|
+
layout_queries: {},
|
|
67733
|
+
artifacts: [],
|
|
67734
|
+
local_schema: false,
|
|
67735
|
+
local_yoga: false
|
|
67736
|
+
},
|
|
67737
|
+
queries: [],
|
|
67738
|
+
layouts: [],
|
|
67739
|
+
variables: {}
|
|
67740
|
+
});
|
|
67741
|
+
if (args.includeArtifacts) {
|
|
67742
|
+
try {
|
|
67743
|
+
for (const artifactPath of await readdir2(args.config.artifactDirectory)) {
|
|
67744
|
+
if (!artifactPath.endsWith(".js") || artifactPath === "index.js") {
|
|
67745
|
+
continue;
|
|
67746
|
+
}
|
|
67747
|
+
manifest.artifacts.push(artifactPath.substring(0, artifactPath.length - 3));
|
|
67748
|
+
}
|
|
67749
|
+
} catch {
|
|
67750
|
+
}
|
|
67751
|
+
}
|
|
67752
|
+
try {
|
|
67753
|
+
await stat(args.config.localApiDir);
|
|
67754
|
+
for (const child of await readdir2(args.config.localApiDir, { withFileTypes: true })) {
|
|
67755
|
+
const name = child.isDirectory() ? child.name : parse3(child.name).name;
|
|
67756
|
+
if (name === "+schema") {
|
|
67757
|
+
manifest.local_schema = true;
|
|
67758
|
+
} else if (name === "+yoga") {
|
|
67759
|
+
manifest.local_yoga = true;
|
|
67760
|
+
}
|
|
67761
|
+
}
|
|
67762
|
+
} catch {
|
|
67763
|
+
}
|
|
67764
|
+
return manifest;
|
|
67765
|
+
}
|
|
67766
|
+
async function walk_routes(args) {
|
|
67767
|
+
const directory_contents = await readdir2(args.filepath, {
|
|
67768
|
+
withFileTypes: true
|
|
67769
|
+
});
|
|
67770
|
+
const variables = { ...args.variables };
|
|
67771
|
+
let newLayouts = args.layouts;
|
|
67772
|
+
let newLayoutQueries = args.queries;
|
|
67773
|
+
let layout = null;
|
|
67774
|
+
let layoutQuery = null;
|
|
67775
|
+
let pageQuery = null;
|
|
67776
|
+
const [
|
|
67777
|
+
[layoutQueryPath, layoutQueryContents],
|
|
67778
|
+
[layoutViewPath, layoutViewContents],
|
|
67779
|
+
[pageQueryPath, pageQueryContents],
|
|
67780
|
+
[pageViewPath, pageViewContents]
|
|
67781
|
+
] = await Promise.all([
|
|
67782
|
+
read_layoutQuery(args.filepath),
|
|
67783
|
+
read_layoutView(args.filepath),
|
|
67784
|
+
read_pageQuery(args.filepath),
|
|
67785
|
+
read_pageView(args.filepath)
|
|
67786
|
+
]);
|
|
67787
|
+
if (layoutQueryContents) {
|
|
67788
|
+
layoutQuery = await add_query({
|
|
67789
|
+
path: layoutQueryPath,
|
|
67790
|
+
config: args.config,
|
|
67791
|
+
url: args.url,
|
|
67792
|
+
project: args.project,
|
|
67793
|
+
type: "layout",
|
|
67794
|
+
contents: layoutQueryContents,
|
|
67795
|
+
variables
|
|
67796
|
+
});
|
|
67797
|
+
newLayoutQueries = [...args.queries, layoutQuery.name];
|
|
67798
|
+
}
|
|
67799
|
+
if (layoutViewContents) {
|
|
67800
|
+
layout = await add_view({
|
|
67801
|
+
url: args.url,
|
|
67802
|
+
path: layoutViewPath,
|
|
67803
|
+
project: args.project,
|
|
67804
|
+
type: "layout",
|
|
67805
|
+
contents: layoutViewContents,
|
|
67806
|
+
layouts: args.layouts,
|
|
67807
|
+
queries: newLayoutQueries,
|
|
67808
|
+
config: args.config,
|
|
67809
|
+
variables
|
|
67810
|
+
});
|
|
67811
|
+
newLayouts = [...args.layouts, page_id(layout.url)];
|
|
67812
|
+
}
|
|
67813
|
+
if (pageQueryContents) {
|
|
67814
|
+
pageQuery = await add_query({
|
|
67815
|
+
path: pageQueryPath,
|
|
67816
|
+
config: args.config,
|
|
67817
|
+
url: args.url,
|
|
67818
|
+
project: args.project,
|
|
67819
|
+
type: "page",
|
|
67820
|
+
contents: pageQueryContents,
|
|
67821
|
+
variables
|
|
67822
|
+
});
|
|
67823
|
+
}
|
|
67824
|
+
if (pageViewContents) {
|
|
67825
|
+
await add_view({
|
|
67826
|
+
path: pageViewPath,
|
|
67827
|
+
url: args.url.substring(0, args.url.length - 1) || "/",
|
|
67828
|
+
project: args.project,
|
|
67829
|
+
type: "page",
|
|
67830
|
+
contents: pageViewContents,
|
|
67831
|
+
layouts: newLayouts,
|
|
67832
|
+
queries: pageQuery ? [...newLayoutQueries, pageQuery.name] : newLayoutQueries,
|
|
67833
|
+
config: args.config,
|
|
67834
|
+
variables
|
|
67835
|
+
});
|
|
67836
|
+
}
|
|
67837
|
+
await Promise.all(
|
|
67838
|
+
directory_contents.map((dir) => {
|
|
67839
|
+
if (!dir.isDirectory()) {
|
|
67840
|
+
return;
|
|
67841
|
+
}
|
|
67842
|
+
return walk_routes({
|
|
67843
|
+
...args,
|
|
67844
|
+
filepath: join2(args.filepath, dir.name),
|
|
67845
|
+
url: `${args.url}${dir.name}/`,
|
|
67846
|
+
queries: newLayoutQueries,
|
|
67847
|
+
layouts: newLayouts,
|
|
67848
|
+
variables
|
|
67849
|
+
});
|
|
67850
|
+
})
|
|
67851
|
+
);
|
|
67852
|
+
return args.project;
|
|
67853
|
+
}
|
|
67854
|
+
async function add_view(args) {
|
|
67855
|
+
const target = args.type === "page" ? args.project.pages : args.project.layouts;
|
|
67856
|
+
const queries = await extractQueries(args.contents);
|
|
67857
|
+
const missing_queries = queries.filter((query2) => !args.queries.includes(query2));
|
|
67858
|
+
if (missing_queries.length > 0) {
|
|
67859
|
+
throw {
|
|
67860
|
+
message: `Unknown queries in ${args.path}: ${missing_queries.join(", ")}`
|
|
67861
|
+
};
|
|
67862
|
+
}
|
|
67863
|
+
const id = page_id(args.url);
|
|
67864
|
+
target[id] = {
|
|
67865
|
+
id,
|
|
67866
|
+
queries,
|
|
67867
|
+
url: args.url,
|
|
67868
|
+
layouts: args.layouts,
|
|
67869
|
+
path: relative(args.config.projectRoot, args.path),
|
|
67870
|
+
query_options: args.queries,
|
|
67871
|
+
params: Object.fromEntries(
|
|
67872
|
+
parse_page_pattern(args.url).params.map((param) => [
|
|
67873
|
+
param.name,
|
|
67874
|
+
args.variables[param.name] ?? null
|
|
67875
|
+
])
|
|
67876
|
+
)
|
|
67877
|
+
};
|
|
67878
|
+
return target[id];
|
|
67478
67879
|
}
|
|
67479
67880
|
async function add_query(args) {
|
|
67480
|
-
const parsed =
|
|
67881
|
+
const parsed = graphql3.parse(args.contents);
|
|
67481
67882
|
const query2 = parsed.definitions.find(
|
|
67482
67883
|
(def) => def.kind === "OperationDefinition" && def.operation === "query"
|
|
67483
67884
|
);
|
|
@@ -67485,7 +67886,7 @@ async function add_query(args) {
|
|
|
67485
67886
|
throw new Error("No query found");
|
|
67486
67887
|
}
|
|
67487
67888
|
let loading = false;
|
|
67488
|
-
await
|
|
67889
|
+
await graphql3.visit(parsed, {
|
|
67489
67890
|
Directive(node) {
|
|
67490
67891
|
if (node.name.value === args.config.loadingDirective) {
|
|
67491
67892
|
loading = true;
|
|
@@ -67504,7 +67905,7 @@ async function add_query(args) {
|
|
|
67504
67905
|
Object.assign(args.variables, queryVariables);
|
|
67505
67906
|
const target = args.type === "page" ? args.project.page_queries : args.project.layout_queries;
|
|
67506
67907
|
target[page_id(args.url)] = {
|
|
67507
|
-
path:
|
|
67908
|
+
path: relative(args.config.routesDir, args.path),
|
|
67508
67909
|
name: query2.name.value,
|
|
67509
67910
|
url: args.url,
|
|
67510
67911
|
loading,
|
|
@@ -67579,7 +67980,7 @@ async function extractQueries(source) {
|
|
|
67579
67980
|
}
|
|
67580
67981
|
|
|
67581
67982
|
// src/lib/router/server.ts
|
|
67582
|
-
import * as
|
|
67983
|
+
import * as graphql4 from "graphql";
|
|
67583
67984
|
import path3 from "node:path";
|
|
67584
67985
|
|
|
67585
67986
|
// src/runtime/lib/flatten.ts
|
|
@@ -71338,14 +71739,14 @@ function internalRoutes(config) {
|
|
|
71338
71739
|
async function buildLocalSchema(config) {
|
|
71339
71740
|
const { build } = await import("vite");
|
|
71340
71741
|
const schema = path3.join(config.localApiDir, "+schema");
|
|
71341
|
-
const outDir =
|
|
71742
|
+
const outDir = temp_dir(config, "schema");
|
|
71342
71743
|
process.env.HOUDINI_SECONDARY_BUILD = "true";
|
|
71343
71744
|
try {
|
|
71344
|
-
await
|
|
71745
|
+
await remove(path3.join(outDir, "assets", "schema.js"));
|
|
71345
71746
|
} catch {
|
|
71346
71747
|
}
|
|
71347
71748
|
try {
|
|
71348
|
-
await
|
|
71749
|
+
await mkdir(outDir);
|
|
71349
71750
|
} catch {
|
|
71350
71751
|
}
|
|
71351
71752
|
await build({
|
|
@@ -71377,14 +71778,14 @@ async function loadLocalSchema(config) {
|
|
|
71377
71778
|
}
|
|
71378
71779
|
try {
|
|
71379
71780
|
const { default: schema } = await import(path3.join(
|
|
71380
|
-
|
|
71781
|
+
temp_dir(config, "schema"),
|
|
71381
71782
|
`schema.js?${Date.now().valueOf()}}`
|
|
71382
71783
|
));
|
|
71383
71784
|
return schema;
|
|
71384
71785
|
} catch (e2) {
|
|
71385
71786
|
const message = "message" in e2 ? e2.message : e2;
|
|
71386
71787
|
console.error("\u26A0\uFE0F Failed to load local schema: ", message);
|
|
71387
|
-
return new
|
|
71788
|
+
return new graphql4.GraphQLSchema({});
|
|
71388
71789
|
}
|
|
71389
71790
|
}
|
|
71390
71791
|
|
|
@@ -71721,7 +72122,7 @@ var Config = class {
|
|
|
71721
72122
|
persistedQueriesPath
|
|
71722
72123
|
} = this.configFile;
|
|
71723
72124
|
if (typeof schema === "string") {
|
|
71724
|
-
this.schema =
|
|
72125
|
+
this.schema = graphql5.buildSchema(schema);
|
|
71725
72126
|
} else {
|
|
71726
72127
|
this.schema = schema;
|
|
71727
72128
|
}
|
|
@@ -71869,7 +72270,7 @@ var Config = class {
|
|
|
71869
72270
|
set newSchema(value) {
|
|
71870
72271
|
this.schemaString = value;
|
|
71871
72272
|
if (value) {
|
|
71872
|
-
this.#newSchemaInstance =
|
|
72273
|
+
this.#newSchemaInstance = graphql5.buildSchema(value);
|
|
71873
72274
|
} else {
|
|
71874
72275
|
this.#newSchemaInstance = null;
|
|
71875
72276
|
}
|
|
@@ -71959,21 +72360,21 @@ var Config = class {
|
|
|
71959
72360
|
}
|
|
71960
72361
|
documentName(document) {
|
|
71961
72362
|
const operation = document.definitions.find(
|
|
71962
|
-
({ kind }) => kind ===
|
|
72363
|
+
({ kind }) => kind === graphql5.Kind.OPERATION_DEFINITION
|
|
71963
72364
|
);
|
|
71964
72365
|
if (operation) {
|
|
71965
72366
|
if (!operation.name) {
|
|
71966
|
-
throw new Error("encountered operation with no name: " +
|
|
72367
|
+
throw new Error("encountered operation with no name: " + graphql5.print(document));
|
|
71967
72368
|
}
|
|
71968
72369
|
return operation.name.value;
|
|
71969
72370
|
}
|
|
71970
72371
|
const fragmentDefinitions = document.definitions.filter(
|
|
71971
|
-
({ kind }) => kind ===
|
|
72372
|
+
({ kind }) => kind === graphql5.Kind.FRAGMENT_DEFINITION
|
|
71972
72373
|
);
|
|
71973
72374
|
if (fragmentDefinitions.length) {
|
|
71974
72375
|
return fragmentDefinitions[0].name.value;
|
|
71975
72376
|
}
|
|
71976
|
-
throw new Error("Could not generate artifact name for document: " +
|
|
72377
|
+
throw new Error("Could not generate artifact name for document: " + graphql5.print(document));
|
|
71977
72378
|
}
|
|
71978
72379
|
isSelectionScalar(type) {
|
|
71979
72380
|
return ["String", "Boolean", "Float", "ID", "Int"].concat(Object.keys(this.scalars || {})).includes(type);
|
|
@@ -72183,10 +72584,10 @@ var Config = class {
|
|
|
72183
72584
|
localDocumentData(document) {
|
|
72184
72585
|
let paginated = false;
|
|
72185
72586
|
let componentFields = [];
|
|
72186
|
-
const typeInfo = new
|
|
72187
|
-
|
|
72587
|
+
const typeInfo = new graphql5.TypeInfo(this.schema);
|
|
72588
|
+
graphql5.visit(
|
|
72188
72589
|
document,
|
|
72189
|
-
|
|
72590
|
+
graphql5.visitWithTypeInfo(typeInfo, {
|
|
72190
72591
|
Directive: (node) => {
|
|
72191
72592
|
if ([this.paginateDirective].includes(node.name.value)) {
|
|
72192
72593
|
paginated = true;
|
|
@@ -72397,7 +72798,7 @@ async function getConfig({
|
|
|
72397
72798
|
if (apiURL) {
|
|
72398
72799
|
if (glob2.hasMagic(_config.schemaPath)) {
|
|
72399
72800
|
console.log(
|
|
72400
|
-
`\u26A0\uFE0F Your houdini configuration contains
|
|
72801
|
+
`\u26A0\uFE0F Your houdini configuration contains a watchSchema url and a path pointing to multiple files.
|
|
72401
72802
|
This will prevent your schema from being pulled.`
|
|
72402
72803
|
);
|
|
72403
72804
|
} else if (!await readFile(_config.schemaPath)) {
|
|
@@ -72486,347 +72887,76 @@ async function pluginPath(plugin_name, config_path) {
|
|
|
72486
72887
|
if (process.versions.pnp) {
|
|
72487
72888
|
const { findPnpApi } = __require("node:module");
|
|
72488
72889
|
const pnp = findPnpApi(config_path);
|
|
72489
|
-
return pnp.resolveRequest(plugin_name, config_path, { conditions: /* @__PURE__ */ new Set(["import"]) });
|
|
72490
|
-
}
|
|
72491
|
-
const pluginDirectory = findModule(plugin_name, config_path);
|
|
72492
|
-
const packageJsonSrc = await readFile(join2(pluginDirectory, "package.json"));
|
|
72493
|
-
if (!packageJsonSrc) {
|
|
72494
|
-
throw new Error("skip");
|
|
72495
|
-
}
|
|
72496
|
-
const packageJSON = JSON.parse(packageJsonSrc);
|
|
72497
|
-
if (!packageJSON.exports?.["."]?.import) {
|
|
72498
|
-
throw new Error("");
|
|
72499
|
-
}
|
|
72500
|
-
return join2(pluginDirectory, packageJSON.exports["."].import);
|
|
72501
|
-
} catch {
|
|
72502
|
-
const err = new Error(
|
|
72503
|
-
`Could not find plugin: ${plugin_name}. Are you sure its installed? If so, please open a ticket on GitHub.`
|
|
72504
|
-
);
|
|
72505
|
-
throw err;
|
|
72506
|
-
}
|
|
72507
|
-
}
|
|
72508
|
-
function findModule(pkg = "houdini", currentLocation) {
|
|
72509
|
-
const pathEndingBy = ["node_modules", pkg];
|
|
72510
|
-
let locationFound = join2(currentLocation, ...pathEndingBy);
|
|
72511
|
-
let previousLocation = "";
|
|
72512
|
-
const backFolder = [];
|
|
72513
|
-
while (previousLocation !== locationFound && !existsSync(locationFound)) {
|
|
72514
|
-
previousLocation = locationFound;
|
|
72515
|
-
backFolder.push("../");
|
|
72516
|
-
locationFound = join2(currentLocation, ...backFolder, ...pathEndingBy);
|
|
72517
|
-
}
|
|
72518
|
-
if (previousLocation === locationFound) {
|
|
72519
|
-
throw new Error("Could not find any node_modules/houdini folder");
|
|
72520
|
-
}
|
|
72521
|
-
return locationFound;
|
|
72522
|
-
}
|
|
72523
|
-
async function loadSchemaFile(schemaPath) {
|
|
72524
|
-
if (isAbsolute(schemaPath)) {
|
|
72525
|
-
const relPath = relative(process.cwd(), schemaPath);
|
|
72526
|
-
const error = new Error(
|
|
72527
|
-
`Invalid config value: 'schemaPath' must now be passed as a relative directory. Please change its value to "./${relPath}".`
|
|
72528
|
-
);
|
|
72529
|
-
error.stack = "";
|
|
72530
|
-
throw error;
|
|
72531
|
-
}
|
|
72532
|
-
if (glob2.hasMagic(schemaPath)) {
|
|
72533
|
-
const sourceFiles = await glob2(schemaPath);
|
|
72534
|
-
return mergeSchemas({
|
|
72535
|
-
typeDefs: await Promise.all(
|
|
72536
|
-
sourceFiles.map(async (filepath) => await readFile(filepath))
|
|
72537
|
-
)
|
|
72538
|
-
});
|
|
72539
|
-
}
|
|
72540
|
-
try {
|
|
72541
|
-
await stat(schemaPath);
|
|
72542
|
-
} catch {
|
|
72543
|
-
throw new HoudiniError({
|
|
72544
|
-
message: `Schema file does not exist! Create it using houdini pull-schema`
|
|
72545
|
-
});
|
|
72546
|
-
}
|
|
72547
|
-
const contents = await readFile(schemaPath);
|
|
72548
|
-
if (schemaPath.endsWith("gql") || schemaPath.endsWith("graphql") || schemaPath.endsWith("graphqls")) {
|
|
72549
|
-
return graphql4.buildSchema(contents);
|
|
72550
|
-
}
|
|
72551
|
-
const jsonContents = JSON.parse(contents);
|
|
72552
|
-
if (jsonContents.data) {
|
|
72553
|
-
return graphql4.buildClientSchema(jsonContents.data);
|
|
72554
|
-
}
|
|
72555
|
-
return graphql4.buildClientSchema(jsonContents);
|
|
72556
|
-
}
|
|
72557
|
-
var emptySchema = graphql4.buildSchema("type Query { hello: String }");
|
|
72558
|
-
var defaultDirectives = emptySchema.getDirectives().map((dir) => dir.name);
|
|
72559
|
-
|
|
72560
|
-
// src/lib/graphql.ts
|
|
72561
|
-
import * as graphql5 from "graphql";
|
|
72562
|
-
import crypto2 from "node:crypto";
|
|
72563
|
-
function getRootType(type) {
|
|
72564
|
-
if (graphql5.isNonNullType(type)) {
|
|
72565
|
-
return getRootType(type.ofType);
|
|
72566
|
-
}
|
|
72567
|
-
if (graphql5.isListType(type)) {
|
|
72568
|
-
return getRootType(type.ofType);
|
|
72569
|
-
}
|
|
72570
|
-
return type;
|
|
72571
|
-
}
|
|
72572
|
-
function processComponentFieldDirective(directive) {
|
|
72573
|
-
let field;
|
|
72574
|
-
let exportValue;
|
|
72575
|
-
let prop;
|
|
72576
|
-
let raw;
|
|
72577
|
-
for (const arg of directive.arguments ?? []) {
|
|
72578
|
-
if (arg.name.value === "field" && arg.value.kind === "StringValue") {
|
|
72579
|
-
field = arg.value.value;
|
|
72580
|
-
} else if (arg.name.value === "export" && arg.value.kind === "StringValue") {
|
|
72581
|
-
exportValue = arg.value.value;
|
|
72582
|
-
} else if (arg.name.value === "prop" && arg.value.kind === "StringValue") {
|
|
72583
|
-
prop = arg.value.value;
|
|
72584
|
-
} else if (arg.name.value === "raw" && arg.value.kind === "StringValue") {
|
|
72585
|
-
raw = arg.value.value;
|
|
72586
|
-
}
|
|
72587
|
-
}
|
|
72588
|
-
const missing = [];
|
|
72589
|
-
if (!field) {
|
|
72590
|
-
missing.push("field");
|
|
72591
|
-
}
|
|
72592
|
-
if (!prop) {
|
|
72593
|
-
missing.push("prop");
|
|
72594
|
-
}
|
|
72595
|
-
if (missing.length > 0) {
|
|
72596
|
-
throw new Error(`missing arguments to @componentField: ${missing.join(", ")}`);
|
|
72597
|
-
}
|
|
72598
|
-
return {
|
|
72599
|
-
prop,
|
|
72600
|
-
field,
|
|
72601
|
-
raw,
|
|
72602
|
-
export: exportValue
|
|
72603
|
-
};
|
|
72604
|
-
}
|
|
72605
|
-
function hashOriginal({ document }) {
|
|
72606
|
-
return hashDocument(document.originalString);
|
|
72607
|
-
}
|
|
72608
|
-
function hashRaw({ document }) {
|
|
72609
|
-
return hashDocument(document.artifact?.raw);
|
|
72610
|
-
}
|
|
72611
|
-
function hashDocument(str) {
|
|
72612
|
-
return crypto2.createHash("sha256").update(str || "").digest("hex");
|
|
72613
|
-
}
|
|
72614
|
-
function parentField(ancestors) {
|
|
72615
|
-
return walkParentField([...ancestors].sort(() => -1));
|
|
72616
|
-
}
|
|
72617
|
-
function walkParentField(ancestors) {
|
|
72618
|
-
let head = ancestors.shift();
|
|
72619
|
-
if (Array.isArray(head) || head.kind === "SelectionSet") {
|
|
72620
|
-
return walkParentField(ancestors);
|
|
72621
|
-
}
|
|
72622
|
-
return head;
|
|
72623
|
-
}
|
|
72624
|
-
function parentTypeFromAncestors(schema, filepath, ancestors) {
|
|
72625
|
-
const parents = [...ancestors];
|
|
72626
|
-
parents.reverse();
|
|
72627
|
-
return walkAncestors(schema, filepath, parents);
|
|
72628
|
-
}
|
|
72629
|
-
function walkAncestors(schema, filepath, ancestors) {
|
|
72630
|
-
let head = ancestors.shift();
|
|
72631
|
-
if (Array.isArray(head)) {
|
|
72632
|
-
return walkAncestors(schema, filepath, ancestors);
|
|
72633
|
-
}
|
|
72634
|
-
if (!head) {
|
|
72635
|
-
throw new HoudiniError({ filepath, message: "Could not figure out type of field" });
|
|
72636
|
-
}
|
|
72637
|
-
if (head.kind === "OperationDefinition") {
|
|
72638
|
-
const operationType = {
|
|
72639
|
-
query: schema.getQueryType(),
|
|
72640
|
-
mutation: schema.getMutationType(),
|
|
72641
|
-
subscription: schema.getSubscriptionType()
|
|
72642
|
-
}[head.operation];
|
|
72643
|
-
if (!operationType) {
|
|
72644
|
-
throw new HoudiniError({ filepath, message: "Could not find operation type" });
|
|
72645
|
-
}
|
|
72646
|
-
return operationType;
|
|
72647
|
-
}
|
|
72648
|
-
if (head.kind === "FragmentDefinition") {
|
|
72649
|
-
const result = schema.getType(head.typeCondition.name.value);
|
|
72650
|
-
if (!result) {
|
|
72651
|
-
throw new HoudiniError({
|
|
72652
|
-
filepath,
|
|
72653
|
-
message: `Could not find definition for ${head.typeCondition.name.value} in the schema`
|
|
72654
|
-
});
|
|
72655
|
-
}
|
|
72656
|
-
return result;
|
|
72657
|
-
}
|
|
72658
|
-
if (head.kind === "FragmentSpread") {
|
|
72659
|
-
throw new Error("How the hell did this happen?");
|
|
72660
|
-
}
|
|
72661
|
-
const parent = walkAncestors(schema, filepath, ancestors);
|
|
72662
|
-
if (head.kind === "InlineFragment") {
|
|
72663
|
-
if (!head.typeCondition) {
|
|
72664
|
-
return parent;
|
|
72665
|
-
}
|
|
72666
|
-
const wrapper = schema.getType(head.typeCondition.name.value);
|
|
72667
|
-
if (!wrapper) {
|
|
72668
|
-
throw new HoudiniError({
|
|
72669
|
-
filepath,
|
|
72670
|
-
message: "Could not find type with name: " + head.typeCondition.name.value
|
|
72671
|
-
});
|
|
72672
|
-
}
|
|
72673
|
-
return wrapper;
|
|
72674
|
-
}
|
|
72675
|
-
if (head.kind === "SelectionSet") {
|
|
72676
|
-
return parent;
|
|
72677
|
-
}
|
|
72678
|
-
const field = parent.getFields()[head.name.value];
|
|
72679
|
-
if (!field) {
|
|
72680
|
-
throw new HoudiniError({
|
|
72681
|
-
filepath,
|
|
72682
|
-
message: `Could not find definition of ${head.name.value} in ${parent.toString()}`
|
|
72683
|
-
});
|
|
72684
|
-
}
|
|
72685
|
-
return getRootType(field.type);
|
|
72686
|
-
}
|
|
72687
|
-
function definitionFromAncestors(ancestors) {
|
|
72688
|
-
let parents = [...ancestors];
|
|
72689
|
-
parents.shift();
|
|
72690
|
-
let definition = parents.shift();
|
|
72691
|
-
while (Array.isArray(definition) && definition) {
|
|
72692
|
-
definition = parents.shift();
|
|
72693
|
-
}
|
|
72694
|
-
return { parents, definition };
|
|
72695
|
-
}
|
|
72696
|
-
function formatErrors(e2, afterError) {
|
|
72697
|
-
const errors = Array.isArray(e2) ? e2 : [e2];
|
|
72698
|
-
for (const error of errors) {
|
|
72699
|
-
if ("filepath" in error && error.filepath) {
|
|
72700
|
-
const relative2 = relative(process.cwd(), error.filepath);
|
|
72701
|
-
console.error(`\u274C Encountered error in ${relative2}`);
|
|
72702
|
-
if (error.message) {
|
|
72703
|
-
console.error(error.message);
|
|
72704
|
-
}
|
|
72705
|
-
} else {
|
|
72706
|
-
console.error(`\u274C ${error.message}`);
|
|
72707
|
-
if ("description" in error && error.description) {
|
|
72708
|
-
console.error(`${error.description}`);
|
|
72709
|
-
}
|
|
72710
|
-
}
|
|
72711
|
-
afterError?.(e2);
|
|
72712
|
-
}
|
|
72713
|
-
}
|
|
72714
|
-
function operation_requires_variables(operation) {
|
|
72715
|
-
return Boolean(
|
|
72716
|
-
operation.variableDefinitions && operation.variableDefinitions?.find(
|
|
72717
|
-
(defn) => defn.type.kind === "NonNullType" && !defn.defaultValue
|
|
72718
|
-
)
|
|
72719
|
-
);
|
|
72720
|
-
}
|
|
72721
|
-
function unwrapType(config, type, wrappers = [], convertRuntimeScalars) {
|
|
72722
|
-
if (type.kind === "NonNullType") {
|
|
72723
|
-
return unwrapType(config, type.type, [TypeWrapper.NonNull, ...wrappers]);
|
|
72724
|
-
}
|
|
72725
|
-
if (type instanceof graphql5.GraphQLNonNull) {
|
|
72726
|
-
return unwrapType(config, type.ofType, [TypeWrapper.NonNull, ...wrappers]);
|
|
72727
|
-
}
|
|
72728
|
-
if (wrappers[0] !== TypeWrapper.NonNull) {
|
|
72729
|
-
wrappers.unshift(TypeWrapper.Nullable);
|
|
72730
|
-
}
|
|
72731
|
-
if (type.kind === "ListType") {
|
|
72732
|
-
return unwrapType(config, type.type, [TypeWrapper.List, ...wrappers]);
|
|
72733
|
-
}
|
|
72734
|
-
if (type instanceof graphql5.GraphQLList) {
|
|
72735
|
-
return unwrapType(config, type.ofType, [TypeWrapper.List, ...wrappers]);
|
|
72736
|
-
}
|
|
72737
|
-
if (convertRuntimeScalars && config.configFile.features?.runtimeScalars?.[type.name.value]) {
|
|
72738
|
-
type = config.schema.getType(
|
|
72739
|
-
config.configFile.features?.runtimeScalars?.[type.name.value].type
|
|
72890
|
+
return pnp.resolveRequest(plugin_name, config_path, { conditions: /* @__PURE__ */ new Set(["import"]) });
|
|
72891
|
+
}
|
|
72892
|
+
const pluginDirectory = findModule(plugin_name, config_path);
|
|
72893
|
+
const packageJsonSrc = await readFile(join2(pluginDirectory, "package.json"));
|
|
72894
|
+
if (!packageJsonSrc) {
|
|
72895
|
+
throw new Error("skip");
|
|
72896
|
+
}
|
|
72897
|
+
const packageJSON = JSON.parse(packageJsonSrc);
|
|
72898
|
+
if (!packageJSON.exports?.["."]?.import) {
|
|
72899
|
+
throw new Error("");
|
|
72900
|
+
}
|
|
72901
|
+
return join2(pluginDirectory, packageJSON.exports["."].import);
|
|
72902
|
+
} catch {
|
|
72903
|
+
const err = new Error(
|
|
72904
|
+
`Could not find plugin: ${plugin_name}. Are you sure its installed? If so, please open a ticket on GitHub.`
|
|
72740
72905
|
);
|
|
72906
|
+
throw err;
|
|
72741
72907
|
}
|
|
72742
|
-
const namedType = config.schema.getType(type.name.value || type.name);
|
|
72743
|
-
if (!namedType) {
|
|
72744
|
-
throw new Error("Unknown type: " + type.name.value || type.name);
|
|
72745
|
-
}
|
|
72746
|
-
return { type: namedType, wrappers };
|
|
72747
72908
|
}
|
|
72748
|
-
function
|
|
72749
|
-
|
|
72750
|
-
|
|
72751
|
-
|
|
72752
|
-
const
|
|
72753
|
-
|
|
72754
|
-
|
|
72755
|
-
|
|
72756
|
-
|
|
72757
|
-
} else if (head === TypeWrapper.NonNull) {
|
|
72758
|
-
kind = graphql5.Kind.NON_NULL_TYPE;
|
|
72909
|
+
function findModule(pkg = "houdini", currentLocation) {
|
|
72910
|
+
const pathEndingBy = ["node_modules", pkg];
|
|
72911
|
+
let locationFound = join2(currentLocation, ...pathEndingBy);
|
|
72912
|
+
let previousLocation = "";
|
|
72913
|
+
const backFolder = [];
|
|
72914
|
+
while (previousLocation !== locationFound && !existsSync(locationFound)) {
|
|
72915
|
+
previousLocation = locationFound;
|
|
72916
|
+
backFolder.push("../");
|
|
72917
|
+
locationFound = join2(currentLocation, ...backFolder, ...pathEndingBy);
|
|
72759
72918
|
}
|
|
72760
|
-
if (
|
|
72761
|
-
|
|
72762
|
-
kind,
|
|
72763
|
-
name: {
|
|
72764
|
-
kind: graphql5.Kind.NAME,
|
|
72765
|
-
value: type.name
|
|
72766
|
-
}
|
|
72767
|
-
};
|
|
72919
|
+
if (previousLocation === locationFound) {
|
|
72920
|
+
throw new Error("Could not find any node_modules/houdini folder");
|
|
72768
72921
|
}
|
|
72769
|
-
return
|
|
72770
|
-
kind,
|
|
72771
|
-
type: wrapType({ type, wrappers: tail })
|
|
72772
|
-
};
|
|
72922
|
+
return locationFound;
|
|
72773
72923
|
}
|
|
72774
|
-
|
|
72775
|
-
|
|
72776
|
-
|
|
72777
|
-
|
|
72778
|
-
|
|
72779
|
-
|
|
72780
|
-
|
|
72781
|
-
|
|
72782
|
-
|
|
72783
|
-
|
|
72784
|
-
|
|
72785
|
-
|
|
72786
|
-
|
|
72787
|
-
|
|
72924
|
+
async function loadSchemaFile(schemaPath) {
|
|
72925
|
+
if (isAbsolute(schemaPath)) {
|
|
72926
|
+
const relPath = relative(process.cwd(), schemaPath);
|
|
72927
|
+
const error = new Error(
|
|
72928
|
+
`Invalid config value: 'schemaPath' must now be passed as a relative directory. Please change its value to "./${relPath}".`
|
|
72929
|
+
);
|
|
72930
|
+
error.stack = "";
|
|
72931
|
+
throw error;
|
|
72932
|
+
}
|
|
72933
|
+
if (glob2.hasMagic(schemaPath)) {
|
|
72934
|
+
const sourceFiles = await glob2(schemaPath);
|
|
72935
|
+
return mergeSchemas({
|
|
72936
|
+
typeDefs: await Promise.all(
|
|
72937
|
+
sourceFiles.map(async (filepath) => await readFile(filepath))
|
|
72938
|
+
)
|
|
72939
|
+
});
|
|
72940
|
+
}
|
|
72788
72941
|
try {
|
|
72789
|
-
|
|
72790
|
-
|
|
72791
|
-
} else if (targets.length === 2) {
|
|
72792
|
-
return (0, import_deepmerge.default)(targets[0], targets[1], {
|
|
72793
|
-
arrayMerge: (source, update) => [...new Set(source.concat(update))]
|
|
72794
|
-
});
|
|
72795
|
-
}
|
|
72796
|
-
return deepMerge2(filepath, targets[0], deepMerge2(filepath, ...targets.slice(1)));
|
|
72797
|
-
} catch (e2) {
|
|
72942
|
+
await stat(schemaPath);
|
|
72943
|
+
} catch {
|
|
72798
72944
|
throw new HoudiniError({
|
|
72799
|
-
|
|
72800
|
-
message: "could not merge: " + JSON.stringify(targets, null, 4),
|
|
72801
|
-
description: e2.message
|
|
72945
|
+
message: `Schema file does not exist! Create it using houdini pull-schema`
|
|
72802
72946
|
});
|
|
72803
72947
|
}
|
|
72804
|
-
|
|
72805
|
-
|
|
72806
|
-
|
|
72807
|
-
function parseJS(str, config) {
|
|
72808
|
-
const defaultConfig = {
|
|
72809
|
-
plugins: [
|
|
72810
|
-
"typescript",
|
|
72811
|
-
"importAssertions",
|
|
72812
|
-
"decorators-legacy",
|
|
72813
|
-
"explicitResourceManagement"
|
|
72814
|
-
],
|
|
72815
|
-
sourceType: "module"
|
|
72816
|
-
};
|
|
72817
|
-
return (0, import_parser.parse)(str || "", config ? deepMerge2("", defaultConfig, config) : defaultConfig).program;
|
|
72818
|
-
}
|
|
72819
|
-
function parseJSON(str) {
|
|
72820
|
-
str = str.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, (m2, g) => g ? "" : m2);
|
|
72821
|
-
return JSON.parse(str);
|
|
72822
|
-
}
|
|
72823
|
-
async function printJS(script, options) {
|
|
72824
|
-
if (options?.pretty) {
|
|
72825
|
-
return (0, import_recast.prettyPrint)(script, options);
|
|
72826
|
-
} else {
|
|
72827
|
-
return (0, import_recast.print)(script, options);
|
|
72948
|
+
const contents = await readFile(schemaPath);
|
|
72949
|
+
if (schemaPath.endsWith("gql") || schemaPath.endsWith("graphql") || schemaPath.endsWith("graphqls")) {
|
|
72950
|
+
return graphql5.buildSchema(contents);
|
|
72828
72951
|
}
|
|
72952
|
+
const jsonContents = JSON.parse(contents);
|
|
72953
|
+
if (jsonContents.data) {
|
|
72954
|
+
return graphql5.buildClientSchema(jsonContents.data);
|
|
72955
|
+
}
|
|
72956
|
+
return graphql5.buildClientSchema(jsonContents);
|
|
72829
72957
|
}
|
|
72958
|
+
var emptySchema = graphql5.buildSchema("type Query { hello: String }");
|
|
72959
|
+
var defaultDirectives = emptySchema.getDirectives().map((dir) => dir.name);
|
|
72830
72960
|
|
|
72831
72961
|
// src/lib/imports.ts
|
|
72832
72962
|
var recast = __toESM(require_main2(), 1);
|
|
@@ -72904,7 +73034,7 @@ async function cleanupFiles(pathFolder, listOfObj) {
|
|
|
72904
73034
|
// src/lib/detectTools.ts
|
|
72905
73035
|
async function detectFromPackageJSON(cwd) {
|
|
72906
73036
|
try {
|
|
72907
|
-
const packageJSONFile = await
|
|
73037
|
+
const packageJSONFile = await readFile(join2(cwd, "package.json"));
|
|
72908
73038
|
if (packageJSONFile) {
|
|
72909
73039
|
var packageJSON = JSON.parse(packageJSONFile);
|
|
72910
73040
|
} else {
|
|
@@ -72929,22 +73059,22 @@ async function detectFromPackageJSON(cwd) {
|
|
|
72929
73059
|
async function detectTools(cwd = process.cwd()) {
|
|
72930
73060
|
let typescript = false;
|
|
72931
73061
|
try {
|
|
72932
|
-
await
|
|
73062
|
+
await stat(join2(cwd, "tsconfig.json"));
|
|
72933
73063
|
typescript = true;
|
|
72934
73064
|
} catch {
|
|
72935
73065
|
}
|
|
72936
73066
|
let package_manager = "npm";
|
|
72937
73067
|
let dir = cwd;
|
|
72938
73068
|
do {
|
|
72939
|
-
if (
|
|
73069
|
+
if (existsSync(join2(dir, "pnpm-lock.yaml"))) {
|
|
72940
73070
|
package_manager = "pnpm";
|
|
72941
73071
|
break;
|
|
72942
73072
|
}
|
|
72943
|
-
if (
|
|
73073
|
+
if (existsSync(join2(dir, "yarn.lock"))) {
|
|
72944
73074
|
package_manager = "yarn";
|
|
72945
73075
|
break;
|
|
72946
73076
|
}
|
|
72947
|
-
} while (dir !== (dir =
|
|
73077
|
+
} while (dir !== (dir = dirname(dir)));
|
|
72948
73078
|
return {
|
|
72949
73079
|
typescript,
|
|
72950
73080
|
package_manager,
|
|
@@ -72952,134 +73082,6 @@ async function detectTools(cwd = process.cwd()) {
|
|
|
72952
73082
|
};
|
|
72953
73083
|
}
|
|
72954
73084
|
|
|
72955
|
-
// src/runtime/router/match.ts
|
|
72956
|
-
var param_pattern = /^(\[)?(\.\.\.)?(\w+)(?:=(\w+))?(\])?$/;
|
|
72957
|
-
function find_match(config, manifest, current, allowNull = true) {
|
|
72958
|
-
let match2 = null;
|
|
72959
|
-
let matchVariables = null;
|
|
72960
|
-
for (const page of Object.values(manifest.pages)) {
|
|
72961
|
-
const urlMatch = current.match(page.pattern);
|
|
72962
|
-
if (!urlMatch) {
|
|
72963
|
-
continue;
|
|
72964
|
-
}
|
|
72965
|
-
match2 = page;
|
|
72966
|
-
matchVariables = exec(urlMatch, page.params) || {};
|
|
72967
|
-
break;
|
|
72968
|
-
}
|
|
72969
|
-
if (!match2 && !allowNull) {
|
|
72970
|
-
throw new Error("404");
|
|
72971
|
-
}
|
|
72972
|
-
let variables = {
|
|
72973
|
-
...matchVariables
|
|
72974
|
-
};
|
|
72975
|
-
for (const document of Object.values(match2?.documents ?? {})) {
|
|
72976
|
-
for (const [variable, { type }] of Object.entries(document.variables)) {
|
|
72977
|
-
if (matchVariables?.[variable]) {
|
|
72978
|
-
variables[variable] = parseScalar(config, type, matchVariables[variable]);
|
|
72979
|
-
}
|
|
72980
|
-
}
|
|
72981
|
-
}
|
|
72982
|
-
return [match2, variables];
|
|
72983
|
-
}
|
|
72984
|
-
function parse_page_pattern(id) {
|
|
72985
|
-
const params = [];
|
|
72986
|
-
const pattern = id === "/" ? /^\/$/ : new RegExp(
|
|
72987
|
-
`^${get_route_segments(id).map((segment) => {
|
|
72988
|
-
const rest_match = /^\[\.\.\.(\w+)(?:=(\w+))?\]$/.exec(segment);
|
|
72989
|
-
if (rest_match) {
|
|
72990
|
-
params.push({
|
|
72991
|
-
name: rest_match[1],
|
|
72992
|
-
matcher: rest_match[2],
|
|
72993
|
-
optional: false,
|
|
72994
|
-
rest: true,
|
|
72995
|
-
chained: true
|
|
72996
|
-
});
|
|
72997
|
-
return "(?:/(.*))?";
|
|
72998
|
-
}
|
|
72999
|
-
const optional_match = /^\[\[(\w+)(?:=(\w+))?\]\]$/.exec(segment);
|
|
73000
|
-
if (optional_match) {
|
|
73001
|
-
params.push({
|
|
73002
|
-
name: optional_match[1],
|
|
73003
|
-
matcher: optional_match[2],
|
|
73004
|
-
optional: true,
|
|
73005
|
-
rest: false,
|
|
73006
|
-
chained: true
|
|
73007
|
-
});
|
|
73008
|
-
return "(?:/([^/]+))?";
|
|
73009
|
-
}
|
|
73010
|
-
if (!segment) {
|
|
73011
|
-
return;
|
|
73012
|
-
}
|
|
73013
|
-
const parts = segment.split(/\[(.+?)\](?!\])/);
|
|
73014
|
-
const result = parts.map((content, i2) => {
|
|
73015
|
-
if (i2 % 2) {
|
|
73016
|
-
if (content.startsWith("x+")) {
|
|
73017
|
-
return escape3(
|
|
73018
|
-
String.fromCharCode(parseInt(content.slice(2), 16))
|
|
73019
|
-
);
|
|
73020
|
-
}
|
|
73021
|
-
if (content.startsWith("u+")) {
|
|
73022
|
-
return escape3(
|
|
73023
|
-
String.fromCharCode(
|
|
73024
|
-
...content.slice(2).split("-").map((code) => parseInt(code, 16))
|
|
73025
|
-
)
|
|
73026
|
-
);
|
|
73027
|
-
}
|
|
73028
|
-
const match2 = param_pattern.exec(content);
|
|
73029
|
-
if (!match2) {
|
|
73030
|
-
throw new Error(
|
|
73031
|
-
`Invalid param: ${content}. Params and matcher names can only have underscores and alphanumeric characters.`
|
|
73032
|
-
);
|
|
73033
|
-
}
|
|
73034
|
-
const [, is_optional, is_rest, name, matcher] = match2;
|
|
73035
|
-
params.push({
|
|
73036
|
-
name,
|
|
73037
|
-
matcher,
|
|
73038
|
-
optional: !!is_optional,
|
|
73039
|
-
rest: !!is_rest,
|
|
73040
|
-
chained: is_rest ? i2 === 1 && parts[0] === "" : false
|
|
73041
|
-
});
|
|
73042
|
-
return is_rest ? "(.*?)" : is_optional ? "([^/]*)?" : "([^/]+?)";
|
|
73043
|
-
}
|
|
73044
|
-
return escape3(content);
|
|
73045
|
-
}).join("");
|
|
73046
|
-
return "/" + result;
|
|
73047
|
-
}).join("")}/?$`
|
|
73048
|
-
);
|
|
73049
|
-
return { pattern, params, page_id: id };
|
|
73050
|
-
}
|
|
73051
|
-
function affects_path(segment) {
|
|
73052
|
-
return !/^\([^)]+\)$/.test(segment);
|
|
73053
|
-
}
|
|
73054
|
-
function get_route_segments(route) {
|
|
73055
|
-
return route.slice(1).split("/").filter(affects_path);
|
|
73056
|
-
}
|
|
73057
|
-
function exec(match2, params) {
|
|
73058
|
-
const result = {};
|
|
73059
|
-
const values = match2.slice(1);
|
|
73060
|
-
let buffered = "";
|
|
73061
|
-
for (let i2 = 0; i2 < (params || []).length; i2 += 1) {
|
|
73062
|
-
const param = params[i2];
|
|
73063
|
-
let value = values[i2];
|
|
73064
|
-
if (param.chained && param.rest && buffered) {
|
|
73065
|
-
value = value ? buffered + "/" + value : buffered;
|
|
73066
|
-
}
|
|
73067
|
-
buffered = "";
|
|
73068
|
-
if (value === void 0) {
|
|
73069
|
-
if (param.rest)
|
|
73070
|
-
result[param.name] = "";
|
|
73071
|
-
} else {
|
|
73072
|
-
result[param.name] = decodeURIComponent(value);
|
|
73073
|
-
}
|
|
73074
|
-
}
|
|
73075
|
-
if (buffered)
|
|
73076
|
-
return;
|
|
73077
|
-
return result;
|
|
73078
|
-
}
|
|
73079
|
-
function escape3(str) {
|
|
73080
|
-
return str.normalize().replace(/[[\]]/g, "\\$&").replace(/%/g, "%25").replace(/\//g, "%2[Ff]").replace(/\?/g, "%3[Ff]").replace(/#/g, "%23").replace(/[.*+?^${}()|\\]/g, "\\$&");
|
|
73081
|
-
}
|
|
73082
|
-
|
|
73083
73085
|
// src/lib/typescript.ts
|
|
73084
73086
|
var recast2 = __toESM(require_main2(), 1);
|
|
73085
73087
|
import * as graphql6 from "graphql";
|
|
@@ -73149,18 +73151,18 @@ function scalarPropertyValue(config, filepath, missingScalars, target, body, fie
|
|
|
73149
73151
|
return AST3.tsNeverKeyword();
|
|
73150
73152
|
}
|
|
73151
73153
|
const component = config.componentFields[field.parent][field.field];
|
|
73152
|
-
const sourcePathRelative =
|
|
73153
|
-
|
|
73154
|
+
const sourcePathRelative = relative(
|
|
73155
|
+
join2(config.projectRoot, "src"),
|
|
73154
73156
|
component.filepath
|
|
73155
73157
|
);
|
|
73156
|
-
let sourcePathParsed =
|
|
73157
|
-
let sourcePath =
|
|
73158
|
+
let sourcePathParsed = parse3(sourcePathRelative);
|
|
73159
|
+
let sourcePath = join2(sourcePathParsed.dir, sourcePathParsed.name);
|
|
73158
73160
|
const localImport = ensureImports({
|
|
73159
73161
|
config,
|
|
73160
73162
|
body,
|
|
73161
73163
|
import: "__component__" + component.fragment,
|
|
73162
|
-
sourceModule:
|
|
73163
|
-
|
|
73164
|
+
sourceModule: join2(
|
|
73165
|
+
relative(dirname(filepath), config.projectRoot),
|
|
73164
73166
|
"src",
|
|
73165
73167
|
sourcePath
|
|
73166
73168
|
)
|
|
@@ -73226,9 +73228,9 @@ function scalarPropertyValue(config, filepath, missingScalars, target, body, fie
|
|
|
73226
73228
|
}
|
|
73227
73229
|
}
|
|
73228
73230
|
async function writeTsConfig(config) {
|
|
73229
|
-
await
|
|
73230
|
-
await
|
|
73231
|
-
|
|
73231
|
+
await mkdirp(config.rootDir);
|
|
73232
|
+
await writeFile(
|
|
73233
|
+
join2(config.rootDir, "tsconfig.json"),
|
|
73232
73234
|
JSON.stringify(
|
|
73233
73235
|
{
|
|
73234
73236
|
compilerOptions: {
|