@parrel/ledger 0.0.0-stage → 5.0.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.
Files changed (239) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +793 -2
  3. package/dist/cli/commands.d.ts +51 -0
  4. package/dist/cli/commands.d.ts.map +1 -0
  5. package/dist/cli/commands.js +968 -0
  6. package/dist/cli/commands.js.map +1 -0
  7. package/dist/cli/index.d.ts +24 -0
  8. package/dist/cli/index.d.ts.map +1 -0
  9. package/dist/cli/index.js +35 -0
  10. package/dist/cli/index.js.map +1 -0
  11. package/dist/cli/parrel.d.ts +3 -0
  12. package/dist/cli/parrel.d.ts.map +1 -0
  13. package/dist/cli/parrel.js +5 -0
  14. package/dist/cli/parrel.js.map +1 -0
  15. package/dist/cli/utils/angular-setup.d.ts +14 -0
  16. package/dist/cli/utils/angular-setup.d.ts.map +1 -0
  17. package/dist/cli/utils/angular-setup.js +96 -0
  18. package/dist/cli/utils/angular-setup.js.map +1 -0
  19. package/dist/cli/utils/api-tree-builder.d.ts +24 -0
  20. package/dist/cli/utils/api-tree-builder.d.ts.map +1 -0
  21. package/dist/cli/utils/api-tree-builder.js +146 -0
  22. package/dist/cli/utils/api-tree-builder.js.map +1 -0
  23. package/dist/cli/utils/bundle-reader.d.ts +185 -0
  24. package/dist/cli/utils/bundle-reader.d.ts.map +1 -0
  25. package/dist/cli/utils/bundle-reader.js +518 -0
  26. package/dist/cli/utils/bundle-reader.js.map +1 -0
  27. package/dist/cli/utils/collision-detector.d.ts +21 -0
  28. package/dist/cli/utils/collision-detector.d.ts.map +1 -0
  29. package/dist/cli/utils/collision-detector.js +53 -0
  30. package/dist/cli/utils/collision-detector.js.map +1 -0
  31. package/dist/cli/utils/map-fields.d.ts +42 -0
  32. package/dist/cli/utils/map-fields.d.ts.map +1 -0
  33. package/dist/cli/utils/map-fields.js +90 -0
  34. package/dist/cli/utils/map-fields.js.map +1 -0
  35. package/dist/cli/utils/map-validator.d.ts +42 -0
  36. package/dist/cli/utils/map-validator.d.ts.map +1 -0
  37. package/dist/cli/utils/map-validator.js +119 -0
  38. package/dist/cli/utils/map-validator.js.map +1 -0
  39. package/dist/cli/utils/media-file.d.ts +41 -0
  40. package/dist/cli/utils/media-file.d.ts.map +1 -0
  41. package/dist/cli/utils/media-file.js +72 -0
  42. package/dist/cli/utils/media-file.js.map +1 -0
  43. package/dist/cli/utils/media-validator.d.ts +10 -0
  44. package/dist/cli/utils/media-validator.d.ts.map +1 -0
  45. package/dist/cli/utils/media-validator.js +85 -0
  46. package/dist/cli/utils/media-validator.js.map +1 -0
  47. package/dist/cli/utils/mock-augmenter.d.ts +19 -0
  48. package/dist/cli/utils/mock-augmenter.d.ts.map +1 -0
  49. package/dist/cli/utils/mock-augmenter.js +102 -0
  50. package/dist/cli/utils/mock-augmenter.js.map +1 -0
  51. package/dist/cli/utils/mock-validator.d.ts +27 -0
  52. package/dist/cli/utils/mock-validator.d.ts.map +1 -0
  53. package/dist/cli/utils/mock-validator.js +214 -0
  54. package/dist/cli/utils/mock-validator.js.map +1 -0
  55. package/dist/cli/utils/project-dir.d.ts +24 -0
  56. package/dist/cli/utils/project-dir.d.ts.map +1 -0
  57. package/dist/cli/utils/project-dir.js +32 -0
  58. package/dist/cli/utils/project-dir.js.map +1 -0
  59. package/dist/cli/utils/schema-loader.d.ts +19 -0
  60. package/dist/cli/utils/schema-loader.d.ts.map +1 -0
  61. package/dist/cli/utils/schema-loader.js +101 -0
  62. package/dist/cli/utils/schema-loader.js.map +1 -0
  63. package/dist/cli/utils/server-entry.d.ts +34 -0
  64. package/dist/cli/utils/server-entry.d.ts.map +1 -0
  65. package/dist/cli/utils/server-entry.js +111 -0
  66. package/dist/cli/utils/server-entry.js.map +1 -0
  67. package/dist/cli/utils/sync.d.ts +116 -0
  68. package/dist/cli/utils/sync.d.ts.map +1 -0
  69. package/dist/cli/utils/sync.js +134 -0
  70. package/dist/cli/utils/sync.js.map +1 -0
  71. package/dist/client/index.d.ts +39 -0
  72. package/dist/client/index.d.ts.map +1 -0
  73. package/dist/client/index.js +88 -0
  74. package/dist/client/index.js.map +1 -0
  75. package/dist/core/browser-session.d.ts +5 -0
  76. package/dist/core/browser-session.d.ts.map +1 -0
  77. package/dist/core/browser-session.js +12 -0
  78. package/dist/core/browser-session.js.map +1 -0
  79. package/dist/core/cache.d.ts +80 -0
  80. package/dist/core/cache.d.ts.map +1 -0
  81. package/dist/core/cache.js +95 -0
  82. package/dist/core/cache.js.map +1 -0
  83. package/dist/core/client.d.ts +64 -0
  84. package/dist/core/client.d.ts.map +1 -0
  85. package/dist/core/client.js +281 -0
  86. package/dist/core/client.js.map +1 -0
  87. package/dist/core/config.d.ts +20 -0
  88. package/dist/core/config.d.ts.map +1 -0
  89. package/dist/core/config.js +32 -0
  90. package/dist/core/config.js.map +1 -0
  91. package/dist/core/copy-read.d.ts +25 -0
  92. package/dist/core/copy-read.d.ts.map +1 -0
  93. package/dist/core/copy-read.js +123 -0
  94. package/dist/core/copy-read.js.map +1 -0
  95. package/dist/core/define-ledger.d.ts +38 -0
  96. package/dist/core/define-ledger.d.ts.map +1 -0
  97. package/dist/core/define-ledger.js +65 -0
  98. package/dist/core/define-ledger.js.map +1 -0
  99. package/dist/core/deprecated.d.ts +16 -0
  100. package/dist/core/deprecated.d.ts.map +1 -0
  101. package/dist/core/deprecated.js +14 -0
  102. package/dist/core/deprecated.js.map +1 -0
  103. package/dist/core/env.d.ts +103 -0
  104. package/dist/core/env.d.ts.map +1 -0
  105. package/dist/core/env.js +208 -0
  106. package/dist/core/env.js.map +1 -0
  107. package/dist/core/error-codes.generated.d.ts +12 -0
  108. package/dist/core/error-codes.generated.d.ts.map +1 -0
  109. package/dist/core/error-codes.generated.js +3 -0
  110. package/dist/core/error-codes.generated.js.map +1 -0
  111. package/dist/core/get-content.d.ts +62 -0
  112. package/dist/core/get-content.d.ts.map +1 -0
  113. package/dist/core/get-content.js +86 -0
  114. package/dist/core/get-content.js.map +1 -0
  115. package/dist/core/get-media.d.ts +58 -0
  116. package/dist/core/get-media.d.ts.map +1 -0
  117. package/dist/core/get-media.js +89 -0
  118. package/dist/core/get-media.js.map +1 -0
  119. package/dist/core/manifest.d.ts +38 -0
  120. package/dist/core/manifest.d.ts.map +1 -0
  121. package/dist/core/manifest.js +93 -0
  122. package/dist/core/manifest.js.map +1 -0
  123. package/dist/core/media-proxy.d.ts +41 -0
  124. package/dist/core/media-proxy.d.ts.map +1 -0
  125. package/dist/core/media-proxy.js +219 -0
  126. package/dist/core/media-proxy.js.map +1 -0
  127. package/dist/core/package-info.d.ts +34 -0
  128. package/dist/core/package-info.d.ts.map +1 -0
  129. package/dist/core/package-info.js +39 -0
  130. package/dist/core/package-info.js.map +1 -0
  131. package/dist/core/parrel-error.d.ts +160 -0
  132. package/dist/core/parrel-error.d.ts.map +1 -0
  133. package/dist/core/parrel-error.js +198 -0
  134. package/dist/core/parrel-error.js.map +1 -0
  135. package/dist/core/transform-content.d.ts +42 -0
  136. package/dist/core/transform-content.d.ts.map +1 -0
  137. package/dist/core/transform-content.js +185 -0
  138. package/dist/core/transform-content.js.map +1 -0
  139. package/dist/core/types.d.ts +406 -0
  140. package/dist/core/types.d.ts.map +1 -0
  141. package/dist/core/types.js +11 -0
  142. package/dist/core/types.js.map +1 -0
  143. package/dist/errors/error-messages.generated.d.ts +5 -0
  144. package/dist/errors/error-messages.generated.d.ts.map +1 -0
  145. package/dist/errors/error-messages.generated.js +971 -0
  146. package/dist/errors/error-messages.generated.js.map +1 -0
  147. package/dist/errors/get-error-info.d.ts +29 -0
  148. package/dist/errors/get-error-info.d.ts.map +1 -0
  149. package/dist/errors/get-error-info.js +43 -0
  150. package/dist/errors/get-error-info.js.map +1 -0
  151. package/dist/errors/index.d.ts +4 -0
  152. package/dist/errors/index.d.ts.map +1 -0
  153. package/dist/errors/index.js +4 -0
  154. package/dist/errors/index.js.map +1 -0
  155. package/dist/errors/types.d.ts +19 -0
  156. package/dist/errors/types.d.ts.map +1 -0
  157. package/dist/errors/types.js +2 -0
  158. package/dist/errors/types.js.map +1 -0
  159. package/dist/generated.d.ts +29 -0
  160. package/dist/generated.d.ts.map +1 -0
  161. package/dist/generated.js +29 -0
  162. package/dist/generated.js.map +1 -0
  163. package/dist/index.d.ts +19 -0
  164. package/dist/index.d.ts.map +1 -0
  165. package/dist/index.js +16 -0
  166. package/dist/index.js.map +1 -0
  167. package/dist/mock/dev-media.d.ts +15 -0
  168. package/dist/mock/dev-media.d.ts.map +1 -0
  169. package/dist/mock/dev-media.js +52 -0
  170. package/dist/mock/dev-media.js.map +1 -0
  171. package/dist/mock/file-store.d.ts +44 -0
  172. package/dist/mock/file-store.d.ts.map +1 -0
  173. package/dist/mock/file-store.js +170 -0
  174. package/dist/mock/file-store.js.map +1 -0
  175. package/dist/mock/index.d.ts +4 -0
  176. package/dist/mock/index.d.ts.map +1 -0
  177. package/dist/mock/index.js +3 -0
  178. package/dist/mock/index.js.map +1 -0
  179. package/dist/mock/media-fields.d.ts +25 -0
  180. package/dist/mock/media-fields.d.ts.map +1 -0
  181. package/dist/mock/media-fields.js +54 -0
  182. package/dist/mock/media-fields.js.map +1 -0
  183. package/dist/mock/mock-adapter.d.ts +65 -0
  184. package/dist/mock/mock-adapter.d.ts.map +1 -0
  185. package/dist/mock/mock-adapter.js +431 -0
  186. package/dist/mock/mock-adapter.js.map +1 -0
  187. package/dist/mock/mock-errors.d.ts +18 -0
  188. package/dist/mock/mock-errors.d.ts.map +1 -0
  189. package/dist/mock/mock-errors.js +56 -0
  190. package/dist/mock/mock-errors.js.map +1 -0
  191. package/dist/mock/node-import.d.ts +13 -0
  192. package/dist/mock/node-import.d.ts.map +1 -0
  193. package/dist/mock/node-import.js +16 -0
  194. package/dist/mock/node-import.js.map +1 -0
  195. package/dist/mock/seed-mock-store.d.ts +14 -0
  196. package/dist/mock/seed-mock-store.d.ts.map +1 -0
  197. package/dist/mock/seed-mock-store.js +106 -0
  198. package/dist/mock/seed-mock-store.js.map +1 -0
  199. package/dist/mock/shared-memory-store.d.ts +35 -0
  200. package/dist/mock/shared-memory-store.d.ts.map +1 -0
  201. package/dist/mock/shared-memory-store.js +46 -0
  202. package/dist/mock/shared-memory-store.js.map +1 -0
  203. package/dist/next/dev-rendering-helpers.d.ts +78 -0
  204. package/dist/next/dev-rendering-helpers.d.ts.map +1 -0
  205. package/dist/next/dev-rendering-helpers.js +103 -0
  206. package/dist/next/dev-rendering-helpers.js.map +1 -0
  207. package/dist/next/index.d.ts +35 -0
  208. package/dist/next/index.d.ts.map +1 -0
  209. package/dist/next/index.js +33 -0
  210. package/dist/next/index.js.map +1 -0
  211. package/dist/next/next-cache-adapter.d.ts +11 -0
  212. package/dist/next/next-cache-adapter.d.ts.map +1 -0
  213. package/dist/next/next-cache-adapter.js +12 -0
  214. package/dist/next/next-cache-adapter.js.map +1 -0
  215. package/dist/nuxt/index.d.ts +22 -0
  216. package/dist/nuxt/index.d.ts.map +1 -0
  217. package/dist/nuxt/index.js +57 -0
  218. package/dist/nuxt/index.js.map +1 -0
  219. package/dist/sveltekit/index.d.ts +35 -0
  220. package/dist/sveltekit/index.d.ts.map +1 -0
  221. package/dist/sveltekit/index.js +56 -0
  222. package/dist/sveltekit/index.js.map +1 -0
  223. package/dist/ui/content-editor.d.ts +9 -0
  224. package/dist/ui/content-editor.d.ts.map +1 -0
  225. package/dist/ui/content-editor.js +27 -0
  226. package/dist/ui/content-editor.js.map +1 -0
  227. package/dist/ui/index.d.ts +8 -0
  228. package/dist/ui/index.d.ts.map +1 -0
  229. package/dist/ui/index.js +8 -0
  230. package/dist/ui/index.js.map +1 -0
  231. package/dist/ui/ledger-overlay.d.ts +10 -0
  232. package/dist/ui/ledger-overlay.d.ts.map +1 -0
  233. package/dist/ui/ledger-overlay.js +27 -0
  234. package/dist/ui/ledger-overlay.js.map +1 -0
  235. package/dist/ui/media-uploader.d.ts +9 -0
  236. package/dist/ui/media-uploader.d.ts.map +1 -0
  237. package/dist/ui/media-uploader.js +27 -0
  238. package/dist/ui/media-uploader.js.map +1 -0
  239. package/package.json +134 -6
