@decocms/blocks 8.9.0 → 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
@@ -0,0 +1,214 @@
1
+ {
2
+ "names": [
3
+ "CMS",
4
+ "extends",
5
+ "footer",
6
+ "footer-a",
7
+ "header",
8
+ "home",
9
+ "plain",
10
+ "redirects",
11
+ "variants"
12
+ ],
13
+ "cases": [
14
+ {
15
+ "name": "home",
16
+ "body": {
17
+ "__resolveType": "website/pages/Page.tsx",
18
+ "path": "/",
19
+ "sections": [
20
+ {
21
+ "__resolveType": "header"
22
+ },
23
+ {
24
+ "__resolveType": "footer"
25
+ },
26
+ {
27
+ "__resolveType": "site/sections/Hero.tsx",
28
+ "title": "Olá"
29
+ }
30
+ ]
31
+ },
32
+ "version": "D8NyAZf7d5YahxJT5yN79A",
33
+ "meta": {
34
+ "type": "website/pages/Page.tsx",
35
+ "path": "/",
36
+ "refs": ["footer", "header"]
37
+ },
38
+ "entry": {
39
+ "version": "D8NyAZf7d5YahxJT5yN79A",
40
+ "meta": {
41
+ "type": "website/pages/Page.tsx",
42
+ "path": "/",
43
+ "refs": ["footer", "header"]
44
+ }
45
+ }
46
+ },
47
+ {
48
+ "name": "footer",
49
+ "body": {
50
+ "__resolveType": "site/sections/Footer.tsx",
51
+ "columns": [
52
+ {
53
+ "__resolveType": "footer-b"
54
+ },
55
+ {
56
+ "__resolveType": "footer-a"
57
+ },
58
+ {
59
+ "__resolveType": "footer-a"
60
+ }
61
+ ]
62
+ },
63
+ "version": "6-WZ8yiUs_rKrbuJOftvQA",
64
+ "meta": {
65
+ "type": "site/sections/Footer.tsx",
66
+ "refs": ["footer-a"]
67
+ },
68
+ "entry": {
69
+ "version": "6-WZ8yiUs_rKrbuJOftvQA",
70
+ "meta": {
71
+ "type": "site/sections/Footer.tsx",
72
+ "refs": ["footer-a"]
73
+ }
74
+ }
75
+ },
76
+ {
77
+ "name": "footer-a",
78
+ "body": {
79
+ "__resolveType": "site/sections/Links.tsx",
80
+ "links": []
81
+ },
82
+ "version": "FKbaI1TQOkKUaJDToMSDXg",
83
+ "meta": {
84
+ "type": "site/sections/Links.tsx"
85
+ },
86
+ "entry": {
87
+ "version": "FKbaI1TQOkKUaJDToMSDXg",
88
+ "meta": {
89
+ "type": "site/sections/Links.tsx"
90
+ }
91
+ }
92
+ },
93
+ {
94
+ "name": "plain",
95
+ "body": {
96
+ "title": "no type"
97
+ },
98
+ "version": "nDqa9jpXsR-37zvd7Y5rrw",
99
+ "meta": {},
100
+ "entry": {
101
+ "version": "nDqa9jpXsR-37zvd7Y5rrw"
102
+ }
103
+ },
104
+ {
105
+ "name": "variants",
106
+ "body": {
107
+ "__resolveType": "multivariate",
108
+ "variants": [
109
+ {
110
+ "rule": {
111
+ "__resolveType": "never"
112
+ },
113
+ "value": {
114
+ "__resolveType": "Promo"
115
+ }
116
+ },
117
+ {
118
+ "rule": {
119
+ "__resolveType": "always"
120
+ },
121
+ "value": {
122
+ "__resolveType": "lazy",
123
+ "value": {
124
+ "__resolveType": "header"
125
+ }
126
+ }
127
+ }
128
+ ]
129
+ },
130
+ "version": "NY3fN7vf-0QANkzlwdvuKg",
131
+ "meta": {
132
+ "type": "multivariate",
133
+ "refs": ["header"]
134
+ },
135
+ "entry": {
136
+ "version": "NY3fN7vf-0QANkzlwdvuKg",
137
+ "meta": {
138
+ "type": "multivariate",
139
+ "refs": ["header"]
140
+ }
141
+ }
142
+ },
143
+ {
144
+ "name": "extends",
145
+ "body": {
146
+ "__resolveType": "header",
147
+ "title": "override",
148
+ "path": "/x"
149
+ },
150
+ "version": "zuj5u8YTRDdaEv_7wSwnjg",
151
+ "meta": {
152
+ "type": "header",
153
+ "path": "/x",
154
+ "refs": ["header"]
155
+ },
156
+ "entry": {
157
+ "version": "zuj5u8YTRDdaEv_7wSwnjg",
158
+ "meta": {
159
+ "type": "header",
160
+ "path": "/x",
161
+ "refs": ["header"]
162
+ }
163
+ }
164
+ },
165
+ {
166
+ "name": "redirects",
167
+ "body": {
168
+ "__resolveType": "website/loaders/redirects.ts",
169
+ "redirects": [
170
+ {
171
+ "from": "/old",
172
+ "to": "/new",
173
+ "type": "permanent"
174
+ }
175
+ ]
176
+ },
177
+ "version": "b5gi6Yu1_tmkwW6fWbs02Q",
178
+ "meta": {
179
+ "type": "website/loaders/redirects.ts"
180
+ },
181
+ "entry": {
182
+ "version": "b5gi6Yu1_tmkwW6fWbs02Q",
183
+ "meta": {
184
+ "type": "website/loaders/redirects.ts"
185
+ }
186
+ }
187
+ },
188
+ {
189
+ "name": "CMS",
190
+ "body": {
191
+ "__resolveType": "cms-settings",
192
+ "telemetry": {
193
+ "enabled": false
194
+ }
195
+ },
196
+ "version": "sBqXj5u549za_Plbqc6R_g",
197
+ "meta": {
198
+ "type": "cms-settings"
199
+ },
200
+ "entry": {
201
+ "version": "sBqXj5u549za_Plbqc6R_g",
202
+ "meta": {
203
+ "type": "cms-settings"
204
+ },
205
+ "data": {
206
+ "__resolveType": "cms-settings",
207
+ "telemetry": {
208
+ "enabled": false
209
+ }
210
+ }
211
+ }
212
+ }
213
+ ]
214
+ }
@@ -77,3 +77,77 @@ export const contentHashFixtures: readonly ContentHashFixture[] = [
77
77
  revision: "6913c5e6aa28f441d3b0102177b372e4fb7c08bc09bdd8698df85e597282ac96",
78
78
  },
