@parrel/ledger 0.0.0-stage → 5.0.0
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/LICENSE +21 -0
- package/README.md +793 -2
- package/dist/cli/commands.d.ts +51 -0
- package/dist/cli/commands.d.ts.map +1 -0
- package/dist/cli/commands.js +968 -0
- package/dist/cli/commands.js.map +1 -0
- package/dist/cli/index.d.ts +24 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +35 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/parrel.d.ts +3 -0
- package/dist/cli/parrel.d.ts.map +1 -0
- package/dist/cli/parrel.js +5 -0
- package/dist/cli/parrel.js.map +1 -0
- package/dist/cli/utils/angular-setup.d.ts +14 -0
- package/dist/cli/utils/angular-setup.d.ts.map +1 -0
- package/dist/cli/utils/angular-setup.js +96 -0
- package/dist/cli/utils/angular-setup.js.map +1 -0
- package/dist/cli/utils/api-tree-builder.d.ts +24 -0
- package/dist/cli/utils/api-tree-builder.d.ts.map +1 -0
- package/dist/cli/utils/api-tree-builder.js +146 -0
- package/dist/cli/utils/api-tree-builder.js.map +1 -0
- package/dist/cli/utils/bundle-reader.d.ts +185 -0
- package/dist/cli/utils/bundle-reader.d.ts.map +1 -0
- package/dist/cli/utils/bundle-reader.js +518 -0
- package/dist/cli/utils/bundle-reader.js.map +1 -0
- package/dist/cli/utils/collision-detector.d.ts +21 -0
- package/dist/cli/utils/collision-detector.d.ts.map +1 -0
- package/dist/cli/utils/collision-detector.js +53 -0
- package/dist/cli/utils/collision-detector.js.map +1 -0
- package/dist/cli/utils/map-fields.d.ts +42 -0
- package/dist/cli/utils/map-fields.d.ts.map +1 -0
- package/dist/cli/utils/map-fields.js +90 -0
- package/dist/cli/utils/map-fields.js.map +1 -0
- package/dist/cli/utils/map-validator.d.ts +42 -0
- package/dist/cli/utils/map-validator.d.ts.map +1 -0
- package/dist/cli/utils/map-validator.js +119 -0
- package/dist/cli/utils/map-validator.js.map +1 -0
- package/dist/cli/utils/media-file.d.ts +41 -0
- package/dist/cli/utils/media-file.d.ts.map +1 -0
- package/dist/cli/utils/media-file.js +72 -0
- package/dist/cli/utils/media-file.js.map +1 -0
- package/dist/cli/utils/media-validator.d.ts +10 -0
- package/dist/cli/utils/media-validator.d.ts.map +1 -0
- package/dist/cli/utils/media-validator.js +85 -0
- package/dist/cli/utils/media-validator.js.map +1 -0
- package/dist/cli/utils/mock-augmenter.d.ts +19 -0
- package/dist/cli/utils/mock-augmenter.d.ts.map +1 -0
- package/dist/cli/utils/mock-augmenter.js +102 -0
- package/dist/cli/utils/mock-augmenter.js.map +1 -0
- package/dist/cli/utils/mock-validator.d.ts +27 -0
- package/dist/cli/utils/mock-validator.d.ts.map +1 -0
- package/dist/cli/utils/mock-validator.js +214 -0
- package/dist/cli/utils/mock-validator.js.map +1 -0
- package/dist/cli/utils/project-dir.d.ts +24 -0
- package/dist/cli/utils/project-dir.d.ts.map +1 -0
- package/dist/cli/utils/project-dir.js +32 -0
- package/dist/cli/utils/project-dir.js.map +1 -0
- package/dist/cli/utils/schema-loader.d.ts +19 -0
- package/dist/cli/utils/schema-loader.d.ts.map +1 -0
- package/dist/cli/utils/schema-loader.js +101 -0
- package/dist/cli/utils/schema-loader.js.map +1 -0
- package/dist/cli/utils/server-entry.d.ts +34 -0
- package/dist/cli/utils/server-entry.d.ts.map +1 -0
- package/dist/cli/utils/server-entry.js +111 -0
- package/dist/cli/utils/server-entry.js.map +1 -0
- package/dist/cli/utils/sync.d.ts +116 -0
- package/dist/cli/utils/sync.d.ts.map +1 -0
- package/dist/cli/utils/sync.js +134 -0
- package/dist/cli/utils/sync.js.map +1 -0
- package/dist/client/index.d.ts +39 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +88 -0
- package/dist/client/index.js.map +1 -0
- package/dist/core/browser-session.d.ts +5 -0
- package/dist/core/browser-session.d.ts.map +1 -0
- package/dist/core/browser-session.js +12 -0
- package/dist/core/browser-session.js.map +1 -0
- package/dist/core/cache.d.ts +80 -0
- package/dist/core/cache.d.ts.map +1 -0
- package/dist/core/cache.js +95 -0
- package/dist/core/cache.js.map +1 -0
- package/dist/core/client.d.ts +64 -0
- package/dist/core/client.d.ts.map +1 -0
- package/dist/core/client.js +281 -0
- package/dist/core/client.js.map +1 -0
- package/dist/core/config.d.ts +20 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +32 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/copy-read.d.ts +25 -0
- package/dist/core/copy-read.d.ts.map +1 -0
- package/dist/core/copy-read.js +123 -0
- package/dist/core/copy-read.js.map +1 -0
- package/dist/core/define-ledger.d.ts +38 -0
- package/dist/core/define-ledger.d.ts.map +1 -0
- package/dist/core/define-ledger.js +65 -0
- package/dist/core/define-ledger.js.map +1 -0
- package/dist/core/deprecated.d.ts +16 -0
- package/dist/core/deprecated.d.ts.map +1 -0
- package/dist/core/deprecated.js +14 -0
- package/dist/core/deprecated.js.map +1 -0
- package/dist/core/env.d.ts +103 -0
- package/dist/core/env.d.ts.map +1 -0
- package/dist/core/env.js +208 -0
- package/dist/core/env.js.map +1 -0
- package/dist/core/error-codes.generated.d.ts +12 -0
- package/dist/core/error-codes.generated.d.ts.map +1 -0
- package/dist/core/error-codes.generated.js +3 -0
- package/dist/core/error-codes.generated.js.map +1 -0
- package/dist/core/get-content.d.ts +62 -0
- package/dist/core/get-content.d.ts.map +1 -0
- package/dist/core/get-content.js +86 -0
- package/dist/core/get-content.js.map +1 -0
- package/dist/core/get-media.d.ts +58 -0
- package/dist/core/get-media.d.ts.map +1 -0
- package/dist/core/get-media.js +89 -0
- package/dist/core/get-media.js.map +1 -0
- package/dist/core/manifest.d.ts +38 -0
- package/dist/core/manifest.d.ts.map +1 -0
- package/dist/core/manifest.js +93 -0
- package/dist/core/manifest.js.map +1 -0
- package/dist/core/media-proxy.d.ts +41 -0
- package/dist/core/media-proxy.d.ts.map +1 -0
- package/dist/core/media-proxy.js +219 -0
- package/dist/core/media-proxy.js.map +1 -0
- package/dist/core/package-info.d.ts +34 -0
- package/dist/core/package-info.d.ts.map +1 -0
- package/dist/core/package-info.js +39 -0
- package/dist/core/package-info.js.map +1 -0
- package/dist/core/parrel-error.d.ts +160 -0
- package/dist/core/parrel-error.d.ts.map +1 -0
- package/dist/core/parrel-error.js +198 -0
- package/dist/core/parrel-error.js.map +1 -0
- package/dist/core/transform-content.d.ts +42 -0
- package/dist/core/transform-content.d.ts.map +1 -0
- package/dist/core/transform-content.js +185 -0
- package/dist/core/transform-content.js.map +1 -0
- package/dist/core/types.d.ts +406 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +11 -0
- package/dist/core/types.js.map +1 -0
- package/dist/errors/error-messages.generated.d.ts +5 -0
- package/dist/errors/error-messages.generated.d.ts.map +1 -0
- package/dist/errors/error-messages.generated.js +971 -0
- package/dist/errors/error-messages.generated.js.map +1 -0
- package/dist/errors/get-error-info.d.ts +29 -0
- package/dist/errors/get-error-info.d.ts.map +1 -0
- package/dist/errors/get-error-info.js +43 -0
- package/dist/errors/get-error-info.js.map +1 -0
- package/dist/errors/index.d.ts +4 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +4 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/types.d.ts +19 -0
- package/dist/errors/types.d.ts.map +1 -0
- package/dist/errors/types.js +2 -0
- package/dist/errors/types.js.map +1 -0
- package/dist/generated.d.ts +29 -0
- package/dist/generated.d.ts.map +1 -0
- package/dist/generated.js +29 -0
- package/dist/generated.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/mock/dev-media.d.ts +15 -0
- package/dist/mock/dev-media.d.ts.map +1 -0
- package/dist/mock/dev-media.js +52 -0
- package/dist/mock/dev-media.js.map +1 -0
- package/dist/mock/file-store.d.ts +44 -0
- package/dist/mock/file-store.d.ts.map +1 -0
- package/dist/mock/file-store.js +170 -0
- package/dist/mock/file-store.js.map +1 -0
- package/dist/mock/index.d.ts +4 -0
- package/dist/mock/index.d.ts.map +1 -0
- package/dist/mock/index.js +3 -0
- package/dist/mock/index.js.map +1 -0
- package/dist/mock/media-fields.d.ts +25 -0
- package/dist/mock/media-fields.d.ts.map +1 -0
- package/dist/mock/media-fields.js +54 -0
- package/dist/mock/media-fields.js.map +1 -0
- package/dist/mock/mock-adapter.d.ts +65 -0
- package/dist/mock/mock-adapter.d.ts.map +1 -0
- package/dist/mock/mock-adapter.js +431 -0
- package/dist/mock/mock-adapter.js.map +1 -0
- package/dist/mock/mock-errors.d.ts +18 -0
- package/dist/mock/mock-errors.d.ts.map +1 -0
- package/dist/mock/mock-errors.js +56 -0
- package/dist/mock/mock-errors.js.map +1 -0
- package/dist/mock/node-import.d.ts +13 -0
- package/dist/mock/node-import.d.ts.map +1 -0
- package/dist/mock/node-import.js +16 -0
- package/dist/mock/node-import.js.map +1 -0
- package/dist/mock/seed-mock-store.d.ts +14 -0
- package/dist/mock/seed-mock-store.d.ts.map +1 -0
- package/dist/mock/seed-mock-store.js +106 -0
- package/dist/mock/seed-mock-store.js.map +1 -0
- package/dist/mock/shared-memory-store.d.ts +35 -0
- package/dist/mock/shared-memory-store.d.ts.map +1 -0
- package/dist/mock/shared-memory-store.js +46 -0
- package/dist/mock/shared-memory-store.js.map +1 -0
- package/dist/next/dev-rendering-helpers.d.ts +78 -0
- package/dist/next/dev-rendering-helpers.d.ts.map +1 -0
- package/dist/next/dev-rendering-helpers.js +103 -0
- package/dist/next/dev-rendering-helpers.js.map +1 -0
- package/dist/next/index.d.ts +35 -0
- package/dist/next/index.d.ts.map +1 -0
- package/dist/next/index.js +33 -0
- package/dist/next/index.js.map +1 -0
- package/dist/next/next-cache-adapter.d.ts +11 -0
- package/dist/next/next-cache-adapter.d.ts.map +1 -0
- package/dist/next/next-cache-adapter.js +12 -0
- package/dist/next/next-cache-adapter.js.map +1 -0
- package/dist/nuxt/index.d.ts +22 -0
- package/dist/nuxt/index.d.ts.map +1 -0
- package/dist/nuxt/index.js +57 -0
- package/dist/nuxt/index.js.map +1 -0
- package/dist/sveltekit/index.d.ts +35 -0
- package/dist/sveltekit/index.d.ts.map +1 -0
- package/dist/sveltekit/index.js +56 -0
- package/dist/sveltekit/index.js.map +1 -0
- package/dist/ui/content-editor.d.ts +9 -0
- package/dist/ui/content-editor.d.ts.map +1 -0
- package/dist/ui/content-editor.js +27 -0
- package/dist/ui/content-editor.js.map +1 -0
- package/dist/ui/index.d.ts +8 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +8 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/ledger-overlay.d.ts +10 -0
- package/dist/ui/ledger-overlay.d.ts.map +1 -0
- package/dist/ui/ledger-overlay.js +27 -0
- package/dist/ui/ledger-overlay.js.map +1 -0
- package/dist/ui/media-uploader.d.ts +9 -0
- package/dist/ui/media-uploader.d.ts.map +1 -0
- package/dist/ui/media-uploader.js +27 -0
- package/dist/ui/media-uploader.js.map +1 -0
- package/package.json +134 -6
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ledgerMediaFileProblem } from "../cli/utils/media-file.js";
|
|
2
|
+
import { ParrelError } from "../core/parrel-error.js";
|
|
3
|
+
/**
|
|
4
|
+
* The errors that the mock adapter raises for a situation in which the real Ledger service answers with an error.
|
|
5
|
+
* They carry the code, the status and the name of the service, so code that handles an error in development
|
|
6
|
+
* handles it the same way in production. The messages are the ones of the service, with a hint for the mock.
|
|
7
|
+
*/
|
|
8
|
+
/** The content types that the Ledger service accepts for a media upload. */
|
|
9
|
+
const ALLOWED_MEDIA_CONTENT_TYPES = [
|
|
10
|
+
"image/jpeg",
|
|
11
|
+
"image/png",
|
|
12
|
+
"image/gif",
|
|
13
|
+
"image/webp",
|
|
14
|
+
"image/svg+xml",
|
|
15
|
+
"video/mp4",
|
|
16
|
+
"video/webm",
|
|
17
|
+
"video/quicktime",
|
|
18
|
+
"application/pdf",
|
|
19
|
+
"application/msword",
|
|
20
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
21
|
+
"text/plain",
|
|
22
|
+
];
|
|
23
|
+
function tokenize(path) {
|
|
24
|
+
return path.match(/[^.[\]]+/g) ?? [];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* `LE02000003` when the resource (the first part of the path) is not in the mock data, `LE02000018` when the
|
|
28
|
+
* resource exists and the rest of the path does not. Both are 404, like the service.
|
|
29
|
+
*/
|
|
30
|
+
export function notFoundError(path, data) {
|
|
31
|
+
const [resource] = tokenize(path);
|
|
32
|
+
if (resource === undefined || !Object.hasOwn(data, resource)) {
|
|
33
|
+
return new ParrelError("LE02000003", `Not found. The mock data has no resource "${resource ?? path}". Add it to parrel/ledger/mock.json.`, { status: 404, codeName: "RESOURCE_NOT_FOUND" });
|
|
34
|
+
}
|
|
35
|
+
return new ParrelError("LE02000018", `Not found. The resource "${resource}" in the mock data has nothing at "${path}". Check the path against parrel/ledger/mock.json.`, { status: 404, codeName: "CONTENT_PATH_NOT_FOUND" });
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The error for a file that Ledger would refuse, or `null` when the file is fine: an empty file (`LE02500009`), a
|
|
39
|
+
* file over 50 MB (`LE02500010`), an extension that is not allowed (`LE02500007`) or a content type that is not
|
|
40
|
+
* allowed (`LE02500008`). All are 400, like the service. The first three are the checks of `assertLedgerMediaFile`, so
|
|
41
|
+
* the mock and the live adapter give the same code and message. A file without a content type is accepted.
|
|
42
|
+
*/
|
|
43
|
+
export function mediaUploadProblem(file) {
|
|
44
|
+
const problem = ledgerMediaFileProblem(file);
|
|
45
|
+
if (problem) {
|
|
46
|
+
return problem;
|
|
47
|
+
}
|
|
48
|
+
if (file.type && !ALLOWED_MEDIA_CONTENT_TYPES.includes(file.type)) {
|
|
49
|
+
return new ParrelError("LE02500008", "This file type is not allowed.", {
|
|
50
|
+
status: 400,
|
|
51
|
+
codeName: "MEDIA_FILE_TYPE_NOT_ALLOWED",
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=mock-errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock-errors.js","sourceRoot":"","sources":["../../src/mock/mock-errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD;;;;GAIG;AAEH,4EAA4E;AAC5E,MAAM,2BAA2B,GAAsB;IACtD,YAAY;IACZ,WAAW;IACX,WAAW;IACX,YAAY;IACZ,eAAe;IACf,WAAW;IACX,YAAY;IACZ,iBAAiB;IACjB,iBAAiB;IACjB,oBAAoB;IACpB,yEAAyE;IACzE,YAAY;CACZ,CAAC;AAEF,SAAS,QAAQ,CAAC,IAAY;IAC7B,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;AACtC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,IAA6B;IACxE,MAAM,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAClC,IAAI,QAAQ,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,CAAC;QAC9D,OAAO,IAAI,WAAW,CACrB,YAAY,EACZ,6CAA6C,QAAQ,IAAI,IAAI,uCAAuC,EACpG,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,oBAAoB,EAAE,CAC/C,CAAC;IACH,CAAC;IACD,OAAO,IAAI,WAAW,CACrB,YAAY,EACZ,4BAA4B,QAAQ,sCAAsC,IAAI,oDAAoD,EAClI,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,wBAAwB,EAAE,CACnD,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAoD;IACtF,MAAM,OAAO,GAAG,sBAAsB,CAAC,IAAI,CAAC,CAAC;IAC7C,IAAI,OAAO,EAAE,CAAC;QACb,OAAO,OAAO,CAAC;IAChB,CAAC;IACD,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,2BAA2B,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACnE,OAAO,IAAI,WAAW,CAAC,YAAY,EAAE,gCAAgC,EAAE;YACtE,MAAM,EAAE,GAAG;YACX,QAAQ,EAAE,6BAA6B;SACvC,CAAC,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bundler-opaque dynamic import for Node built-ins (`fs/promises`, `path`, `buffer`).
|
|
3
|
+
*
|
|
4
|
+
* The mock file store only runs in a Node runtime (every caller guards with `isNodeRuntime()`). But the package
|
|
5
|
+
* root reaches the mock store, so a client component that imports the root bundles it for the browser. A
|
|
6
|
+
* string-literal `import("fs/promises")` is resolved at build time by browser bundlers (webpack, Turbopack,
|
|
7
|
+
* Vite, esbuild) and fails with "Can't resolve 'fs/promises'".
|
|
8
|
+
*
|
|
9
|
+
* Passing the specifier through a variable, with the ignore comments of each bundler, leaves a real runtime
|
|
10
|
+
* `import()` that only executes under Node.
|
|
11
|
+
*/
|
|
12
|
+
export declare function nodeImport(specifier: string): Promise<any>;
|
|
13
|
+
//# sourceMappingURL=node-import.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-import.d.ts","sourceRoot":"","sources":["../../src/mock/node-import.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAE1D"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bundler-opaque dynamic import for Node built-ins (`fs/promises`, `path`, `buffer`).
|
|
3
|
+
*
|
|
4
|
+
* The mock file store only runs in a Node runtime (every caller guards with `isNodeRuntime()`). But the package
|
|
5
|
+
* root reaches the mock store, so a client component that imports the root bundles it for the browser. A
|
|
6
|
+
* string-literal `import("fs/promises")` is resolved at build time by browser bundlers (webpack, Turbopack,
|
|
7
|
+
* Vite, esbuild) and fails with "Can't resolve 'fs/promises'".
|
|
8
|
+
*
|
|
9
|
+
* Passing the specifier through a variable, with the ignore comments of each bundler, leaves a real runtime
|
|
10
|
+
* `import()` that only executes under Node.
|
|
11
|
+
*/
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
|
+
export function nodeImport(specifier) {
|
|
14
|
+
return import(/* webpackIgnore: true */ /* turbopackIgnore: true */ /* @vite-ignore */ specifier);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=node-import.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-import.js","sourceRoot":"","sources":["../../src/mock/node-import.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,8DAA8D;AAC9D,MAAM,UAAU,UAAU,CAAC,SAAiB;IAC3C,OAAO,MAAM,CAAC,yBAAyB,CAAC,2BAA2B,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;AACnG,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Seed utilities for Ledger mock store.
|
|
3
|
+
* Initializes mock data from seed files.
|
|
4
|
+
*
|
|
5
|
+
* @note This module uses dynamic imports for Node.js modules
|
|
6
|
+
* and is intended for Node.js runtime only (development server backend).
|
|
7
|
+
* @ts-nocheck - Allow dynamic imports without type definitions
|
|
8
|
+
*/
|
|
9
|
+
export declare function seedMockStoreFromFile(seedPath: string, targetDir: string): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Seed mock store with inline data.
|
|
12
|
+
*/
|
|
13
|
+
export declare function seedMockStoreFromData(data: any, targetDir: string): Promise<void>;
|
|
14
|
+
//# sourceMappingURL=seed-mock-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seed-mock-store.d.ts","sourceRoot":"","sources":["../../src/mock/seed-mock-store.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAUH,wBAAsB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA4E9F;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CAAC,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA6BvF"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// @ts-nocheck - This module uses dynamic imports for Node.js modules (fs, path)
|
|
2
|
+
/**
|
|
3
|
+
* Seed utilities for Ledger mock store.
|
|
4
|
+
* Initializes mock data from seed files.
|
|
5
|
+
*
|
|
6
|
+
* @note This module uses dynamic imports for Node.js modules
|
|
7
|
+
* and is intended for Node.js runtime only (development server backend).
|
|
8
|
+
* @ts-nocheck - Allow dynamic imports without type definitions
|
|
9
|
+
*/
|
|
10
|
+
import { nodeImport } from "./node-import.js";
|
|
11
|
+
/**
|
|
12
|
+
* Seed Ledger mock store from a JSON file or data object.
|
|
13
|
+
* Copies seed resources and media to the target directory.
|
|
14
|
+
*/
|
|
15
|
+
import { ParrelError } from "../core/parrel-error.js";
|
|
16
|
+
export async function seedMockStoreFromFile(seedPath, targetDir) {
|
|
17
|
+
try {
|
|
18
|
+
const fs = await nodeImport("fs/promises");
|
|
19
|
+
const path = await nodeImport("path");
|
|
20
|
+
const { initFileMockStore, writeMockFile } = await import("./file-store.js");
|
|
21
|
+
// Initialize target directory
|
|
22
|
+
await initFileMockStore(targetDir);
|
|
23
|
+
// Read seed data
|
|
24
|
+
let seedData;
|
|
25
|
+
try {
|
|
26
|
+
const content = await fs.readFile(seedPath, "utf-8");
|
|
27
|
+
seedData = JSON.parse(content);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
throw new ParrelError("SD06000010", `The Ledger seed file ${seedPath} could not be read. Check that the file exists and contains valid JSON.`, { cause: error });
|
|
31
|
+
}
|
|
32
|
+
// Ensure resources and media objects exist
|
|
33
|
+
if (!seedData.resources) {
|
|
34
|
+
seedData.resources = {};
|
|
35
|
+
}
|
|
36
|
+
if (!seedData.media) {
|
|
37
|
+
seedData.media = {};
|
|
38
|
+
}
|
|
39
|
+
if (!seedData.manifest) {
|
|
40
|
+
seedData.manifest = {
|
|
41
|
+
version: 0,
|
|
42
|
+
updatedAt: new Date().toISOString(),
|
|
43
|
+
resources: [],
|
|
44
|
+
media: [],
|
|
45
|
+
maps: [],
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
// Copy media files if they reference local files
|
|
49
|
+
const mediaDir = path.join(targetDir, "media");
|
|
50
|
+
const seedMediaRefs = Object.keys(seedData.media || {});
|
|
51
|
+
for (const mediaRef of seedMediaRefs) {
|
|
52
|
+
const mediaValue = seedData.media[mediaRef];
|
|
53
|
+
// If it's a path string, copy from seed directory to target
|
|
54
|
+
if (typeof mediaValue === "string" && !mediaValue.startsWith("data:")) {
|
|
55
|
+
try {
|
|
56
|
+
const sourcePath = path.join(path.dirname(seedPath), mediaValue);
|
|
57
|
+
const targetPath = path.join(mediaDir, path.basename(mediaValue));
|
|
58
|
+
// Ensure target directory exists
|
|
59
|
+
await fs.mkdir(path.dirname(targetPath), { recursive: true });
|
|
60
|
+
// Copy file
|
|
61
|
+
await fs.copyFile(sourcePath, targetPath);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
console.warn(`Failed to copy media file ${mediaValue}: ${error}`);
|
|
65
|
+
// Continue with other files
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// Write seed data to target
|
|
70
|
+
await writeMockFile(targetDir, seedData);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
if (error instanceof ParrelError && error.code === "SD06000010") {
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
throw new ParrelError("SD06000011", `The Ledger mock store at ${targetDir} could not be seeded from ${seedPath}. Check the seed file and that you can write to the target folder.`, { cause: error });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Seed mock store with inline data.
|
|
81
|
+
*/
|
|
82
|
+
export async function seedMockStoreFromData(data, targetDir) {
|
|
83
|
+
try {
|
|
84
|
+
const { initFileMockStore, writeMockFile } = await import("./file-store.js");
|
|
85
|
+
// Initialize target directory
|
|
86
|
+
await initFileMockStore(targetDir);
|
|
87
|
+
// Ensure resources and media objects exist
|
|
88
|
+
const normalizedData = {
|
|
89
|
+
resources: data.resources ?? {},
|
|
90
|
+
media: data.media ?? {},
|
|
91
|
+
manifest: data.manifest ?? {
|
|
92
|
+
version: 0,
|
|
93
|
+
updatedAt: new Date().toISOString(),
|
|
94
|
+
resources: [],
|
|
95
|
+
media: [],
|
|
96
|
+
maps: [],
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
// Write data to target
|
|
100
|
+
await writeMockFile(targetDir, normalizedData);
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
throw new ParrelError("SD06000012", `The Ledger mock store at ${targetDir} could not be seeded with the data. Check the data and that you can write to the target folder.`, { cause: error });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=seed-mock-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seed-mock-store.js","sourceRoot":"","sources":["../../src/mock/seed-mock-store.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared in-memory store for mock Ledger data in development mode.
|
|
3
|
+
*
|
|
4
|
+
* This singleton ensures that:
|
|
5
|
+
* - Admin pages writing data and content pages reading data share the same store
|
|
6
|
+
* - In development: Real-time updates without server rebuild
|
|
7
|
+
* - In production: Not used (each adapter instance is independent)
|
|
8
|
+
*
|
|
9
|
+
* ARCHITECTURE NOTE:
|
|
10
|
+
* - Next.js static pages cache data at BUILD TIME (production)
|
|
11
|
+
* - But each request-time fetch in dev gets the same in-memory store
|
|
12
|
+
* - So admin changes ARE visible in dev (real-time) but NOT in production (static HTML)
|
|
13
|
+
*
|
|
14
|
+
* STRUCTURE:
|
|
15
|
+
* Flat: { resourceName: {...}, resourceName2: {...}, ... }
|
|
16
|
+
* Media is referenced by filename within resources (e.g., "heroImage": "hero.jpg")
|
|
17
|
+
*/
|
|
18
|
+
type MockData = Record<string, unknown>;
|
|
19
|
+
/**
|
|
20
|
+
* Get the shared in-memory mock store.
|
|
21
|
+
* Returns the same instance across all calls in the same process.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getSharedMockStore(): MockData;
|
|
24
|
+
/**
|
|
25
|
+
* Reset the shared mock store to initial state.
|
|
26
|
+
* Useful for testing or explicit clearing.
|
|
27
|
+
*/
|
|
28
|
+
export declare function resetSharedMockStore(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Hydrate the shared mock store with initial data (flat structure).
|
|
31
|
+
* Called at startup to populate mock data.
|
|
32
|
+
*/
|
|
33
|
+
export declare function hydrateSharedMockStore(initialData: MockData): void;
|
|
34
|
+
export {};
|
|
35
|
+
//# sourceMappingURL=shared-memory-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-memory-store.d.ts","sourceRoot":"","sources":["../../src/mock/shared-memory-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,KAAK,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAIxC;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,QAAQ,CAK7C;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAE3C;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,QAAQ,GAAG,IAAI,CAKlE"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared in-memory store for mock Ledger data in development mode.
|
|
3
|
+
*
|
|
4
|
+
* This singleton ensures that:
|
|
5
|
+
* - Admin pages writing data and content pages reading data share the same store
|
|
6
|
+
* - In development: Real-time updates without server rebuild
|
|
7
|
+
* - In production: Not used (each adapter instance is independent)
|
|
8
|
+
*
|
|
9
|
+
* ARCHITECTURE NOTE:
|
|
10
|
+
* - Next.js static pages cache data at BUILD TIME (production)
|
|
11
|
+
* - But each request-time fetch in dev gets the same in-memory store
|
|
12
|
+
* - So admin changes ARE visible in dev (real-time) but NOT in production (static HTML)
|
|
13
|
+
*
|
|
14
|
+
* STRUCTURE:
|
|
15
|
+
* Flat: { resourceName: {...}, resourceName2: {...}, ... }
|
|
16
|
+
* Media is referenced by filename within resources (e.g., "heroImage": "hero.jpg")
|
|
17
|
+
*/
|
|
18
|
+
let globalMockStore = null;
|
|
19
|
+
/**
|
|
20
|
+
* Get the shared in-memory mock store.
|
|
21
|
+
* Returns the same instance across all calls in the same process.
|
|
22
|
+
*/
|
|
23
|
+
export function getSharedMockStore() {
|
|
24
|
+
if (globalMockStore === null) {
|
|
25
|
+
globalMockStore = {};
|
|
26
|
+
}
|
|
27
|
+
return globalMockStore;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Reset the shared mock store to initial state.
|
|
31
|
+
* Useful for testing or explicit clearing.
|
|
32
|
+
*/
|
|
33
|
+
export function resetSharedMockStore() {
|
|
34
|
+
globalMockStore = null;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Hydrate the shared mock store with initial data (flat structure).
|
|
38
|
+
* Called at startup to populate mock data.
|
|
39
|
+
*/
|
|
40
|
+
export function hydrateSharedMockStore(initialData) {
|
|
41
|
+
globalMockStore = {
|
|
42
|
+
...getSharedMockStore(),
|
|
43
|
+
...initialData,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=shared-memory-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-memory-store.js","sourceRoot":"","sources":["../../src/mock/shared-memory-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,IAAI,eAAe,GAAoB,IAAI,CAAC;AAE5C;;;GAGG;AACH,MAAM,UAAU,kBAAkB;IACjC,IAAI,eAAe,KAAK,IAAI,EAAE,CAAC;QAC9B,eAAe,GAAG,EAAE,CAAC;IACtB,CAAC;IACD,OAAO,eAAe,CAAC;AACxB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB;IACnC,eAAe,GAAG,IAAI,CAAC;AACxB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,WAAqB;IAC3D,eAAe,GAAG;QACjB,GAAG,kBAAkB,EAAE;QACvB,GAAG,WAAW;KACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Next.js helpers for Parrel Ledger in development mode.
|
|
3
|
+
*
|
|
4
|
+
* EXPLANATION OF THE PROBLEM & SOLUTION:
|
|
5
|
+
* ========================================
|
|
6
|
+
*
|
|
7
|
+
* In Next.js 16 (App Router):
|
|
8
|
+
* - Pages WITHOUT `revalidate` or `dynamic` directive = STATIC (build-time rendering)
|
|
9
|
+
* - Static pages fetch data ONCE at build time, then serve same HTML forever
|
|
10
|
+
* - Admin changes are written to mock.json but static HTML doesn't re-read it
|
|
11
|
+
*
|
|
12
|
+
* The issue with mock-based Ledger:
|
|
13
|
+
* 1. Production (static pages): Data fetched at build-time, never updated until next build
|
|
14
|
+
* 2. Development (dynamic on-demand): Each refresh re-fetches, so feels real-time
|
|
15
|
+
* 3. BUT: Mock data is lost between requests unless we use a SHARED IN-MEMORY STORE
|
|
16
|
+
*
|
|
17
|
+
* The solution:
|
|
18
|
+
* - Use getSharedMockStore() which maintains data in memory across requests
|
|
19
|
+
* - Mark pages as `dynamic = 'force-dynamic'` in dev (will be stripped in production)
|
|
20
|
+
* - Admin and content pages now share the SAME in-memory data
|
|
21
|
+
* - Result: Real-time updates in dev, production still static (as intended)
|
|
22
|
+
*
|
|
23
|
+
* USAGE IN YOUR PAGE:
|
|
24
|
+
* ==================
|
|
25
|
+
*
|
|
26
|
+
* // app/locatie/page.tsx
|
|
27
|
+
* import { getDynamicRenderingForDev } from '@parrel/ledger/next';
|
|
28
|
+
*
|
|
29
|
+
* // Only in development: Make page dynamic so it re-renders on each request
|
|
30
|
+
* // (This shows the latest mock data from admin changes)
|
|
31
|
+
* export const dynamic = getDynamicRenderingForDev();
|
|
32
|
+
*
|
|
33
|
+
* // In dev: Returns 'force-dynamic' → re-renders every request → sees live admin updates
|
|
34
|
+
* // In prod: Returns undefined → builds as static → baked-in data at build time
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* Returns the correct dynamic rendering mode for the current environment.
|
|
38
|
+
*
|
|
39
|
+
* @param forceMode - Override the auto-detection (optional)
|
|
40
|
+
* @returns 'force-dynamic' in development, undefined in production
|
|
41
|
+
*
|
|
42
|
+
* EXAMPLE:
|
|
43
|
+
* ```tsx
|
|
44
|
+
* export const dynamic = getDynamicRenderingForDev();
|
|
45
|
+
* // In dev: Pages re-render every request, admin changes are visible
|
|
46
|
+
* // In prod: Pages are static (baked-in at build time)
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare function getDynamicRenderingForDev(forceMode?: "force-dynamic" | "force-static" | undefined): "force-dynamic" | "force-static" | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Returns the correct ISR revalidation time for the current environment.
|
|
52
|
+
*
|
|
53
|
+
* Use this if you want INCREMENTAL STATIC REVALIDATION instead of full dynamic:
|
|
54
|
+
* - In dev: Returns 1 (revalidate every second, essentially dynamic)
|
|
55
|
+
* - In prod: Returns your specified value (default 3600 = 1 hour)
|
|
56
|
+
*
|
|
57
|
+
* @param prodRevalidate - ISR revalidation interval in production (seconds, default 3600)
|
|
58
|
+
* @returns Revalidation time in seconds
|
|
59
|
+
*
|
|
60
|
+
* EXAMPLE:
|
|
61
|
+
* ```tsx
|
|
62
|
+
* export const revalidate = getISRRevalidateForDev(86400); // 24 hours in prod
|
|
63
|
+
* // In dev: Revalidates every second (near real-time)
|
|
64
|
+
* // In prod: Revalidates every 24 hours (better performance)
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare function getISRRevalidateForDev(prodRevalidate?: number): number;
|
|
68
|
+
/**
|
|
69
|
+
* Helper to understand which rendering mode your page is using.
|
|
70
|
+
* Useful for debugging.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* console.log(getRenderingModeDescription());
|
|
74
|
+
* // In dev with mock: "DYNAMIC (force-dynamic) - real-time admin updates visible"
|
|
75
|
+
* // In prod: "STATIC (ISR=3600) - data baked in at build time"
|
|
76
|
+
*/
|
|
77
|
+
export declare function getRenderingModeDescription(): string;
|
|
78
|
+
//# sourceMappingURL=dev-rendering-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev-rendering-helpers.d.ts","sourceRoot":"","sources":["../../src/next/dev-rendering-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,CACxC,SAAS,CAAC,EAAE,eAAe,GAAG,cAAc,GAAG,SAAS,GACtD,eAAe,GAAG,cAAc,GAAG,SAAS,CAY9C;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,sBAAsB,CAAC,cAAc,GAAE,MAAa,GAAG,MAAM,CAU5E;AAED;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B,IAAI,MAAM,CASpD"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Next.js helpers for Parrel Ledger in development mode.
|
|
3
|
+
*
|
|
4
|
+
* EXPLANATION OF THE PROBLEM & SOLUTION:
|
|
5
|
+
* ========================================
|
|
6
|
+
*
|
|
7
|
+
* In Next.js 16 (App Router):
|
|
8
|
+
* - Pages WITHOUT `revalidate` or `dynamic` directive = STATIC (build-time rendering)
|
|
9
|
+
* - Static pages fetch data ONCE at build time, then serve same HTML forever
|
|
10
|
+
* - Admin changes are written to mock.json but static HTML doesn't re-read it
|
|
11
|
+
*
|
|
12
|
+
* The issue with mock-based Ledger:
|
|
13
|
+
* 1. Production (static pages): Data fetched at build-time, never updated until next build
|
|
14
|
+
* 2. Development (dynamic on-demand): Each refresh re-fetches, so feels real-time
|
|
15
|
+
* 3. BUT: Mock data is lost between requests unless we use a SHARED IN-MEMORY STORE
|
|
16
|
+
*
|
|
17
|
+
* The solution:
|
|
18
|
+
* - Use getSharedMockStore() which maintains data in memory across requests
|
|
19
|
+
* - Mark pages as `dynamic = 'force-dynamic'` in dev (will be stripped in production)
|
|
20
|
+
* - Admin and content pages now share the SAME in-memory data
|
|
21
|
+
* - Result: Real-time updates in dev, production still static (as intended)
|
|
22
|
+
*
|
|
23
|
+
* USAGE IN YOUR PAGE:
|
|
24
|
+
* ==================
|
|
25
|
+
*
|
|
26
|
+
* // app/locatie/page.tsx
|
|
27
|
+
* import { getDynamicRenderingForDev } from '@parrel/ledger/next';
|
|
28
|
+
*
|
|
29
|
+
* // Only in development: Make page dynamic so it re-renders on each request
|
|
30
|
+
* // (This shows the latest mock data from admin changes)
|
|
31
|
+
* export const dynamic = getDynamicRenderingForDev();
|
|
32
|
+
*
|
|
33
|
+
* // In dev: Returns 'force-dynamic' → re-renders every request → sees live admin updates
|
|
34
|
+
* // In prod: Returns undefined → builds as static → baked-in data at build time
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* Returns the correct dynamic rendering mode for the current environment.
|
|
38
|
+
*
|
|
39
|
+
* @param forceMode - Override the auto-detection (optional)
|
|
40
|
+
* @returns 'force-dynamic' in development, undefined in production
|
|
41
|
+
*
|
|
42
|
+
* EXAMPLE:
|
|
43
|
+
* ```tsx
|
|
44
|
+
* export const dynamic = getDynamicRenderingForDev();
|
|
45
|
+
* // In dev: Pages re-render every request, admin changes are visible
|
|
46
|
+
* // In prod: Pages are static (baked-in at build time)
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export function getDynamicRenderingForDev(forceMode) {
|
|
50
|
+
if (forceMode !== undefined) {
|
|
51
|
+
return forceMode;
|
|
52
|
+
}
|
|
53
|
+
// Detect if running in development
|
|
54
|
+
const isDev = process.env.NODE_ENV !== "production";
|
|
55
|
+
// Only apply force-dynamic in development
|
|
56
|
+
// This makes pages re-render on every request (no static caching)
|
|
57
|
+
// So they'll see the latest data from the in-memory mock store
|
|
58
|
+
return isDev ? "force-dynamic" : undefined;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Returns the correct ISR revalidation time for the current environment.
|
|
62
|
+
*
|
|
63
|
+
* Use this if you want INCREMENTAL STATIC REVALIDATION instead of full dynamic:
|
|
64
|
+
* - In dev: Returns 1 (revalidate every second, essentially dynamic)
|
|
65
|
+
* - In prod: Returns your specified value (default 3600 = 1 hour)
|
|
66
|
+
*
|
|
67
|
+
* @param prodRevalidate - ISR revalidation interval in production (seconds, default 3600)
|
|
68
|
+
* @returns Revalidation time in seconds
|
|
69
|
+
*
|
|
70
|
+
* EXAMPLE:
|
|
71
|
+
* ```tsx
|
|
72
|
+
* export const revalidate = getISRRevalidateForDev(86400); // 24 hours in prod
|
|
73
|
+
* // In dev: Revalidates every second (near real-time)
|
|
74
|
+
* // In prod: Revalidates every 24 hours (better performance)
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export function getISRRevalidateForDev(prodRevalidate = 3600) {
|
|
78
|
+
const isDev = process.env.NODE_ENV !== "production";
|
|
79
|
+
// In development: revalidate frequently (1 second) for near real-time
|
|
80
|
+
if (isDev) {
|
|
81
|
+
return 1;
|
|
82
|
+
}
|
|
83
|
+
// In production: use the specified value
|
|
84
|
+
return prodRevalidate;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Helper to understand which rendering mode your page is using.
|
|
88
|
+
* Useful for debugging.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* console.log(getRenderingModeDescription());
|
|
92
|
+
* // In dev with mock: "DYNAMIC (force-dynamic) - real-time admin updates visible"
|
|
93
|
+
* // In prod: "STATIC (ISR=3600) - data baked in at build time"
|
|
94
|
+
*/
|
|
95
|
+
export function getRenderingModeDescription() {
|
|
96
|
+
const isDev = process.env.NODE_ENV !== "production";
|
|
97
|
+
const env = process.env.NODE_ENV || "unknown";
|
|
98
|
+
if (isDev) {
|
|
99
|
+
return `DYNAMIC (force-dynamic) in ${env} - real-time admin updates visible in dev`;
|
|
100
|
+
}
|
|
101
|
+
return `STATIC (built at build-time) in ${env} - updates require rebuild`;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=dev-rendering-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev-rendering-helpers.js","sourceRoot":"","sources":["../../src/next/dev-rendering-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,yBAAyB,CACxC,SAAwD;IAExD,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC7B,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,mCAAmC;IACnC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC;IAEpD,0CAA0C;IAC1C,kEAAkE;IAClE,+DAA+D;IAC/D,OAAO,KAAK,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC;AAC5C,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,sBAAsB,CAAC,iBAAyB,IAAI;IACnE,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC;IAEpD,sEAAsE;IACtE,IAAI,KAAK,EAAE,CAAC;QACX,OAAO,CAAC,CAAC;IACV,CAAC;IAED,yCAAyC;IACzC,OAAO,cAAc,CAAC;AACvB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,2BAA2B;IAC1C,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC;IACpD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,SAAS,CAAC;IAE9C,IAAI,KAAK,EAAE,CAAC;QACX,OAAO,8BAA8B,GAAG,2CAA2C,CAAC;IACrF,CAAC;IAED,OAAO,mCAAmC,GAAG,4BAA4B,CAAC;AAC3E,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createParrelLedgerNextCacheAdapter } from "./next-cache-adapter.js";
|
|
2
|
+
export { createParrelLedgerNextCacheAdapter };
|
|
3
|
+
export { getDynamicRenderingForDev, getISRRevalidateForDev, getRenderingModeDescription, } from "./dev-rendering-helpers.js";
|
|
4
|
+
type NextMediaRouteContext = {
|
|
5
|
+
params: Promise<{
|
|
6
|
+
path: string[];
|
|
7
|
+
}> | {
|
|
8
|
+
path: string[];
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* App Router route handlers for the same-origin production media proxy.
|
|
13
|
+
*
|
|
14
|
+
* Scaffolded into `app/api/cms-media/[...path]/route.ts` by `parrel ledger init`:
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { createLedgerMediaRouteHandlers } from "@parrel/ledger/next";
|
|
18
|
+
* export const { GET } = createLedgerMediaRouteHandlers();
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* To point the proxy at a local API, pass `{ apiOrigin }`. Without it the `apiOrigin` of `defineParrelLedger` and then
|
|
22
|
+
* `PARREL_API_ORIGIN` are used. The origin never comes from the request.
|
|
23
|
+
*
|
|
24
|
+
* @param options `apiOrigin` overrides the origin for this route
|
|
25
|
+
*/
|
|
26
|
+
export declare function createLedgerMediaRouteHandlers(options?: {
|
|
27
|
+
apiOrigin?: string;
|
|
28
|
+
}): {
|
|
29
|
+
GET(request: Request, context: NextMediaRouteContext): Promise<Response>;
|
|
30
|
+
};
|
|
31
|
+
/** @deprecated Use {@link createLedgerMediaRouteHandlers}. Removed in the next major version. */
|
|
32
|
+
export declare const createCmsMediaRouteHandlers: typeof createLedgerMediaRouteHandlers;
|
|
33
|
+
/** @deprecated Use {@link createParrelLedgerNextCacheAdapter}. Removed in the next major version. */
|
|
34
|
+
export declare const createParrelCmsNextCacheAdapter: typeof createParrelLedgerNextCacheAdapter;
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/next/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kCAAkC,EAAE,MAAM,yBAAyB,CAAC;AAE7E,OAAO,EAAE,kCAAkC,EAAE,CAAC;AAC9C,OAAO,EACN,yBAAyB,EACzB,sBAAsB,EACtB,2BAA2B,GAC3B,MAAM,4BAA4B,CAAC;AAEpC,KAAK,qBAAqB,GAAG;IAC5B,MAAM,EAAE,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,GAAG;QAAE,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;CACzD,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,8BAA8B,CAAC,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO;iBAE9D,OAAO,WAAW,qBAAqB,GAAG,OAAO,CAAC,QAAQ,CAAC;EAK/E;AAED,iGAAiG;AACjG,eAAO,MAAM,2BAA2B,uCAAiC,CAAC;AAE1E,qGAAqG;AACrG,eAAO,MAAM,+BAA+B,2CAAqC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Next.js integration
|
|
2
|
+
import { proxyLedgerMedia } from "../core/media-proxy.js";
|
|
3
|
+
import { createParrelLedgerNextCacheAdapter } from "./next-cache-adapter.js";
|
|
4
|
+
export { createParrelLedgerNextCacheAdapter };
|
|
5
|
+
export { getDynamicRenderingForDev, getISRRevalidateForDev, getRenderingModeDescription, } from "./dev-rendering-helpers.js";
|
|
6
|
+
/**
|
|
7
|
+
* App Router route handlers for the same-origin production media proxy.
|
|
8
|
+
*
|
|
9
|
+
* Scaffolded into `app/api/cms-media/[...path]/route.ts` by `parrel ledger init`:
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { createLedgerMediaRouteHandlers } from "@parrel/ledger/next";
|
|
13
|
+
* export const { GET } = createLedgerMediaRouteHandlers();
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* To point the proxy at a local API, pass `{ apiOrigin }`. Without it the `apiOrigin` of `defineParrelLedger` and then
|
|
17
|
+
* `PARREL_API_ORIGIN` are used. The origin never comes from the request.
|
|
18
|
+
*
|
|
19
|
+
* @param options `apiOrigin` overrides the origin for this route
|
|
20
|
+
*/
|
|
21
|
+
export function createLedgerMediaRouteHandlers(options = {}) {
|
|
22
|
+
return {
|
|
23
|
+
async GET(request, context) {
|
|
24
|
+
const params = await context.params;
|
|
25
|
+
return proxyLedgerMedia(params.path ?? [], { apiOrigin: options.apiOrigin, request });
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/** @deprecated Use {@link createLedgerMediaRouteHandlers}. Removed in the next major version. */
|
|
30
|
+
export const createCmsMediaRouteHandlers = createLedgerMediaRouteHandlers;
|
|
31
|
+
/** @deprecated Use {@link createParrelLedgerNextCacheAdapter}. Removed in the next major version. */
|
|
32
|
+
export const createParrelCmsNextCacheAdapter = createParrelLedgerNextCacheAdapter;
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/next/index.ts"],"names":[],"mappings":"AAAA,sBAAsB;AAEtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,kCAAkC,EAAE,MAAM,yBAAyB,CAAC;AAE7E,OAAO,EAAE,kCAAkC,EAAE,CAAC;AAC9C,OAAO,EACN,yBAAyB,EACzB,sBAAsB,EACtB,2BAA2B,GAC3B,MAAM,4BAA4B,CAAC;AAMpC;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,8BAA8B,CAAC,UAAkC,EAAE;IAClF,OAAO;QACN,KAAK,CAAC,GAAG,CAAC,OAAgB,EAAE,OAA8B;YACzD,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC;YACpC,OAAO,gBAAgB,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;QACvF,CAAC;KACD,CAAC;AACH,CAAC;AAED,iGAAiG;AACjG,MAAM,CAAC,MAAM,2BAA2B,GAAG,8BAA8B,CAAC;AAE1E,qGAAqG;AACrG,MAAM,CAAC,MAAM,+BAA+B,GAAG,kCAAkC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ParrelLedgerAdapter } from "../core/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Wraps Ledger adapter calls with Next.js unstable_cache for SSR contexts.
|
|
4
|
+
*
|
|
5
|
+
* Note: Full implementation requires Next.js runtime detection.
|
|
6
|
+
* For now, this is a placeholder that returns the adapter as-is.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createParrelLedgerNextCacheAdapter(adapter: ParrelLedgerAdapter, options?: {
|
|
9
|
+
revalidate?: number;
|
|
10
|
+
}): ParrelLedgerAdapter;
|
|
11
|
+
//# sourceMappingURL=next-cache-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next-cache-adapter.d.ts","sourceRoot":"","sources":["../../src/next/next-cache-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAsC,MAAM,kBAAkB,CAAC;AAEhG;;;;;GAKG;AACH,wBAAgB,kCAAkC,CACjD,OAAO,EAAE,mBAAmB,EAC5B,OAAO,CAAC,EAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,GAC/B,mBAAmB,CAIrB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wraps Ledger adapter calls with Next.js unstable_cache for SSR contexts.
|
|
3
|
+
*
|
|
4
|
+
* Note: Full implementation requires Next.js runtime detection.
|
|
5
|
+
* For now, this is a placeholder that returns the adapter as-is.
|
|
6
|
+
*/
|
|
7
|
+
export function createParrelLedgerNextCacheAdapter(adapter, options) {
|
|
8
|
+
// In a real implementation, this would wrap calls with unstable_cache()
|
|
9
|
+
// For now, just return the adapter
|
|
10
|
+
return adapter;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=next-cache-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next-cache-adapter.js","sourceRoot":"","sources":["../../src/next/next-cache-adapter.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,UAAU,kCAAkC,CACjD,OAA4B,EAC5B,OAAiC;IAEjC,wEAAwE;IACxE,mCAAmC;IACnC,OAAO,OAAO,CAAC;AAChB,CAAC"}
|