@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,42 @@
1
+ /**
2
+ * Map fields - tells the settings of a Ledger map from its fields
3
+ *
4
+ * A map file has two forms, and the Ledger service accepts both (`extractFieldDefinitions` in its `MapService`):
5
+ *
6
+ * - the wrapper form `{ "mediaDir": "...", "fields": { ... } }`: the fields are the `fields` object;
7
+ * - the flat form `{ "mediaDir": "...", "title": { ... } }`: every top-level key is a field, except the keys that
8
+ * belong to the map itself: `mediaDir`, `version` and `name`.
9
+ *
10
+ * The code generator and the mock checks must read the fields through {@link getMapFields}, never with
11
+ * `Object.entries(map)`, or the settings of the map turn into fields.
12
+ */
13
+ import type { LedgerMapSchema } from "../../core/types.js";
14
+ /** The top-level keys of a flat map that are settings of the map and never fields. The same list as the service. */
15
+ export declare const MAP_LEVEL_KEYS: readonly ["mediaDir", "version", "name"];
16
+ /**
17
+ * The fields of a map, without its settings. A map with a `fields` object gives that object; a flat map gives its
18
+ * top-level keys except {@link MAP_LEVEL_KEYS}.
19
+ */
20
+ export declare function getMapFields(map: LedgerMapSchema | Record<string, unknown>): LedgerMapSchema;
21
+ /**
22
+ * The reserved keys that a flat map uses as a field. A flat map with `"name": "homepage"` or `"version": 2` has a
23
+ * setting, but a flat map with `"name": { "type": "string" }` has a field that the service drops at sync, because
24
+ * `name`, `version` and `mediaDir` belong to the map. A map with a `fields` object may use any name.
25
+ */
26
+ export declare function findReservedFieldKeys(map: LedgerMapSchema | Record<string, unknown>): string[];
27
+ /** One field of a map whose type is not one of the seven types of LED-3. */
28
+ export interface UnknownFieldType {
29
+ /** The path of the field in the map, for example `items[].price` (`[]` is the `items` of an array). */
30
+ path: string;
31
+ /** The type that the map gives, or `undefined` when the field has no `type`. */
32
+ type: unknown;
33
+ }
34
+ /**
35
+ * The fields of a map whose `type` is not one of the seven types (`string`, `number`, `boolean`, `media`,
36
+ * `media-reference`, `array`, `object`), nested fields included. `media-reference` is valid and is handled like `media`.
37
+ * An empty list means every field has a known type.
38
+ */
39
+ export declare function findUnknownFieldTypes(map: LedgerMapSchema | Record<string, unknown>): UnknownFieldType[];
40
+ /** The text that names one unknown field type, for an error message. */
41
+ export declare function describeUnknownFieldType({ path, type }: UnknownFieldType): string;
42
+ //# sourceMappingURL=map-fields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map-fields.d.ts","sourceRoot":"","sources":["../../../src/cli/utils/map-fields.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EAAyB,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAElF,oHAAoH;AACpH,eAAO,MAAM,cAAc,0CAA2C,CAAC;AAUvE;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,eAAe,CAgB5F;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,EAAE,CAM9F;AAED,4EAA4E;AAC5E,MAAM,WAAW,gBAAgB;IAChC,uGAAuG;IACvG,IAAI,EAAE,MAAM,CAAC;IACb,gFAAgF;IAChF,IAAI,EAAE,OAAO,CAAC;CACd;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,gBAAgB,EAAE,CA2BxG;AAED,wEAAwE;AACxE,wBAAgB,wBAAwB,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,gBAAgB,GAAG,MAAM,CAEjF"}
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Map fields - tells the settings of a Ledger map from its fields
3
+ *
4
+ * A map file has two forms, and the Ledger service accepts both (`extractFieldDefinitions` in its `MapService`):
5
+ *
6
+ * - the wrapper form `{ "mediaDir": "...", "fields": { ... } }`: the fields are the `fields` object;
7
+ * - the flat form `{ "mediaDir": "...", "title": { ... } }`: every top-level key is a field, except the keys that
8
+ * belong to the map itself: `mediaDir`, `version` and `name`.
9
+ *
10
+ * The code generator and the mock checks must read the fields through {@link getMapFields}, never with
11
+ * `Object.entries(map)`, or the settings of the map turn into fields.
12
+ */
13
+ import { LEDGER_FIELD_TYPES } from "../../core/types.js";
14
+ /** The top-level keys of a flat map that are settings of the map and never fields. The same list as the service. */
15
+ export const MAP_LEVEL_KEYS = ["mediaDir", "version", "name"];
16
+ function isPlainObject(value) {
17
+ return value !== null && typeof value === "object" && !Array.isArray(value);
18
+ }
19
+ function isWrapperForm(map) {
20
+ return isPlainObject(map.fields);
21
+ }
22
+ /**
23
+ * The fields of a map, without its settings. A map with a `fields` object gives that object; a flat map gives its
24
+ * top-level keys except {@link MAP_LEVEL_KEYS}.
25
+ */
26
+ export function getMapFields(map) {
27
+ const raw = map;
28
+ if (!isPlainObject(raw)) {
29
+ return {};
30
+ }
31
+ if (isWrapperForm(raw)) {
32
+ return raw.fields;
33
+ }
34
+ const fields = {};
35
+ for (const [key, value] of Object.entries(raw)) {
36
+ if (MAP_LEVEL_KEYS.includes(key)) {
37
+ continue;
38
+ }
39
+ fields[key] = value;
40
+ }
41
+ return fields;
42
+ }
43
+ /**
44
+ * The reserved keys that a flat map uses as a field. A flat map with `"name": "homepage"` or `"version": 2` has a
45
+ * setting, but a flat map with `"name": { "type": "string" }` has a field that the service drops at sync, because
46
+ * `name`, `version` and `mediaDir` belong to the map. A map with a `fields` object may use any name.
47
+ */
48
+ export function findReservedFieldKeys(map) {
49
+ const raw = map;
50
+ if (!isPlainObject(raw) || isWrapperForm(raw)) {
51
+ return [];
52
+ }
53
+ return MAP_LEVEL_KEYS.filter((key) => isPlainObject(raw[key]));
54
+ }
55
+ /**
56
+ * The fields of a map whose `type` is not one of the seven types (`string`, `number`, `boolean`, `media`,
57
+ * `media-reference`, `array`, `object`), nested fields included. `media-reference` is valid and is handled like `media`.
58
+ * An empty list means every field has a known type.
59
+ */
60
+ export function findUnknownFieldTypes(map) {
61
+ const found = [];
62
+ const known = LEDGER_FIELD_TYPES;
63
+ function visit(definition, path) {
64
+ if (!isPlainObject(definition)) {
65
+ found.push({ path, type: undefined });
66
+ return;
67
+ }
68
+ if (!known.includes(definition.type)) {
69
+ found.push({ path, type: definition.type });
70
+ return;
71
+ }
72
+ if (isPlainObject(definition.fields)) {
73
+ for (const [name, child] of Object.entries(definition.fields)) {
74
+ visit(child, `${path}.${name}`);
75
+ }
76
+ }
77
+ if (definition.items !== undefined) {
78
+ visit(definition.items, `${path}[]`);
79
+ }
80
+ }
81
+ for (const [name, field] of Object.entries(getMapFields(map))) {
82
+ visit(field, name);
83
+ }
84
+ return found;
85
+ }
86
+ /** The text that names one unknown field type, for an error message. */
87
+ export function describeUnknownFieldType({ path, type }) {
88
+ return typeof type === "string" ? `"${path}" has the type "${type}"` : `"${path}" has no valid type`;
89
+ }
90
+ //# sourceMappingURL=map-fields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map-fields.js","sourceRoot":"","sources":["../../../src/cli/utils/map-fields.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAGzD,oHAAoH;AACpH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,UAAU,EAAE,SAAS,EAAE,MAAM,CAAU,CAAC;AAEvE,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,aAAa,CAAC,GAA4B;IAClD,OAAO,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AAClC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,GAA8C;IAC1E,MAAM,GAAG,GAAG,GAA8B,C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UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YACtC,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;YAC5C,OAAO;QACR,CAAC;QACD,IAAI,aAAa,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;YACtC,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC/D,KAAK,CAAC,KAAK,EAAE,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC;YACjC,CAAC;QACF,CAAC;QACD,IAAI,UAAU,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YACpC,KAAK,CAAC,UAAU,CAAC,KAAK,EAAE,GAAG,IAAI,IAAI,CAAC,CAAC;QACtC,CAAC;IACF,CAAC;IAED,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;QAC/D,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACpB,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,wBAAwB,CAAC,EAAE,IAAI,EAAE,IAAI,EAAoB;IACxE,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,mBAAmB,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,IAAI,qBAAqB,CAAC;AACtG,CAAC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Map validator: the local request limits of a Ledger map sync (rulebook LIM-7)
3
+ *
4
+ * `parrel ledger sync` checks these limits before it sends anything, so a request that breaks a limit is never sent.
5
+ * Ledger checks the same limits on its side.
6
+ */
7
+ /** The largest request body of one map sync, in bytes (10 MB). */
8
+ export declare const MAX_SYNC_BODY_BYTES: number;
9
+ /** The most maps in one sync. */
10
+ export declare const MAX_SYNC_MAPS = 200;
11
+ /** The most fields in one map, nested fields included. */
12
+ export declare const MAX_FIELDS_PER_MAP = 500;
13
+ /** The deepest nesting of fields in a map. A field at the top of a map is level 1. */
14
+ export declare const MAX_FIELD_DEPTH = 8;
15
+ /** One limit that a map set breaks. `map` is the name of the map, or an empty string when the whole set is meant. */
16
+ export interface MapSetProblem {
17
+ map: string;
18
+ message: string;
19
+ }
20
+ /** The request body of a sync, as it is sent. The apply call adds `confirm` or `previewId`, which are small. */
21
+ export declare function syncRequestBody(maps: Record<string, unknown>, extra?: Record<string, unknown>): string;
22
+ /**
23
+ * Checks a set of maps against the request limits of a map sync: a body of at most 10 MB, at most 200 maps, at most
24
+ * 500 fields in one map (nested fields included) and nesting of at most 8 levels. It also reports a field with a type
25
+ * outside the seven field types. It returns one problem for each limit that is broken, and an empty list when the set is within the limits. It sends nothing.
26
+ *
27
+ * @param maps - The maps by name, as `parrel ledger sync` sends them.
28
+ * @returns The problems; each one names the map (empty for a limit of the whole set) and says what to change.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * const problems = validateMapSet({ homepage: { title: { type: "string" } } });
33
+ * if (problems.length > 0) console.error(problems.map((p) => p.message).join("\n"));
34
+ * ```
35
+ */
36
+ export declare function validateMapSet(maps: Record<string, unknown>): MapSetProblem[];
37
+ /**
38
+ * Throws the first limit that the maps break as a `ParrelError` (`SD05000010` to `SD05000013`, or `SD05000023` for an unknown field type). Does nothing when the
39
+ * maps are within the limits.
40
+ */
41
+ export declare function assertMapSetWithinLimits(maps: Record<string, unknown>): void;
42
+ //# sourceMappingURL=map-validator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map-validator.d.ts","sourceRoot":"","sources":["../../../src/cli/utils/map-validator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,kEAAkE;AAClE,eAAO,MAAM,mBAAmB,QAAmB,CAAC;AACpD,iCAAiC;AACjC,eAAO,MAAM,aAAa,MAAM,CAAC;AACjC,0DAA0D;AAC1D,eAAO,MAAM,kBAAkB,MAAM,CAAC;AACtC,sFAAsF;AACtF,eAAO,MAAM,eAAe,IAAI,CAAC;AAEjC,qHAAqH;AACrH,MAAM,WAAW,aAAa;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;CAChB;AA2BD,gHAAgH;AAChH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,MAAM,CAE1G;AA0DD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa,EAAE,CAE7E;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAK5E"}
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Map validator: the local request limits of a Ledger map sync (rulebook LIM-7)
3
+ *
4
+ * `parrel ledger sync` checks these limits before it sends anything, so a request that breaks a limit is never sent.
5
+ * Ledger checks the same limits on its side.
6
+ */
7
+ import { ParrelError } from "../../core/parrel-error.js";
8
+ import { describeUnknownFieldType, findUnknownFieldTypes, getMapFields } from "./map-fields.js";
9
+ /** The largest request body of one map sync, in bytes (10 MB). */
10
+ export const MAX_SYNC_BODY_BYTES = 10 * 1024 * 1024;
11
+ /** The most maps in one sync. */
12
+ export const MAX_SYNC_MAPS = 200;
13
+ /** The most fields in one map, nested fields included. */
14
+ export const MAX_FIELDS_PER_MAP = 500;
15
+ /** The deepest nesting of fields in a map. A field at the top of a map is level 1. */
16
+ export const MAX_FIELD_DEPTH = 8;
17
+ function isPlainObject(value) {
18
+ return value !== null && typeof value === "object" && !Array.isArray(value);
19
+ }
20
+ /** Counts a field and the fields below it (`fields` of an object, `items` of an array) and finds the deepest level. */
21
+ function measureField(definition, depth, totals) {
22
+ totals.fields += 1;
23
+ totals.depth = Math.max(totals.depth, depth);
24
+ if (!isPlainObject(definition)) {
25
+ return;
26
+ }
27
+ if (isPlainObject(definition.fields)) {
28
+ for (const child of Object.values(definition.fields)) {
29
+ measureField(child, depth + 1, totals);
30
+ }
31
+ }
32
+ if (isPlainObject(definition.items)) {
33
+ measureField(definition.items, depth + 1, totals);
34
+ }
35
+ }
36
+ /** The request body of a sync, as it is sent. The apply call adds `confirm` or `previewId`, which are small. */
37
+ export function syncRequestBody(maps, extra = {}) {
38
+ return JSON.stringify({ maps, ...extra });
39
+ }
40
+ function collectProblems(maps) {
41
+ const problems = [];
42
+ const bodyBytes = Buffer.byteLength(syncRequestBody(maps), "utf8");
43
+ if (bodyBytes > MAX_SYNC_BODY_BYTES) {
44
+ problems.push({
45
+ map: "",
46
+ code: "SD05000010",
47
+ message: "The maps are larger than 10 MB. Split them into smaller maps or remove unused fields.",
48
+ });
49
+ }
50
+ const names = Object.keys(maps);
51
+ if (names.length > MAX_SYNC_MAPS) {
52
+ problems.push({
53
+ map: "",
54
+ code: "SD05000011",
55
+ message: "There are more than 200 maps. Remove the maps you no longer use.",
56
+ });
57
+ }
58
+ for (const name of names) {
59
+ const map = maps[name];
60
+ if (!isPlainObject(map)) {
61
+ continue;
62
+ }
63
+ const totals = { fields: 0, depth: 0 };
64
+ for (const field of Object.values(getMapFields(map))) {
65
+ measureField(field, 1, totals);
66
+ }
67
+ const [unknownType] = findUnknownFieldTypes(map);
68
+ if (unknownType) {
69
+ problems.push({
70
+ map: name,
71
+ code: "SD05000023",
72
+ message: `The map \`${name}\`: the field ${describeUnknownFieldType(unknownType)}. Use one of string, number, boolean, media, media-reference, array or object.`,
73
+ });
74
+ }
75
+ if (totals.fields > MAX_FIELDS_PER_MAP) {
76
+ problems.push({
77
+ map: name,
78
+ code: "SD05000012",
79
+ message: `The map \`${name}\` has more than 500 fields, nested fields included. Split it into smaller maps.`,
80
+ });
81
+ }
82
+ if (totals.depth > MAX_FIELD_DEPTH) {
83
+ problems.push({
84
+ map: name,
85
+ code: "SD05000013",
86
+ message: `The map \`${name}\` is nested deeper than 8 levels. Flatten it.`,
87
+ });
88
+ }
89
+ }
90
+ return problems;
91
+ }
92
+ /**
93
+ * Checks a set of maps against the request limits of a map sync: a body of at most 10 MB, at most 200 maps, at most
94
+ * 500 fields in one map (nested fields included) and nesting of at most 8 levels. It also reports a field with a type
95
+ * outside the seven field types. It returns one problem for each limit that is broken, and an empty list when the set is within the limits. It sends nothing.
96
+ *
97
+ * @param maps - The maps by name, as `parrel ledger sync` sends them.
98
+ * @returns The problems; each one names the map (empty for a limit of the whole set) and says what to change.
99
+ *
100
+ * @example
101
+ * ```ts
102
+ * const problems = validateMapSet({ homepage: { title: { type: "string" } } });
103
+ * if (problems.length > 0) console.error(problems.map((p) => p.message).join("\n"));
104
+ * ```
105
+ */
106
+ export function validateMapSet(maps) {
107
+ return collectProblems(maps).map(({ map, message }) => ({ map, message }));
108
+ }
109
+ /**
110
+ * Throws the first limit that the maps break as a `ParrelError` (`SD05000010` to `SD05000013`, or `SD05000023` for an unknown field type). Does nothing when the
111
+ * maps are within the limits.
112
+ */
113
+ export function assertMapSetWithinLimits(maps) {
114
+ const [first] = collectProblems(maps);
115
+ if (first) {
116
+ throw new ParrelError(first.code, first.message);
117
+ }
118
+ }
119
+ //# sourceMappingURL=map-validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map-validator.js","sourceRoot":"","sources":["../../../src/cli/utils/map-validator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAEzD,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEhG,kEAAkE;AAClE,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,GAAG,IAAI,GAAG,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iBAAiB,wBAAwB,CAAC,WAAW,CAAC,gFAAgF;aAChK,CAAC,CAAC;QACJ,CAAC;QACD,IAAI,MAAM,CAAC,MAAM,GAAG,kBAAkB,EAAE,CAAC;YACxC,QAAQ,CAAC,IAAI,CAAC;gBACb,GAAG,EAAE,IAAI;gBACT,IAAI,EAAE,YAAY;gBAClB,OAAO,EAAE,aAAa,IAAI,kFAAkF;aAC5G,CAAC,CAAC;QACJ,CAAC;QACD,IAAI,MAAM,CAAC,KAAK,GAAG,eAAe,EAAE,CAAC;YACpC,QAAQ,CAAC,IAAI,CAAC;gBACb,GAAG,EAAE,IAAI;gBACT,IAAI,EAAE,YAAY;gBAClB,OAAO,EAAE,aAAa,IAAI,gDAAgD;aAC1E,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;IACD,OAAO,QAAQ,CAAC;AACjB,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,cAAc,CAAC,IAA6B;IAC3D,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;AAC5E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CAAC,IAA6B;IACrE,MAAM,CAAC,KAAK,CAAC,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IACtC,IAAI,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,WAAW,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAClD,CAAC;AACF,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Media file check: the pre-check before a media upload (rulebook LED-10)
3
+ *
4
+ * Ledger refuses an empty file, a file whose extension is not on the list and a file over 50 MB. The package checks the
5
+ * same three things before it sends the file, so a visitor gets the answer at once and the upload is never sent.
6
+ * Ledger still decides: it also checks the content type, and it may accept less than the list says.
7
+ */
8
+ import { ParrelError } from "../../core/parrel-error.js";
9
+ /** The largest media file that Ledger accepts, in bytes (50 MB). */
10
+ export declare const LEDGER_MAX_MEDIA_BYTES = 52428800;
11
+ /** The extensions that Ledger accepts for a media upload, in lower case, without the dot. */
12
+ export declare const LEDGER_MEDIA_EXTENSIONS: readonly string[];
13
+ /** The error for a file that Ledger would refuse, or `null` when the file passes the three checks. */
14
+ export declare function ledgerMediaFileProblem(file: {
15
+ name?: string;
16
+ size: number;
17
+ }): ParrelError | null;
18
+ /**
19
+ * Checks a file before it is uploaded as media. The service still decides: this only gives the same answer sooner,
20
+ * with the same codes.
21
+ *
22
+ * @param file - The file to check: its name and its size in bytes.
23
+ * @throws {ParrelError} `LE02500009` when the file is empty
24
+ * @throws {ParrelError} `LE02500010` when the file is larger than 50 MB (52428800 bytes)
25
+ * @throws {ParrelError} `LE02500007` when the extension is not one of jpg, jpeg, png, gif, webp, svg, mp4, webm, mov,
26
+ * pdf, doc, docx or txt
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * import { assertLedgerMediaFile } from "@parrel/ledger";
31
+ *
32
+ * const file = input.files[0];
33
+ * assertLedgerMediaFile(file); // throws before anything is sent
34
+ * await ledgerClient.homepage.heroImage.setMedia(file);
35
+ * ```
36
+ */
37
+ export declare function assertLedgerMediaFile(file: {
38
+ name: string;
39
+ size: number;
40
+ }): void;
41
+ //# sourceMappingURL=media-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media-file.d.ts","sourceRoot":"","sources":["../../../src/cli/utils/media-file.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAEzD,oEAAoE;AACpE,eAAO,MAAM,sBAAsB,WAAa,CAAC;AAEjD,6FAA6F;AAC7F,eAAO,MAAM,uBAAuB,EAAE,SAAS,MAAM,EAcpD,CAAC;AAEF,sGAAsG;AACtG,wBAAgB,sBAAsB,CAAC,IAAI,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,WAAW,GAAG,IAAI,CAsBhG;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAKhF"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Media file check: the pre-check before a media upload (rulebook LED-10)
3
+ *
4
+ * Ledger refuses an empty file, a file whose extension is not on the list and a file over 50 MB. The package checks the
5
+ * same three things before it sends the file, so a visitor gets the answer at once and the upload is never sent.
6
+ * Ledger still decides: it also checks the content type, and it may accept less than the list says.
7
+ */
8
+ import { ParrelError } from "../../core/parrel-error.js";
9
+ /** The largest media file that Ledger accepts, in bytes (50 MB). */
10
+ export const LEDGER_MAX_MEDIA_BYTES = 52_428_800;
11
+ /** The extensions that Ledger accepts for a media upload, in lower case, without the dot. */
12
+ export const LEDGER_MEDIA_EXTENSIONS = [
13
+ "jpg",
14
+ "jpeg",
15
+ "png",
16
+ "gif",
17
+ "webp",
18
+ "svg",
19
+ "mp4",
20
+ "webm",
21
+ "mov",
22
+ "pdf",
23
+ "doc",
24
+ "docx",
25
+ "txt",
26
+ ];
27
+ /** The error for a file that Ledger would refuse, or `null` when the file passes the three checks. */
28
+ export function ledgerMediaFileProblem(file) {
29
+ if (file.size === 0) {
30
+ return new ParrelError("LE02500009", "The file is empty. Choose a file that has content.", {
31
+ status: 400,
32
+ codeName: "MEDIA_FILE_EMPTY",
33
+ });
34
+ }
35
+ if (file.size > LEDGER_MAX_MEDIA_BYTES) {
36
+ return new ParrelError("LE02500010", "The file is larger than 50 MB. Choose a smaller file.", {
37
+ status: 400,
38
+ codeName: "MEDIA_FILE_TOO_LARGE",
39
+ });
40
+ }
41
+ const extension = /\.([^./\\]+)$/.exec(file.name ?? "")?.[1]?.toLowerCase();
42
+ if (!extension || !LEDGER_MEDIA_EXTENSIONS.includes(extension)) {
43
+ return new ParrelError("LE02500007", `This file type is not allowed. Allowed types: ${LEDGER_MEDIA_EXTENSIONS.join(", ")}.`, { status: 400, codeName: "MEDIA_FILE_EXTENSION_NOT_ALLOWED" });
44
+ }
45
+ return null;
46
+ }
47
+ /**
48
+ * Checks a file before it is uploaded as media. The service still decides: this only gives the same answer sooner,
49
+ * with the same codes.
50
+ *
51
+ * @param file - The file to check: its name and its size in bytes.
52
+ * @throws {ParrelError} `LE02500009` when the file is empty
53
+ * @throws {ParrelError} `LE02500010` when the file is larger than 50 MB (52428800 bytes)
54
+ * @throws {ParrelError} `LE02500007` when the extension is not one of jpg, jpeg, png, gif, webp, svg, mp4, webm, mov,
55
+ * pdf, doc, docx or txt
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * import { assertLedgerMediaFile } from "@parrel/ledger";
60
+ *
61
+ * const file = input.files[0];
62
+ * assertLedgerMediaFile(file); // throws before anything is sent
63
+ * await ledgerClient.homepage.heroImage.setMedia(file);
64
+ * ```
65
+ */
66
+ export function assertLedgerMediaFile(file) {
67
+ const problem = ledgerMediaFileProblem(file);
68
+ if (problem) {
69
+ throw problem;
70
+ }
71
+ }
72
+ //# sourceMappingURL=media-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media-file.js","sourceRoot":"","sources":["../../../src/cli/utils/media-file.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAEzD,oEAAoE;AACpE,MAAM,CAAC,MAAM,sBAAsB,GAAG,UAAU,CAAC;AAEjD,6FAA6F;AAC7F,MAAM,CAAC,MAAM,uBAAuB,GAAsB;IACzD,KAAK;IACL,MAAM;IACN,KAAK;IACL,KAAK;IACL,MAAM;IACN,KAAK;IACL,KAAK;IACL,MAAM;IACN,KAAK;IACL,KAAK;IACL,KAAK;IACL,MAAM;IACN,KAAK;CACL,CAAC;AAEF,sGAAsG;AACtG,MAAM,UAAU,sBAAsB,CAAC,IAAqC;IAC3E,IAAI,IAAI,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;QACrB,OAAO,IAAI,WAAW,CAAC,YAAY,EAAE,oDAAoD,EAAE;YAC1F,MAAM,EAAE,GAAG;YACX,QAAQ,EAAE,kBAAkB;SAC5B,CAAC,CAAC;IACJ,CAAC;IACD,IAAI,IAAI,CAAC,IAAI,GAAG,sBAAsB,EAAE,CAAC;QACxC,OAAO,IAAI,WAAW,CAAC,YAAY,EAAE,uDAAuD,EAAE;YAC7F,MAAM,EAAE,GAAG;YACX,QAAQ,EAAE,sBAAsB;SAChC,CAAC,CAAC;IACJ,CAAC;IACD,MAAM,SAAS,GAAG,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC;IAC5E,IAAI,CAAC,SAAS,IAAI,CAAC,uBAAuB,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;QAChE,OAAO,IAAI,WAAW,CACrB,YAAY,EACZ,iDAAiD,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EACtF,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,kCAAkC,EAAE,CAC7D,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAoC;IACzE,MAAM,OAAO,GAAG,sBAAsB,CAAC,IAAI,CAAC,CAAC;IAC7C,IAAI,OAAO,EAAE,CAAC;QACb,MAAM,OAAO,CAAC;IACf,CAAC;AACF,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Media Validator - Validates media file references in mock data
3
+ */
4
+ import type { LedgerMapSchema } from "../../core/types.js";
5
+ /**
6
+ * Validate all media file references in content
7
+ * Returns errors if files are missing
8
+ */
9
+ export declare function validateMediaFilesExist(mockData: Record<string, unknown>, schemaMap: Map<string, LedgerMapSchema>, mediaDir: string): string[];
10
+ //# sourceMappingURL=media-validator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media-validator.d.ts","sourceRoot":"","sources":["../../../src/cli/utils/media-validator.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAG3D;;;GAGG;AACH,wBAAgB,uBAAuB,CACtC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,EACvC,QAAQ,EAAE,MAAM,GACd,MAAM,EAAE,CAyBV"}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Media Validator - Validates media file references in mock data
3
+ */
4
+ import { readdirSync } from "node:fs";
5
+ import { getMapFields } from "./map-fields.js";
6
+ /**
7
+ * Validate all media file references in content
8
+ * Returns errors if files are missing
9
+ */
10
+ export function validateMediaFilesExist(mockData, schemaMap, mediaDir) {
11
+ const errors = [];
12
+ // Get list of media files
13
+ let mediaFiles;
14
+ try {
15
+ const files = readdirSync(mediaDir);
16
+ mediaFiles = new Set(files);
17
+ }
18
+ catch {
19
+ // mediaDir might not exist yet
20
+ mediaFiles = new Set();
21
+ }
22
+ // Validate each resource
23
+ for (const [resourceName, resourceData] of Object.entries(mockData)) {
24
+ const schema = schemaMap.get(resourceName);
25
+ if (!schema) {
26
+ continue; // Resource not in schema
27
+ }
28
+ const resourceErrors = validateResourceMediaFiles(resourceData, schema, resourceName, mediaFiles);
29
+ errors.push(...resourceErrors);
30
+ }
31
+ return errors;
32
+ }
33
+ /**
34
+ * Validate media files for a single resource
35
+ */
36
+ function validateResourceMediaFiles(resourceData, schema, resourcePath, mediaFiles) {
37
+ const errors = [];
38
+ if (!resourceData || typeof resourceData !== "object") {
39
+ return errors;
40
+ }
41
+ const dataObj = resourceData;
42
+ for (const [fieldName, fieldDef] of Object.entries(getMapFields(schema))) {
43
+ const fieldValue = dataObj[fieldName];
44
+ const fieldPath = `${resourcePath}.${fieldName}`;
45
+ const fieldErrors = validateFieldMediaFiles(fieldValue, fieldDef, fieldPath, mediaFiles);
46
+ errors.push(...fieldErrors);
47
+ }
48
+ return errors;
49
+ }
50
+ /**
51
+ * Validate media files in a field (handles nested structures)
52
+ */
53
+ function validateFieldMediaFiles(value, fieldDef, fieldPath, mediaFiles) {
54
+ const errors = [];
55
+ if (value === null || value === undefined) {
56
+ return errors;
57
+ }
58
+ if (fieldDef.type === "media" || fieldDef.type === "media-reference") {
59
+ // Check if file exists
60
+ if (value && typeof value === "object") {
61
+ const obj = value;
62
+ const filename = obj.file;
63
+ if (filename && !mediaFiles.has(filename)) {
64
+ errors.push(`[parrel] Missing media file: ${fieldPath}.file = "${filename}"`);
65
+ }
66
+ }
67
+ }
68
+ else if (fieldDef.type === "array" && fieldDef.items && Array.isArray(value)) {
69
+ // Validate array items
70
+ value.forEach((item, idx) => {
71
+ const itemErrors = validateFieldMediaFiles(item, fieldDef.items, `${fieldPath}[${idx}]`, mediaFiles);
72
+ errors.push(...itemErrors);
73
+ });
74
+ }
75
+ else if (fieldDef.type === "object" && fieldDef.fields && typeof value === "object") {
76
+ // Validate nested object fields
77
+ const objValue = value;
78
+ for (const [nestedFieldName, nestedFieldDef] of Object.entries(fieldDef.fields)) {
79
+ const nestedErrors = validateFieldMediaFiles(objValue[nestedFieldName], nestedFieldDef, `${fieldPath}.${nestedFieldName}`, mediaFiles);
80
+ errors.push(...nestedErrors);
81
+ }
82
+ }
83
+ return errors;
84
+ }
85
+ //# sourceMappingURL=media-validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media-validator.js","sourceRoot":"","sources":["../../../src/cli/utils/media-validator.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGtC,OAAO,EAAE,Y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G,uBAAuB,CAAC,IAAI,EAAE,QAAQ,CAAC,KAAM,EAAE,GAAG,SAAS,IAAI,GAAG,GAAG,EAAE,UAAU,CAAC,CAAC;YACtG,MAAM,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;IACJ,CAAC;SAAM,IAAI,QAAQ,CAAC,IAAI,KAAK,QAAQ,IAAI,QAAQ,CAAC,MAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACvF,gCAAgC;QAChC,MAAM,QAAQ,GAAG,KAAgC,CAAC;QAClD,KAAK,MAAM,CAAC,eAAe,EAAE,cAAc,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACjF,MAAM,YAAY,GAAG,uBAAuB,CAC3C,QAAQ,CAAC,eAAe,CAAC,EACzB,cAAc,EACd,GAAG,SAAS,IAAI,eAAe,EAAE,EACjC,UAAU,CACV,CAAC;YACF,MAAM,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,CAAC;QAC9B,CAAC;IACF,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Mock Augmenter - Adds missing keys to mock.json based on schemas
3
+ */
4
+ import type { LedgerMapSchema } from "../../core/types.js";
5
+ export interface AugmentationResult {
6
+ added: string[];
7
+ modified: boolean;
8
+ }
9
+ /**
10
+ * Merge schema defaults into existing data
11
+ * Only adds missing keys, never removes or overwrites existing values
12
+ */
13
+ export declare function augmentMockData(mockData: Record<string, unknown>, schema: LedgerMapSchema, prefix?: string): AugmentationResult;
14
+ /**
15
+ * Augment all resources in mock data based on schemas
16
+ * Returns list of all added keys
17
+ */
18
+ export declare function augmentAllMockData(mockData: Record<string, unknown>, schemas: Map<string, LedgerMapSchema>): AugmentationResult;
19
+ //# sourceMappingURL=mock-augmenter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock-augmenter.d.ts","sourceRoot":"","sources":["../../../src/cli/utils/mock-augmenter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAyB,MAAM,qBAAqB,CAAC;AAGlF,MAAM,WAAW,kBAAkB;IAClC,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;CAClB;AA6CD;;;GAGG;AACH,wBAAgB,eAAe,CAC9B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,MAAM,EAAE,eAAe,EACvB,MAAM,SAAK,GACT,kBAAkB,CA6BpB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CACjC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,GACnC,kBAAkB,CA6BpB"}