79
79
  ];
80
+
81
+ export interface BlockVersionFixture {
82
+ id: string;
83
+ /** The block (any JSON value). */
84
+ block: unknown;
85
+ /** Its canonical JSON. */
86
+ canonical: string;
87
+ /** `blockVersion(block)`: the first 16 bytes of SHA-256 over the canonical JSON, base64url, no padding. */
88
+ version: string;
89
+ }
90
+
91
+ /**
92
+ * Golden fixtures for block versions (`blockVersion`, in
93
+ * `@decocms/blocks/protocol`): every implementation that writes or checks
94
+ * `ifMatch` produces these exact versions.
95
+ */
96
+ export const blockVersionFixtures: readonly BlockVersionFixture[] = [
97
+ { id: "empty", block: {}, canonical: "{}", version: "RBNvo1WzZ4oRRq0W9-hkng" },
98
+ {
99
+ id: "key-order",
100
+ block: { b: 1, a: [true, null, "x"] },
101
+ canonical: '{"a":[true,null,"x"],"b":1}',
102
+ version: "VKZUFa03AiiFGh2ksxtv1A",
103
+ },
104
+ {
105
+ id: "unicode-numbers",
106
+ block: {
107
+ __resolveType: "site/sections/Hero.tsx",
108
+ title: "Olá — ünïcode 😀",
109
+ n: -0,
110
+ f: 1.5e-7,
111
+ big: 1e21,
112
+ int: 10,
113
+ },
114
+ canonical:
115
+ '{"__resolveType":"site/sections/Hero.tsx","big":1e+21,"f":1.5e-7,"int":10,"n":0,"title":"Olá — ünïcode 😀"}',
116
+ version: "cvNhsZmxtnrgaCwRg73Kxw",
117
+ },
118
+ {
119
+ id: "code-unit-order",
120
+ block: { é: 1, Z: 2, a: 3, aa: 4, "": 0 },
121
+ canonical: '{"":0,"Z":2,"a":3,"aa":4,"é":1}',
122
+ version: "psFj7dEx0yLDzHd3f9mabQ",
123
+ },
124
+ {
125
+ id: "nested-escapes",
126
+ block: { nested: { z: { y: [1, { b: 2, a: 1 }] }, a: 'line\nbreak "q" \\ \u0001' } },
127
+ canonical: '{"nested":{"a":"line\\nbreak \\"q\\" \\\\ \\u0001","z":{"y":[1,{"a":1,"b":2}]}}}',
128
+ version: "-F2yA3CkzEaGhmts3kOA3w",
129
+ },
130
+ ];
131
+
132
+ export interface RevisionIdFixture {
133
+ id: string;
134
+ /** Whether it has the shape of a revision id (`isRevisionId`). */
135
+ valid: boolean;
136
+ }
137
+
138
+ /** Revision ids (`<inv>-<uuidv7>`) and strings that aren't one. */
139
+ export const revisionIdFixtures: readonly RevisionIdFixture[] = [
140
+ { id: "fe6c5e0d97ff-0193a1f2-6800-7c3e-9d2a-4b8e1f0c7a55", valid: true },
141
+ { id: "fe5e5eb831ff-01a1a147-ce00-7000-8000-000000000000", valid: true },
142
+ { id: "fe5e5eb831fe-01a1a147-ce01-7fff-bfff-ffffffffffff", valid: true },
143
+ // A git commit SHA, a content hash, a bare UUIDv7.
144
+ { id: "1".repeat(40), valid: false },
145
+ { id: "f".repeat(64), valid: false },
146
+ { id: "0193a1f2-6800-7c3e-9d2a-4b8e1f0c7a55", valid: false },
147
+ // Uppercase, another UUID version, the wrong variant, a path.
148
+ { id: "FE6C5E0D97FF-0193A1F2-6800-7C3E-9D2A-4B8E1F0C7A55", valid: false },
149
+ { id: "fe6c5e0d97ff-0193a1f2-6800-4c3e-9d2a-4b8e1f0c7a55", valid: false },
150
+ { id: "fe6c5e0d97ff-0193a1f2-6800-7c3e-cd2a-4b8e1f0c7a55", valid: false },
151
+ { id: "fe6c5e0d97ff-0193a1f2-6800-7c3e-9d2a-4b8e1f0c7a55/../x", valid: false },
152
+ { id: "", valid: false },
153
+ ];
@@ -31,8 +31,16 @@ import { writeCases } from "./cases/writes.ts";
31
31
  import { ConformanceContext, type ConformanceOptions, SkipCase } from "./context.ts";