@@ -0,0 +1,111 @@
1
+ // @ts-nocheck (loose JSON shapes)
2
+ /**
3
+ * What `init` writes so that a server-rendered app loads the Ledger or Docket configuration where reads happen: the
4
+ * SvelteKit `src/hooks.server.ts` imports the config, and for Nuxt a server plugin uses it.
5
+ *
6
+ * Sign-in, writes and uploads run in the browser, so nothing here forwards a visitor or touches a session.
7
+ * `@parrel/ledger` and `@parrel/docket` carry the same file, with their own product passed in.
8
+ */
9
+ import { existsSync } from "node:fs";
10
+ import { readFile, writeFile } from "node:fs/promises";
11
+ import path from "node:path";
12
+ import { log, reportWrite, style, svelteKitLibImport, writeFileSafe } from "@parrel/sentinel/cli";
13
+ const HOOKS_FILE = path.join("src", "hooks.server.ts");
14
+ const HOOKS_LABEL = "src/hooks.server.ts";
15
+ /** The names that older versions of `init` wrote and that no longer exist in `@parrel/sentinel`. */
16
+ const REMOVED_SENTINEL_NAMES = /createParrelSentinel(?:Handle|Middleware)/;
17
+ /** The import line of the config; `specifier` is `svelteKitLibImport(root, product.name)`. */
18
+ function configImportLine(product, specifier) {
19
+ return `import "${specifier}"; // registers ${product.define}(...)`;
20
+ }
21
+ function hooksFileContent(product, specifier) {
22
+ return `${configImportLine(product, specifier)}
23
+ `;
24
+ }
25
+ function importsConfig(source, product) {
26
+ return new RegExp(`import\\s+(?:[^;]*?from\\s+)?["'][^"']*/${product.name}(?:\\.[jt]s)?["']`).test(source);
27
+ }
28
+ /** Adds `line` after the last import of the file, or at the top when it has none. */
29
+ function addImport(source, line) {
30
+ const eol = source.includes("\r\n") ? "\r\n" : "\n";
31
+ const lines = source.split(/\r?\n/);
32
+ let last = -1;
33
+ lines.forEach((text, index) => {
34
+ if (/^import\s/.test(text) && /["'];?\s*(\/\/.*)?$/.test(text))
35
+ last = index;
36
+ });
37
+ lines.splice(last + 1, 0, line);
38
+ return lines.join(eol);
39
+ }
40
+ /** Tells the person to remove a Sentinel server helper that an older `init` wrote and that no longer exists. */
41
+ function warnAboutRemovedSentinelNames(label, source) {
42
+ if (REMOVED_SENTINEL_NAMES.test(source)) {
43
+ log.warn(`${label} uses createParrelSentinelHandle or createParrelSentinelMiddleware, which @parrel/sentinel no longer exports (the session lives in the browser). Remove it.`);
44
+ }
45
+ }
46
+ /**
47
+ * Writes `src/hooks.server.ts` for a SvelteKit app so that a load function finds the configuration: it imports the
48
+ * config. Reads run on the server, so the config must be loaded there.
49
+ *
50
+ * A file that does not exist is created. An existing file is never overwritten without `force`: only the missing
51
+ * import is added, and the rest of the file is left alone.
52
+ */
53
+ export async function writeSveltekitServerEntry(root, product, force = false) {
54
+ const specifier = await svelteKitLibImport(root, product.name);
55
+ const file = path.join(root, HOOKS_FILE);
56
+ if (!existsSync(file) || force) {
57
+ const action = await writeFileSafe(file, hooksFileContent(product, specifier), true);
58
+ reportWrite(root, file, action);
59
+ return action;
60
+ }
61
+ const source = await readFile(file, "utf8");
62
+ warnAboutRemovedSentinelNames(HOOKS_LABEL, source);
63
+ if (importsConfig(source, product)) {
64
+ log.hint(`${HOOKS_LABEL} already loads ${product.label}`);
65
+ return "unchanged";
66
+ }
67
+ await writeFile(file, addImport(source, configImportLine(product, specifier)), "utf8");
68
+ log.ok(`extended ${HOOKS_LABEL}`);
69
+ return "extended";
70
+ }
71
+ /** Path of the Nuxt server plugin that loads the configuration. */
72
+ export function nuxtPluginFile(product) {
73
+ return path.join("server", "plugins", `parrel-${product.name}.ts`);
74
+ }
75
+ /** The Nuxt server plugin. It uses the configuration inside a function, because Nitro drops anything less. */
76
+ export function nuxtPluginContent(product, packageName) {
77
+ return `import { ParrelError } from "${packageName}";
78
+ import { ${product.exportName} } from "~~/lib/${product.name}";
79
+
80
+ // Loads the ${product.label} configuration on the server: Nuxt does not import lib/ by itself.
81
+ // Nitro drops a bare side-effect import and an export that nothing uses, so the plugin really uses it.
82
+ export default defineNitroPlugin(() => {
83
+ if (!${product.exportName}) {
84
+ throw new ParrelError(
85
+ "${product.notConfiguredCode}",
86
+ "lib/${product.name}.ts must export the result of ${product.define}(...) as \`${product.exportName}\`, so the ${product.label} configuration is kept.",
87
+ );
88
+ }
89
+ });
90
+ `;
91
+ }
92
+ /**
93
+ * Writes the server plugin of a Nuxt app, which loads the configuration on the server. An old
94
+ * `server/middleware/parrel-request.ts` from an earlier `init` gets a warning: the Sentinel middleware it uses is gone.
95
+ */
96
+ export async function writeNuxtServerEntry(root, product, packageName, force = false) {
97
+ const plugin = path.join(root, nuxtPluginFile(product));
98
+ reportWrite(root, plugin, await writeFileSafe(plugin, nuxtPluginContent(product, packageName), force));
99
+ const oldMiddleware = path.join(root, "server", "middleware", "parrel-request.ts");
100
+ if (existsSync(oldMiddleware)) {
101
+ warnAboutRemovedSentinelNames("server/middleware/parrel-request.ts", await readFile(oldMiddleware, "utf8"));
102
+ }
103
+ }
104
+ /** The next-steps text for a server-rendered app that got the files above. */
105
+ export function serverEntryNextStep(framework, product, specifier) {
106
+ if (framework === "sveltekit") {
107
+ return `${style.cyan(HOOKS_LABEL)} imports ${style.cyan(specifier)}, so a load function finds the ${product.label} configuration.`;
108
+ }
109
+ return `${style.cyan(nuxtPluginFile(product).split(path.sep).join("/"))} loads the ${product.label} configuration on the server. The config is at the project root, outside the app/ folder of Nuxt 4: import it as ${style.cyan(`~~/lib/${product.name}`)}.`;
110
+ }
111
+ //# sourceMappingURL=server-entry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-entry.js","sourceRoot":"","sources":["../../../src/cli/utils/server-entry.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAElC;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE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C;AAED,8EAA8E;AAC9E,MAAM,UAAU,mBAAmB,CAAC,SAAiB,EAAE,OAA2B,EAAE,SAAiB;IACpG,IAAI,SAAS,KAAK,WAAW,EAAE,CAAC;QAC/B,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,kCAAkC,OAAO,CAAC,KAAK,iBAAiB,CAAC;IACpI,CAAC;IACD,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,cAAc,OAAO,CAAC,KAAK,oHAAoH,KAAK,CAAC,IAAI,CAAC,UAAU,OAAO,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC;AAC/P,CAAC"}
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Map sync helpers: preview and apply (rulebook LED-4)
3
+ *
4
+ * `previewMapSync` asks Ledger what a sync would delete or retype (`POST /v1/map/sync/{slug}/preview`), and changes
5
+ * nothing. `applyMapSync` runs the sync (`POST /v1/map/sync/{slug}`). Both take the same deployment token: it is valid
6
+ * for 5 minutes and only the newest token of the service works (LED-15).
7
+ */
8
+ /** A map that the sync would delete, with what goes with it. */
9
+ export interface MapSyncDeletedMap {
10
+ name: string;
11
+ resourceCount: number;
12
+ mediaCount: number;
13
+ }
14
+ /** A field that the sync would remove from a map. */
15
+ export interface MapSyncRemovedField {
16
+ map: string;
17
+ field: string;
18
+ resourceCount: number;
19
+ }
20
+ /** A field that the sync would give another type. */
21
+ export interface MapSyncRetypedField {
22
+ map: string;
23
+ field: string;
24
+ fromType: string;
25
+ toType: string;
26
+ resourceCount: number;
27
+ }
28
+ /** What Ledger says a sync would do. */
29
+ export interface MapSyncPreview {
30
+ status: "preview";
31
+ /** Pass it to {@link applyMapSync} as `{ previewId }` to apply exactly what the preview showed. */
32
+ previewId: string;
33
+ expiresAt: string;
34
+ mapsAdded: string[];
35
+ mapsUpdated: string[];
36
+ mapsUnchanged: string[];
37
+ mapsDeleted: MapSyncDeletedMap[];
38
+ fieldsRemoved: MapSyncRemovedField[];
39
+ fieldsRetyped: MapSyncRetypedField[];
40
+ /** The number of media files the sync deletes. */
41
+ mediaDeleted: number;
42
+ /** The names of the first 50 media files that the sync deletes. */
43
+ mediaDeletedNames: string[];
44
+ /** True when the sync deletes or retypes something, so it needs a confirmation. */
45
+ requiresConfirmation: boolean;
46
+ }
47
+ /** The answer of Ledger to an applied sync. */
48
+ export interface MapSyncReport {
49
+ slug?: string;
50
+ mapsAdded?: string[];
51
+ mapsUpdated?: string[];
52
+ mapsDeleted?: string[];
53
+ mapsUnchanged?: string[];
54
+ errors?: string[];
55
+ message?: string;
56
+ [key: string]: unknown;
57
+ }
58
+ /** Options of {@link previewMapSync} and {@link applyMapSync}. */
59
+ export interface MapSyncOptions {
60
+ /** The origin of the Parrel API. Default: `PARREL_API_ORIGIN`, or the production API. */
61
+ apiOrigin?: string;
62
+ }
63
+ /** How a sync is confirmed: `{ confirm: true }` for `--force`, `{ previewId }` for what the person saw in the preview. */
64
+ export type MapSyncConfirmation = {
65
+ confirm: true;
66
+ } | {
67
+ previewId: string;
68
+ };
69
+ /**
70
+ * Asks Ledger what a map sync would do, without doing it. The maps are checked against the local limits first
71
+ * (`SD05000010` to `SD05000013`), so a request that breaks a limit is never sent. The preview is valid for 5 minutes,
72
+ * and only while the maps and the content of the service do not change.
73
+ *
74
+ * Every answer that is not a preview is an error: a `404` or a `405` is the error that Ledger sent, and the caller
75
+ * syncs nothing (LED-4).
76
+ *
77
+ * @param slug - The slug of the Ledger service.
78
+ * @param token - The map deployment token from the Parrel portal. It is valid for 5 minutes, only the newest token of
79
+ * the service works, and the same token serves the preview and the {@link applyMapSync} after it.
80
+ * @param maps - The maps by name, as `parrel ledger sync` sends them.
81
+ * @param options - `apiOrigin` to use another origin than the production API.
82
+ * @returns The preview.
83
+ * @throws ParrelError - A local limit code, `SD01000014` when Ledger cannot be reached, the error Ledger returned, or
84
+ * `SD01000012` when the answer is not a preview.
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * const preview = await previewMapSync("my-site", token, { homepage: { title: { type: "string" } } });
89
+ * if (preview.requiresConfirmation) console.log(preview.mapsDeleted);
90
+ * ```
91
+ */
92
+ export declare function previewMapSync(slug: string, token: string, maps: Record<string, unknown>, options?: MapSyncOptions): Promise<MapSyncPreview>;
93
+ /**
94
+ * Runs the map sync. A sync that deletes or retypes something needs `{ confirm: true }` (what `--force` sends) or
95
+ * `{ previewId }` (the preview the person agreed to); Ledger answers `409` (`MAP_SYNC_CONFIRMATION_REQUIRED`,
96
+ * `MAP_SYNC_PREVIEW_EXPIRED` or `MAP_SYNC_PREVIEW_STALE`) otherwise, and the error keeps that code. The maps are
97
+ * checked against the local limits first.
98
+ *
99
+ * @param slug - The slug of the Ledger service.
100
+ * @param token - The map deployment token from the Parrel portal: the same token as the preview. It is valid for
101
+ * 5 minutes, and only the newest token of the service works; an older one gets `DEPLOYMENT_TOKEN_SUPERSEDED`.
102
+ * @param maps - The maps by name.
103
+ * @param confirm - `{ confirm: true }` or `{ previewId }`.
104
+ * @param options - `apiOrigin` to use another origin than the production API.
105
+ * @returns The report of Ledger.
106
+ * @throws ParrelError - A local limit code, `SD01000014` when Ledger cannot be reached, or the error Ledger returned.
107
+ *
108
+ * @example
109
+ * ```ts
110
+ * const preview = await previewMapSync("my-site", token, maps);
111
+ * const report = await applyMapSync("my-site", token, maps, { previewId: preview.previewId });
112
+ * console.log(report.mapsAdded);
113
+ * ```
114
+ */
115
+ export declare function applyMapSync(slug: string, token: string, maps: Record<string, unknown>, confirm: MapSyncConfirmation, options?: MapSyncOptions): Promise<MapSyncReport>;
116
+ //# sourceMappingURL=sync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../../src/cli/utils/sync.ts"],"names":[],"mappings":"AAAA;;;;;;GA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IACzB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACvB;AAED,kEAAkE;AAClE,MAAM,WAAW,cAAc;IAC9B,yFAAyF;IACzF,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,0HAA0H;AAC1H,MAAM,MAAM,mBAAmB,GAAG;IAAE,OAAO,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;AAoD5E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,cAAc,CACnC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,GAAE,cAAmB,GAC1B,OAAO,CAAC,cAAc,CAAC,CAiBzB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,YAAY,CACjC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,EAAE,mBAAmB,EAC5B,OAAO,GAAE,cAAmB,GAC1B,OAAO,CAAC,aAAa,CAAC,CAYxB"}
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Map sync helpers: preview and apply (rulebook LED-4)
3
+ *
4
+ * `previewMapSync` asks Ledger what a sync would delete or retype (`POST /v1/map/sync/{slug}/preview`), and changes
5
+ * nothing. `applyMapSync` runs the sync (`POST /v1/map/sync/{slug}`). Both take the same deployment token: it is valid
6
+ * for 5 minutes and only the newest token of the service works (LED-15).
7
+ */
8
+ import { resolveParrelApiOrigin } from "../../core/env.js";
9
+ import { parrelHandshakeHeader } from "../../core/package-info.js";
10
+ import { ParrelError, parseApiError } from "../../core/parrel-error.js";
11
+ import { assertMapSetWithinLimits, syncRequestBody } from "./map-validator.js";
12
+ function syncUrl(slug, options, suffix = "") {
13
+ const origin = options.apiOrigin ?? resolveParrelApiOrigin();
14
+ return `${origin}/cms/v1/map/sync/${encodeURIComponent(slug)}${suffix}`;
15
+ }
16
+ /**
17
+ * Sends the sync request. A request that gets no answer is `SD01000014`; the caller turns an error answer of Ledger
18
+ * into the error with its own code.
19
+ */
20
+ async function postSync(url, token, body) {
21
+ try {
22
+ return await fetch(url, {
23
+ method: "POST",
24
+ headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}`, ...parrelHandshakeHeader() },
25
+ body,
26
+ });
27
+ }
28
+ catch (error) {
29
+ throw new ParrelError("SD01000014", "Ledger could not be reached to sync the maps. Check your internet connection and PARREL_API_ORIGIN (if you set it), then run the command again. " +
30
+ "A request from an origin that is not allowed fails the same way in a browser: check the allowed origins of your Ledger service in the Parrel portal.", { cause: error });
31
+ }
32
+ }
33
+ function toPreview(value) {
34
+ if (typeof value !== "object" || value === null) {
35
+ return undefined;
36
+ }
37
+ const body = value;
38
+ if (body.status !== "preview" || typeof body.previewId !== "string") {
39
+ return undefined;
40
+ }
41
+ return {
42
+ status: "preview",
43
+ previewId: body.previewId,
44
+ expiresAt: body.expiresAt ?? "",
45
+ mapsAdded: body.mapsAdded ?? [],
46
+ mapsUpdated: body.mapsUpdated ?? [],
47
+ mapsUnchanged: body.mapsUnchanged ?? [],
48
+ mapsDeleted: body.mapsDeleted ?? [],
49
+ fieldsRemoved: body.fieldsRemoved ?? [],
50
+ fieldsRetyped: body.fieldsRetyped ?? [],
51
+ mediaDeleted: body.mediaDeleted ?? 0,
52
+ mediaDeletedNames: body.mediaDeletedNames ?? [],
53
+ requiresConfirmation: body.requiresConfirmation === true,
54
+ };
55
+ }
56
+ /**
57
+ * Asks Ledger what a map sync would do, without doing it. The maps are checked against the local limits first
58
+ * (`SD05000010` to `SD05000013`), so a request that breaks a limit is never sent. The preview is valid for 5 minutes,
59
+ * and only while the maps and the content of the service do not change.
60
+ *
61
+ * Every answer that is not a preview is an error: a `404` or a `405` is the error that Ledger sent, and the caller
62
+ * syncs nothing (LED-4).
63
+ *
64
+ * @param slug - The slug of the Ledger service.
65
+ * @param token - The map deployment token from the Parrel portal. It is valid for 5 minutes, only the newest token of
66
+ * the service works, and the same token serves the preview and the {@link applyMapSync} after it.
67
+ * @param maps - The maps by name, as `parrel ledger sync` sends them.
68
+ * @param options - `apiOrigin` to use another origin than the production API.
69
+ * @returns The preview.
70
+ * @throws ParrelError - A local limit code, `SD01000014` when Ledger cannot be reached, the error Ledger returned, or
71
+ * `SD01000012` when the answer is not a preview.
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * const preview = await previewMapSync("my-site", token, { homepage: { title: { type: "string" } } });
76
+ * if (preview.requiresConfirmation) console.log(preview.mapsDeleted);
77
+ * ```
78
+ */
79
+ export async function previewMapSync(slug, token, maps, options = {}) {
80
+ assertMapSetWithinLimits(maps);
81
+ const response = await postSync(syncUrl(slug, options, "/preview"), token, syncRequestBody(maps));
82
+ if (!response.ok) {
83
+ throw await parseApiError(response);
84
+ }
85
+ let body;
86
+ try {
87
+ body = await response.json();
88
+ }
89
+ catch {
90
+ body = undefined;
91
+ }
92
+ const preview = toPreview(body);
93
+ if (!preview) {
94
+ throw parseApiError({ status: response.status, body });
95
+ }
96
+ return preview;
97
+ }
98
+ /**
99
+ * Runs the map sync. A sync that deletes or retypes something needs `{ confirm: true }` (what `--force` sends) or
100
+ * `{ previewId }` (the preview the person agreed to); Ledger answers `409` (`MAP_SYNC_CONFIRMATION_REQUIRED`,
101
+ * `MAP_SYNC_PREVIEW_EXPIRED` or `MAP_SYNC_PREVIEW_STALE`) otherwise, and the error keeps that code. The maps are
102
+ * checked against the local limits first.
103
+ *
104
+ * @param slug - The slug of the Ledger service.
105
+ * @param token - The map deployment token from the Parrel portal: the same token as the preview. It is valid for
106
+ * 5 minutes, and only the newest token of the service works; an older one gets `DEPLOYMENT_TOKEN_SUPERSEDED`.
107
+ * @param maps - The maps by name.
108
+ * @param confirm - `{ confirm: true }` or `{ previewId }`.
109
+ * @param options - `apiOrigin` to use another origin than the production API.
110
+ * @returns The report of Ledger.
111
+ * @throws ParrelError - A local limit code, `SD01000014` when Ledger cannot be reached, or the error Ledger returned.
112
+ *
113
+ * @example
114
+ * ```ts
115
+ * const preview = await previewMapSync("my-site", token, maps);
116
+ * const report = await applyMapSync("my-site", token, maps, { previewId: preview.previewId });
117
+ * console.log(report.mapsAdded);
118
+ * ```
119
+ */
120
+ export async function applyMapSync(slug, token, maps, confirm, options = {}) {
121
+ assertMapSetWithinLimits(maps);
122
+ const response = await postSync(syncUrl(slug, options), token, syncRequestBody(maps, confirm));
123
+ if (!response.ok) {
124
+ throw await parseApiError(response);
125
+ }
126
+ try {
127
+ const report = await response.json();
128
+ return typeof report === "object" && report !== null ? report : {};
129
+ }
130
+ catch {
131
+ return {};
132
+ }
133
+ }
134
+ //# sourceMappingURL=sync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync.js","sourceRoot":"","sources":["../../../src/cli/utils/sync.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,EAAE,wBAAwB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAkE/E,SAAS,OAAO,CAAC,IAAY,EAAE,OAAuB,EAAE,MAAM,GAAG,EAAE;IAClE,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,IAAI,sBAAsB,EAAE,CAAC;IAC7D,OAAO,GAAG,MAAM,oBAAoB,kBAAkB,CAAC,IAAI,CAAC,GAAG,MAAM,EAAE,CAAC;AACzE,CAAC;AAED;;;GAGG;AACH,KAAK,UAAU,QAAQ,CAAC,GAAW,EAAE,KAAa,EAAE,IAAY;IAC/D,IA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AC,QAAQ,CAAC,EAAE,EAAE,CAAC;QAClB,MAAM,MAAM,aAAa,CAAC,QAAQ,CAAC,CAAC;IACrC,CAAC;IACD,IAAI,CAAC;QACJ,MAAM,MAAM,GAAY,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAC9C,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,CAAC,CAAC,CAAE,MAAwB,CAAC,CAAC,CAAC,EAAE,CAAC;IACvF,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,EAAE,CAAC;IACX,CAAC;AACF,CAAC"}
@@ -0,0 +1,39 @@
1
+ import type { ContentAccessOptions } from "../core/types.js";
2
+ export interface LedgerClientNode {
3
+ getContent<T = unknown>(options?: ContentAccessOptions): Promise<T>;
4
+ /**
5
+ * Writes the fields you pass and leaves every other field as it is. Given an object, each field is written at
6
+ * its own path, so `setContent({ title: "x" })` never erases the other fields of the resource. The value of a
7
+ * field (a text, a number, an array, a nested object) replaces that field as a whole. Given anything else (a
8
+ * text, a number, an array), the value replaces what is at this node. The fields are written one after the
9
+ * other: when a write fails, its error is thrown and the fields after it are not written.
10
+ */
11
+ setContent(data: unknown): Promise<void>;
12
+ getMedia(options?: ContentAccessOptions): Promise<string>;
13
+ setMedia(file: File): Promise<void>;
14
+ [key: string]: any;
15
+ }
16
+ export type LedgerClient = Record<string, LedgerClientNode>;
17
+ export declare function createLedgerClient(): LedgerClient;
18
+ /**
19
+ * Untyped Ledger client. After `npx parrel ledger generate`, the declaration of
20
+ * `@parrel/ledger/client` is replaced by one typed from your maps.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * import { ledgerClient } from "@parrel/ledger/client";
25
+ *
26
+ * const page = await ledgerClient.homepage.getContent();
27
+ * const heroUrl = await ledgerClient.homepage.heroImage.getMedia();
28
+ * ```
29
+ */
30
+ export declare const ledgerClient: LedgerClient;
31
+ /** @deprecated Use {@link LedgerClientNode}. Removed in the next major version. */
32
+ export type CmsClientNode = LedgerClientNode;
33
+ /** @deprecated Use {@link LedgerClient}. Removed in the next major version. */
34
+ export type CmsClient = LedgerClient;
35
+ /** @deprecated Use {@link createLedgerClient}. Removed in the next major version. */
36
+ export declare const createCmsClient: typeof createLedgerClient;
37
+ /** @deprecated Use {@link ledgerClient}. Removed in the next major version. */
38
+ export declare const cmsClient: LedgerClient;
39
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAE7D,MAAM,WAAW,gBAAgB;IAChC,UAAU,CAAC,CAAC,GAAG,OAAO,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACpE;;;;;;OAMG;IACH,UAAU,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzC,QAAQ,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC1D,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACnB;AAED,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;AA8E5D,wBAAgB,kBAAkB,IAAI,YAAY,CAEjD;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,YAAY,cAAuB,CAAC;AAEjD,mFAAmF;AACnF,MAAM,MAAM,aAAa,GAAG,gBAAgB,CAAC;AAE7C,+EAA+E;AAC/E,MAAM,MAAM,SAAS,GAAG,YAAY,CAAC;AAErC,qFAAqF;AACrF,eAAO,MAAM,eAAe,2BAAqB,CAAC;AAElD,+EAA+E;AAC/E,eAAO,MAAM,SAAS,cAAe,CAAC"}
@@ -0,0 +1,88 @@
1
+ import { getContent, uploadContent } from "../core/get-content.js";
2
+ import { getMedia, uploadMedia } from "../core/get-media.js";
3
+ function isNumericSegment(segment) {
4
+ return /^\d+$/.test(segment);
5
+ }
6
+ function isPlainObject(value) {
7
+ return value !== null && typeof value === "object" && !Array.isArray(value);
8
+ }
9
+ function joinPath(segments) {
10
+ if (segments.length === 0) {
11
+ return "";
12
+ }
13
+ let path = segments[0];
14
+ for (let index = 1; index < segments.length; index += 1) {
15
+ const segment = segments[index];
16
+ if (isNumericSegment(segment)) {
17
+ path += `[${segment}]`;
18
+ }
19
+ else {
20
+ path += `.${segment}`;
21
+ }
22
+ }
23
+ return path;
24
+ }
25
+ function createClientNode(segments) {
26
+ const node = {
27
+ async getContent(options) {
28
+ return getContent(joinPath(segments), options);
29
+ },
30
+ async setContent(data) {
31
+ const path = joinPath(segments);
32
+ if (isPlainObject(data)) {
33
+ for (const [field, value] of Object.entries(data)) {
34
+ // undefined means "not passed" (JSON would drop it too); null is a value and is written.
35
+ if (value !== undefined) {
36
+ await uploadContent(`${path}.${field}`, value);
37
+ }
38
+ }
39
+ return;
40
+ }
41
+ await uploadContent(path, data);
42
+ },
43
+ async getMedia(options) {
44
+ return getMedia(joinPath(segments), options);
45
+ },
46
+ async setMedia(file) {
47
+ await uploadMedia(joinPath(segments), file);
48
+ },
49
+ };
50
+ return new Proxy(node, {
51
+ get(target, property, receiver) {
52
+ if (property === "then") {
53
+ return undefined;
54
+ }
55
+ if (property === Symbol.toStringTag) {
56
+ return "LedgerClientNode";
57
+ }
58
+ if (typeof property === "string") {
59
+ if (property in target) {
60
+ return Reflect.get(target, property, receiver);
61
+ }
62
+ return createClientNode([...segments, property]);
63
+ }
64
+ return Reflect.get(target, property, receiver);
65
+ },
66
+ });
67
+ }
68
+ export function createLedgerClient() {
69
+ return createClientNode([]);
70
+ }
71
+ /**
72
+ * Untyped Ledger client. After `npx parrel ledger generate`, the declaration of
73
+ * `@parrel/ledger/client` is replaced by one typed from your maps.
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * import { ledgerClient } from "@parrel/ledger/client";
78
+ *
79
+ * const page = await ledgerClient.homepage.getContent();
80
+ * const heroUrl = await ledgerClient.homepage.heroImage.getMedia();
81
+ * ```
82
+ */
83
+ export const ledgerClient = createLedgerClient();
84
+ /** @deprecated Use {@link createLedgerClient}. Removed in the next major version. */
85
+ export const createCmsClient = createLedgerClient;
86
+ /** @deprecated Use {@link ledgerClient}. Removed in the next major version. */
87
+ export const cmsClient = ledgerClient;
88
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAoB7D,SAAS,gBAAgB,CAAC,OAAe;IACxC,OAAO,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAC9B,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACpC,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC;AAED,SAAS,QAAQ,CAAC,QAAkB;IACnC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO,EAAE,CAAC;IACX,CAAC;IAED,IAAI,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IAEvB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACzD,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;QAChC,IAAI,gBAAgB,CAAC,OAAO,CAAC,EAAE,CAAC;YAC/B,IAAI,IAAI,IA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OAAO,SAAS,CAAC;YAClB,CAAC;YAED,IAAI,QAAQ,KAAK,MAAM,CAAC,WAAW,EAAE,CAAC;gBACrC,OAAO,kBAAkB,CAAC;YAC3B,CAAC;YAED,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;gBAClC,IAAI,QAAQ,IAAI,MAAM,EAAE,CAAC;oBACxB,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;gBAChD,CAAC;gBAED,OAAO,gBAAgB,CAAC,CAAC,GAAG,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;YAClD,CAAC;YAED,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAChD,CAAC;KACD,CAAqB,CAAC;AACxB,CAAC;AAED,MAAM,UAAU,kBAAkB;IACjC,OAAO,gBAAgB,CAAC,EAAE,CAAiB,CAAC;AAC7C,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,kBAAkB,EAAE,CAAC;AAQjD,qFAAqF;AACrF,MAAM,CAAC,MAAM,eAAe,GAAG,kBAAkB,CAAC;AAElD,+EAA+E;AAC/E,MAAM,CAAC,MAAM,SAAS,GAAG,YAAY,CAAC"}
@@ -0,0 +1,5 @@
1
+ /** True when the code runs in a browser page. A write needs the browser session of the visitor, which a server does not have. */
2
+ export declare function isBrowser(): boolean;
3
+ /** Refuses a write on a server: the session lives in the browser only. The live adapter and the mock share this check. */
4
+ export declare function assertBrowserSession(): void;
5
+ //# sourceMappingURL=browser-session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-session.d.ts","sourceRoot":"","sources":["../../src/core/browser-session.ts"],"names":[],"mappings":"AAEA,iIAAiI;AACjI,wBAAgB,SAAS,IAAI,OAAO,CAEnC;AAED,0HAA0H;AAC1H,wBAAgB,oBAAoB,IAAI,IAAI,CAO3C"}
@@ -0,0 +1,12 @@
1
+ import { ParrelError } from "./parrel-error.js";
2
+ /** True when the code runs in a browser page. A write needs the browser session of the visitor, which a server does not have. */
3
+ export function isBrowser() {
4
+ return typeof document !== "undefined";
5
+ }
6
+ /** Refuses a write on a server: the session lives in the browser only. The live adapter and the mock share this check. */
7
+ export function assertBrowserSession() {
8
+ if (!isBrowser()) {
9
+ throw new ParrelError("SD02000008", "Writes need a signed-in session in the browser. Sign in with Sentinel, then call this from client code.");
10
+ }
11
+ }
12
+ //# sourceMappingURL=browser-session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-session.js","sourceRoot":"","sources":["../../src/core/browser-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,iIAAiI;AACjI,MAAM,UAAU,SAAS;IACxB,OAAO,OAAO,QAAQ,KAAK,WAAW,CAAC;AACxC,CAAC;AAED,0HAA0H;AAC1H,MAAM,UAAU,oBAAoB;IACnC,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC;QAClB,MAAM,IAAI,WAAW,CACpB,YAAY,EACZ,yGAAyG,CACzG,CAAC;IACH,CAAC;AACF,CAAC"}
@@ -0,0 +1,80 @@
1
+ import type { ParrelLedgerRuntimeConfig } from "./types.js";
2
+ /** How long, in seconds, a copy is fresh: within this time it is returned without any request (rulebook LIM-13). */
3
+ export declare const DEFAULT_COPY_TTL_SECONDS = 300;
4
+ /** How long, in seconds, a copy is kept at most after it was downloaded, also when its hash did not change. */
5
+ export declare const DEFAULT_COPY_MAX_AGE_SECONDS = 86400;
6
+ /**
7
+ * One copy of a resource or a media URL that the package read, with its three times (rulebook LIM-13).
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const copy = LedgerCache.getCopy<string>("cms-content:my-site:homepage.title");
12
+ * if (copy && Date.now() - copy.checkedAt < 300_000) console.log(copy.value);
13
+ * ```
14
+ */
15
+ export interface LedgerCopy<T = unknown> {
16
+ value: T;
17
+ /** The manifest hash of the resource that the copy was read under, or `undefined` when none was known. */
18
+ hash: string | undefined;
19
+ /** When the copy was downloaded, in milliseconds since the epoch. */
20
+ downloadedAt: number;
21
+ /** When the copy was last downloaded or found unchanged in the manifest, in milliseconds since the epoch. */
22
+ checkedAt: number;
23
+ }
24
+ /**
25
+ * The cache times of a configuration, in seconds, with the defaults of rulebook LIM-13 filled in.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * const { ttlSeconds, manifestTtlSeconds, maxAgeSeconds } = copyTimes(requireParrelLedgerConfig()); // 300, 300, 86400
30
+ * ```
31
+ */
32
+ export interface CopyTimes {
33
+ /** How long a copy is fresh. */
34
+ ttlSeconds: number;
35
+ /** How long one read of the manifest serves every copy that is checked. */
36
+ manifestTtlSeconds: number;
37
+ /** How long a copy is kept at most after it was downloaded. */
38
+ maxAgeSeconds: number;
39
+ }
40
+ /**
41
+ * The cache times of `config`: `cache.ttlSeconds` (default 300), `cache.manifestTtlSeconds` (default 300) and
42
+ * `cache.maxAgeSeconds` (default 86400).
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * copyTimes({ cache: { ttlSeconds: 60 } }); // { ttlSeconds: 60, manifestTtlSeconds: 300, maxAgeSeconds: 86400 }
47
+ * ```
48
+ */
49
+ export declare function copyTimes(config: Pick<ParrelLedgerRuntimeConfig, "cache">): CopyTimes;
50
+ /**
51
+ * The copies of content and media URLs that `getContent` and `getMedia` keep in the memory of the process (rulebook
52
+ * LIM-13). Each copy has its value, the manifest hash it was read under, when it was downloaded and when it was last
53
+ * checked: it is fresh for `cache.ttlSeconds` after that check, then checked against the manifest, and downloaded again
54
+ * at the latest `cache.maxAgeSeconds` after the download. Call `LedgerCache.clear()` to drop everything, for example
55
+ * in tests.
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * LedgerCache.invalidatePrefix("cms-content:my-site:");
60
+ * ```
61
+ */
62
+ export declare class LedgerCache {
63
+ /** The value of `key`, or `null` when there is none or its time is over. */
64
+ static get<T>(key: string): T | null;
65
+ /** Keeps `value` for `ttlSeconds` (default 300), as a copy without a hash that is downloaded now. */
66
+ static set<T>(key: string, value: T, ttlSeconds?: number): void;
67
+ /** The copy of `key` with its hash and times, whatever its age, or `null` when there is none. */
68
+ static getCopy<T>(key: string): LedgerCopy<T> | null;
69
+ /** Stores a copy that was downloaded now under `hash`, kept at most `maxAgeSeconds` (default 86400). */
70
+ static setCopy<T>(key: string, value: T, hash: string | undefined, maxAgeSeconds?: number): void;
71
+ /** Records that the copy of `key` was found unchanged now, so it is fresh again. */
72
+ static markChecked(key: string): void;
73
+ static invalidate(key: string): void;
74
+ static invalidatePrefix(prefix: string): void;
75
+ /** Drops every copy whose key matches `test`. */
76
+ static invalidateWhere(test: (key: string) => boolean): void;
77
+ static clear(): void;
78
+ static size(): number;
79
+ }
80
+ //# sourceMappingURL=cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/core/cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAE5D,oHAAoH;AACpH,eAAO,MAAM,wBAAwB,MAAM,CAAC;AAE5C,+GAA+G;AAC/G,eAAO,MAAM,4BAA4B,QAAS,CAAC;AAEnD;;;;;;;;GAQG;AACH,MAAM,WAAW,UAAU,CAAC,CAAC,GAAG,OAAO;IACtC,KAAK,EAAE,CAAC,CAAC;IACT,0GAA0G;IAC1G,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,qEAAqE;IACrE,YAAY,EAAE,MAAM,CAAC;IACrB,6GAA6G;IAC7G,SAAS,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,SAAS;IACzB,gCAAgC;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,2EAA2E;IAC3E,kBAAkB,EAAE,MAAM,CAAC;IAC3B,+DAA+D;IAC/D,aAAa,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;GAQG;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