@decocms/blocks 8.9.1 → 8.10.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.
Files changed (257) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/protocol/channel.d.ts +98 -0
  6. package/dist/protocol/channel.d.ts.map +1 -0
  7. package/dist/protocol/channel.js +58 -0
  8. package/dist/protocol/channel.js.map +1 -0
  9. package/dist/protocol/client.js +2 -2
  10. package/dist/protocol/client.js.map +1 -1
  11. package/dist/protocol/conformance/blockMetaVectors.json +214 -0
  12. package/dist/protocol/conformance/contentHashFixtures.d.ts +22 -0
  13. package/dist/protocol/conformance/contentHashFixtures.d.ts.map +1 -1
  14. package/dist/protocol/conformance/contentHashFixtures.js +55 -0
  15. package/dist/protocol/conformance/contentHashFixtures.js.map +1 -1
  16. package/dist/protocol/conformance/index.d.ts +2 -1
  17. package/dist/protocol/conformance/index.d.ts.map +1 -1
  18. package/dist/protocol/conformance/index.js +2 -1
  19. package/dist/protocol/conformance/index.js.map +1 -1
  20. package/dist/protocol/conformance/vectors.d.ts +33 -0
  21. package/dist/protocol/conformance/vectors.d.ts.map +1 -0
  22. package/dist/protocol/conformance/vectors.js +3 -0
  23. package/dist/protocol/conformance/vectors.js.map +1 -0
  24. package/dist/protocol/index.d.ts +11 -1
  25. package/dist/protocol/index.d.ts.map +1 -1
  26. package/dist/protocol/index.js +11 -1
  27. package/dist/protocol/index.js.map +1 -1
  28. package/dist/protocol/keys.d.ts +1 -1
  29. package/dist/protocol/keys.js +1 -1
  30. package/dist/v8/background.d.ts +13 -0
  31. package/dist/v8/background.d.ts.map +1 -1
  32. package/dist/v8/background.js +41 -0
  33. package/dist/v8/background.js.map +1 -1
  34. package/dist/v8/blockMeta.d.ts +27 -0
  35. package/dist/v8/blockMeta.d.ts.map +1 -0
  36. package/dist/v8/blockMeta.js +75 -0
  37. package/dist/v8/blockMeta.js.map +1 -0
  38. package/dist/v8/blockStore.d.ts +43 -0
  39. package/dist/v8/blockStore.d.ts.map +1 -0
  40. package/dist/v8/blockStore.js +95 -0
  41. package/dist/v8/blockStore.js.map +1 -0
  42. package/dist/v8/boundedJson.d.ts +5 -0
  43. package/dist/v8/boundedJson.d.ts.map +1 -1
  44. package/dist/v8/boundedJson.js +10 -2
  45. package/dist/v8/boundedJson.js.map +1 -1
  46. package/dist/v8/boundedMap.d.ts +19 -0
  47. package/dist/v8/boundedMap.d.ts.map +1 -0
  48. package/dist/v8/boundedMap.js +52 -0
  49. package/dist/v8/boundedMap.js.map +1 -0
  50. package/dist/v8/builtins/data.d.ts +18 -2
  51. package/dist/v8/builtins/data.d.ts.map +1 -1
  52. package/dist/v8/builtins/data.js +17 -1
  53. package/dist/v8/builtins/data.js.map +1 -1
  54. package/dist/v8/builtins/index.d.ts.map +1 -1
  55. package/dist/v8/builtins/index.js +2 -1
  56. package/dist/v8/builtins/index.js.map +1 -1
  57. package/dist/v8/builtins/legacy.d.ts +6 -3
  58. package/dist/v8/builtins/legacy.d.ts.map +1 -1
  59. package/dist/v8/builtins/legacy.js +6 -3
  60. package/dist/v8/builtins/legacy.js.map +1 -1
  61. package/dist/v8/canonical.d.ts +8 -0
  62. package/dist/v8/canonical.d.ts.map +1 -1
  63. package/dist/v8/canonical.js +15 -0
  64. package/dist/v8/canonical.js.map +1 -1
  65. package/dist/v8/cli/builtins.d.ts.map +1 -1
  66. package/dist/v8/cli/builtins.js +1 -0
  67. package/dist/v8/cli/builtins.js.map +1 -1
  68. package/dist/v8/cli/check/index.d.ts +10 -0
  69. package/dist/v8/cli/check/index.d.ts.map +1 -1
  70. package/dist/v8/cli/check/index.js +91 -7
  71. package/dist/v8/cli/check/index.js.map +1 -1
  72. package/dist/v8/cli/content.d.ts +12 -25
  73. package/dist/v8/cli/content.d.ts.map +1 -1
  74. package/dist/v8/cli/content.js +46 -75
  75. package/dist/v8/cli/content.js.map +1 -1
  76. package/dist/v8/cli/index.d.ts +1 -2
  77. package/dist/v8/cli/index.d.ts.map +1 -1
  78. package/dist/v8/cli/index.js +1 -2
  79. package/dist/v8/cli/index.js.map +1 -1
  80. package/dist/v8/cli/remote/commands.d.ts +71 -0
  81. package/dist/v8/cli/remote/commands.d.ts.map +1 -0
  82. package/dist/v8/cli/remote/commands.js +644 -0
  83. package/dist/v8/cli/remote/commands.js.map +1 -0
  84. package/dist/v8/cli/remote/diff.d.ts +15 -0
  85. package/dist/v8/cli/remote/diff.d.ts.map +1 -0
  86. package/dist/v8/cli/remote/diff.js +102 -0
  87. package/dist/v8/cli/remote/diff.js.map +1 -0
  88. package/dist/v8/cli/remote/env.d.ts +35 -0
  89. package/dist/v8/cli/remote/env.d.ts.map +1 -0
  90. package/dist/v8/cli/remote/env.js +84 -0
  91. package/dist/v8/cli/remote/env.js.map +1 -0
  92. package/dist/v8/cli/remote/http.d.ts +149 -0
  93. package/dist/v8/cli/remote/http.d.ts.map +1 -0
  94. package/dist/v8/cli/remote/http.js +381 -0
  95. package/dist/v8/cli/remote/http.js.map +1 -0
  96. package/dist/v8/cli/remote/local.d.ts +90 -0
  97. package/dist/v8/cli/remote/local.d.ts.map +1 -0
  98. package/dist/v8/cli/remote/local.js +309 -0
  99. package/dist/v8/cli/remote/local.js.map +1 -0
  100. package/dist/v8/cli/root.d.ts +29 -0
  101. package/dist/v8/cli/root.d.ts.map +1 -1
  102. package/dist/v8/cli/root.js +28 -0
  103. package/dist/v8/cli/root.js.map +1 -1
  104. package/dist/v8/cli/run.d.ts +11 -1
  105. package/dist/v8/cli/run.d.ts.map +1 -1
  106. package/dist/v8/cli/run.js +281 -124
  107. package/dist/v8/cli/run.js.map +1 -1
  108. package/dist/v8/cli/schema/builtinSchemas.d.ts.map +1 -1
  109. package/dist/v8/cli/schema/builtinSchemas.js +28 -10
  110. package/dist/v8/cli/schema/builtinSchemas.js.map +1 -1
  111. package/dist/v8/cli/schema/generate.js +1 -1
  112. package/dist/v8/cli/schema/generate.js.map +1 -1
  113. package/dist/v8/client.d.ts +9 -9
  114. package/dist/v8/client.d.ts.map +1 -1
  115. package/dist/v8/client.js +138 -50
  116. package/dist/v8/client.js.map +1 -1
  117. package/dist/v8/cms.d.ts +2 -1
  118. package/dist/v8/cms.d.ts.map +1 -1
  119. package/dist/v8/cms.js +55 -46
  120. package/dist/v8/cms.js.map +1 -1
  121. package/dist/v8/content.d.ts +39 -78
  122. package/dist/v8/content.d.ts.map +1 -1
  123. package/dist/v8/content.js +155 -195
  124. package/dist/v8/content.js.map +1 -1
  125. package/dist/v8/contentIndex.d.ts +71 -0
  126. package/dist/v8/contentIndex.d.ts.map +1 -0
  127. package/dist/v8/contentIndex.js +137 -0
  128. package/dist/v8/contentIndex.js.map +1 -0
  129. package/dist/v8/draft.d.ts +7 -7
  130. package/dist/v8/draft.d.ts.map +1 -1
  131. package/dist/v8/draft.js +10 -9
  132. package/dist/v8/draft.js.map +1 -1
  133. package/dist/v8/draftChanges.d.ts +59 -32
  134. package/dist/v8/draftChanges.d.ts.map +1 -1
  135. package/dist/v8/draftChanges.js +139 -75
  136. package/dist/v8/draftChanges.js.map +1 -1
  137. package/dist/v8/errors.d.ts +21 -0
  138. package/dist/v8/errors.d.ts.map +1 -1
  139. package/dist/v8/errors.js +22 -0
  140. package/dist/v8/errors.js.map +1 -1
  141. package/dist/v8/hostedSource.d.ts +57 -0
  142. package/dist/v8/hostedSource.d.ts.map +1 -0
  143. package/dist/v8/hostedSource.js +18 -0
  144. package/dist/v8/hostedSource.js.map +1 -0
  145. package/dist/v8/identity.d.ts +1 -1
  146. package/dist/v8/identity.js +1 -1
  147. package/dist/v8/index.d.ts +1 -0
  148. package/dist/v8/index.d.ts.map +1 -1
  149. package/dist/v8/index.js +1 -0
  150. package/dist/v8/index.js.map +1 -1
  151. package/dist/v8/matchRoute.js +7 -4
  152. package/dist/v8/matchRoute.js.map +1 -1
  153. package/dist/v8/pin.d.ts +34 -0
  154. package/dist/v8/pin.d.ts.map +1 -0
  155. package/dist/v8/pin.js +156 -0
  156. package/dist/v8/pin.js.map +1 -0
  157. package/dist/v8/preview/StudioBridge.d.ts +8 -8
  158. package/dist/v8/preview/StudioBridge.d.ts.map +1 -1
  159. package/dist/v8/preview/StudioBridge.js +8 -10
  160. package/dist/v8/preview/StudioBridge.js.map +1 -1
  161. package/dist/v8/preview/StudioChannel.d.ts +51 -0
  162. package/dist/v8/preview/StudioChannel.d.ts.map +1 -0
  163. package/dist/v8/preview/StudioChannel.js +104 -0
  164. package/dist/v8/preview/StudioChannel.js.map +1 -0
  165. package/dist/v8/preview/index.d.ts +3 -0
  166. package/dist/v8/preview/index.d.ts.map +1 -1
  167. package/dist/v8/preview/index.js +3 -0
  168. package/dist/v8/preview/index.js.map +1 -1
  169. package/dist/v8/remoteLoader.d.ts +42 -5
  170. package/dist/v8/remoteLoader.d.ts.map +1 -1
  171. package/dist/v8/remoteLoader.js +317 -259
  172. package/dist/v8/remoteLoader.js.map +1 -1
  173. package/dist/v8/resolver.d.ts +22 -8
  174. package/dist/v8/resolver.d.ts.map +1 -1
  175. package/dist/v8/resolver.js +37 -32
  176. package/dist/v8/resolver.js.map +1 -1
  177. package/dist/v8/revisionId.d.ts +11 -0
  178. package/dist/v8/revisionId.d.ts.map +1 -0
  179. package/dist/v8/revisionId.js +13 -0
  180. package/dist/v8/revisionId.js.map +1 -0
  181. package/dist/v8/settings.d.ts +6 -6
  182. package/dist/v8/settings.d.ts.map +1 -1
  183. package/dist/v8/settings.js +8 -7
  184. package/dist/v8/settings.js.map +1 -1
  185. package/dist/v8/telemetry.d.ts +4 -2
  186. package/dist/v8/telemetry.d.ts.map +1 -1
  187. package/dist/v8/telemetry.js +2 -2
  188. package/dist/v8/telemetry.js.map +1 -1
  189. package/dist/v8/types.d.ts +52 -40
  190. package/dist/v8/types.d.ts.map +1 -1
  191. package/dist/v8/variants.d.ts +7 -2
  192. package/dist/v8/variants.d.ts.map +1 -1
  193. package/dist/v8/variants.js +21 -24
  194. package/dist/v8/variants.js.map +1 -1
  195. package/dist/v8/vite/index.d.ts +2 -2
  196. package/dist/v8/vite/index.js +1 -1
  197. package/dist/v8/vite/index.js.map +1 -1
  198. package/package.json +1 -1
  199. package/src/index.ts +2 -0
  200. package/src/protocol/channel.ts +127 -0
  201. package/src/protocol/client.ts +2 -2
  202. package/src/protocol/conformance/blockMetaVectors.json +214 -0
  203. package/src/protocol/conformance/contentHashFixtures.ts +74 -0
  204. package/src/protocol/conformance/index.ts +9 -1
  205. package/src/protocol/conformance/vectors.ts +36 -0
  206. package/src/protocol/index.ts +32 -0
  207. package/src/protocol/keys.ts +1 -1
  208. package/src/v8/background.ts +42 -0
  209. package/src/v8/blockMeta.ts +100 -0
  210. package/src/v8/blockStore.ts +124 -0
  211. package/src/v8/boundedJson.ts +20 -2
  212. package/src/v8/boundedMap.ts +53 -0
  213. package/src/v8/builtins/data.ts +26 -2
  214. package/src/v8/builtins/index.ts +2 -1
  215. package/src/v8/builtins/legacy.ts +6 -3
  216. package/src/v8/canonical.ts +15 -0
  217. package/src/v8/cli/builtins.ts +1 -0
  218. package/src/v8/cli/check/index.ts +97 -7
  219. package/src/v8/cli/content.ts +49 -91
  220. package/src/v8/cli/index.ts +1 -2
  221. package/src/v8/cli/remote/commands.ts +834 -0
  222. package/src/v8/cli/remote/diff.ts +100 -0
  223. package/src/v8/cli/remote/env.ts +107 -0
  224. package/src/v8/cli/remote/http.ts +484 -0
  225. package/src/v8/cli/remote/local.ts +343 -0
  226. package/src/v8/cli/root.ts +40 -0
  227. package/src/v8/cli/run.ts +333 -136
  228. package/src/v8/cli/schema/builtinSchemas.ts +29 -10
  229. package/src/v8/cli/schema/generate.ts +1 -1
  230. package/src/v8/client.ts +162 -60
  231. package/src/v8/cms.ts +62 -53
  232. package/src/v8/content.ts +179 -229
  233. package/src/v8/contentIndex.ts +183 -0
  234. package/src/v8/draft.ts +15 -14
  235. package/src/v8/draftChanges.ts +151 -85
  236. package/src/v8/errors.ts +37 -0
  237. package/src/v8/hostedSource.ts +67 -0
  238. package/src/v8/identity.ts +1 -1
  239. package/src/v8/index.ts +1 -0
  240. package/src/v8/matchRoute.ts +7 -4
  241. package/src/v8/pin.ts +176 -0
  242. package/src/v8/preview/StudioBridge.ts +8 -10
  243. package/src/v8/preview/StudioChannel.ts +116 -0
  244. package/src/v8/preview/index.ts +3 -0
  245. package/src/v8/remoteLoader.ts +350 -286
  246. package/src/v8/resolver.ts +56 -33
  247. package/src/v8/revisionId.ts +14 -0
  248. package/src/v8/settings.ts +10 -9
  249. package/src/v8/telemetry.ts +3 -3
  250. package/src/v8/types.ts +52 -40
  251. package/src/v8/variants.ts +30 -26
  252. package/src/v8/vite/index.ts +3 -3
  253. package/dist/v8/cli/serve/server.d.ts +0 -29
  254. package/dist/v8/cli/serve/server.d.ts.map +0 -1
  255. package/dist/v8/cli/serve/server.js +0 -296
  256. package/dist/v8/cli/serve/server.js.map +0 -1
  257. package/src/v8/cli/serve/server.ts +0 -348