32
32
 
33
33
  export type { ConformanceCase } from "./cases/types.ts";
34
- export { type ContentHashFixture, contentHashFixtures } from "./contentHashFixtures.ts";
34
+ export {
35
+ type BlockVersionFixture,
36
+ blockVersionFixtures,
37
+ type ContentHashFixture,
38
+ contentHashFixtures,
39
+ type RevisionIdFixture,
40
+ revisionIdFixtures,
41
+ } from "./contentHashFixtures.ts";
35
42
  export type { ConformanceOptions } from "./context.ts";
43
+ export { type BlockMetaVector, type BlockMetaVectors, blockMetaVectors } from "./vectors.ts";
36
44
 
37
45
  /** Every conformance case, in the order they run. */
38
46
  export const conformanceCases: readonly ConformanceCase[] = [
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Golden vectors for `blockMeta` and `indexEntry` (see
3
+ * `@decocms/blocks/protocol`): every implementation that writes or reads a
4
+ * revision index (the SDK, the CLI, Studio's publish) checks it computes these
5
+ * exact entries. The JSON file is shared byte for byte with Studio's vendored
6
+ * copy.
7
+ *
8
+ * ```ts
9
+ * import { blockMetaVectors } from "@decocms/blocks/protocol/conformance";
10
+ * for (const c of blockMetaVectors.cases) {
11
+ * expect(blockMeta(c.body, blockMetaVectors.names)).toEqual(c.meta);
12
+ * }
13
+ * ```
14
+ */
15
+ import type { BlockMeta, IndexEntry } from "../../v8/blockMeta.ts";
16
+ import vectors from "./blockMetaVectors.json" with { type: "json" };
17
+
18
+ export interface BlockMetaVector {
19
+ /** The block's name in the index. */
20
+ name: string;
21
+ body: unknown;
22
+ /** `blockVersion(body)`. */
23
+ version: string;
24
+ /** `blockMeta(body, names)`. */
25
+ meta: BlockMeta;
26
+ /** `indexEntry(name, body, names)`. */
27
+ entry: IndexEntry;
28
+ }
29
+
30
+ export interface BlockMetaVectors {
31
+ /** The block names of the index the cases are computed for. */
32
+ names: readonly string[];
33
+ cases: readonly BlockMetaVector[];
34
+ }
35
+
36
+ export const blockMetaVectors: BlockMetaVectors = vectors as BlockMetaVectors;
@@ -14,18 +14,50 @@
14
14
  * - `@decocms/blocks/protocol/storage/fs` — the filesystem storage (Node only)
15
15
  * - `@decocms/blocks/protocol/conformance` — a black-box test suite over HTTP
16
16
  *
17
+ * The Studio channel's messages (`deco:ready`, `deco:load`, ...) and the
18
+ * context a Studio module gets are here too (`./channel.ts`):
19
+ * the page's bootstrap is `StudioChannel` in `@decocms/blocks/preview`.
20
+ *
21
+ * `blockMeta`/`indexEntry` compute a hosted revision index's entries (the
22
+ * SDK's own browser-safe module, shared with Studio and the CLI).
23
+ *
17
24
  * The SDK's runtime never imports the protocol, so it never reaches an app
18
25
  * bundle. The canonical hash it re-exports is the SDK's own dependency-free
19
26
  * leaf module (see ./canonical.ts). Draft previews and the draft lifecycle
20
27
  * are outside the protocol (see /next/content-delivery#draft-previews).
21
28
  */
29
+
22
30
  export {
31
+ type BlockIndex,
32
+ type BlockMeta,
33
+ blockMeta,
34
+ type IndexEntry,
35
+ indexEntry,
36
+ } from "../v8/blockMeta.ts";
37
+ export { isRevisionId, REVISION_ID_RE } from "../v8/revisionId.ts";
38
+ export {
39
+ blockVersion,
23
40
  CanonicalJsonError,
24
41
  CONTENT_HASH_FORMAT,
25
42
  canonicalJson,
26
43
  computeContentRevision,
27
44
  sha256Hex,
28
45
  } from "./canonical.ts";
46
+ export {
47
+ CHANNEL_MESSAGE,
48
+ type ChannelLoadErrorMessage,
49
+ type ChannelLoadedMessage,
50
+ type ChannelLoadMessage,
51
+ type ChannelReadyMessage,
52
+ DEFAULT_STUDIO_ORIGIN,
53
+ DEFAULT_STUDIO_ORIGINS,
54
+ defineStudioModule,
55
+ type ModuleMessage,
56
+ type PageChannelMessage,
57
+ type StudioChannelContext,
58
+ type StudioChannelMessage,
59
+ type StudioChannelModule,
60
+ } from "./channel.ts";
29
61
  export {
30
62
  assertSupportedEndpoint,
31
63
  type BatchCall,
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * The one file-name rule for saved blocks (`@decocms/blocks/protocol/keys`).
3
3
  *
4
- * The site editor, `deco serve` and `deco content` all import this module, so
4
+ * The site editor, the deco CLI and the content module all import this module, so
5
5
  * an entry the site editor edits is the entry the app renders:
6
6
  *
7
7
  * - **Name to file:** `encodeURIComponent(name) + ".json"`, directly in
@@ -95,6 +95,48 @@ export function runInBackground(task: Task): void {
95
95
  });
96
96
  }
97
97
 
98
+ /**
99
+ * Keeps the request that started `promise` alive until it settles, where the
100
+ * runtime ends a request's work with its response: a host's hook, or on
101
+ * Cloudflare Workers the platform's `waitUntil`. Unlike
102
+ * {@link runInBackground}, the work has already started: nothing is
103
+ * deferred. Elsewhere a pending promise needs nothing to settle, so this does
104
+ * nothing. Never throws.
105
+ *
106
+ * Shared work goes through here: a fetch a later request may await (a block
107
+ * body by hash, `latest.json`, a revision's index) must not die with the
108
+ * request that happened to start it.
109
+ */
110
+ export function keepAlive(promise: Promise<unknown>): void {
111
+ const settled = promise.then(
112
+ () => {},
113
+ () => {},
114
+ );
115
+ const g = globalThis as BackgroundGlobals;
116
+ const hook = g[BACKGROUND_HOOK];
117
+ try {
118
+ if (typeof hook === "function") {
119
+ hook(() => settled);
120
+ return;
121
+ }
122
+ if (onWorkers()) {
123
+ void workersWaitUntil().then((waitUntil) => {
124
+ if (waitUntil === undefined) return;
125
+ if (typeof g[BACKGROUND_HOOK] !== "function") {
126
+ g[BACKGROUND_HOOK] = (next) => waitUntil(next());
127
+ }
128
+ try {
129
+ g[BACKGROUND_HOOK]?.(() => settled);
130
+ } catch {
131
+ // As below.
132
+ }
133
+ });
134
+ }
135
+ } catch {
136
+ // Outside a request there is no request to keep: the work just runs.
137
+ }
138
+ }
139
+
98
140
  /** `setTimeout` that never keeps a Node process alive. */
99
141
  export function later(ms: number, callback: () => void): void {
100
142
  const timer = setTimeout(callback, ms) as unknown as { unref?: () => void };
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Index entries of a hosted release (see /next/hosted-releases-internals):
3
+ * `revisions/<id>/index.json` and `latest.json` map each block name to its
4
+ * hash (`version`) plus the little metadata routing and the reference walk
5
+ * need, so neither needs a block body.
6
+ *
7
+ * `blockMeta(body, names)` is the one helper Studio, the SDK and the CLI use
8
+ * to compute that metadata, so all three write and read the same entries.
9
+ * Pure, synchronous, browser-safe; its only import is the dependency-free
10
+ * canonical hash (for `indexEntry`).
11
+ *
12
+ * - `type`: the body's raw top-level `__resolveType`, copied without alias
13
+ * mapping (readers map it with their alias rules).
14
+ * - `path`: the body's top-level `path`, when it is a string (any type).
15
+ * - `refs`: every `__resolveType` string anywhere in the body (the top-level
16
+ * one included, every variant, `never` and `lazy` values included) that is
17
+ * one of `names`, deduped and sorted in code-unit order.
18
+ *
19
+ * A key is present only when it has a value (`refs: []` is left out), so a
20
+ * body with nothing to say gives `{}` and its entry carries no `meta`.
21
+ */
22
+ import { blockVersion } from "./canonical.ts";
23
+
24
+ /** What an index says about a block, besides its hash. */
25
+ export interface BlockMeta {
26
+ /** The body's raw `__resolveType`. */
27
+ type?: string;
28
+ /** The body's top-level `path`. */
29
+ path?: string;
30
+ /** The block names the body references, deduped, in code-unit order. */
31
+ refs?: string[];
32
+ }
33
+
34
+ /** One entry of a revision index. */
35
+ export interface IndexEntry {
36
+ /** `blockVersion(body)`: the hash the body is stored under (`blocks/<version>.json`). */
37
+ version: string;
38
+ /** Omitted when empty. */
39
+ meta?: BlockMeta;
40
+ /** The body itself, only on the CMS settings entry (`CMS`). */
41
+ data?: unknown;
42
+ }
43
+
44
+ /** A revision index's blocks: block name → entry. */
45
+ export type BlockIndex = Record<string, IndexEntry>;
46
+
47
+ /** The well-known name whose body every index inlines as `data`. */
48
+ export const INLINE_BLOCK = "CMS";
49
+
50
+ /** The metadata of one block body; `names` are the block names of the index being built. */
51
+ export function blockMeta(
52
+ body: unknown,
53
+ names: ReadonlySet<string> | readonly string[],
54
+ ): BlockMeta {
55
+ const meta: BlockMeta = {};
56
+ if (!isRecord(body)) return meta;
57
+ if (typeof body.__resolveType === "string") meta.type = body.__resolveType;
58
+ if (typeof body.path === "string") meta.path = body.path;
59
+ const known: ReadonlySet<string> = isSet(names) ? names : new Set(names);
60
+ const found = new Set<string>();
61
+ collectRefs(body, known, found);
62
+ if (found.size > 0) meta.refs = [...found].sort();
63
+ return meta;
64
+ }
65
+
66
+ /** The index entry for a block: its hash, its metadata when any, and its body when it is `CMS`. */
67
+ export async function indexEntry(
68
+ name: string,
69
+ body: unknown,
70
+ names: ReadonlySet<string> | readonly string[],
71
+ ): Promise<IndexEntry> {
72
+ const entry: IndexEntry = { version: await blockVersion(body) };
73
+ const meta = blockMeta(body, names);
74
+ if (Object.keys(meta).length > 0) entry.meta = meta;
75
+ if (name === INLINE_BLOCK) entry.data = body;
76
+ return entry;
77
+ }
78
+
79
+ function collectRefs(node: unknown, names: ReadonlySet<string>, found: Set<string>): void {
80
+ if (Array.isArray(node)) {
81
+ for (const item of node) collectRefs(item, names, found);
82
+ return;
83
+ }
84
+ if (!isRecord(node)) return;
85
+ for (const [key, value] of Object.entries(node)) {
86
+ if (key === "__resolveType") {
87
+ if (typeof value === "string" && names.has(value)) found.add(value);
88
+ } else {
89
+ collectRefs(value, names, found);
90
+ }
91
+ }
92
+ }
93
+
94
+ function isRecord(value: unknown): value is Record<string, unknown> {
95
+ return typeof value === "object" && value !== null && !Array.isArray(value);
96
+ }
97
+
98
+ function isSet(value: ReadonlySet<string> | readonly string[]): value is ReadonlySet<string> {
99
+ return !Array.isArray(value);
100
+ }
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Hosted block bodies by hash (see /next/hosted-releases-internals): an LRU
3
+ * per isolate, bounded by bytes, in front of plain `fetch()` of
4
+ * `sites/<site>/blocks/<hash>.json` through the delivery CDN.
5
+ *
6
+ * A hash always means the same body, so nothing here is ever invalidated.
7
+ * Concurrent requests for one hash share one fetch; a fetch that fails isn't
8
+ * kept, so the next request that needs it tries again.
9
+ *
10
+ * A shared fetch belongs to the request that started it, and some runtimes
11
+ * (Cloudflare Workers) stop a request's I/O with its response: a fetch the
12
+ * request only prefetched would then never settle, and every later request
13
+ * that needs the body would wait on it forever. So:
14
+ * - every fetch is kept alive until it settles (`keepAlive`: the platform's
15
+ * `waitUntil`), whoever started it;
16
+ * - a request that joins another's fetch waits for it no longer than that
17
+ * fetch's own deadline (the 10 s every fetch has, plus a margin): past it
18
+ * the fetch is dropped from the map, that request's read fails with a
19
+ * `"timeout"` `ContentUnavailableError`, and the next request fetches
20
+ * again; a fetch already past its deadline when a request asks is dropped
21
+ * and fetched again at once.
22
+ */
23
+
24
+ import { keepAlive } from "./background.ts";
25
+ import { BoundedMap } from "./boundedMap.ts";
26
+ import type { BodySource } from "./contentIndex.ts";
27
+ import { ContentUnavailableError } from "./errors.ts";
28
+
29
+ /** The default byte bound of the LRU: the sum of the bodies' JSON text lengths. */
30
+ export const DEFAULT_BLOCK_CACHE_BYTES = 32 * 1024 * 1024;
31
+
32
+ /**
33
+ * How long a shared fetch may stay in flight: the 10 s each fetch has
34
+ * (headers and body), plus a second's margin. A fetch still in flight past
35
+ * it is one whose request went away.
36
+ */
37
+ export const IN_FLIGHT_DEADLINE_MS = 11_000;
38
+
39
+ /** A fetched body and the length of its JSON text. */
40
+ export interface FetchedBody {
41
+ body: unknown;
42
+ bytes: number;
43
+ }
44
+
45
+ interface InFlight {
46
+ body: Promise<unknown>;
47
+ /** When it started, in ms since the epoch. */
48
+ at: number;
49
+ }
50
+
51
+ export class BlockStore implements BodySource {
52
+ readonly #fetch: (hash: string, name: string) => Promise<FetchedBody>;
53
+ readonly #lru: BoundedMap<string, FetchedBody>;
54
+ readonly #deadlineMs: number;
55
+ readonly #inFlight = new Map<string, InFlight>();
56
+
57
+ constructor(
58
+ fetchBody: (hash: string, name: string) => Promise<FetchedBody>,
59
+ limitBytes = DEFAULT_BLOCK_CACHE_BYTES,
60
+ deadlineMs = IN_FLIGHT_DEADLINE_MS,
61
+ ) {
62
+ this.#fetch = fetchBody;
63
+ this.#lru = new BoundedMap(limitBytes, (entry) => entry.bytes);
64
+ this.#deadlineMs = deadlineMs;
65
+ }
66
+
67
+ peek(hash: string): unknown | undefined {
68
+ return this.#lru.get(hash)?.body;
69
+ }
70
+
71
+ get(hash: string, name: string): Promise<unknown> {
72
+ const held = this.#lru.get(hash);
73
+ if (held !== undefined) return Promise.resolve(held.body);
74
+ const shared = this.#inFlight.get(hash);
75
+ if (shared !== undefined) {
76
+ const left = shared.at + this.#deadlineMs - Date.now();
77
+ if (left > 0) return this.#join(hash, name, shared, left);
78
+ // Past its deadline: its request went away without settling it.
79
+ this.#inFlight.delete(hash);
80
+ }
81
+ return this.#start(hash, name);
82
+ }
83
+
84
+ #start(hash: string, name: string): Promise<unknown> {
85
+ const body = this.#fetch(hash, name).then((fetched) => {
86
+ this.#lru.set(hash, fetched);
87
+ return fetched.body;
88
+ });
89
+ const entry: InFlight = { body, at: Date.now() };
90
+ this.#inFlight.set(hash, entry);
91
+ const settle = () => {
92
+ if (this.#inFlight.get(hash) === entry) this.#inFlight.delete(hash);
93
+ };
94
+ body.then(settle, settle);
95
+ keepAlive(body);
96
+ return body;
97
+ }
98
+
99
+ /** Another request's fetch, awaited for at most `ms`. */
100
+ #join(hash: string, name: string, entry: InFlight, ms: number): Promise<unknown> {
101
+ return new Promise((resolve, reject) => {
102
+ const timer = setTimeout(() => {
103
+ if (this.#inFlight.get(hash) === entry) this.#inFlight.delete(hash);
104
+ reject(
105
+ new ContentUnavailableError(
106
+ "timeout",
107
+ `block "${name}" (${hash}): no answer within ${this.#deadlineMs} ms`,
108
+ ),
109
+ );
110
+ }, ms) as unknown as { unref?: () => void };
111
+ timer?.unref?.();
112
+ entry.body.then(
113
+ (body) => {
114
+ clearTimeout(timer as unknown as number);
115
+ resolve(body);
116
+ },
117
+ (error: unknown) => {
118
+ clearTimeout(timer as unknown as number);
119
+ reject(error);
120
+ },
121
+ );
122
+ });
123
+ }
124
+ }