goatly 0.1.0 → 0.1.1
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/README.md +853 -1
- package/bin/goatly.js +91 -0
- package/dist/cli/index.js +234 -0
- package/dist/compat/gatsby-node-entry.js +16 -0
- package/dist/compat/gatsby-package.json +6 -0
- package/dist/compat/md5-file.js +47 -0
- package/dist/compat-apis.json +72 -0
- package/dist/compat-apis.json.js +62 -0
- package/dist/graphql.js +3 -0
- package/dist/node/actions/index.js +619 -0
- package/dist/node/actions/job-store.js +180 -0
- package/dist/node/actions/jobs.js +174 -0
- package/dist/node/api-runner.js +258 -0
- package/dist/node/bootstrap.js +539 -0
- package/dist/node/build/assets.js +110 -0
- package/dist/node/build/incremental.js +208 -0
- package/dist/node/build/index.js +752 -0
- package/dist/node/build/memory-governor.js +448 -0
- package/dist/node/build/output-dirs.js +70 -0
- package/dist/node/build/page-data.js +40 -0
- package/dist/node/build/page-files.js +54 -0
- package/dist/node/build/partitioned-state.js +258 -0
- package/dist/node/build/query-worker.js +536 -0
- package/dist/node/build/query-workers.js +832 -0
- package/dist/node/build/render-worker.js +131 -0
- package/dist/node/build/state.js +24 -0
- package/dist/node/build/timing-breakdown.js +155 -0
- package/dist/node/build/worker-pool.js +236 -0
- package/dist/node/cache-layout.js +99 -0
- package/dist/node/cache.js +1430 -0
- package/dist/node/compat/chokidar-shim.js +148 -0
- package/dist/node/compat/core-utils-lmdb.js +145 -0
- package/dist/node/compat/create-node-id-shim.js +1 -0
- package/dist/node/compat/module-hooks.js +245 -0
- package/dist/node/compat/redux-shim.js +1 -0
- package/dist/node/config/index.js +162 -0
- package/dist/node/config/not-found-pages.js +95 -0
- package/dist/node/datastore/codec.js +144 -0
- package/dist/node/datastore/index.js +127 -0
- package/dist/node/datastore/logfile/cache.js +89 -0
- package/dist/node/datastore/logfile/index.js +1329 -0
- package/dist/node/datastore/logfile/record.js +71 -0
- package/dist/node/datastore/types.js +1 -0
- package/dist/node/develop/express-compat.js +207 -0
- package/dist/node/develop/graphiql.js +22 -0
- package/dist/node/develop/hydration-report.js +41 -0
- package/dist/node/develop/index.js +618 -0
- package/dist/node/develop/local-url.js +10 -0
- package/dist/node/develop/ssr-runner.js +66 -0
- package/dist/node/gql.js +5 -0
- package/dist/node/index.js +15 -0
- package/dist/node/info.js +270 -0
- package/dist/node/internal-plugins/data-bridge.js +196 -0
- package/dist/node/internal-plugins/page-creator.js +318 -0
- package/dist/node/loader/import-module.js +160 -0
- package/dist/node/node-helpers.js +66 -0
- package/dist/node/not-found-pages.js +220 -0
- package/dist/node/plugins/api-list.js +12 -0
- package/dist/node/plugins/load-plugins.js +427 -0
- package/dist/node/plugins/resolve-plugin.js +79 -0
- package/dist/node/plugins/static-exports.js +64 -0
- package/dist/node/query/compile.js +326 -0
- package/dist/node/query/dependencies.js +45 -0
- package/dist/node/query/execute.js +417 -0
- package/dist/node/query/extract.js +372 -0
- package/dist/node/query/gql-tada-introspection.js +124 -0
- package/dist/node/query/graphql-env.js +231 -0
- package/dist/node/query/graphql-runner.js +79 -0
- package/dist/node/redux/actions.js +1 -0
- package/dist/node/redux/index.js +133 -0
- package/dist/node/redux/node-changes.js +128 -0
- package/dist/node/redux/reducers.js +193 -0
- package/dist/node/redux/state.js +71 -0
- package/dist/node/renderer.js +124 -0
- package/dist/node/reporter-transports.js +259 -0
- package/dist/node/reporter.js +497 -0
- package/dist/node/schema/date.js +539 -0
- package/dist/node/schema/extensions.js +315 -0
- package/dist/node/schema/index.js +542 -0
- package/dist/node/schema/infer.js +388 -0
- package/dist/node/schema/inline-objects.js +128 -0
- package/dist/node/schema/naming.js +20 -0
- package/dist/node/schema/node-model.js +207 -0
- package/dist/node/schema/query-engine.js +1808 -0
- package/dist/node/schema/resolver-kinds.js +7 -0
- package/dist/node/schema/resolvers.js +273 -0
- package/dist/node/schema/type-builders.js +45 -0
- package/dist/node/schema/types.js +241 -0
- package/dist/node/serve.js +90 -0
- package/dist/node/site-page-nodes.js +277 -0
- package/dist/node/types.js +1 -0
- package/dist/node/utils/content-digest.js +107 -0
- package/dist/node/utils/create-node-id.js +51 -0
- package/dist/node/utils/env.js +24 -0
- package/dist/node/utils/fs-retry.js +74 -0
- package/dist/node/utils/memory-signals.js +410 -0
- package/dist/node/utils/memory.js +400 -0
- package/dist/node/utils/murmurhash.js +32 -0
- package/dist/node/utils/parser.js +33 -0
- package/dist/node/utils/partition-hash.js +19 -0
- package/dist/node/utils/paths.js +122 -0
- package/dist/node/utils/resolver.js +48 -0
- package/dist/node/utils/runtime.js +5 -0
- package/dist/node/utils/serializable.js +41 -0
- package/dist/node/utils/strings.js +41 -0
- package/dist/node/vite/config.js +289 -0
- package/dist/node/vite/paths.js +12 -0
- package/dist/node/vite/plugin-deps.js +232 -0
- package/dist/node/vite/plugin.js +281 -0
- package/dist/node/vite/react-compiler.js +362 -0
- package/dist/node/vite/source-files.js +83 -0
- package/dist/node/vite/static-image.js +136 -0
- package/dist/node/vite/styled-components.js +73 -0
- package/dist/node/vite/transforms.js +299 -0
- package/dist/node/wasm-data/host.js +406 -0
- package/dist/node/wasm-data/lower.js +406 -0
- package/dist/node/wasm-data/runner.js +79 -0
- package/dist/node/wasm-data/worker.js +95 -0
- package/dist/reporter.js +5 -0
- package/dist/runtime/api-runner.js +81 -0
- package/dist/runtime/app.js +256 -0
- package/dist/runtime/client-entry.js +4 -0
- package/dist/runtime/client.js +383 -0
- package/dist/runtime/default-html.js +31 -0
- package/dist/runtime/head-markup.js +100 -0
- package/dist/runtime/head-sync.js +101 -0
- package/dist/runtime/head-tags.js +45 -0
- package/dist/runtime/hydration-report.js +111 -0
- package/dist/runtime/index.js +12 -0
- package/dist/runtime/link.js +293 -0
- package/dist/runtime/loader.js +449 -0
- package/dist/runtime/not-found.js +61 -0
- package/dist/runtime/page-renderer.js +35 -0
- package/dist/runtime/preamble.js +47 -0
- package/dist/runtime/react-compat.js +14 -0
- package/dist/runtime/renderer-shared.js +10 -0
- package/dist/runtime/renderers/react-client.js +14 -0
- package/dist/runtime/renderers/react-server.js +99 -0
- package/dist/runtime/renderers/react.js +17 -0
- package/dist/runtime/renderers/types.js +1 -0
- package/dist/runtime/root-error-handlers.js +29 -0
- package/dist/runtime/router/history.js +132 -0
- package/dist/runtime/router/index.js +240 -0
- package/dist/runtime/router/utils.js +118 -0
- package/dist/runtime/script.js +110 -0
- package/dist/runtime/scroll.js +40 -0
- package/dist/runtime/slice.js +11 -0
- package/dist/runtime/ssr.js +240 -0
- package/dist/runtime/static-query.js +47 -0
- package/dist/utils.js +4 -0
- package/package.json +105 -3
- package/types/graphql-tada.d.ts +223 -0
- package/types/graphql.d.ts +2 -0
- package/types/index.d.ts +2287 -0
- package/types/node.d.ts +380 -0
- package/types/reporter.d.ts +187 -0
- package/types/router.d.ts +102 -0
- package/types/vendor/gql-tada.d.ts +2529 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { importModule, normalizeModuleExports, resolveApiFile } from "../loader/import-module.js";
|
|
2
|
+
import reporter from "../reporter.js";
|
|
3
|
+
import { validateRendererConfig } from "../renderer.js";
|
|
4
|
+
import { normalizeNotFoundPagesOption } from "./not-found-pages.js";
|
|
5
|
+
import { unknownReactCompilerKeys, validateReactCompilerConfig } from "../vite/react-compiler.js";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import fs from "node:fs";
|
|
8
|
+
// src/node/config/index.ts
|
|
9
|
+
async function loadConfigFile(dir, base = "gatsby-config") {
|
|
10
|
+
const file = resolveApiFile(dir, base);
|
|
11
|
+
if (!file) return { config: {} };
|
|
12
|
+
try {
|
|
13
|
+
const mod = await importModule(file);
|
|
14
|
+
let config = mod?.default ?? mod;
|
|
15
|
+
if (config && typeof config === "object" && "default" in config && Object.keys(config).length === 1) config = config.default;
|
|
16
|
+
if (typeof config !== "function") config = normalizeModuleExports(mod);
|
|
17
|
+
return {
|
|
18
|
+
file,
|
|
19
|
+
config
|
|
20
|
+
};
|
|
21
|
+
} catch (e) {
|
|
22
|
+
reporter.panic({
|
|
23
|
+
id: "10123",
|
|
24
|
+
context: { sourceMessage: `Error loading "${file}"` },
|
|
25
|
+
error: e
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function normalizePathPrefix(prefix) {
|
|
30
|
+
if (typeof prefix !== "string" || prefix === "" || prefix === "/") return "";
|
|
31
|
+
let p = prefix.trim();
|
|
32
|
+
if (/^https?:\/\//.test(p)) return p.replace(/\/$/, "");
|
|
33
|
+
if (!p.startsWith("/")) p = `/${p}`;
|
|
34
|
+
return p.replace(/\/+$/, "");
|
|
35
|
+
}
|
|
36
|
+
/** Validates and normalizes a gatsby-config object, filling Gatsby's defaults. */
|
|
37
|
+
function normalizeConfig(raw = {}) {
|
|
38
|
+
const known = /* @__PURE__ */ new Set([
|
|
39
|
+
"siteMetadata",
|
|
40
|
+
"plugins",
|
|
41
|
+
"flags",
|
|
42
|
+
"pathPrefix",
|
|
43
|
+
"trailingSlash",
|
|
44
|
+
"assetPrefix",
|
|
45
|
+
"graphqlTypegen",
|
|
46
|
+
"polyfill",
|
|
47
|
+
"mapping",
|
|
48
|
+
"jsxRuntime",
|
|
49
|
+
"jsxImportSource",
|
|
50
|
+
"proxy",
|
|
51
|
+
"partytownProxiedURLs",
|
|
52
|
+
"developMiddleware",
|
|
53
|
+
"headers",
|
|
54
|
+
"adapter",
|
|
55
|
+
"datastore",
|
|
56
|
+
"reporter",
|
|
57
|
+
"vite",
|
|
58
|
+
"renderWorkers",
|
|
59
|
+
"parallelQueryRunning",
|
|
60
|
+
"inlinePageData",
|
|
61
|
+
"inlineCss",
|
|
62
|
+
"devSSR",
|
|
63
|
+
"renderer",
|
|
64
|
+
"gatsbyModuleAlias",
|
|
65
|
+
"gqlTada",
|
|
66
|
+
"notFoundPages",
|
|
67
|
+
"reactCompiler",
|
|
68
|
+
"prefetch"
|
|
69
|
+
]);
|
|
70
|
+
for (const key of Object.keys(raw)) if (!known.has(key)) reporter.warn(`Unknown key "${key}" in gatsby-config. It will be ignored.`);
|
|
71
|
+
const rendererProblems = validateRendererConfig(raw.renderer);
|
|
72
|
+
if (rendererProblems.length) reporter.panic(`Invalid "renderer" option in gatsby-config:\n- ${rendererProblems.join("\n- ")}`);
|
|
73
|
+
const reactCompilerProblems = validateReactCompilerConfig(raw.reactCompiler);
|
|
74
|
+
if (reactCompilerProblems.length) reporter.panic(`Invalid "reactCompiler" option in gatsby-config:\n- ${reactCompilerProblems.join("\n- ")}`);
|
|
75
|
+
for (const key of unknownReactCompilerKeys(raw.reactCompiler)) reporter.warn(`Unknown key "${key}" in the reactCompiler option of gatsby-config. It will be ignored.`);
|
|
76
|
+
if (raw.plugins !== void 0 && !Array.isArray(raw.plugins)) reporter.panic(`"plugins" in gatsby-config must be an array`);
|
|
77
|
+
const gqlTada = raw.gqlTada ?? void 0;
|
|
78
|
+
if (gqlTada !== void 0 && typeof gqlTada !== "boolean" && !(typeof gqlTada === "object" && !Array.isArray(gqlTada) && (gqlTada.typesOutputPath === void 0 || typeof gqlTada.typesOutputPath === "string" && gqlTada.typesOutputPath.endsWith(".d.ts")))) reporter.panic(`"gqlTada" in gatsby-config must be true, false or { typesOutputPath: "<path>.d.ts" } (the declaration file with the GraphQL types of graphql() queries), got ${JSON.stringify(gqlTada)}`);
|
|
79
|
+
if (typeof gqlTada === "object") {
|
|
80
|
+
for (const key of Object.keys(gqlTada)) if (key !== "typesOutputPath") reporter.warn(`Unknown key "${key}" in the gqlTada option of gatsby-config. It will be ignored.`);
|
|
81
|
+
}
|
|
82
|
+
const trailingSlash = raw.trailingSlash ?? "always";
|
|
83
|
+
if (![
|
|
84
|
+
"always",
|
|
85
|
+
"never",
|
|
86
|
+
"ignore"
|
|
87
|
+
].includes(trailingSlash)) reporter.panic(`"trailingSlash" must be one of "always", "never" or "ignore"`);
|
|
88
|
+
const prefetch = raw.prefetch === true ? "viewport" : raw.prefetch ?? "viewport";
|
|
89
|
+
if (![
|
|
90
|
+
"viewport",
|
|
91
|
+
"intent",
|
|
92
|
+
false
|
|
93
|
+
].includes(prefetch)) reporter.panic(`"prefetch" in gatsby-config must be "viewport", "intent" or false, got ${JSON.stringify(raw.prefetch)}`);
|
|
94
|
+
const pathPrefix = normalizePathPrefix(raw.pathPrefix);
|
|
95
|
+
const notFound = normalizeNotFoundPagesOption(raw.notFoundPages, {
|
|
96
|
+
pathPrefix,
|
|
97
|
+
trailingSlash
|
|
98
|
+
});
|
|
99
|
+
if (notFound.problems.length) reporter.panic(`Invalid "notFoundPages" option in gatsby-config:\n- ${notFound.problems.join("\n- ")}`);
|
|
100
|
+
for (const warning of notFound.warnings) reporter.warn(warning);
|
|
101
|
+
let graphqlTypegen = false;
|
|
102
|
+
if (raw.graphqlTypegen) {
|
|
103
|
+
const opts = typeof raw.graphqlTypegen === "object" ? raw.graphqlTypegen : {};
|
|
104
|
+
graphqlTypegen = {
|
|
105
|
+
typesOutputPath: opts.typesOutputPath ?? "src/gatsby-types.d.ts",
|
|
106
|
+
generateOnBuild: opts.generateOnBuild ?? false,
|
|
107
|
+
documentSearchPaths: opts.documentSearchPaths ?? ["./gatsby-node.ts", "./plugins/**/gatsby-node.ts"]
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
...raw,
|
|
112
|
+
siteMetadata: { ...raw.siteMetadata },
|
|
113
|
+
plugins: raw.plugins ?? [],
|
|
114
|
+
pathPrefix,
|
|
115
|
+
assetPrefix: typeof raw.assetPrefix === "string" ? raw.assetPrefix.replace(/\/+$/, "") : "",
|
|
116
|
+
trailingSlash,
|
|
117
|
+
prefetch,
|
|
118
|
+
polyfill: raw.polyfill ?? false,
|
|
119
|
+
jsxRuntime: raw.jsxRuntime ?? "automatic",
|
|
120
|
+
jsxImportSource: raw.jsxImportSource,
|
|
121
|
+
graphqlTypegen,
|
|
122
|
+
gqlTada,
|
|
123
|
+
flags: raw.flags ?? {},
|
|
124
|
+
mapping: raw.mapping ?? {},
|
|
125
|
+
headers: raw.headers ?? [],
|
|
126
|
+
notFoundPages: raw.notFoundPages == null ? void 0 : notFound.scopes
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
const escapeRegExp = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
130
|
+
/**
|
|
131
|
+
* Gatsby's `proxy` option (`{ prefix, url }` or an array of them) as Vite `server.proxy` entries.
|
|
132
|
+
* Like Gatsby, requests below `prefix` go to `url` with their full path (`/api/a` → `${url}/api/a`).
|
|
133
|
+
*/
|
|
134
|
+
function proxyToVite(proxy) {
|
|
135
|
+
if (proxy === void 0 || proxy === null) return void 0;
|
|
136
|
+
const entries = Array.isArray(proxy) ? proxy : [proxy];
|
|
137
|
+
const out = {};
|
|
138
|
+
for (const entry of entries) {
|
|
139
|
+
const { prefix, url } = entry ?? {};
|
|
140
|
+
const base = typeof prefix === "string" ? prefix.replace(/\/+$/, "") : "";
|
|
141
|
+
if (!base.startsWith("/") || typeof url !== "string" || !url) reporter.panic(`Invalid "proxy" in gatsby-config: ${JSON.stringify(entry)}. Each entry needs a "prefix" starting with "/" (other than "/" itself) and a "url", e.g. { prefix: "/api", url: "http://localhost:3000" }.`);
|
|
142
|
+
out[`^${escapeRegExp(base)}/`] = {
|
|
143
|
+
target: url.replace(/\/+$/, ""),
|
|
144
|
+
changeOrigin: true
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
return out;
|
|
148
|
+
}
|
|
149
|
+
/** Warns about gatsby-config options that goatly accepts but does not act on. */
|
|
150
|
+
function reportIgnoredConfig(config) {
|
|
151
|
+
if (Array.isArray(config.headers) && config.headers.length) reporter.warn(`The "headers" option in gatsby-config is ignored: goatly builds static files and has no adapters that could apply them. Set the headers in your host's configuration instead (e.g. a "_headers" file, netlify.toml or vercel.json).`);
|
|
152
|
+
if (config.adapter) reporter.warn(`The "adapter" option in gatsby-config is ignored: goatly has no adapters. It builds a static site into public/, which any static host can serve; set headers and redirects in the host's configuration.`);
|
|
153
|
+
if (config.graphqlTypegen) reporter.warn(`The "graphqlTypegen" option in gatsby-config is ignored: goatly does not generate Gatsby's \`Queries\` types, so "${config.graphqlTypegen.typesOutputPath}" is not created or updated. Instead, queries written as graphql("...") calls are typed from the site's schema with gql.tada, and tags with QueryResult<"QueryName"> from "gatsby" (types in src/gatsby-graphql-env.d.ts) (see "Typed GraphQL" in the goatly README). For \`Queries\` types, run GraphQL Code Generator (@graphql-codegen/cli with the "typescript" and "typescript-operations" plugins) against the /___graphql endpoint of "gatsby develop".`);
|
|
154
|
+
}
|
|
155
|
+
function readSitePackageJson(dir) {
|
|
156
|
+
try {
|
|
157
|
+
return JSON.parse(fs.readFileSync(path.join(dir, "package.json"), "utf8"));
|
|
158
|
+
} catch {
|
|
159
|
+
return {};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
export { loadConfigFile, normalizeConfig, proxyToVite, readSitePackageJson, reportIgnoredConfig };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { applyTrailingSlashOption } from "../utils/paths.js";
|
|
2
|
+
import { compareNotFoundEntries } from "../../runtime/not-found.js";
|
|
3
|
+
// src/node/config/not-found-pages.ts
|
|
4
|
+
const EXAMPLE = `Example: notFoundPages: ["/de", "/fr"] or { "/de": "/de/404/", "/de-at": "/de/404/" }`;
|
|
5
|
+
function decode(p) {
|
|
6
|
+
try {
|
|
7
|
+
return decodeURIComponent(p);
|
|
8
|
+
} catch {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const isPattern = (p) => /[*?#\s\\]|\/\//.test(p) || p.split("/").some((s) => s.startsWith(":") || s === "." || s === "..");
|
|
13
|
+
/**
|
|
14
|
+
* Validates and normalizes the gatsby-config option `notFoundPages` (404 pages per site section):
|
|
15
|
+
* a list of sections (`["/de"]`: the 404 page of /de/… is `/de/404/`) or an object mapping each
|
|
16
|
+
* section to its 404 page (`{ "/de": "/de/nicht-gefunden/" }`). Pure: `serve` loads it too.
|
|
17
|
+
*/
|
|
18
|
+
function normalizeNotFoundPagesOption(raw, { pathPrefix, trailingSlash }) {
|
|
19
|
+
const scopes = [];
|
|
20
|
+
const problems = [];
|
|
21
|
+
const warnings = [];
|
|
22
|
+
if (raw === void 0 || raw === null) return {
|
|
23
|
+
scopes,
|
|
24
|
+
problems,
|
|
25
|
+
warnings
|
|
26
|
+
};
|
|
27
|
+
let entries;
|
|
28
|
+
const explicit = !Array.isArray(raw);
|
|
29
|
+
if (Array.isArray(raw)) entries = raw.map((key) => [key, void 0]);
|
|
30
|
+
else if (typeof raw === "object" && [Object.prototype, null].includes(Object.getPrototypeOf(raw))) entries = Object.entries(raw);
|
|
31
|
+
else {
|
|
32
|
+
problems.push(`it must be a list of sections like ["/de", "/fr"] or an object like { "/de": "/de/404/" }, got ${JSON.stringify(raw)}`);
|
|
33
|
+
return {
|
|
34
|
+
scopes,
|
|
35
|
+
problems,
|
|
36
|
+
warnings
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
const seen = /* @__PURE__ */ new Map();
|
|
40
|
+
for (const [key, value] of entries) {
|
|
41
|
+
if (typeof key !== "string" || !key.trim().startsWith("/")) {
|
|
42
|
+
const hint = typeof key === "string" && key.trim() ? ` (did you mean "/${key.trim()}"?)` : "";
|
|
43
|
+
problems.push(`${JSON.stringify(key)}: a section must be a path starting with "/"${hint}`);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const decoded = decode(key.trim());
|
|
47
|
+
if (decoded === void 0) {
|
|
48
|
+
problems.push(`${JSON.stringify(key)}: invalid %-escape`);
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const prefix = decoded.replace(/\/+$/, "");
|
|
52
|
+
const last = prefix.split("/").pop();
|
|
53
|
+
const parent = prefix.slice(0, -last.length - 1);
|
|
54
|
+
if (!prefix || !parent && (last === "404" || last === "404.html")) {
|
|
55
|
+
problems.push(`${JSON.stringify(key)}: the 404 page of all other URLs is always src/pages/404 ("/404/", built as "/404.html"); remove this entry`);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (isPattern(prefix)) {
|
|
59
|
+
problems.push(`${JSON.stringify(key)}: only plain path prefixes are supported, not patterns; list each section, e.g. "/de", "/fr"`);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (last === "404" || last.endsWith(".html")) {
|
|
63
|
+
problems.push(`${JSON.stringify(key)} looks like a 404 page path; list its section ("${parent || "/"}"), or map the section to the page: { ${JSON.stringify(parent || "/de")}: ${JSON.stringify(key)} }`);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
let page = `${prefix}/404/`;
|
|
67
|
+
if (explicit) {
|
|
68
|
+
const decodedPage = typeof value === "string" ? decode(value.trim()) : void 0;
|
|
69
|
+
if (decodedPage === void 0 || !decodedPage.startsWith("/") || /[*?#]/.test(decodedPage) || decodedPage.split("/").some((s) => s.startsWith(":"))) {
|
|
70
|
+
problems.push(`${JSON.stringify(key)}: the 404 page must be a page path starting with "/" (no "?", "#", "*" or ":param"), got ${JSON.stringify(value)}`);
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
page = decodedPage;
|
|
74
|
+
}
|
|
75
|
+
const other = seen.get(prefix);
|
|
76
|
+
if (other !== void 0) {
|
|
77
|
+
problems.push(`"${prefix}" is listed twice (${JSON.stringify(other)} and ${JSON.stringify(key)})`);
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
seen.set(prefix, key);
|
|
81
|
+
if (pathPrefix.startsWith("/") && (prefix === pathPrefix || prefix.startsWith(`${pathPrefix}/`))) warnings.push(`notFoundPages: the section "${prefix}" starts with the pathPrefix "${pathPrefix}"; sections are site paths without pathPrefix ("${prefix.slice(pathPrefix.length) || "/"}")`);
|
|
82
|
+
scopes.push({
|
|
83
|
+
prefix,
|
|
84
|
+
page: applyTrailingSlashOption(page, trailingSlash),
|
|
85
|
+
explicit
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
if (problems.length) problems.push(EXAMPLE);
|
|
89
|
+
return {
|
|
90
|
+
scopes: scopes.sort(compareNotFoundEntries),
|
|
91
|
+
problems,
|
|
92
|
+
warnings
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
export { normalizeNotFoundPagesOption };
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { isBun } from "../utils/runtime.js";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { Packr, RESET_BUFFER_MODE, isNativeAccelerationEnabled } from "msgpackr";
|
|
4
|
+
// src/node/datastore/codec.ts
|
|
5
|
+
/**
|
|
6
|
+
* How nodes are encoded, by the built-in logfile datastore and by the
|
|
7
|
+
* SQLite package, so a node has the same values whichever store holds it.
|
|
8
|
+
*
|
|
9
|
+
* msgpackr with its structured clone extension: plain data, `Date`, `Map`, `Set`, `RegExp`, `Error`,
|
|
10
|
+
* `BigInt`, typed arrays, `Buffer`s and cyclic references are kept. Class instances lose their
|
|
11
|
+
* prototype, functions are dropped (`undefined`), `-0` and holes in sparse arrays come back as `0`
|
|
12
|
+
* and `undefined`, and a class instance with a `toJSON()` method (e.g. a `URL`) is stored as what
|
|
13
|
+
* that method returns, a plain object keeps its fields (like Gatsby's LMDB store, which encodes
|
|
14
|
+
* nodes with msgpackr too). Decoded `Buffer`s are copies,
|
|
15
|
+
* not views of a (reused) read buffer.
|
|
16
|
+
*/
|
|
17
|
+
const NODE_CODEC = {
|
|
18
|
+
structuredClone: true,
|
|
19
|
+
maxSharedStructures: 8160,
|
|
20
|
+
copyBuffers: true
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* A codec whose shared record structures are stored with the nodes (the logfile store; the
|
|
24
|
+
* SQLite package does the same). Stored structures reach msgpackr only through `load`
|
|
25
|
+
* (`getStructures`): msgpackr marks the structures it loads that way, e.g. the two-byte record ids
|
|
26
|
+
* from the 33rd structure on. Structures passed as the `structures` option are not marked, and nodes
|
|
27
|
+
* that use them can't be decoded after a reload or in a query worker.
|
|
28
|
+
*/
|
|
29
|
+
function createStoredNodeCodec(options) {
|
|
30
|
+
const codec = new Packr({
|
|
31
|
+
...NODE_CODEC,
|
|
32
|
+
getStructures: options.load,
|
|
33
|
+
saveStructures: options.save
|
|
34
|
+
});
|
|
35
|
+
loadStructures(codec);
|
|
36
|
+
return codec;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Loads a codec's stored structures now (packing any value merges them): a decode that has to load
|
|
40
|
+
* them continues with a plain Uint8Array copy of its input, and would return that node's Buffers as
|
|
41
|
+
* Uint8Arrays.
|
|
42
|
+
*/
|
|
43
|
+
function loadStructures(codec) {
|
|
44
|
+
codec.pack(null);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The shared structures of a structures list (msgpackr also puts a node's own record definitions
|
|
48
|
+
* after them, from index `maxSharedStructures` on): what a store saves and loads.
|
|
49
|
+
*/
|
|
50
|
+
function sharedStructures(structures) {
|
|
51
|
+
return structures.slice(0, Math.min(structures.length, NODE_CODEC.maxSharedStructures));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Encodes a value into msgpackr's reused output buffer. msgpackr shares that buffer between all its
|
|
55
|
+
* codecs: the bytes are valid until any codec's next `pack()`, so copy them (`PendingBytes`) or
|
|
56
|
+
* decode them right away, before anything else can encode.
|
|
57
|
+
*/
|
|
58
|
+
function encodeReused(codec, value) {
|
|
59
|
+
return codec.pack(value, RESET_BUFFER_MODE);
|
|
60
|
+
}
|
|
61
|
+
const PENDING_BYTES = 1048576;
|
|
62
|
+
/**
|
|
63
|
+
* The encoded nodes of writes that are not stored yet, back to back in a buffer that is reused for
|
|
64
|
+
* every batch: `add()` copies a node's bytes (from `encodeReused()`, right after it) and returns a
|
|
65
|
+
* view of the copy, which stays valid until `clear()`, called when the batch is stored. (Keeping
|
|
66
|
+
* msgpackr's own output buffers until then, a new one every few nodes, made the garbage collector
|
|
67
|
+
* promote them, and writes took twice as long.)
|
|
68
|
+
*/
|
|
69
|
+
var PendingBytes = class {
|
|
70
|
+
buffer = Buffer.allocUnsafeSlow(PENDING_BYTES);
|
|
71
|
+
used = 0;
|
|
72
|
+
added = 0;
|
|
73
|
+
add(bytes) {
|
|
74
|
+
if (this.used + bytes.length > this.buffer.length) {
|
|
75
|
+
this.buffer = Buffer.allocUnsafeSlow(Math.max(this.buffer.length * 2, bytes.length));
|
|
76
|
+
this.used = 0;
|
|
77
|
+
}
|
|
78
|
+
const at = this.used;
|
|
79
|
+
this.buffer.set(bytes, at);
|
|
80
|
+
this.used += bytes.length;
|
|
81
|
+
this.added += bytes.length;
|
|
82
|
+
return this.buffer.subarray(at, this.used);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The batch should be stored: 32 MB were added since `clear()` (a write that replaces a pending
|
|
86
|
+
* one adds its bytes too, so updating a few nodes many times fills it before the batch is full).
|
|
87
|
+
*/
|
|
88
|
+
get full() {
|
|
89
|
+
return this.added >= 32 * PENDING_BYTES;
|
|
90
|
+
}
|
|
91
|
+
/** the batch was stored: no view of it is used any more */
|
|
92
|
+
clear() {
|
|
93
|
+
this.used = 0;
|
|
94
|
+
this.added = 0;
|
|
95
|
+
if (this.buffer.length > 16 * PENDING_BYTES) this.buffer = Buffer.allocUnsafeSlow(PENDING_BYTES);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
/** a codec with record structures kept in memory (they are not persisted) */
|
|
99
|
+
function createMemoryNodeCodec() {
|
|
100
|
+
return new Packr({
|
|
101
|
+
...NODE_CODEC,
|
|
102
|
+
structures: [],
|
|
103
|
+
saveStructures: () => true
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* A codec whose messages carry their own record structures (one `pack()` call can be decoded by any
|
|
108
|
+
* codec with these options): for files that are written and read in one piece.
|
|
109
|
+
*/
|
|
110
|
+
function createSelfContainedNodeCodec() {
|
|
111
|
+
return new Packr({
|
|
112
|
+
structuredClone: true,
|
|
113
|
+
copyBuffers: true
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/** the largest values createSelfContainedNodeDecoder decodes with msgpackr's no-eval build */
|
|
117
|
+
const NO_EVAL_MAX_BYTES = 131072;
|
|
118
|
+
/**
|
|
119
|
+
* A decoder for many self-contained messages (the plugin cache: one per value): on Bun, values up
|
|
120
|
+
* to 128 KB are decoded by msgpackr's build without `new Function` – the same format and values.
|
|
121
|
+
* msgpackr compiles a reader for a record structure once it has read three records of it, which
|
|
122
|
+
* pays off for shared structures (the node stores) and large messages, but every self-contained
|
|
123
|
+
* message defines its structures anew. V8 finds the readers in its compilation cache, JSC compiles
|
|
124
|
+
* every one: remark's ASTs (gatsby-transformer-remark) decoded 1.4–3× faster on Bun without them,
|
|
125
|
+
* from 2 to 180 KB (on Node only up to about 3 KB: elsewhere the compiled readers are faster).
|
|
126
|
+
* The no-eval build is given msgpackr's native string extractor (msgpackr-extract, an optional
|
|
127
|
+
* dependency of msgpackr), like msgpackr's default entry: without it, strings are decoded in
|
|
128
|
+
* JavaScript, 5–10× slower for values of many short strings.
|
|
129
|
+
*/
|
|
130
|
+
function createSelfContainedNodeDecoder(codec, bun = isBun) {
|
|
131
|
+
if (!bun) return codec;
|
|
132
|
+
const require = createRequire(import.meta.url);
|
|
133
|
+
const file = require.resolve("msgpackr/unpack-no-eval");
|
|
134
|
+
const noEval = require(file);
|
|
135
|
+
if (isNativeAccelerationEnabled && !noEval.isNativeAccelerationEnabled) try {
|
|
136
|
+
noEval.setExtractor(createRequire(file)("msgpackr-extract").extractStrings);
|
|
137
|
+
} catch {}
|
|
138
|
+
const unpackr = new noEval.Unpackr({
|
|
139
|
+
structuredClone: true,
|
|
140
|
+
copyBuffers: true
|
|
141
|
+
});
|
|
142
|
+
return { unpack: (bytes) => bytes.length <= NO_EVAL_MAX_BYTES ? unpackr.unpack(bytes) : codec.unpack(bytes) };
|
|
143
|
+
}
|
|
144
|
+
export { NODE_CODEC, PendingBytes, createMemoryNodeCodec, createSelfContainedNodeCodec, createSelfContainedNodeDecoder, createStoredNodeCodec, encodeReused, loadStructures, sharedStructures };
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { LogFileDataStore, logFileDataStore } from "./logfile/index.js";
|
|
2
|
+
import { isMainThread } from "node:worker_threads";
|
|
3
|
+
import { inspect } from "node:util";
|
|
4
|
+
// src/node/datastore/index.ts
|
|
5
|
+
let current = new LogFileDataStore();
|
|
6
|
+
/** changes with every setDataStore (cached query results of another store are not valid) */
|
|
7
|
+
let generation = 0;
|
|
8
|
+
function setDataStore(store) {
|
|
9
|
+
current = store;
|
|
10
|
+
generation++;
|
|
11
|
+
}
|
|
12
|
+
function getDataStoreGeneration() {
|
|
13
|
+
return generation;
|
|
14
|
+
}
|
|
15
|
+
function getDataStore() {
|
|
16
|
+
return current;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Called before code reads SitePage nodes – while that has to be known (see `site-page-nodes.ts`:
|
|
20
|
+
* the nodes are only created once something can read them). Unset when nobody needs to know.
|
|
21
|
+
*/
|
|
22
|
+
let sitePageReads = null;
|
|
23
|
+
function watchSitePageReads(fn) {
|
|
24
|
+
sitePageReads = fn;
|
|
25
|
+
}
|
|
26
|
+
function getSitePageReadWatcher() {
|
|
27
|
+
return sitePageReads;
|
|
28
|
+
}
|
|
29
|
+
/** the id prefix of SitePage nodes (`SitePage <path>`) */
|
|
30
|
+
const SITE_PAGE_ID_PREFIX = "SitePage ";
|
|
31
|
+
/** reports a read of nodes of these types (queries, `nodeModel`) when it includes SitePage nodes */
|
|
32
|
+
function readingNodesOfTypes(typeNames) {
|
|
33
|
+
if (sitePageReads !== null && typeNames.includes("SitePage")) sitePageReads(`nodes of type ${typeNames.length > 1 ? typeNames.join(" | ") : "SitePage"}`);
|
|
34
|
+
}
|
|
35
|
+
/** reports a read of all nodes (they include SitePage nodes) */
|
|
36
|
+
function readingAllNodes(read) {
|
|
37
|
+
sitePageReads?.(read);
|
|
38
|
+
}
|
|
39
|
+
const getNode = (id) => {
|
|
40
|
+
if (id == null) return void 0;
|
|
41
|
+
if (sitePageReads !== null && typeof id === "string" && id.startsWith("SitePage ")) sitePageReads(`getNode("${id}")`);
|
|
42
|
+
return current.getNode(id);
|
|
43
|
+
};
|
|
44
|
+
/** a node's type – without loading the node when the store has a type index */
|
|
45
|
+
const nodeTypeOf = (id) => id == null ? void 0 : typeof current.getNodeType === "function" ? current.getNodeType(id) : current.getNode(id)?.internal.type;
|
|
46
|
+
/**
|
|
47
|
+
* `getNodes()` / `getNodesByType()` for plugins. In query workers lazy stores return an array that
|
|
48
|
+
* loads nodes when an element is read (in chunks, without filling the store's cache): plugins often
|
|
49
|
+
* keep such a list for the life of the process (e.g. gatsby-transformer-remark's File nodes) without
|
|
50
|
+
* reading most of it. Loaded elements are kept, so scanning the list again does not load them
|
|
51
|
+
* again (each read still costs a proxy trap). Only in workers: their store is read-only, so no node
|
|
52
|
+
* of the list is deleted before it is read, and nothing there stores node lists in nodes or page
|
|
53
|
+
* context (a proxy cannot be serialized). The main thread gets plain arrays.
|
|
54
|
+
*/
|
|
55
|
+
const lazyLists = () => !isMainThread && current.lazy === true && typeof current.getNodeIdsByType === "function";
|
|
56
|
+
const getNodes = () => {
|
|
57
|
+
readingAllNodes("getNodes()");
|
|
58
|
+
return lazyLists() ? lazyNodeList(current.getTypes().flatMap((type) => current.getNodeIdsByType(type))) : current.getNodes();
|
|
59
|
+
};
|
|
60
|
+
const getNodesByType = (type) => {
|
|
61
|
+
if (type === "SitePage") readingNodesOfTypes([type]);
|
|
62
|
+
return lazyLists() ? lazyNodeList(current.getNodeIdsByType(type)) : current.getNodesByType(type);
|
|
63
|
+
};
|
|
64
|
+
const LIST_CHUNK = 500;
|
|
65
|
+
/** @internal (exported for tests) */
|
|
66
|
+
function lazyNodeList(ids) {
|
|
67
|
+
const store = current;
|
|
68
|
+
const target = Array.from({ length: ids.length });
|
|
69
|
+
const loaded = new Uint8Array(ids.length);
|
|
70
|
+
Object.defineProperty(target, inspect.custom, { value(depth, options) {
|
|
71
|
+
return inspect(Array.from(this), {
|
|
72
|
+
...options,
|
|
73
|
+
depth
|
|
74
|
+
});
|
|
75
|
+
} });
|
|
76
|
+
const load = (i) => {
|
|
77
|
+
if (loaded[i]) return;
|
|
78
|
+
const start = i - i % LIST_CHUNK;
|
|
79
|
+
const end = Math.min(ids.length, start + LIST_CHUNK);
|
|
80
|
+
const chunk = ids.slice(start, end);
|
|
81
|
+
const nodes = typeof store.getNodesByIds === "function" ? store.getNodesByIds(chunk, { cache: false }) : chunk.map((id) => store.getNode(id));
|
|
82
|
+
for (let k = start; k < end; k++) {
|
|
83
|
+
if (!loaded[k]) target[k] = nodes[k - start];
|
|
84
|
+
loaded[k] = 1;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const indexOf = (key) => {
|
|
88
|
+
if (typeof key !== "string") return -1;
|
|
89
|
+
const n = Number(key);
|
|
90
|
+
return Number.isInteger(n) && n >= 0 && n < ids.length && String(n) === key ? n : -1;
|
|
91
|
+
};
|
|
92
|
+
return new Proxy(target, {
|
|
93
|
+
get(t, key, receiver) {
|
|
94
|
+
const i = indexOf(key);
|
|
95
|
+
if (i !== -1) load(i);
|
|
96
|
+
return Reflect.get(t, key, receiver);
|
|
97
|
+
},
|
|
98
|
+
getOwnPropertyDescriptor(t, key) {
|
|
99
|
+
const i = indexOf(key);
|
|
100
|
+
if (i !== -1) load(i);
|
|
101
|
+
return Reflect.getOwnPropertyDescriptor(t, key);
|
|
102
|
+
},
|
|
103
|
+
has(t, key) {
|
|
104
|
+
return indexOf(key) !== -1 || Reflect.has(t, key);
|
|
105
|
+
},
|
|
106
|
+
set(t, key, value, receiver) {
|
|
107
|
+
const i = indexOf(key);
|
|
108
|
+
if (i !== -1) loaded[i] = 1;
|
|
109
|
+
return Reflect.set(t, key, value, receiver);
|
|
110
|
+
},
|
|
111
|
+
ownKeys(t) {
|
|
112
|
+
for (let i = 0; i < ids.length; i += LIST_CHUNK) load(i);
|
|
113
|
+
return Reflect.ownKeys(t);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
const getTypes = () => current.getTypes();
|
|
118
|
+
const countNodes = (type) => {
|
|
119
|
+
if (type === void 0) readingAllNodes("countNodes()");
|
|
120
|
+
else if (type === "SitePage") readingNodesOfTypes([type]);
|
|
121
|
+
return current.countNodes(type);
|
|
122
|
+
};
|
|
123
|
+
const iterateNodesByType = (type) => {
|
|
124
|
+
if (type === "SitePage") readingNodesOfTypes([type]);
|
|
125
|
+
return current.iterateNodesByType(type);
|
|
126
|
+
};
|
|
127
|
+
export { LogFileDataStore, SITE_PAGE_ID_PREFIX, countNodes, getDataStore, getDataStoreGeneration, getNode, getNodes, getNodesByType, getSitePageReadWatcher, getTypes, iterateNodesByType, lazyNodeList, logFileDataStore, nodeTypeOf, readingAllNodes, readingNodesOfTypes, setDataStore, watchSitePageReads };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// src/node/datastore/logfile/cache.ts
|
|
2
|
+
/**
|
|
3
|
+
* Approximate LRU cache with two generations: entries go into `young`; when it is full it becomes
|
|
4
|
+
* `old` and the previous `old` generation is dropped. A hit in `old` moves the entry back to
|
|
5
|
+
* `young`. At most `max` entries are kept and – with `maxBytes` – about that many bytes (the sizes
|
|
6
|
+
* given with the entries, e.g. the encoded size of a node: a few thousand nodes of a CMS can take
|
|
7
|
+
* gigabytes once decoded).
|
|
8
|
+
*
|
|
9
|
+
* A Map based LRU (delete + set on every hit, evict with `keys().next()`) is several times slower
|
|
10
|
+
* in V8: deleted entries stay in the Map's table as holes until it is rehashed, so evicting the
|
|
11
|
+
* oldest entry has to skip over a growing run of them.
|
|
12
|
+
*/
|
|
13
|
+
var NodeCache = class {
|
|
14
|
+
young = /* @__PURE__ */ new Map();
|
|
15
|
+
old = /* @__PURE__ */ new Map();
|
|
16
|
+
youngBytes = 0;
|
|
17
|
+
oldBytes = 0;
|
|
18
|
+
half;
|
|
19
|
+
halfBytes;
|
|
20
|
+
/** the most entries kept */
|
|
21
|
+
max;
|
|
22
|
+
/** about the most bytes kept (Infinity: no limit) */
|
|
23
|
+
maxBytes;
|
|
24
|
+
constructor(max, maxBytes = 1e400) {
|
|
25
|
+
this.max = max;
|
|
26
|
+
this.half = Math.max(1, Math.ceil(max / 2));
|
|
27
|
+
this.maxBytes = maxBytes;
|
|
28
|
+
this.halfBytes = maxBytes / 2;
|
|
29
|
+
}
|
|
30
|
+
get size() {
|
|
31
|
+
return this.young.size + this.old.size;
|
|
32
|
+
}
|
|
33
|
+
/** the bytes of the entries kept (their sizes as given) */
|
|
34
|
+
get bytes() {
|
|
35
|
+
return this.youngBytes + this.oldBytes;
|
|
36
|
+
}
|
|
37
|
+
get(key) {
|
|
38
|
+
const entry = this.young.get(key);
|
|
39
|
+
if (entry !== void 0) return entry.value;
|
|
40
|
+
const old = this.old.get(key);
|
|
41
|
+
if (old === void 0) return void 0;
|
|
42
|
+
this.old.delete(key);
|
|
43
|
+
this.oldBytes -= old.bytes;
|
|
44
|
+
this.add(key, old);
|
|
45
|
+
return old.value;
|
|
46
|
+
}
|
|
47
|
+
/** without counting as a use */
|
|
48
|
+
peek(key) {
|
|
49
|
+
return (this.young.get(key) ?? this.old.get(key))?.value;
|
|
50
|
+
}
|
|
51
|
+
/** `bytes`: the entry's size (e.g. its encoded size) for `maxBytes` */
|
|
52
|
+
set(key, value, bytes = 0) {
|
|
53
|
+
this.delete(key);
|
|
54
|
+
if (bytes > this.halfBytes) return;
|
|
55
|
+
this.add(key, {
|
|
56
|
+
value,
|
|
57
|
+
bytes
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
delete(key) {
|
|
61
|
+
const young = this.young.get(key);
|
|
62
|
+
if (young !== void 0) {
|
|
63
|
+
this.young.delete(key);
|
|
64
|
+
this.youngBytes -= young.bytes;
|
|
65
|
+
}
|
|
66
|
+
const old = this.old.get(key);
|
|
67
|
+
if (old !== void 0) {
|
|
68
|
+
this.old.delete(key);
|
|
69
|
+
this.oldBytes -= old.bytes;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
clear() {
|
|
73
|
+
this.young = /* @__PURE__ */ new Map();
|
|
74
|
+
this.old = /* @__PURE__ */ new Map();
|
|
75
|
+
this.youngBytes = 0;
|
|
76
|
+
this.oldBytes = 0;
|
|
77
|
+
}
|
|
78
|
+
add(key, entry) {
|
|
79
|
+
this.young.set(key, entry);
|
|
80
|
+
this.youngBytes += entry.bytes;
|
|
81
|
+
if (this.young.size >= this.half || this.youngBytes >= this.halfBytes) {
|
|
82
|
+
this.old = this.young;
|
|
83
|
+
this.oldBytes = this.youngBytes;
|
|
84
|
+
this.young = /* @__PURE__ */ new Map();
|
|
85
|
+
this.youngBytes = 0;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
export { NodeCache };
|