@@ -26,12 +26,24 @@ import { isMultivariateBuiltin } from "./builtins/multivariate.ts";
26
26
  import { runWithClient } from "./current.ts";
27
27
  import { errors, isResolutionError } from "./errors.ts";
28
28
  import { canonicalKey, isPlainObject, type JsonObject, own } from "./json.ts";
29
- import type { BlockFunction, Blocks, Client, Lazy, Snapshot } from "./types.ts";
29
+ import type { BlockFunction, Blocks, Client, Lazy } from "./types.ts";
30
30
 
31
31
  type Path = (string | number)[];
32
32
 
33
+ /**
34
+ * The content a resolver reads (a request's pin, see ./pin.ts): whether a
35
+ * saved block exists comes from the index, synchronously; its body may take a
36
+ * fetch.
37
+ */
38
+ export interface ContentView {
39
+ has(name: string): boolean;
40
+ /** The body of a name `has` knows; rejects with `LOADER_FAILED` when it can't be fetched. */
41
+ body(name: string, path?: Path): Promise<unknown>;
42
+ readonly aliases?: Readonly<Record<string, string>>;
43
+ }
44
+
33
45
  interface ResolverOptions {
34
- snapshot: Snapshot;
46
+ content: ContentView;
35
47
  blocks: Blocks;
36
48
  /** The built-in blocks. */
37
49
  builtIns: Readonly<Blocks>;
@@ -44,7 +56,7 @@ interface ResolverOptions {
44
56
  }
45
57
 
46
58
  export class Resolver {
47
- readonly #snapshot: Snapshot;
59
+ readonly #content: ContentView;
48
60
  readonly #blocks: Blocks;
49
61
  readonly #builtIns: Readonly<Blocks>;
50
62
  readonly #client: Client | undefined;
@@ -53,8 +65,8 @@ export class Resolver {
53
65
  readonly #memo = new WeakMap<BlockFunction, Map<string, Promise<unknown>>>();
54
66
  readonly #keys = new WeakMap<object, string | null>();
55
67
 
56
- constructor({ snapshot, blocks, builtIns, client, onCollision, onBlock }: ResolverOptions) {
57
- this.#snapshot = snapshot;
68
+ constructor({ content, blocks, builtIns, client, onCollision, onBlock }: ResolverOptions) {
69
+ this.#content = content;
58
70
  this.#blocks = blocks;
59
71
  this.#builtIns = builtIns;
60
72
  this.#client = client;
@@ -62,9 +74,9 @@ export class Resolver {
62
74
  this.#onBlock = onBlock;
63
75
  }
64
76
 
65
- /** The saved entry with this name, or `undefined`. */
66
- entry(name: string): unknown {
67
- return own(this.#snapshot.blocks, name);
77
+ /** Whether the content has a saved block with this name. */
78
+ has(name: string): boolean {
79
+ return this.#content.has(name);
68
80
  }
69
81
 
70
82
  /** The type an alias points at, or the type itself. */
@@ -74,17 +86,20 @@ export class Resolver {
74
86
 
75
87
  /** The snapshot's alias table first, then the built-in legacy one. */
76
88
  #alias(type: string): string | undefined {
77
- return own(this.#snapshot.aliases, type) ?? own(LEGACY_ALIASES, type);
89
+ return (
90
+ own(this.#content.aliases as Record<string, string> | undefined, type) ??
91
+ own(LEGACY_ALIASES, type)
92
+ );
78
93
  }
79
94
 
80
95
  /** Resolves a saved entry by name (the target is known to exist). */
81
- resolveEntry(name: string): Promise<unknown> {
82
- return this.resolve(this.entry(name), [], [name], true);
96
+ async resolveEntry(name: string): Promise<unknown> {
97
+ return this.resolve(await this.#content.body(name), [], [name], true);
83
98
  }
84
99
 
85
100
  /** Expands a saved entry by name without running anything. */
86
- expandEntry(name: string): unknown {
87
- return this.expand(this.entry(name), [], [name], true);
101
+ async expandEntry(name: string): Promise<unknown> {
102
+ return this.expand(await this.#content.body(name), [], [name], true);
88
103
  }
89
104
 
90
105
  /**
@@ -112,10 +127,15 @@ export class Resolver {
112
127
  return this.#resolveFields(node, path, chain, fromContent);
113
128
  }
114
129
 
115
- /** Expands saved blocks in place without running any function (`{ run: false }`). */
116
- expand(node: unknown, path: Path, chain: string[], fromContent: boolean): unknown {
130
+ /**
131
+ * Expands saved blocks in place without running any function (`{ run: false }`).
132
+ * Async only because a saved block's body may take a fetch.
133
+ */
134
+ async expand(node: unknown, path: Path, chain: string[], fromContent: boolean): Promise<unknown> {
117
135
  if (Array.isArray(node)) {
118
- const items = node.map((item, i) => this.expand(item, [...path, i], chain, fromContent));
136
+ const items = await Promise.all(
137
+ node.map((item, i) => this.expand(item, [...path, i], chain, fromContent)),
138
+ );
119
139
  return !fromContent && sameItems(node, items) ? node : items;
120
140
  }
121
141
  if (!isPlainObject(node)) return node;
@@ -123,22 +143,24 @@ export class Resolver {
123
143
  if (
124
144
  typeof type === "string" &&
125
145
  this.#functionFor(type) === undefined &&
126
- this.#aliasFor(type) === undefined
146
+ this.#aliasFor(type) === undefined &&
147
+ this.#content.has(type)
127
148
  ) {
128
- const saved = this.entry(type);
129
- if (saved !== undefined) {
130
- const next = [...chain, type];
131
- if (chain.includes(type)) throw errors.cycle(next);
132
- return this.expand(mergeReference(saved, node), path, next, true);
133
- }
149
+ const next = [...chain, type];
150
+ if (chain.includes(type)) throw errors.cycle(next);
151
+ const saved = await this.#content.body(type, path);
152
+ return this.expand(mergeReference(saved, node), path, next, true);
134
153
  }
135
154
  let changed = fromContent;
136
155
  const out: JsonObject = {};
137
- for (const [key, value] of Object.entries(node)) {
138
- const expanded = this.expand(value, [...path, key], chain, fromContent);
139
- if (expanded !== value) changed = true;
140
- out[key] = expanded;
141
- }
156
+ const keys = Object.keys(node);
157
+ const values = await Promise.all(
158
+ keys.map((key) => this.expand(node[key], [...path, key], chain, fromContent)),
159
+ );
160
+ keys.forEach((key, i) => {
161
+ if (values[i] !== node[key]) changed = true;
162
+ out[key] = values[i];
163
+ });
142
164
  return changed ? out : node;
143
165
  }
144
166
 
@@ -180,12 +202,13 @@ export class Resolver {
180
202
  // An alias is a second key for a type, so like a function it wins over a
181
203
  // saved block of the same name (with a warning; deco check rejects it).
182
204
  const alias = viaAlias ? undefined : this.#aliasFor(type);
183
- const saved = alias === undefined ? this.entry(type) : undefined;
184
- if (saved !== undefined) {
205
+ if (alias === undefined && this.#content.has(type)) {
185
206
  const next = [...chain, type];
186
207
  if (chain.includes(type)) return Promise.reject(errors.cycle(next));
187
208
  if (RESERVED_NAMES.has(type)) this.#onCollision?.(type);
188
- return this.resolve(mergeReference(saved, node), path, next, true);
209
+ return this.#content
210
+ .body(type, path)
211
+ .then((saved) => this.resolve(mergeReference(saved, node), path, next, true));
189
212
  }
190
213
 
191
214
  if (alias !== undefined) {
@@ -205,7 +228,7 @@ export class Resolver {
205
228
  #aliasFor(type: string): string | undefined {
206
229
  const alias = this.#alias(type);
207
230
  if (alias === undefined || alias === type) return undefined;
208
- if (this.entry(type) !== undefined) this.#onCollision?.(type);
231
+ if (this.#content.has(type)) this.#onCollision?.(type);
209
232
  return alias;
210
233
  }
211
234
 
@@ -213,7 +236,7 @@ export class Resolver {
213
236
  #functionFor(type: string): BlockFunction | undefined {
214
237
  const fn = own(this.#blocks, type) ?? own(this.#builtIns, type);
215
238
  if (typeof fn !== "function") return undefined;
216
- if (this.entry(type) !== undefined) this.#onCollision?.(type);
239
+ if (this.#content.has(type)) this.#onCollision?.(type);
217
240
  return fn;
218
241
  }
219
242
 
@@ -0,0 +1,14 @@
1
+ /**
2
+ * A published revision's id: `<inv>-<uuidv7>`, a UUIDv7 (RFC 9562, lowercase)
3
+ * after 12 hex digits of `2^48 - 1 -` its millisecond timestamp, so ids sort
4
+ * newest first. Only Studio mints them; the SDK and the CLI only check the
5
+ * shape (the prefix isn't recomputed). `latest.json` names one, and it is
6
+ * the folder of `sites/<site>/revisions/<id>/index.json`.
7
+ */
8
+ export const REVISION_ID_RE =
9
+ /^[0-9a-f]{12}-[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
10
+
11
+ /** Whether `value` has the shape of a revision id. */
12
+ export function isRevisionId(value: unknown): value is string {
13
+ return typeof value === "string" && REVISION_ID_RE.test(value);
14
+ }
@@ -4,8 +4,10 @@
4
4
  * type `cms-settings`, read from the release, with the defaults filled in and
5
5
  * code's caps applied.
6
6
  *
7
- * - The caller hands in the release snapshot already in memory; nothing here
8
- * loads content, so reading settings never fetches.
7
+ * - The caller hands in the `CMS` body already in memory (local content
8
+ * holds it; a hosted index carries it inline); nothing here loads content,
9
+ * so reading settings never fetches (a section referencing another saved
10
+ * block resolves it as any read would).
9
11
  * - A missing block, a block of another type, or a section that fails to
10
12
  * resolve gives that section's defaults, still capped. Nothing rejects.
11
13
  * - Telemetry rates are the lower of content's and `telemetry.limits`.
@@ -22,10 +24,10 @@ import {
22
24
  SETTINGS_TYPE,
23
25
  telemetrySection,
24
26
  } from "./builtins/data.ts";
25
- import type { ReleasePreviewHosts } from "./content.ts";
27
+ import type { ReleasePreviewHosts } from "./hostedSource.ts";
26
28
  import { EVERY_HOST, formatHostPattern, type HostPattern, parseHostPattern } from "./hosts.ts";
27
29
  import { isPlainObject } from "./json.ts";
28
- import type { Client, CMSConfig, EffectiveSettings, Snapshot } from "./types.ts";
30
+ import type { Client, CMSConfig, EffectiveSettings } from "./types.ts";
29
31
 
30
32
  /** What code allows: the caps every section's content is held to. */
31
33
  export interface SettingsCaps {
@@ -76,17 +78,16 @@ export function defaultSettings(caps: SettingsCaps): SavedSettings {
76
78
  }
77
79
 
78
80
  /**
79
- * The settings a release holds. `client` reads that same release; it resolves
80
- * the `CMS` block whole and, if that fails, each section on its own, so one
81
- * failing section falls back to its defaults alone.
81
+ * The settings a release holds, from its `CMS` body. `client` reads that same
82
+ * release; it resolves the `CMS` block whole and, if that fails, each section
83
+ * on its own, so one failing section falls back to its defaults alone.
82
84
  */
83
85
  export async function readSettings(
84
- snapshot: Snapshot | undefined,
86
+ entry: unknown,
85
87
  client: () => Client,
86
88
  caps: SettingsCaps,
87
89
  ): Promise<SavedSettings> {
88
90
  try {
89
- const entry = snapshot?.blocks[SETTINGS_BLOCK];
90
91
  if (!isPlainObject(entry) || entry.__resolveType !== SETTINGS_TYPE) {
91
92
  return defaultSettings(caps);
92
93
  }
@@ -20,7 +20,7 @@
20
20
  import { hasBackgroundHook, later, runInBackground } from "./background.ts";
21
21
  import { rate, TELEMETRY_DEFAULTS } from "./builtins/data.ts";
22
22
  import { isResolutionError } from "./errors.ts";
23
- import type { CMSError, Snapshot, Telemetry, TelemetryConfig } from "./types.ts";
23
+ import type { CMSError, Telemetry, TelemetryConfig } from "./types.ts";
24
24
 
25
25
  /** The hosted Deco CMS collector, for `createCMS({ token })`. */
26
26
  const HOSTED_TELEMETRY_ENDPOINT = "https://otel.decocms.com";
@@ -137,8 +137,8 @@ export class TelemetryPipeline {
137
137
  }
138
138
 
139
139
  /** The release being served: its revision labels batches. */
140
- useRelease(snapshot: Snapshot): void {
141
- this.#release = snapshot.revision;
140
+ useRelease(release: { revision: string }): void {
141
+ this.#release = release.revision;
142
142
  }
143
143
 
144
144
  /**
package/src/v8/types.ts CHANGED
@@ -22,37 +22,23 @@ export type BlockFunction = (inputs: any) => unknown | Promise<unknown>;
22
22
  /** A block map: what `.deco/index.ts` exports and the CLI reads. */
23
23
  export type Blocks = Record<string, BlockFunction>;
24
24
 
25
- /** One fixed copy of the content: what the content module exports and `load()` returns. */
25
+ /** One fixed copy of the content: what a content module exports and `load()` returns. */
26
26
  export type Snapshot = {
27
27
  revision: string;
28
28
  /** The content map: entry name → saved JSON. */
29
29
  blocks: Record<string, unknown>;
30
- /** The alias table `deco content` writes: old type name → your type. */
30
+ /** An alias table: old type name → your type. */
31
31
  aliases?: Record<string, string>;
32
32
  /**
33
- * The hash of the `.deco/schema.gen.json` this content was built with, which
34
- * `deco content` writes. A hosted release is swapped in only when its
35
- * `schemaHash` equals the bundled content's; without one, never.
36
- */
37
- schemaHash?: string;
38
- /**
39
- * The commit time of the git HEAD `deco content` built this content from
40
- * (committer date, ISO 8601). A hosted release is swapped in only when its
41
- * `publishedAt` is later; without one (a custom loader, an older content
42
- * module, a build outside git), the bundled content counts as the oldest.
43
- */
44
- committedAt?: string;
45
- /**
46
- * The hosts this release may be previewed on (host patterns), as Studio
47
- * wrote them into the release metadata on delivery.decocms.com
48
- * (`latest.json` and `revisions/<sha>.json`). Previews are checked against
49
- * the current release's list; the bundled content has none.
33
+ * The hosts this content may be previewed on (host patterns), for content
34
+ * with no remote site. A hosted release's list is Studio's, in
35
+ * `latest.json` on delivery.decocms.com, and the CMS reads it from there.
50
36
  */
51
37
  previewHosts?: string[];
52
38
  };
53
39
 
54
40
  /**
55
- * The content module `deco content` writes: a snapshot plus `root`, the
41
+ * The content module the CLI's `content()` writes: a snapshot plus `root`, the
56
42
  * `.deco` folder it was generated from, which `createCMS` keys its instance
57
43
  * on (see /next/api-reference#one-instance-per-process). Not exported.
58
44
  */
@@ -73,7 +59,7 @@ export interface DraftPointer {
73
59
  host: string;
74
60
  /** Starts with `/`; opaque to the app. Never carries the `__variant` parameters. */
75
61
  path: string;
76
- /** Opaque: identifies the editor's last save. `"local"` names no draft (`deco serve`). */
62
+ /** Opaque: identifies the editor's last save. `"local"` names no draft (the release itself). */
77
63
  version: string;
78
64
  /** The variants this preview forces (the query's `__variant` parameters); absent when none. */
79
65
  variants?: ForcedVariant[];
@@ -127,7 +113,7 @@ export interface Redirect {
127
113
  */
128
114
  from: string;
129
115
  to: string;
130
- /** `true` for a 301, `false` for a 302. */
116
+ /** `true` for a 301, `false` (a temporary redirect) for a 307. */
131
117
  permanent: boolean;
132
118
  /** Wins over `permanent`. */
133
119
  status?: RedirectStatus;
@@ -269,17 +255,14 @@ export interface TelemetryConfig {
269
255
  export interface CMSConfig {
270
256
  /** Your block functions; the CMS uses `{ ...builtIns, ...blocks }`. */
271
257
  blocks: Blocks;
272
- /** The content module (`.deco/blocks.gen.ts`), or any {@link Loader}. */
273
- content: ContentModule | Loader;
274
- /** ms between `update()` checks of a content source that has one; minimum 60 000. */
275
- interval?: number;
276
258
  /**
277
- * Local development: hosted releases are never swapped in, so local files win.
278
- * Drafts still load. Default: `process.env.NODE_ENV === "development"` (read
279
- * guarded, so `false` where there is no `process`: Workers, browsers). Pass it
280
- * to override that, e.g. `dev: import.meta.env.DEV` or `dev: false`.
259
+ * The content without `site`: a snapshot, or any {@link Loader}. With
260
+ * `site`, leave it out: content comes from the delivery CDN at runtime,
261
+ * never from the bundle (passing both is an error).
281
262
  */
282
- dev?: boolean;
263
+ content?: ContentModule | Loader;
264
+ /** ms between `update()` checks of a content source that has one; minimum 60 000. */
265
+ interval?: number;
283
266
  /** Where telemetry goes; see /next/telemetry. */
284
267
  telemetry?: false | TelemetryConfig;
285
268
  preview?: {
@@ -300,8 +283,11 @@ export interface CMSConfig {
300
283
  draftHosts?: string[];
301
284
  };
302
285
  /**
303
- * Your site ID (Studio's site slug): turns on hosted releases from
304
- * `delivery.decocms.com`. Drafts don't need it.
286
+ * Your site ID (Studio's site slug): the content is the site's latest
287
+ * release on `delivery.decocms.com`, fetched at runtime (the first client
288
+ * loads it, with 10 s per fetch; until a load succeeds, clients answer
289
+ * `LOADER_FAILED` with a `ContentUnavailableError` cause) and followed
290
+ * every `interval`. Drafts don't need it.
305
291
  */
306
292
  site?: string;
307
293
  /**
@@ -335,7 +321,33 @@ export interface ListOptions<T> {
335
321
  */
336
322
  export interface Client {
337
323
  resolve<T = unknown>(target: unknown, options?: ResolveOptions): Promise<Result<T>>;
324
+ /**
325
+ * Every saved block of a type, read whole. For tools and type lists; routing
326
+ * reads `routes()` and `redirects()`, which need no body (a `page` or
327
+ * `redirect` list warns outside production).
328
+ */
338
329
  list<T = Block>(type: string, options?: ListOptions<T>): Promise<Result<T[]>>;
330
+ /**
331
+ * `{ name, path }` of every page (a saved block whose type is `page`, or an
332
+ * alias of it, with a `path`), from the index alone, in code-unit order of
333
+ * name so the same page wins a path conflict everywhere. The same array for
334
+ * the same revision, so `matchRoute` builds its trie once per revision.
335
+ * `name` is the saved block's name: `resolve(name)` reads the page.
336
+ */
337
+ routes(): Promise<Result<Route[]>>;
338
+ /**
339
+ * The rules of the site's redirects block (the saved block of type
340
+ * `redirects`; the first in code-unit order of name when there are
341
+ * several), `[]` when there is none.
342
+ */
343
+ redirects(): Promise<Result<Redirect[]>>;
344
+ /**
345
+ * Starts fetching the saved block `name` and everything it references,
346
+ * with the redirects block, in one parallel wave, so `redirects()` and
347
+ * `resolve(name)` find them in memory. Never throws; a block that can't be
348
+ * fetched fails where it is read.
349
+ */
350
+ prefetch(name: string): void;
339
351
  /**
340
352
  * The revision this client reads (loads it on first use). Unlike `resolve`
341
353
  * and `list`, it rejects with the `LOADER_FAILED` error when the content
@@ -345,8 +357,8 @@ export interface Client {
345
357
  /** Who is visiting, as passed to `cms.client()` (a frozen copy); `null` for none. */
346
358
  readonly visitor: Visitor | null;
347
359
  /**
348
- * The version it reads: the release's commit SHA, or the draft pointer, as
349
- * passed to `cms.client()`. For the current release, the SHA of the release
360
+ * The version it reads: the release's revision id, or the draft pointer, as
361
+ * passed to `cms.client()`. For the current release, the id of the release
350
362
  * it loaded (`undefined` until its first `resolve`, `list` or `revision()`).
351
363
  */
352
364
  readonly version: string | undefined;
@@ -364,7 +376,7 @@ export interface Client {
364
376
  export interface ClientOptions {
365
377
  /**
366
378
  * What to read: `undefined` (or `null`) for the current release; a
367
- * published release's commit SHA (40 hex characters), read from hosted
379
+ * published release's revision id (`<inv>-<uuidv7>`), read from hosted
368
380
  * releases; or a draft pointer, the draft's changes over the current
369
381
  * release. Only a version: a Studio link's moment and switched tests are
370
382
  * the options below (`cms.readVersion(request)` reads all of them).
@@ -375,7 +387,7 @@ export interface ClientOptions {
375
387
  * (`cms.checkRelease()`), so the draft waits for it instead of making a
376
388
  * check of its own; one request, one read of the release metadata. An id
377
389
  * this CMS didn't make (another process's) is a check of its own. Ignored
378
- * for the release and a release's SHA.
390
+ * for the release and a release's revision id.
379
391
  */
380
392
  releaseCheck?: string | null;
381
393
  /**
@@ -409,7 +421,7 @@ export interface ClientOptions {
409
421
  * in the shape of `ClientOptions`, so it spreads into `cms.client()`.
410
422
  */
411
423
  export interface RequestVersion {
412
- /** A draft pointer, or a published release's commit SHA. */
424
+ /** A draft pointer, or a published release's revision id. */
413
425
  version: string;
414
426
  /** The moment the preview shows (`__at`). */
415
427
  date?: Date;
@@ -466,7 +478,7 @@ export interface CMS {
466
478
  settings(): Promise<EffectiveSettings>;
467
479
  /**
468
480
  * What a Studio link asks for: `?__draft=` first, then the `__deco_draft`
469
- * cookie, holding a draft pointer or a published release's commit SHA,
481
+ * cookie, holding a draft pointer or a published release's revision id,
470
482
  * with the preview's moment (`__at`) and switched tests (`__test`) and
471
483
  * campaigns (`__campaign`) as `date`, `experiments` and `campaigns`.
472
484
  * `null` when neither is present, for `?__draft=off`, on a host outside
@@ -476,7 +488,7 @@ export interface CMS {
476
488
  * `preview.hosts`; no host while the metadata can't be read, besides
477
489
  * `preview.hosts`), and for a value that doesn't parse (ignored,
478
490
  * as if absent): in each case the request gets the current release. A
479
- * draft and an older release's SHA are both checked against the current
491
+ * draft and an older release's id are both checked against the current
480
492
  * release's list.
481
493
  *
482
494
  * ```ts
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * Forced variants (see /next/releases-and-drafts#preview-a-variant): the
3
- * variants a draft pointer's `__variant` parameters name, applied to a
4
- * snapshot for one preview. Each addressed multivariate keeps only the forced
5
- * variant, with the rule `true`, so it shows that variant's value and no other
6
- * rule runs. The snapshot is copied along the addressed paths only; the shared
7
- * one is never touched.
3
+ * variants a draft pointer's `__variant` parameters name, applied to each body
4
+ * a preview request reads (see ./pin.ts). Each addressed multivariate keeps
5
+ * only the forced variant, with the rule `true`, so it shows that variant's
6
+ * value and no other rule runs. A body is copied along the addressed paths
7
+ * only; the shared one is never touched.
8
8
  *
9
9
  * An address that doesn't reach a multivariate block with that variant (a
10
10
  * renamed block, a moved section, an index past the end) is ignored, so a
@@ -12,48 +12,52 @@
12
12
  */
13
13
  import { LEGACY_ALIASES } from "./builtins/legacy.ts";
14
14
  import { isPlainObject, own } from "./json.ts";
15
- import type { ForcedVariant, Snapshot } from "./types.ts";
15
+ import type { ForcedVariant } from "./types.ts";
16
16
 
17
- export function forceVariants(
18
- snapshot: Snapshot,
19
- variants: readonly ForcedVariant[] | undefined,
20
- ): Snapshot {
21
- if (variants === undefined || variants.length === 0) return snapshot;
22
- let blocks: Record<string, unknown> | undefined;
17
+ /**
18
+ * One saved block's body with the variants forced on it (those whose `block`
19
+ * is `name`), copied along the addressed paths only; the body itself when none
20
+ * applies. How a request applies forced variants to bodies it reads lazily.
21
+ */
22
+ export function forceBody(
23
+ name: string,
24
+ body: unknown,
25
+ variants: readonly ForcedVariant[],
26
+ aliases: Readonly<Record<string, string>> | undefined,
27
+ ): unknown {
28
+ let out = body;
23
29
  for (const { block, path, index } of variants) {
24
- const entry = own(blocks ?? snapshot.blocks, block);
25
- if (entry === undefined) continue;
26
- const keys = path === "" ? [] : path.split(".");
27
- const next = forceAt(entry, keys, index, snapshot);
28
- if (next === entry) continue;
29
- blocks ??= { ...snapshot.blocks };
30
- blocks[block] = next;
30
+ if (block !== name) continue;
31
+ out = forceAt(out, path === "" ? [] : path.split("."), index, aliases);
31
32
  }
32
- return blocks === undefined ? snapshot : { ...snapshot, blocks };
33
+ return out;
33
34
  }
34
35
 
35
- function forceAt(node: unknown, keys: string[], index: number, snapshot: Snapshot): unknown {
36
- if (keys.length === 0) return forceNode(node, index, snapshot);
36
+ type Aliases = Readonly<Record<string, string>> | undefined;
37
+
38
+ function forceAt(node: unknown, keys: string[], index: number, aliases: Aliases): unknown {
39
+ if (keys.length === 0) return forceNode(node, index, aliases);
37
40
  const [key, ...rest] = keys as [string, ...string[]];
38
41
  if (Array.isArray(node)) {
39
42
  const i = Number(key);
40
43
  if (!Number.isInteger(i) || String(i) !== key || i < 0 || i >= node.length) return node;
41
- const child = forceAt(node[i], rest, index, snapshot);
44
+ const child = forceAt(node[i], rest, index, aliases);
42
45
  if (child === node[i]) return node;
43
46
  const copy = node.slice();
44
47
  copy[i] = child;
45
48
  return copy;
46
49
  }
47
50
  if (!isPlainObject(node) || !Object.hasOwn(node, key)) return node;
48
- const child = forceAt(node[key], rest, index, snapshot);
51
+ const child = forceAt(node[key], rest, index, aliases);
49
52
  return child === node[key] ? node : { ...node, [key]: child };
50
53
  }
51
54
 
52
55
  /** A multivariate block (by its own name or an alias) with only `variants[index]`, ruled `true`. */
53
- function forceNode(node: unknown, index: number, snapshot: Snapshot): unknown {
56
+ function forceNode(node: unknown, index: number, aliases: Aliases): unknown {
54
57
  if (!isPlainObject(node) || typeof node.__resolveType !== "string") return node;
55
58
  const type = node.__resolveType;
56
- const canonical = own(snapshot.aliases, type) ?? own(LEGACY_ALIASES, type) ?? type;
59
+ const canonical =
60
+ own(aliases as Record<string, string> | undefined, type) ?? own(LEGACY_ALIASES, type) ?? type;
57
61
  if (canonical !== "multivariate" || !Array.isArray(node.variants)) return node;
58
62
  const variant = node.variants[index];
59
63
  if (!isPlainObject(variant)) return node;
@@ -3,8 +3,8 @@
3
3
  * block in open pages during `vite dev`. Vite sites add it to
4
4
  * `vite.config.ts`; Next.js sites don't use it.
5
5
  *
6
- * `deco serve` (the site editor's local server) rewrites
7
- * `.deco/blocks.gen.ts` on every save. In `vite dev`, in the server
6
+ * Whatever rewrites `.deco/blocks.gen.ts` (content without a site: the
7
+ * CLI's `content()`) triggers it. In `vite dev`, in the server
8
8
  * environments, the plugin makes each module that imports it (usually
9
9
  * `src/cms.ts`) accept that import's updates: the new content goes into the
10
10
  * CMS already created for its `.deco` folder (`adoptContent`), and only then
@@ -34,7 +34,7 @@ const RELOAD_DELAY_MS = 100;
34
34
  /** The module the footer imports `adoptContent` from. */
35
35
  const HOT_MODULE = "@decocms/blocks/vite/hot";
36
36
 
37
- /** The content module `deco content` writes, wherever the `.deco` folder is. */
37
+ /** The content module (the CLI's `content()` writes it), wherever the `.deco` folder is. */
38
38
  const CONTENT_MODULE = /(?:^|[\\/])\.deco[\\/]blocks\.gen\.ts$/;
39
39
 
40
40
  /** Source files whose imports the plugin reads. */
@@ -1,29 +0,0 @@
1
- import { type Reporter } from "../log.ts";
2
- export interface ServeOptions {
3
- root?: string;
4
- cwd?: string;
5
- port?: number;
6
- host?: string;
7
- /** The local app the site editor previews: `localhost:8001` or a full loopback URL. */
8
- preview?: string;
9
- /** The upload folder, relative to the folder that contains `.deco`. */
10
- assets?: string;
11
- readOnly?: boolean;
12
- reporter?: Reporter;
13
- /** The git binary (default `git`, from `PATH`); tests point it elsewhere. */
14
- git?: string;
15
- }
16
- export interface RunningServer {
17
- /** The content protocol endpoint, `http://localhost:4545/rpc`. */
18
- endpoint: string;
19
- siteEditorUrl: string;
20
- port: number;
21
- close(): Promise<void>;
22
- }
23
- /** The app the site editor previews when `--preview` isn't given and no Vite port is set. */
24
- export declare const DEFAULT_PREVIEW_URL = "http://localhost:5173";
25
- /** Start the server; resolves once it listens. */
26
- export declare function startServer(options?: ServeOptions): Promise<RunningServer>;
27
- /** `deco serve`: start, then run until interrupted. */
28
- export declare function serve(options?: ServeOptions): Promise<number>;
29
- //# sourceMappingURL=server.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../../src/v8/cli/serve/server.ts"],"names":[],"mappings":"AAoCA,OAAO,EAAmB,KAAK,QAAQ,EAAE,MAAM,WAAW,CAAC;AAY3D,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uFAAuF;IACvF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uEAAuE;IACvE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,6EAA6E;IAC7E,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,aAAa;IAC5B,kEAAkE;IAClE,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED,6FAA6F;AAC7F,eAAO,MAAM,mBAAmB,0BAA0B,CAAC;AA2D3D,kDAAkD;AAClD,wBAAsB,WAAW,CAAC,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,aAAa,CAAC,CA6IpF;AAgED,uDAAuD;AACvD,wBAAsB,KAAK,CAAC,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,CASvE"}