@hamur/content 0.0.1 → 0.0.3

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.
Files changed (47) hide show
  1. package/dist/chunks/{bun-render-7jxnxg3v.js → bun-render-wckjnzsa.js} +5 -3
  2. package/dist/src/index.js +132 -73
  3. package/dist/src/query.js +4 -2
  4. package/dist/src/server/index.js +1 -1
  5. package/dist/types/src/adapters/ContentRenderer.svelte +27 -0
  6. package/dist/types/src/adapters/ProseA.svelte +11 -0
  7. package/dist/types/src/adapters/ProseBlockquote.svelte +7 -0
  8. package/dist/types/src/adapters/ProseCode.svelte +7 -0
  9. package/dist/types/src/adapters/ProseEm.svelte +7 -0
  10. package/dist/types/src/adapters/ProseH1.svelte +7 -0
  11. package/dist/types/src/adapters/ProseH2.svelte +7 -0
  12. package/dist/types/src/adapters/ProseH3.svelte +7 -0
  13. package/dist/types/src/adapters/ProseH4.svelte +7 -0
  14. package/dist/types/src/adapters/ProseH5.svelte +7 -0
  15. package/dist/types/src/adapters/ProseH6.svelte +7 -0
  16. package/dist/types/src/adapters/ProseHr.svelte +5 -0
  17. package/dist/types/src/adapters/ProseImg.svelte +5 -0
  18. package/dist/types/src/adapters/ProseLi.svelte +7 -0
  19. package/dist/types/src/adapters/ProseOl.svelte +7 -0
  20. package/dist/types/src/adapters/ProseP.svelte +7 -0
  21. package/dist/types/src/adapters/ProsePre.svelte +21 -0
  22. package/dist/types/src/adapters/ProseStrong.svelte +7 -0
  23. package/dist/types/src/adapters/ProseTable.svelte +7 -0
  24. package/dist/types/src/adapters/ProseUl.svelte +7 -0
  25. package/dist/types/src/build/access.d.ts +15 -0
  26. package/dist/types/src/build/query.d.ts +8 -4
  27. package/dist/types/src/build/search.d.ts +2 -1
  28. package/dist/types/src/runtime/client.d.ts +2 -1
  29. package/dist/types/src/runtime/query.d.ts +12 -3
  30. package/dist/types/src/server/access.d.ts +4 -0
  31. package/dist/types/src/server/graphql.d.ts +3 -2
  32. package/dist/types/src/server/rest.d.ts +4 -4
  33. package/package.json +48 -18
  34. package/src/build/access.ts +37 -0
  35. package/src/build/api.ts +1 -1
  36. package/src/build/dev.ts +3 -1
  37. package/src/build/graphql.ts +5 -2
  38. package/src/build/query.ts +47 -8
  39. package/src/build/raw.ts +9 -2
  40. package/src/build/search.ts +9 -4
  41. package/src/module.ts +2 -2
  42. package/src/runtime/client.ts +7 -2
  43. package/src/runtime/query.ts +30 -4
  44. package/src/server/access.ts +26 -0
  45. package/src/server/endpoint.ts +3 -2
  46. package/src/server/graphql.ts +13 -6
  47. package/src/server/rest.ts +14 -6
@@ -35,6 +35,7 @@ var PAGE_FIELDS = [
35
35
  "toc",
36
36
  "readingTime"
37
37
  ];
38
+ var QUERY_PATH = "/_hamur/content/query";
38
39
  var QUERY_LIMITS = {
39
40
  conditions: 100,
40
41
  depth: 8,
@@ -339,10 +340,11 @@ function pick(entry, select) {
339
340
  }
340
341
  return out;
341
342
  }
342
- function runQuery(name, collection, entries, value) {
343
+ function runQuery(name, collection, entries, value, visible) {
343
344
  const query = checkQuery(value, knownFields(collection.type, entries), name);
344
345
  const where = query.where ?? [];
345
- const found = where.length ? entries.filter((entry) => passes(entry, where)) : [...entries];
346
+ const readable = visible ? entries.filter(visible) : entries;
347
+ const found = where.length ? readable.filter((entry) => passes(entry, where)) : [...readable];
346
348
  if (query.count)
347
349
  return found.length;
348
350
  const order = query.order ?? (collection.order ? [collection.order] : []);
@@ -711,4 +713,4 @@ async function searchSectionsOf(query, options) {
711
713
  return rows.flatMap((row) => sectionsOf(row, resolved));
712
714
  }
713
715
 
714
- export { QueryError, runQuery, queryStore, createQuery, navigationOf, surroundingsOf, findPageHeadline2, findPageBreadcrumb2, findPageChildren2, findPageSiblings2, searchSectionsOf };
716
+ export { QueryError, QUERY_PATH, runQuery, queryStore, createQuery, navigationOf, surroundingsOf, findPageHeadline2, findPageBreadcrumb2, findPageChildren2, findPageSiblings2, searchSectionsOf };
package/dist/src/index.js CHANGED
@@ -30,58 +30,8 @@ function parseRefreshBody(text) {
30
30
  return collections === undefined ? {} : { collections };
31
31
  }
32
32
 
33
- // packages/content/src/build/dev-route.ts
34
- var DEV_ROUTE = "/_hamur/content/dev";
35
- var REFRESH_ROUTE = "/_hamur/content/refresh";
36
-
37
- // packages/content/src/build/search.ts
38
- import { DiagnosticError, addAppPlugin, addTemplate, createResolver } from "hamur/kit";
39
-
40
- // packages/content/src/runtime/search.ts
41
- var SEPARATORS = /[^\p{L}\p{N}]+/u;
42
- var fold = (text) => text.toLowerCase().normalize("NFD").replace(/\p{M}/gu, "");
43
- var tokenize = (text) => fold(text).split(SEPARATORS).filter(Boolean);
44
- var compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
45
- var mean = (values) => values.length ? values.reduce((sum, value) => sum + value, 0) / values.length : 0;
46
- function buildSearchIndex(sections) {
47
- const found = new Map;
48
- const titleLengths = [];
49
- const bodyLengths = [];
50
- sections.forEach((section, number) => {
51
- const counts = new Map;
52
- const add = (token, field) => {
53
- let pair = counts.get(token);
54
- if (!pair)
55
- counts.set(token, pair = [0, 0]);
56
- pair[field]++;
57
- };
58
- const title = tokenize(section.title);
59
- const body = tokenize(section.content);
60
- for (const token of title)
61
- add(token, 0);
62
- for (const token of body)
63
- add(token, 1);
64
- titleLengths.push(title.length);
65
- bodyLengths.push(body.length);
66
- for (const [term, [inTitle, inBody]] of counts) {
67
- let list = found.get(term);
68
- if (!list)
69
- found.set(term, list = []);
70
- list.push(number, inTitle, inBody);
71
- }
72
- });
73
- const terms = [...found.keys()].sort(compare);
74
- return {
75
- version: 1,
76
- sections: sections.map(({ id, title, titles, level }) => ({ id, title, titles, level })),
77
- titleLengths,
78
- bodyLengths,
79
- avgTitleLength: mean(titleLengths),
80
- avgBodyLength: mean(bodyLengths),
81
- terms,
82
- postings: terms.map((term) => found.get(term))
83
- };
84
- }
33
+ // packages/content/src/build/access.ts
34
+ import { accessRuleOf, hasPlatformFiles } from "hamur/server/internal";
85
35
 
86
36
  // packages/content/src/runtime/query.ts
87
37
  class QueryError extends Error {
@@ -119,6 +69,7 @@ var PAGE_FIELDS = [
119
69
  "toc",
120
70
  "readingTime"
121
71
  ];
72
+ var QUERY_PATH = "/_hamur/content/query";
122
73
  var QUERY_LIMITS = {
123
74
  conditions: 100,
124
75
  depth: 8,
@@ -293,7 +244,7 @@ function compareText(a, b) {
293
244
  return delta < 0 ? -1 : 1;
294
245
  }
295
246
  }
296
- function compare2(a, b) {
247
+ function compare(a, b) {
297
248
  const ka = kind(a);
298
249
  const kb = kind(b);
299
250
  if (ka !== kb)
@@ -306,8 +257,8 @@ function compare2(a, b) {
306
257
  return compareText(a, b);
307
258
  return compareText(JSON.stringify(a), JSON.stringify(b));
308
259
  }
309
- var equal = (a, b) => a !== null && b !== null && compare2(a, b) === 0;
310
- var ordered = (a, b, test) => a === null || b === null ? null : test(compare2(a, b));
260
+ var equal = (a, b) => a !== null && b !== null && compare(a, b) === 0;
261
+ var ordered = (a, b, test) => a === null || b === null ? null : test(compare(a, b));
311
262
  var textOf = (value) => typeof value === "string" ? value : typeof value === "boolean" ? value ? "1" : "0" : typeof value === "number" ? String(value) : JSON.stringify(value);
312
263
  var foldAscii = (char) => char.length === 1 && char >= "A" && char <= "Z" ? String.fromCharCode(char.charCodeAt(0) + 32) : char;
313
264
  function like(text, pattern) {
@@ -392,7 +343,7 @@ function sorter(order) {
392
343
  for (const [field, direction] of order) {
393
344
  const x = valueAt(a, field);
394
345
  const y = valueAt(b, field);
395
- const result = x === null ? y === null ? 0 : -1 : y === null ? 1 : compare2(x, y);
346
+ const result = x === null ? y === null ? 0 : -1 : y === null ? 1 : compare(x, y);
396
347
  if (result)
397
348
  return direction === "DESC" ? -result : result;
398
349
  }
@@ -423,10 +374,11 @@ function pick(entry, select) {
423
374
  }
424
375
  return out;
425
376
  }
426
- function runQuery(name, collection, entries, value) {
377
+ function runQuery(name, collection, entries, value, visible) {
427
378
  const query = checkQuery(value, knownFields(collection.type, entries), name);
428
379
  const where = query.where ?? [];
429
- const found = where.length ? entries.filter((entry) => passes(entry, where)) : [...entries];
380
+ const readable = visible ? entries.filter(visible) : entries;
381
+ const found = where.length ? readable.filter((entry) => passes(entry, where)) : [...readable];
430
382
  if (query.count)
431
383
  return found.length;
432
384
  const order = query.order ?? (collection.order ? [collection.order] : []);
@@ -436,6 +388,81 @@ function runQuery(name, collection, entries, value) {
436
388
  return query.select ? page.map((entry) => pick(entry, query.select)) : page.map((entry) => structuredClone(entry));
437
389
  }
438
390
 
391
+ // packages/content/src/build/access.ts
392
+ function publicIn(hamur) {
393
+ const ruleOf = accessRuleOf(hamur.routeRules);
394
+ if (ruleOf.empty)
395
+ return () => true;
396
+ const alone = hasPlatformFiles(hamur);
397
+ return (entry, file) => {
398
+ const { path } = entry;
399
+ return typeof path !== "string" || ruleOf(path, alone ? undefined : file) === undefined;
400
+ };
401
+ }
402
+ function signedIn(hamur) {
403
+ const ruleOf = accessRuleOf(hamur.routeRules);
404
+ if (ruleOf.empty)
405
+ return () => false;
406
+ return (entry) => {
407
+ const { path } = entry;
408
+ return typeof path === "string" && ruleOf(path, QUERY_PATH)?.key === "basicAuth";
409
+ };
410
+ }
411
+ var chunkFile = (hamur) => `/${hamur.options.app.buildAssetsDir.replace(/^\/+|\/+$/g, "")}/content.js`.replace("//", "/");
412
+
413
+ // packages/content/src/build/dev-route.ts
414
+ var DEV_ROUTE = "/_hamur/content/dev";
415
+ var REFRESH_ROUTE = "/_hamur/content/refresh";
416
+
417
+ // packages/content/src/build/search.ts
418
+ import { DiagnosticError, addAppPlugin, addTemplate, createResolver } from "hamur/kit";
419
+
420
+ // packages/content/src/runtime/search.ts
421
+ var SEPARATORS = /[^\p{L}\p{N}]+/u;
422
+ var fold = (text) => text.toLowerCase().normalize("NFD").replace(/\p{M}/gu, "");
423
+ var tokenize = (text) => fold(text).split(SEPARATORS).filter(Boolean);
424
+ var compare2 = (a, b) => a < b ? -1 : a > b ? 1 : 0;
425
+ var mean = (values) => values.length ? values.reduce((sum, value) => sum + value, 0) / values.length : 0;
426
+ function buildSearchIndex(sections) {
427
+ const found = new Map;
428
+ const titleLengths = [];
429
+ const bodyLengths = [];
430
+ sections.forEach((section, number) => {
431
+ const counts = new Map;
432
+ const add = (token, field) => {
433
+ let pair = counts.get(token);
434
+ if (!pair)
435
+ counts.set(token, pair = [0, 0]);
436
+ pair[field]++;
437
+ };
438
+ const title = tokenize(section.title);
439
+ const body = tokenize(section.content);
440
+ for (const token of title)
441
+ add(token, 0);
442
+ for (const token of body)
443
+ add(token, 1);
444
+ titleLengths.push(title.length);
445
+ bodyLengths.push(body.length);
446
+ for (const [term, [inTitle, inBody]] of counts) {
447
+ let list = found.get(term);
448
+ if (!list)
449
+ found.set(term, list = []);
450
+ list.push(number, inTitle, inBody);
451
+ }
452
+ });
453
+ const terms = [...found.keys()].sort(compare2);
454
+ return {
455
+ version: 1,
456
+ sections: sections.map(({ id, title, titles, level }) => ({ id, title, titles, level })),
457
+ titleLengths,
458
+ bodyLengths,
459
+ avgTitleLength: mean(titleLengths),
460
+ avgBodyLength: mean(bodyLengths),
461
+ terms,
462
+ postings: terms.map((term) => found.get(term))
463
+ };
464
+ }
465
+
439
466
  // packages/content/src/runtime/sections.ts
440
467
  var BLOCKS = new Set([
441
468
  "root",
@@ -569,14 +596,18 @@ function searchModule(names, devLoad) {
569
596
  return [...imports, "export default {", ...loaders, "};", ""].join(`
570
597
  `);
571
598
  }
572
- function setupSearch(options, config, entries, dev = false) {
599
+ function setupSearch(options, config, entries, hamur) {
573
600
  const names = resolveSearch(options.search, config);
574
601
  const resolver = createResolver(new URL("../../src/build/search.ts", import.meta.url).href);
575
- const devLoad = dev ? resolver.resolve("../runtime/dev-client.ts") : undefined;
602
+ const devLoad = hamur.options.dev ? resolver.resolve("../runtime/dev-client.ts") : undefined;
576
603
  for (const name of names)
577
604
  addTemplate({
578
605
  filename: `content/search-index/${name}.json`,
579
- getContents: async () => JSON.stringify(searchIndexOf((await entries())[name]))
606
+ getContents: async () => {
607
+ const isPublic = publicIn(hamur);
608
+ const listed = (await entries())[name].filter((entry) => isPublic(entry, chunkFile(hamur)));
609
+ return JSON.stringify(searchIndexOf(listed));
610
+ }
580
611
  });
581
612
  addTemplate({ filename: "content/search", getContents: () => searchModule(names, devLoad) });
582
613
  if (names.length)
@@ -738,7 +769,8 @@ function setupDev(hamur, config, index, search) {
738
769
  const collection = Object.hasOwn(config.collections, name) ? config.collections[name] : undefined;
739
770
  if (!collection || collection.expose === false || kind === "search" && !search.includes(name))
740
771
  return;
741
- const entries = (await index.read())[name];
772
+ const isPublic = publicIn(hamur);
773
+ const entries = (await index.read())[name].filter((entry) => isPublic(entry, chunkFile(hamur)));
742
774
  return Response.json(kind === "chunks" ? entries : searchIndexOf(entries), {
743
775
  headers: { "cache-control": "no-store" }
744
776
  });
@@ -2006,7 +2038,7 @@ function restModule(config, runtime) {
2006
2038
  " input: restInput,",
2007
2039
  ` output: restOutput(${q(restSchema(name, config.collections[name]))}),`,
2008
2040
  ` meta: { summary: ${q(`Query the ${name} collection`)}, description: REST_DESCRIPTION, tags: ["content"], operationId: ${q(`getContent${exportOf(name).slice("contentRest".length)}`)}, responses: restResponses },`,
2009
- ` handler: (input) => answerRest(store, ${q(name)}, input),`,
2041
+ ` handler: (input, { event }) => answerRest(store, ${q(name)}, input, event),`,
2010
2042
  "});",
2011
2043
  ""
2012
2044
  ].join(`
@@ -2159,7 +2191,7 @@ function contentGraphQL(config, runtime) {
2159
2191
  taken.set(field, name);
2160
2192
  }
2161
2193
  roots.push(` ${name}(where: [ContentWhere!], order: [ContentOrder!], limit: Int, skip: Int): [${type}!]!`, ` ${name}Item(${key}: String!): ${type}`);
2162
- query.push(` ${name}: (_parent: unknown, args: ListArgs) => contentList(store, ${q(name)}, args),`, ` ${name}Item: (_parent: unknown, args: { ${key}: string }) => contentItem(store, ${q(name)}, ${q(key)}, args.${key}),`);
2194
+ query.push(` ${name}: (_parent: unknown, args: ListArgs, { event }: Context) => contentList(store, ${q(name)}, args, event),`, ` ${name}Item: (_parent: unknown, args: { ${key}: string }, { event }: Context) => contentItem(store, ${q(name)}, ${q(key)}, args.${key}, event),`);
2163
2195
  }
2164
2196
  for (const shared of ["ContentWhere", "ContentOrder", "ContentDirection", "Query"]) {
2165
2197
  if (objects.has(shared))
@@ -2193,8 +2225,11 @@ function contentGraphQL(config, runtime) {
2193
2225
  const jsonTypes = [...objects].filter(([, { json }]) => json.length).map(([name, { json }]) => ` ${name}: { ${json.map((field) => `${field}: jsonField(${q(field)})`).join(", ")} },`);
2194
2226
  const resolvers = [
2195
2227
  `import store from "#hamur/content/store";`,
2228
+ `import type { HamurEvent } from "hamur/server";`,
2196
2229
  `import { contentItem, contentList, jsonField, type ListArgs } from ${q(runtime)};`,
2197
2230
  "",
2231
+ "type Context = { event: HamurEvent };",
2232
+ "",
2198
2233
  "export default {",
2199
2234
  " Query: {",
2200
2235
  ...query,
@@ -2307,11 +2342,14 @@ function setupRaw(options, config, index, hamur) {
2307
2342
  const file = index.file(entry.collection, entry.id);
2308
2343
  return file === undefined ? undefined : Bun.file(file).text();
2309
2344
  };
2345
+ const isPublic = publicIn(hamur);
2310
2346
  if (raw) {
2311
2347
  for (const [name, collection] of Object.entries(config.collections)) {
2312
2348
  if (collection.type !== "page")
2313
2349
  continue;
2314
2350
  for (const entry of entries[name] ?? []) {
2351
+ if (!isPublic(entry, rawPath(entry.path)))
2352
+ continue;
2315
2353
  const source = await text(entry);
2316
2354
  if (source !== undefined)
2317
2355
  emitPublicAsset(rawPath(entry.path), source);
@@ -2320,12 +2358,16 @@ function setupRaw(options, config, index, hamur) {
2320
2358
  }
2321
2359
  if (llms) {
2322
2360
  const sections = llmsSections(llms, config, entries);
2323
- emitPublicAsset("/llms.txt", llmsText(llms, sections, hamur.options.site.url, hamur.options.app.baseURL));
2361
+ const listed = sections.map(({ title, entries }) => ({
2362
+ title,
2363
+ entries: entries.filter((entry) => isPublic(entry, "/llms.txt"))
2364
+ }));
2365
+ emitPublicAsset("/llms.txt", llmsText(llms, listed, hamur.options.site.url, hamur.options.app.baseURL));
2324
2366
  const seen = new Set;
2325
2367
  const sources = [];
2326
2368
  for (const entry of sections.flatMap((section) => section.entries)) {
2327
2369
  const key = `${entry.collection}\x00${entry.id}`;
2328
- if (seen.has(key))
2370
+ if (seen.has(key) || !isPublic(entry, "/llms-full.txt"))
2329
2371
  continue;
2330
2372
  seen.add(key);
2331
2373
  const source = await text(entry);
@@ -2348,11 +2390,16 @@ function resolveClientQuery(value, preset) {
2348
2390
  throw new DiagnosticError10("HAMUR_E5333", 'content.clientQuery "api" needs a server; the static preset uses "local"');
2349
2391
  return value;
2350
2392
  }
2351
- function clientModule(config, mode, devLoad, raw) {
2393
+ function clientModule(config, mode, devLoad, raw, asked, signed) {
2352
2394
  const collections = Object.entries(config.collections).map(([name, { type, expose = true, order }]) => {
2353
- const meta = JSON.stringify({ type, expose, ...order ? { order } : {} });
2395
+ const meta = JSON.stringify({
2396
+ type,
2397
+ expose,
2398
+ ...order ? { order } : {},
2399
+ ...signed?.has(name) ? { basicAuth: true } : {}
2400
+ });
2354
2401
  const loader = devLoad ? `devLoad(${JSON.stringify(`${DEV_ROUTE}/chunks/${name}.json`)})` : `() => import(${JSON.stringify(`#hamur/content/chunks/${name}.json`)})`;
2355
- const load = mode === "local" && expose ? `, load: ${loader} }` : "";
2402
+ const load = mode === "local" && expose && !asked?.has(name) ? `, load: ${loader} }` : "";
2356
2403
  return ` ${JSON.stringify(name)}: ${load ? `${meta.slice(0, -1)}${load}` : meta},`;
2357
2404
  });
2358
2405
  const imports = devLoad && mode === "local" ? [`import { devLoad } from ${JSON.stringify(devLoad)};`, ""] : [];
@@ -2374,7 +2421,7 @@ function doorOf(preset, dev) {
2374
2421
  return preset === "static" ? "../server/door-dev-static.ts" : "../server/door-dev.ts";
2375
2422
  return preset === "static" ? "../server/door-static.ts" : "../server/door.ts";
2376
2423
  }
2377
- function setupQuery(options, config, hamur) {
2424
+ function setupQuery(options, config, entries, hamur) {
2378
2425
  const { preset } = hamur.options;
2379
2426
  const mode = resolveClientQuery(options.clientQuery, preset);
2380
2427
  const client = hamur.options.build.importProtection.client ??= {};
@@ -2390,7 +2437,19 @@ function setupQuery(options, config, hamur) {
2390
2437
  addAppPlugin3({ src: createResolver7(new URL("../../src/build/query.ts", import.meta.url).href).resolve("../runtime/page-plugin.ts"), mode: "all" });
2391
2438
  addTemplate6({
2392
2439
  filename: "content/client",
2393
- getContents: () => clientModule(config, mode, devLoad, resolveRaw(options.raw) ? hamur.options.app.baseURL : undefined)
2440
+ getContents: async () => {
2441
+ const raw = resolveRaw(options.raw) ? hamur.options.app.baseURL : undefined;
2442
+ if (preset === "static")
2443
+ return clientModule(config, mode, devLoad, raw);
2444
+ const all = Object.entries(await entries());
2445
+ const names = (test) => new Set(all.filter(([, list]) => list.some(test)).map(([name]) => name));
2446
+ const signed = names(signedIn(hamur));
2447
+ if (mode === "api")
2448
+ return clientModule(config, mode, devLoad, raw, undefined, signed);
2449
+ const isPublic = publicIn(hamur);
2450
+ const file = chunkFile(hamur);
2451
+ return clientModule(config, mode, devLoad, raw, names((entry) => !isPublic(entry, file)), signed);
2452
+ }
2394
2453
  });
2395
2454
  }
2396
2455
 
@@ -2670,10 +2729,10 @@ var module_default = defineModule({
2670
2729
  async setup(options, hamur) {
2671
2730
  const config = await setupConfig(hamur.options.rootDir);
2672
2731
  const index = setupIndex(hamur, config, options);
2673
- setupQuery(options, config, hamur);
2732
+ setupQuery(options, config, index.read, hamur);
2674
2733
  setupPrerender(options, config, index.read, hamur);
2675
2734
  setupRaw(options, config, index, hamur);
2676
- const search = setupSearch(options, config, index.read, hamur.options.dev);
2735
+ const search = setupSearch(options, config, index.read, hamur);
2677
2736
  setupDev(hamur, config, index, search);
2678
2737
  setupLive(config, hamur);
2679
2738
  setupTypes(config, hamur);
package/dist/src/query.js CHANGED
@@ -1,6 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  QueryError,
4
+ QUERY_PATH,
4
5
  runQuery,
5
6
  queryStore,
6
7
  createQuery,
@@ -11,7 +12,7 @@ import {
11
12
  findPageChildren2,
12
13
  findPageSiblings2,
13
14
  searchSectionsOf
14
- } from "../chunks/bun-render-7jxnxg3v.js";
15
+ } from "../chunks/bun-render-wckjnzsa.js";
15
16
 
16
17
  // packages/content/src/query.ts
17
18
  import client from "#hamur/content/client";
@@ -19,7 +20,6 @@ import { noteDependency } from "hamur/app";
19
20
 
20
21
  // packages/content/src/runtime/client.ts
21
22
  import { $fetch, FetchError } from "hamur/app";
22
- var QUERY_PATH = "/_hamur/content/query";
23
23
  async function postQuery(body) {
24
24
  try {
25
25
  return await $fetch(QUERY_PATH, { method: "POST", body, retry: 0 });
@@ -47,6 +47,8 @@ function createClientQuery(config, post = postQuery) {
47
47
  throw new QueryError(`queryCollection: unknown collection ${JSON.stringify(name)}`);
48
48
  if (!collection.expose)
49
49
  throw new QueryError(`queryCollection(${JSON.stringify(name)}): the collection is not exposed to the client (expose: false)`);
50
+ if (collection.basicAuth)
51
+ throw new QueryError(`queryCollection(${JSON.stringify(name)}): pages of the collection are under basicAuth, whose credentials a browser does not send to ${QUERY_PATH}; query it in a load, which runs on the server for the page's own request`);
50
52
  const { load } = collection;
51
53
  if (config.mode === "local" && load)
52
54
  return createQuery(async (query) => runQuery(name, collection, await entries(name, load), query));
@@ -9,7 +9,7 @@ import {
9
9
  findPageChildren2,
10
10
  findPageSiblings2,
11
11
  searchSectionsOf
12
- } from "../../chunks/bun-render-7jxnxg3v.js";
12
+ } from "../../chunks/bun-render-wckjnzsa.js";
13
13
  import {
14
14
  searchIndex
15
15
  } from "../../chunks/bun-render-65mwzeq2.js";
@@ -0,0 +1,27 @@
1
+ <script lang="ts">
2
+ import type { Component } from "svelte"
3
+ import { MarkdownRenderer } from "@hamur/adapter-svelte"
4
+ import type { MdRoot } from "hamur/markdown"
5
+ import type { PageFields } from "../types.ts"
6
+ import { prepare } from "./prose.ts"
7
+ import { DEFAULTS } from "./svelte-defaults.ts"
8
+
9
+ let {
10
+ value,
11
+ components,
12
+ tag = "div",
13
+ excerpt,
14
+ unwrap,
15
+ }: {
16
+ value: PageFields | MdRoot
17
+ components?: Record<string, Component<any>> | false
18
+ tag?: string
19
+ excerpt?: boolean
20
+ unwrap?: string
21
+ } = $props()
22
+ const prepared = $derived(prepare({ value, components, defaults: DEFAULTS, excerpt, unwrap }))
23
+ </script>
24
+
25
+ {#if prepared}<svelte:element this={tag}
26
+ ><MarkdownRenderer value={prepared.root} components={prepared.components} /></svelte:element
27
+ >{/if}
@@ -0,0 +1,11 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte"
3
+ import { Link } from "@hamur/adapter-svelte"
4
+ import { isInternal } from "./prose.ts"
5
+
6
+ let { href, children, ...rest }: { href?: string; children?: Snippet; [attribute: string]: unknown } = $props()
7
+ </script>
8
+
9
+ {#if isInternal(href)}<Link {...rest} to={href}>{@render children?.()}</Link>{:else}<a {href} {...rest}
10
+ >{@render children?.()}</a
11
+ >{/if}
@@ -0,0 +1,7 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte"
3
+
4
+ let { children, ...rest }: { children?: Snippet; [attribute: string]: unknown } = $props()
5
+ </script>
6
+
7
+ <blockquote {...rest}>{@render children?.()}</blockquote>
@@ -0,0 +1,7 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte"
3
+
4
+ let { children, ...rest }: { children?: Snippet; [attribute: string]: unknown } = $props()
5
+ </script>
6
+
7
+ <code {...rest}>{@render children?.()}</code>
@@ -0,0 +1,7 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte"
3
+
4
+ let { children, ...rest }: { children?: Snippet; [attribute: string]: unknown } = $props()
5
+ </script>
6
+
7
+ <em {...rest}>{@render children?.()}</em>
@@ -0,0 +1,7 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte"
3
+
4
+ let { children, ...rest }: { children?: Snippet; [attribute: string]: unknown } = $props()
5
+ </script>
6
+
7
+ <h1 {...rest}>{@render children?.()}</h1>
@@ -0,0 +1,7 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte"
3
+
4
+ let { children, ...rest }: { children?: Snippet; [attribute: string]: unknown } = $props()
5
+ </script>
6
+
7
+ <h2 {...rest}>{@render children?.()}</h2>
@@ -0,0 +1,7 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte"
3
+
4
+ let { children, ...rest }: { children?: Snippet; [attribute: string]: unknown } = $props()
5
+ </script>
6
+
7
+ <h3 {...rest}>{@render children?.()}</h3>
@@ -0,0 +1,7 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte"
3
+
4
+ let { children, ...rest }: { children?: Snippet; [attribute: string]: unknown } = $props()
5
+ </script>
6
+
7
+ <h4 {...rest}>{@render children?.()}</h4>
@@ -0,0 +1,7 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte"
3
+
4
+ let { children, ...rest }: { children?: Snippet; [attribute: string]: unknown } = $props()
5
+ </script>
6
+
7
+ <h5 {...rest}>{@render children?.()}</h5>
@@ -0,0 +1,7 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte"
3
+
4
+ let { children, ...rest }: { children?: Snippet; [attribute: string]: unknown } = $props()
5
+ </script>
6
+
7
+ <h6 {...rest}>{@render children?.()}</h6>
@@ -0,0 +1,5 @@
1
+ <script lang="ts">
2
+ let { ...rest }: { [attribute: string]: unknown } = $props()
3
+ </script>
4
+
5
+ <hr {...rest} />
@@ -0,0 +1,5 @@
1
+ <script lang="ts">
2
+ let { ...rest }: { [attribute: string]: unknown } = $props()
3
+ </script>
4
+
5
+ <svelte:element this="img" {...rest} />
@@ -0,0 +1,7 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte"
3
+
4
+ let { children, ...rest }: { children?: Snippet; [attribute: string]: unknown } = $props()
5
+ </script>
6
+
7
+ <li {...rest}>{@render children?.()}</li>
@@ -0,0 +1,7 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte"
3
+
4
+ let { children, ...rest }: { children?: Snippet; [attribute: string]: unknown } = $props()
5
+ </script>
6
+
7
+ <ol {...rest}>{@render children?.()}</ol>
@@ -0,0 +1,7 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte"
3
+
4
+ let { children, ...rest }: { children?: Snippet; [attribute: string]: unknown } = $props()
5
+ </script>
6
+
7
+ <p {...rest}>{@render children?.()}</p>
@@ -0,0 +1,21 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte"
3
+
4
+ let {
5
+ language: _language,
6
+ highlights: _highlights,
7
+ code: _code,
8
+ filename,
9
+ children,
10
+ ...rest
11
+ }: {
12
+ language?: string
13
+ highlights?: number[]
14
+ code?: string
15
+ filename?: string
16
+ children?: Snippet
17
+ [attribute: string]: unknown
18
+ } = $props()
19
+ </script>
20
+
21
+ <pre {...rest} data-filename={filename}>{@render children?.()}</pre>
@@ -0,0 +1,7 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte"
3
+
4
+ let { children, ...rest }: { children?: Snippet; [attribute: string]: unknown } = $props()
5
+ </script>
6
+
7
+ <strong {...rest}>{@render children?.()}</strong>
@@ -0,0 +1,7 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte"
3
+
4
+ let { children, ...rest }: { children?: Snippet; [attribute: string]: unknown } = $props()
5
+ </script>
6
+
7
+ <table {...rest}>{@render children?.()}</table>
@@ -0,0 +1,7 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte"
3
+
4
+ let { children, ...rest }: { children?: Snippet; [attribute: string]: unknown } = $props()
5
+ </script>
6
+
7
+ <ul {...rest}>{@render children?.()}</ul>
@@ -0,0 +1,15 @@
1
+ import type { HamurContext } from "hamur/kit";
2
+ import type { ContentEntry } from "../types.ts";
3
+ export type IsPublic = (entry: ContentEntry, file: string) => boolean;
4
+ /**
5
+ * Whether a build may write what a document says into the public file `file`: its page has no access rule, or the file has the same one
6
+ * and the server runs it. A document of a data collection has no page.
7
+ */
8
+ export declare function publicIn(hamur: Pick<HamurContext, "options" | "routeRules">): IsPublic;
9
+ /**
10
+ * Whether a query from the browser cannot read the document: its page is under a `basicAuth` rule that the query endpoint does not
11
+ * share, so a browser that was let in sends no credentials with the query.
12
+ */
13
+ export declare function signedIn(hamur: Pick<HamurContext, "routeRules">): (entry: ContentEntry) => boolean;
14
+ /** A stand-in for the hashed file the client build gives a chunk. */
15
+ export declare const chunkFile: (hamur: Pick<HamurContext, "options">) => string;