@nuasite/cms-core 0.64.3 → 0.65.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 (187) hide show
  1. package/dist/asset-paths.d.ts.map +1 -0
  2. package/dist/asset-paths.js +55 -0
  3. package/dist/astro-source-analysis.d.ts.map +1 -0
  4. package/dist/astro-source-analysis.js +503 -0
  5. package/dist/byte-range.d.ts.map +1 -0
  6. package/dist/byte-range.js +31 -0
  7. package/dist/{types/check-entries.d.ts → check-entries.d.ts} +3 -3
  8. package/dist/check-entries.d.ts.map +1 -0
  9. package/dist/check-entries.js +98 -0
  10. package/dist/{types/check-live.d.ts → check-live.d.ts} +4 -4
  11. package/dist/check-live.d.ts.map +1 -0
  12. package/dist/check-live.js +49 -0
  13. package/dist/{types/check-shape.d.ts → check-shape.d.ts} +4 -4
  14. package/dist/check-shape.d.ts.map +1 -0
  15. package/dist/check-shape.js +119 -0
  16. package/dist/{types/check-write.d.ts → check-write.d.ts} +4 -4
  17. package/dist/check-write.d.ts.map +1 -0
  18. package/dist/check-write.js +273 -0
  19. package/dist/{types/check.d.ts → check.d.ts} +2 -2
  20. package/dist/check.d.ts.map +1 -0
  21. package/dist/check.js +366 -0
  22. package/dist/{types/collection-scanner.d.ts → collection-scanner.d.ts} +2 -2
  23. package/dist/collection-scanner.d.ts.map +1 -0
  24. package/dist/collection-scanner.js +1483 -0
  25. package/dist/{types/component-registry.d.ts → component-registry.d.ts} +1 -1
  26. package/dist/component-registry.d.ts.map +1 -0
  27. package/dist/component-registry.js +271 -0
  28. package/dist/{types/content-config-ast.d.ts → content-config-ast.d.ts} +1 -1
  29. package/dist/content-config-ast.d.ts.map +1 -0
  30. package/dist/content-config-ast.js +1614 -0
  31. package/dist/{types/core.d.ts → core.d.ts} +3 -3
  32. package/dist/core.d.ts.map +1 -0
  33. package/dist/core.js +94 -0
  34. package/dist/editor-write-model.d.ts.map +1 -0
  35. package/dist/editor-write-model.js +101 -0
  36. package/dist/fs/glob.d.ts.map +1 -0
  37. package/dist/fs/glob.js +79 -0
  38. package/dist/{types/fs → fs}/node-fs.d.ts +1 -1
  39. package/dist/fs/node-fs.d.ts.map +1 -0
  40. package/dist/fs/node-fs.js +199 -0
  41. package/dist/{types/fs → fs}/staged.d.ts +1 -1
  42. package/dist/fs/staged.d.ts.map +1 -0
  43. package/dist/fs/staged.js +203 -0
  44. package/dist/fs/types.d.ts.map +1 -0
  45. package/dist/fs/types.js +0 -0
  46. package/dist/{types/handlers → handlers}/entry-ops.d.ts +2 -2
  47. package/dist/handlers/entry-ops.d.ts.map +1 -0
  48. package/dist/handlers/entry-ops.js +846 -0
  49. package/dist/{types/handlers → handlers}/page-ops.d.ts +1 -1
  50. package/dist/handlers/page-ops.d.ts.map +1 -0
  51. package/dist/handlers/page-ops.js +165 -0
  52. package/dist/{types/handlers → handlers}/redirect-ops.d.ts +1 -1
  53. package/dist/handlers/redirect-ops.d.ts.map +1 -0
  54. package/dist/handlers/redirect-ops.js +111 -0
  55. package/dist/index.d.ts +5 -0
  56. package/dist/index.d.ts.map +1 -0
  57. package/dist/index.js +4 -0
  58. package/dist/media/contember.d.ts.map +1 -0
  59. package/dist/media/contember.js +79 -0
  60. package/dist/media/errors.d.ts.map +1 -0
  61. package/dist/media/errors.js +22 -0
  62. package/dist/{types/media → media}/file-system.d.ts +1 -1
  63. package/dist/media/file-system.d.ts.map +1 -0
  64. package/dist/media/file-system.js +124 -0
  65. package/dist/{types/media → media}/index.d.ts +8 -8
  66. package/dist/media/index.d.ts.map +1 -0
  67. package/dist/media/index.js +8 -0
  68. package/dist/media/local.d.ts.map +1 -0
  69. package/dist/media/local.js +209 -0
  70. package/dist/media/mime.d.ts.map +1 -0
  71. package/dist/media/mime.js +21 -0
  72. package/dist/media/names.d.ts.map +1 -0
  73. package/dist/media/names.js +23 -0
  74. package/dist/{types/media → media}/project-images.d.ts +1 -1
  75. package/dist/media/project-images.d.ts.map +1 -0
  76. package/dist/media/project-images.js +99 -0
  77. package/dist/media/s3.d.ts.map +1 -0
  78. package/dist/media/s3.js +160 -0
  79. package/dist/media/type-filter.d.ts.map +1 -0
  80. package/dist/media/type-filter.js +164 -0
  81. package/dist/{types/portable.d.ts → portable.d.ts} +25 -25
  82. package/dist/portable.d.ts.map +1 -0
  83. package/dist/portable.js +27 -0
  84. package/dist/{types/project-config-ast.d.ts → project-config-ast.d.ts} +1 -1
  85. package/dist/project-config-ast.d.ts.map +1 -0
  86. package/dist/project-config-ast.js +324 -0
  87. package/dist/public-static-file.d.ts.map +1 -0
  88. package/dist/public-static-file.js +40 -0
  89. package/dist/redirects.d.ts.map +1 -0
  90. package/dist/redirects.js +185 -0
  91. package/dist/route-scan.d.ts.map +1 -0
  92. package/dist/route-scan.js +23 -0
  93. package/dist/schema-port.d.ts.map +1 -0
  94. package/dist/schema-port.js +30 -0
  95. package/dist/{types/schema-probe.d.ts → schema-probe.d.ts} +2 -2
  96. package/dist/schema-probe.d.ts.map +1 -0
  97. package/dist/schema-probe.js +119 -0
  98. package/dist/shared.d.ts.map +1 -0
  99. package/dist/shared.js +163 -0
  100. package/dist/tsconfig.tsbuildinfo +1 -0
  101. package/package.json +12 -12
  102. package/src/check-entries.ts +4 -4
  103. package/src/check-live.ts +4 -4
  104. package/src/check-shape.ts +5 -5
  105. package/src/check-write.ts +6 -6
  106. package/src/check.ts +15 -9
  107. package/src/collection-scanner.ts +3 -3
  108. package/src/component-registry.ts +1 -1
  109. package/src/content-config-ast.ts +1 -1
  110. package/src/core.ts +8 -8
  111. package/src/editor-write-model.ts +1 -1
  112. package/src/fs/node-fs.ts +2 -2
  113. package/src/fs/staged.ts +6 -3
  114. package/src/handlers/entry-ops.ts +7 -7
  115. package/src/handlers/page-ops.ts +2 -2
  116. package/src/handlers/redirect-ops.ts +2 -2
  117. package/src/index.ts +4 -4
  118. package/src/media/contember.ts +1 -1
  119. package/src/media/file-system.ts +4 -4
  120. package/src/media/index.ts +8 -8
  121. package/src/media/local.ts +3 -3
  122. package/src/media/project-images.ts +2 -2
  123. package/src/media/s3.ts +3 -3
  124. package/src/portable.ts +25 -25
  125. package/src/project-config-ast.ts +1 -1
  126. package/src/route-scan.ts +1 -1
  127. package/src/schema-probe.ts +2 -2
  128. package/src/tsconfig.json +5 -1
  129. package/dist/types/asset-paths.d.ts.map +0 -1
  130. package/dist/types/astro-source-analysis.d.ts.map +0 -1
  131. package/dist/types/byte-range.d.ts.map +0 -1
  132. package/dist/types/check-entries.d.ts.map +0 -1
  133. package/dist/types/check-live.d.ts.map +0 -1
  134. package/dist/types/check-shape.d.ts.map +0 -1
  135. package/dist/types/check-write.d.ts.map +0 -1
  136. package/dist/types/check.d.ts.map +0 -1
  137. package/dist/types/collection-scanner.d.ts.map +0 -1
  138. package/dist/types/component-registry.d.ts.map +0 -1
  139. package/dist/types/content-config-ast.d.ts.map +0 -1
  140. package/dist/types/core.d.ts.map +0 -1
  141. package/dist/types/editor-write-model.d.ts.map +0 -1
  142. package/dist/types/fs/glob.d.ts.map +0 -1
  143. package/dist/types/fs/node-fs.d.ts.map +0 -1
  144. package/dist/types/fs/staged.d.ts.map +0 -1
  145. package/dist/types/fs/types.d.ts.map +0 -1
  146. package/dist/types/handlers/entry-ops.d.ts.map +0 -1
  147. package/dist/types/handlers/page-ops.d.ts.map +0 -1
  148. package/dist/types/handlers/redirect-ops.d.ts.map +0 -1
  149. package/dist/types/index.d.ts +0 -5
  150. package/dist/types/index.d.ts.map +0 -1
  151. package/dist/types/media/contember.d.ts.map +0 -1
  152. package/dist/types/media/errors.d.ts.map +0 -1
  153. package/dist/types/media/file-system.d.ts.map +0 -1
  154. package/dist/types/media/index.d.ts.map +0 -1
  155. package/dist/types/media/local.d.ts.map +0 -1
  156. package/dist/types/media/mime.d.ts.map +0 -1
  157. package/dist/types/media/names.d.ts.map +0 -1
  158. package/dist/types/media/project-images.d.ts.map +0 -1
  159. package/dist/types/media/s3.d.ts.map +0 -1
  160. package/dist/types/media/type-filter.d.ts.map +0 -1
  161. package/dist/types/portable.d.ts.map +0 -1
  162. package/dist/types/project-config-ast.d.ts.map +0 -1
  163. package/dist/types/public-static-file.d.ts.map +0 -1
  164. package/dist/types/redirects.d.ts.map +0 -1
  165. package/dist/types/route-scan.d.ts.map +0 -1
  166. package/dist/types/schema-port.d.ts.map +0 -1
  167. package/dist/types/schema-probe.d.ts.map +0 -1
  168. package/dist/types/shared.d.ts.map +0 -1
  169. package/dist/types/tsconfig.tsbuildinfo +0 -1
  170. /package/dist/{types/asset-paths.d.ts → asset-paths.d.ts} +0 -0
  171. /package/dist/{types/astro-source-analysis.d.ts → astro-source-analysis.d.ts} +0 -0
  172. /package/dist/{types/byte-range.d.ts → byte-range.d.ts} +0 -0
  173. /package/dist/{types/editor-write-model.d.ts → editor-write-model.d.ts} +0 -0
  174. /package/dist/{types/fs → fs}/glob.d.ts +0 -0
  175. /package/dist/{types/fs → fs}/types.d.ts +0 -0
  176. /package/dist/{types/media → media}/contember.d.ts +0 -0
  177. /package/dist/{types/media → media}/errors.d.ts +0 -0
  178. /package/dist/{types/media → media}/local.d.ts +0 -0
  179. /package/dist/{types/media → media}/mime.d.ts +0 -0
  180. /package/dist/{types/media → media}/names.d.ts +0 -0
  181. /package/dist/{types/media → media}/s3.d.ts +0 -0
  182. /package/dist/{types/media → media}/type-filter.d.ts +0 -0
  183. /package/dist/{types/public-static-file.d.ts → public-static-file.d.ts} +0 -0
  184. /package/dist/{types/redirects.d.ts → redirects.d.ts} +0 -0
  185. /package/dist/{types/route-scan.d.ts → route-scan.d.ts} +0 -0
  186. /package/dist/{types/schema-port.d.ts → schema-port.d.ts} +0 -0
  187. /package/dist/{types/shared.d.ts → shared.d.ts} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asset-paths.d.ts","sourceRoot":"","sources":["../src/asset-paths.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,qFAAqF;AACrF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGjD;AAED,0FAA0F;AAC1F,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAY5E;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CASzF"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Where an asset value in frontmatter points on disk.
3
+ *
4
+ * Extracted from the entry read path so the content check resolves an image the
5
+ * same way serving it does — two implementations would disagree the moment one
6
+ * of the shapes below changes, and the check would then report missing files
7
+ * that the CMS happily serves.
8
+ */
9
+ /** The directory a relative asset value in `file`'s frontmatter resolves against. */
10
+ export function assetBaseDir(file) {
11
+ const lastSlash = file.lastIndexOf('/');
12
+ return lastSlash >= 0 ? file.slice(0, lastSlash) : '';
13
+ }
14
+ /** Join `rel` onto `base` segments, applying `.`/`..`; `null` on traversal above root. */
15
+ export function normalizeSegments(base, rel) {
16
+ const out = base.slice();
17
+ for (const seg of rel.replace(/^\/+/, '').split('/')) {
18
+ if (seg === '' || seg === '.')
19
+ continue;
20
+ if (seg === '..') {
21
+ if (out.length === 0)
22
+ return null;
23
+ out.pop();
24
+ continue;
25
+ }
26
+ out.push(seg);
27
+ }
28
+ return out.join('/');
29
+ }
30
+ /**
31
+ * Resolve a stored asset value (as it appears in frontmatter) to candidate on-disk
32
+ * paths, root-relative, in priority order. Handles the shapes that actually occur:
33
+ *
34
+ * - **Leading `/`** — a runtime URL (`/assets/x.jpeg`, `/uploads/x.webp`). Astro
35
+ * serves the `public/` dir at the site root, so try `public/<path>` first, then
36
+ * `<path>` from the project root (assets kept outside `public/`). `baseDir` is
37
+ * irrelevant, so these resolve without an owning entry.
38
+ * - **Relative** (`../../src/assets/x.webp`, `./x.png`, `x.png`) — an Astro
39
+ * `image()` value, resolved against `baseDir` (the entry's directory), honoring
40
+ * `.`/`..`.
41
+ *
42
+ * Returns `[]` when the path climbs above the project root, or is relative with no `baseDir`.
43
+ */
44
+ export function resolveAssetCandidates(baseDir, rel) {
45
+ if (rel.startsWith('/')) {
46
+ const fromRoot = normalizeSegments([], rel);
47
+ if (fromRoot === null || fromRoot === '')
48
+ return [];
49
+ return [`public/${fromRoot}`, fromRoot];
50
+ }
51
+ if (baseDir === undefined)
52
+ return [];
53
+ const joined = normalizeSegments(baseDir.split('/').filter(Boolean), rel);
54
+ return joined === null ? [] : [joined];
55
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astro-source-analysis.d.ts","sourceRoot":"","sources":["../src/astro-source-analysis.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,CAAC,MAAM,cAAc,CAAA;AAEtC,MAAM,MAAM,oBAAoB,GAAG,eAAe,GAAG,UAAU,GAAG,gBAAgB,GAAG,YAAY,CAAA;AAEjG,MAAM,WAAW,iBAAiB;IACjC,MAAM,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,gBAAgB;IAChC,QAAQ,EAAE,oBAAoB,CAAA;IAC9B,cAAc,EAAE,MAAM,GAAG,IAAI,CAAA;IAC7B,wBAAwB,EAAE,OAAO,CAAA;CACjC;AAED,MAAM,WAAW,sBAAsB;IACtC,SAAS,EAAE,MAAM,CAAA;IACjB,cAAc,EAAE,MAAM,CAAA;IACtB,oFAAoF;IACpF,QAAQ,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,mBAAmB;IACnC,OAAO,EAAE,iBAAiB,EAAE,CAAA;IAC5B,eAAe,EAAE,gBAAgB,EAAE,CAAA;IACnC,kBAAkB,EAAE,sBAAsB,EAAE,CAAA;CAC5C;AAqgBD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,GAAG,mBAAmB,CAG/E;AAED,oEAAoE;AACpE,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,mBAAmB,CAKtE"}
@@ -0,0 +1,503 @@
1
+ import { parse as parseBabel } from '@babel/parser';
2
+ const FUNCTION_NODE_TYPES = new Set([
3
+ 'ArrowFunctionExpression',
4
+ 'FunctionDeclaration',
5
+ 'FunctionExpression',
6
+ 'ObjectMethod',
7
+ 'ClassMethod',
8
+ 'ClassPrivateMethod',
9
+ ]);
10
+ const SKIPPED_CHILD_KEYS = new Set([
11
+ 'loc',
12
+ 'start',
13
+ 'end',
14
+ 'range',
15
+ 'leadingComments',
16
+ 'trailingComments',
17
+ 'innerComments',
18
+ 'extra',
19
+ 'errors',
20
+ ]);
21
+ function isContentAccessor(value) {
22
+ return value === 'getCollection'
23
+ || value === 'getEntry'
24
+ || value === 'getEntryBySlug'
25
+ || value === 'getEntries';
26
+ }
27
+ function isNode(value) {
28
+ return typeof value === 'object' && value !== null && typeof Reflect.get(value, 'type') === 'string';
29
+ }
30
+ function childNodes(node) {
31
+ const children = [];
32
+ for (const key of Object.keys(node)) {
33
+ if (SKIPPED_CHILD_KEYS.has(key))
34
+ continue;
35
+ const value = Reflect.get(node, key);
36
+ if (isNode(value)) {
37
+ children.push(value);
38
+ }
39
+ else if (Array.isArray(value)) {
40
+ for (const item of value) {
41
+ if (isNode(item))
42
+ children.push(item);
43
+ }
44
+ }
45
+ }
46
+ return children;
47
+ }
48
+ /** Matches the opening fence: an optional BOM, any leading whitespace, `---`, then the end of that line. */
49
+ const OPENING_FENCE = /^?\s*---[ \t]*\r?\n/;
50
+ /**
51
+ * Extract the frontmatter of an Astro component.
52
+ *
53
+ * Mirrors `@astrojs/compiler` on the fences it accepts: blank lines or indentation before the
54
+ * opening `---`, and spaces or tabs around either fence. Anything other than whitespace before
55
+ * the opening fence means there is no frontmatter to read.
56
+ */
57
+ function extractAstroFrontmatter(source) {
58
+ const opening = OPENING_FENCE.exec(source);
59
+ if (!opening)
60
+ return null;
61
+ const codeStart = opening[0].length;
62
+ let lineStart = codeStart;
63
+ while (lineStart <= source.length) {
64
+ const newline = source.indexOf('\n', lineStart);
65
+ const lineEnd = newline === -1 ? source.length : newline;
66
+ if (source.slice(lineStart, lineEnd).trim() === '---') {
67
+ let codeEnd = lineStart;
68
+ if (codeEnd > codeStart && source.charCodeAt(codeEnd - 1) === 10) {
69
+ codeEnd--;
70
+ if (codeEnd > codeStart && source.charCodeAt(codeEnd - 1) === 13)
71
+ codeEnd--;
72
+ }
73
+ return source.slice(codeStart, codeEnd);
74
+ }
75
+ if (newline === -1)
76
+ return null;
77
+ lineStart = newline + 1;
78
+ }
79
+ return null;
80
+ }
81
+ function parseScript(source) {
82
+ try {
83
+ return parseBabel(source, {
84
+ sourceType: 'module',
85
+ plugins: ['typescript', 'jsx'],
86
+ errorRecovery: true,
87
+ });
88
+ }
89
+ catch {
90
+ return null;
91
+ }
92
+ }
93
+ function importedName(specifier) {
94
+ return specifier.imported.type === 'Identifier' ? specifier.imported.name : specifier.imported.value;
95
+ }
96
+ function importFacts(ast) {
97
+ return ast.program.body.flatMap(statement => statement.type === 'ImportDeclaration' ? [{ source: statement.source.value }] : []);
98
+ }
99
+ function contentImportBindings(ast) {
100
+ const named = new Map();
101
+ const namespaces = new Set();
102
+ for (const statement of ast.program.body) {
103
+ if (statement.type !== 'ImportDeclaration'
104
+ || statement.source.value !== 'astro:content'
105
+ || statement.importKind === 'type'
106
+ || statement.importKind === 'typeof')
107
+ continue;
108
+ for (const specifier of statement.specifiers) {
109
+ if (specifier.type === 'ImportNamespaceSpecifier')
110
+ namespaces.add(specifier.local.name);
111
+ if (specifier.type === 'ImportSpecifier'
112
+ && specifier.importKind !== 'type'
113
+ && specifier.importKind !== 'typeof') {
114
+ const name = importedName(specifier);
115
+ if (isContentAccessor(name))
116
+ named.set(specifier.local.name, name);
117
+ }
118
+ }
119
+ }
120
+ return { named, namespaces };
121
+ }
122
+ function addPatternNames(pattern, names) {
123
+ if (!pattern)
124
+ return;
125
+ switch (pattern.type) {
126
+ case 'Identifier':
127
+ names.add(pattern.name);
128
+ return;
129
+ case 'ObjectPattern':
130
+ for (const property of pattern.properties) {
131
+ if (property.type === 'RestElement')
132
+ addPatternNames(property.argument, names);
133
+ else
134
+ addPatternNames(property.value, names);
135
+ }
136
+ return;
137
+ case 'ArrayPattern':
138
+ for (const element of pattern.elements)
139
+ addPatternNames(element, names);
140
+ return;
141
+ case 'AssignmentPattern':
142
+ addPatternNames(pattern.left, names);
143
+ return;
144
+ case 'RestElement':
145
+ addPatternNames(pattern.argument, names);
146
+ return;
147
+ case 'TSParameterProperty':
148
+ addPatternNames(pattern.parameter, names);
149
+ return;
150
+ }
151
+ }
152
+ function declarationFromStatement(statement) {
153
+ if (statement.type === 'VariableDeclaration' || statement.type === 'FunctionDeclaration' || statement.type === 'ClassDeclaration') {
154
+ return statement;
155
+ }
156
+ if (statement.type !== 'ExportNamedDeclaration' && statement.type !== 'ExportDefaultDeclaration')
157
+ return null;
158
+ const declaration = statement.declaration;
159
+ return declaration?.type === 'VariableDeclaration'
160
+ || declaration?.type === 'FunctionDeclaration'
161
+ || declaration?.type === 'ClassDeclaration'
162
+ ? declaration
163
+ : null;
164
+ }
165
+ function addDirectLexicalNames(statements, names, includeVar) {
166
+ for (const statement of statements) {
167
+ const declaration = declarationFromStatement(statement);
168
+ if (!declaration)
169
+ continue;
170
+ if (declaration.type === 'VariableDeclaration') {
171
+ if (!includeVar && declaration.kind === 'var')
172
+ continue;
173
+ for (const declarator of declaration.declarations)
174
+ addPatternNames(declarator.id, names);
175
+ }
176
+ else if ((declaration.type === 'FunctionDeclaration' || declaration.type === 'ClassDeclaration')
177
+ && declaration.id) {
178
+ names.add(declaration.id.name);
179
+ }
180
+ }
181
+ }
182
+ function addVarNames(node, names, root = true) {
183
+ if (!root && FUNCTION_NODE_TYPES.has(node.type))
184
+ return;
185
+ if (node.type === 'VariableDeclaration' && node.kind === 'var') {
186
+ for (const declarator of node.declarations)
187
+ addPatternNames(declarator.id, names);
188
+ }
189
+ for (const child of childNodes(node))
190
+ addVarNames(child, names, false);
191
+ }
192
+ function functionScopeNames(node) {
193
+ const names = new Set();
194
+ switch (node.type) {
195
+ case 'ArrowFunctionExpression':
196
+ case 'FunctionExpression':
197
+ case 'FunctionDeclaration':
198
+ case 'ObjectMethod':
199
+ case 'ClassMethod':
200
+ case 'ClassPrivateMethod':
201
+ for (const parameter of node.params)
202
+ addPatternNames(parameter, names);
203
+ if ((node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration') && node.id) {
204
+ names.add(node.id.name);
205
+ }
206
+ addVarNames(node.body, names);
207
+ return names;
208
+ default:
209
+ return null;
210
+ }
211
+ }
212
+ function withNames(base, additions) {
213
+ if (additions.size === 0)
214
+ return base;
215
+ return new Set([...base, ...additions]);
216
+ }
217
+ function topLevelShadowedNames(ast, importedLocals) {
218
+ const declared = new Set();
219
+ addDirectLexicalNames(ast.program.body, declared, true);
220
+ addVarNames(ast.program, declared);
221
+ for (const imported of importedLocals)
222
+ declared.delete(imported);
223
+ return declared;
224
+ }
225
+ function exportedName(specifier) {
226
+ return specifier.exported.type === 'Identifier' ? specifier.exported.name : specifier.exported.value;
227
+ }
228
+ function unwrapExpression(node) {
229
+ let current = node;
230
+ while (current.type === 'AwaitExpression'
231
+ || current.type === 'TSAsExpression'
232
+ || current.type === 'TSSatisfiesExpression'
233
+ || current.type === 'TSTypeAssertion'
234
+ || current.type === 'TSNonNullExpression'
235
+ || current.type === 'ParenthesizedExpression'
236
+ || current.type === 'TypeCastExpression') {
237
+ current = current.type === 'AwaitExpression' ? current.argument : current.expression;
238
+ }
239
+ return current;
240
+ }
241
+ function topLevelValueNodes(ast) {
242
+ const values = new Map();
243
+ for (const statement of ast.program.body) {
244
+ const declaration = declarationFromStatement(statement);
245
+ if (!declaration)
246
+ continue;
247
+ if (declaration.type === 'FunctionDeclaration' && declaration.id) {
248
+ values.set(declaration.id.name, declaration);
249
+ }
250
+ else if (declaration.type === 'VariableDeclaration') {
251
+ for (const declarator of declaration.declarations) {
252
+ if (declarator.id.type === 'Identifier' && declarator.init) {
253
+ values.set(declarator.id.name, unwrapExpression(declarator.init));
254
+ }
255
+ }
256
+ }
257
+ }
258
+ return values;
259
+ }
260
+ function exportedGetStaticPathsNodes(ast) {
261
+ const exportedLocals = new Set();
262
+ for (const statement of ast.program.body) {
263
+ if (statement.type !== 'ExportNamedDeclaration')
264
+ continue;
265
+ const declaration = statement.declaration;
266
+ if (declaration?.type === 'FunctionDeclaration' && declaration.id?.name === 'getStaticPaths') {
267
+ exportedLocals.add('getStaticPaths');
268
+ }
269
+ else if (declaration?.type === 'VariableDeclaration') {
270
+ for (const declarator of declaration.declarations) {
271
+ if (declarator.id.type === 'Identifier' && declarator.id.name === 'getStaticPaths') {
272
+ exportedLocals.add('getStaticPaths');
273
+ }
274
+ }
275
+ }
276
+ if (statement.source)
277
+ continue;
278
+ for (const specifier of statement.specifiers) {
279
+ if (specifier.type === 'ExportSpecifier' && exportedName(specifier) === 'getStaticPaths') {
280
+ exportedLocals.add(specifier.local.name);
281
+ }
282
+ }
283
+ }
284
+ const values = topLevelValueNodes(ast);
285
+ const nodes = new Set();
286
+ for (const local of exportedLocals) {
287
+ const node = values.get(local);
288
+ if (node && FUNCTION_NODE_TYPES.has(node.type))
289
+ nodes.add(node);
290
+ }
291
+ return nodes;
292
+ }
293
+ function staticString(node) {
294
+ if (!node)
295
+ return null;
296
+ const value = unwrapExpression(node);
297
+ if (value.type === 'StringLiteral')
298
+ return value.value;
299
+ if (value.type === 'TemplateLiteral' && value.expressions.length === 0 && value.quasis.length === 1) {
300
+ return value.quasis[0]?.value.cooked ?? value.quasis[0]?.value.raw ?? null;
301
+ }
302
+ return null;
303
+ }
304
+ function memberPropertyName(node) {
305
+ if (!node.computed && node.property.type === 'Identifier')
306
+ return node.property.name;
307
+ if (node.computed && node.property.type === 'StringLiteral')
308
+ return node.property.value;
309
+ return null;
310
+ }
311
+ function callAccessor(node, named, namespaces, shadowed) {
312
+ const callee = unwrapExpression(node.callee);
313
+ if (callee.type === 'Identifier') {
314
+ if (shadowed.has(callee.name))
315
+ return null;
316
+ return named.get(callee.name) ?? null;
317
+ }
318
+ if (callee.type !== 'MemberExpression' && callee.type !== 'OptionalMemberExpression')
319
+ return null;
320
+ const object = unwrapExpression(callee.object);
321
+ if (object.type !== 'Identifier' || shadowed.has(object.name) || !namespaces.has(object.name))
322
+ return null;
323
+ const property = memberPropertyName(callee);
324
+ if (!property || !isContentAccessor(property))
325
+ return null;
326
+ return property;
327
+ }
328
+ function collectionNameFromCall(node) {
329
+ const first = node.arguments[0];
330
+ return first && first.type !== 'SpreadElement' && first.type !== 'ArgumentPlaceholder'
331
+ ? staticString(first)
332
+ : null;
333
+ }
334
+ function collectCalls(ast, named, namespaces) {
335
+ const calls = [];
336
+ const staticPathsNodes = exportedGetStaticPathsNodes(ast);
337
+ const importedLocals = new Set([...named.keys(), ...namespaces]);
338
+ const rootShadowed = topLevelShadowedNames(ast, importedLocals);
339
+ function visit(node, context) {
340
+ let shadowed = context.shadowed;
341
+ const functionNames = functionScopeNames(node);
342
+ if (functionNames)
343
+ shadowed = withNames(shadowed, functionNames);
344
+ if (node.type === 'BlockStatement') {
345
+ const blockNames = new Set();
346
+ addDirectLexicalNames(node.body, blockNames, false);
347
+ shadowed = withNames(shadowed, blockNames);
348
+ }
349
+ else if (node.type === 'CatchClause') {
350
+ const catchNames = new Set();
351
+ addPatternNames(node.param, catchNames);
352
+ shadowed = withNames(shadowed, catchNames);
353
+ }
354
+ const insideExportedGetStaticPaths = context.insideExportedGetStaticPaths || staticPathsNodes.has(node);
355
+ if (node.type === 'CallExpression' || node.type === 'OptionalCallExpression') {
356
+ const accessor = callAccessor(node, named, namespaces, shadowed);
357
+ if (accessor) {
358
+ calls.push({
359
+ accessor,
360
+ collectionName: collectionNameFromCall(node),
361
+ inExportedGetStaticPaths: insideExportedGetStaticPaths,
362
+ });
363
+ }
364
+ }
365
+ const childContext = { insideExportedGetStaticPaths, shadowed };
366
+ for (const child of childNodes(node))
367
+ visit(child, childContext);
368
+ }
369
+ const context = { insideExportedGetStaticPaths: false, shadowed: rootShadowed };
370
+ for (const statement of ast.program.body)
371
+ visit(statement, context);
372
+ return calls;
373
+ }
374
+ function expressionAccessor(node) {
375
+ const value = unwrapExpression(node);
376
+ if (value.type === 'Identifier')
377
+ return { base: value.name, path: '' };
378
+ if (value.type !== 'MemberExpression' && value.type !== 'OptionalMemberExpression')
379
+ return null;
380
+ const object = expressionAccessor(value.object);
381
+ if (!object)
382
+ return null;
383
+ if (!value.computed && value.property.type === 'Identifier') {
384
+ return { base: object.base, path: `${object.path}.${value.property.name}` };
385
+ }
386
+ if (value.computed && value.property.type === 'NumericLiteral') {
387
+ return { base: object.base, path: `${object.path}[${value.property.value}]` };
388
+ }
389
+ return null;
390
+ }
391
+ function returnedExpression(callback) {
392
+ if (callback.body.type !== 'BlockStatement')
393
+ return callback.body;
394
+ for (const statement of callback.body.body) {
395
+ if (statement.type === 'ReturnStatement' && statement.argument)
396
+ return statement.argument;
397
+ }
398
+ return null;
399
+ }
400
+ function mapBinding(node, bindings) {
401
+ const value = unwrapExpression(node);
402
+ if (value.type !== 'CallExpression' && value.type !== 'OptionalCallExpression')
403
+ return null;
404
+ const callee = unwrapExpression(value.callee);
405
+ if (callee.type !== 'MemberExpression' && callee.type !== 'OptionalMemberExpression')
406
+ return null;
407
+ if (memberPropertyName(callee) !== 'map')
408
+ return null;
409
+ const source = expressionAccessor(callee.object);
410
+ if (!source || source.path !== '')
411
+ return null;
412
+ const sourceBinding = bindings.get(source.base);
413
+ if (!sourceBinding || sourceBinding.shape !== 'array')
414
+ return null;
415
+ const callback = value.arguments[0];
416
+ if (!callback || (callback.type !== 'ArrowFunctionExpression' && callback.type !== 'FunctionExpression'))
417
+ return null;
418
+ const parameter = callback.params[0];
419
+ if (!parameter || parameter.type !== 'Identifier')
420
+ return null;
421
+ const returned = returnedExpression(callback);
422
+ if (!returned)
423
+ return null;
424
+ const projection = expressionAccessor(returned);
425
+ if (!projection || projection.base !== parameter.name)
426
+ return null;
427
+ return { ...sourceBinding, itemPath: sourceBinding.itemPath + projection.path };
428
+ }
429
+ function directCallBinding(node, named, namespaces, shadowed) {
430
+ const value = unwrapExpression(node);
431
+ if (value.type !== 'CallExpression' && value.type !== 'OptionalCallExpression')
432
+ return null;
433
+ const matched = callAccessor(value, named, namespaces, shadowed);
434
+ const collectionName = collectionNameFromCall(value);
435
+ if (!matched || matched === 'getEntries' || !collectionName)
436
+ return null;
437
+ return {
438
+ collectionName,
439
+ shape: matched === 'getCollection' ? 'array' : 'entry',
440
+ itemPath: '',
441
+ };
442
+ }
443
+ function topLevelVariableDeclarations(ast) {
444
+ const declarations = [];
445
+ for (const statement of ast.program.body) {
446
+ if (statement.type === 'VariableDeclaration')
447
+ declarations.push(statement);
448
+ else if (statement.type === 'ExportNamedDeclaration' && statement.declaration?.type === 'VariableDeclaration') {
449
+ declarations.push(statement.declaration);
450
+ }
451
+ }
452
+ return declarations;
453
+ }
454
+ function collectBindings(ast, named, namespaces) {
455
+ const facts = [];
456
+ const bindings = new Map();
457
+ const importedLocals = new Set([...named.keys(), ...namespaces]);
458
+ const shadowed = topLevelShadowedNames(ast, importedLocals);
459
+ for (const declaration of topLevelVariableDeclarations(ast)) {
460
+ for (const declarator of declaration.declarations) {
461
+ if (declarator.id.type !== 'Identifier' || !declarator.init)
462
+ continue;
463
+ const name = declarator.id.name;
464
+ const direct = directCallBinding(declarator.init, named, namespaces, shadowed);
465
+ const alias = expressionAccessor(declarator.init);
466
+ const aliased = alias?.path === '' ? bindings.get(alias.base) : undefined;
467
+ const mapped = mapBinding(declarator.init, bindings);
468
+ const base = direct ?? mapped ?? aliased;
469
+ if (!base)
470
+ continue;
471
+ bindings.set(name, base);
472
+ facts.push({ localName: name, collectionName: base.collectionName, itemPath: base.itemPath });
473
+ }
474
+ }
475
+ return facts;
476
+ }
477
+ function analyzeAstroContentAst(ast) {
478
+ const imports = importFacts(ast);
479
+ const { named, namespaces } = contentImportBindings(ast);
480
+ return {
481
+ imports,
482
+ collectionCalls: collectCalls(ast, named, namespaces),
483
+ collectionBindings: collectBindings(ast, named, namespaces),
484
+ };
485
+ }
486
+ /**
487
+ * Analyze JavaScript or TypeScript containing Astro content accessors: a module, or the
488
+ * frontmatter of an `.astro` file once it has been extracted.
489
+ *
490
+ * A caller that already holds the frontmatter (or a Babel parse of it, as the CMS source
491
+ * finder does) passes that directly, so the source is neither re-extracted nor re-parsed.
492
+ */
493
+ export function analyzeAstroScript(source) {
494
+ const ast = typeof source === 'string' ? parseScript(source) : source;
495
+ return ast ? analyzeAstroContentAst(ast) : { imports: [], collectionCalls: [], collectionBindings: [] };
496
+ }
497
+ /** Analyze the frontmatter of a complete `.astro` source string. */
498
+ export function analyzeAstroSource(source) {
499
+ const frontmatter = extractAstroFrontmatter(source);
500
+ return frontmatter === null
501
+ ? { imports: [], collectionCalls: [], collectionBindings: [] }
502
+ : analyzeAstroScript(frontmatter);
503
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"byte-range.d.ts","sourceRoot":"","sources":["../src/byte-range.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,MAAM,WAAW,SAAS;IACzB,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;CACX;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,eAAe,GAAG,IAAI,CAkBxG"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Resolve a request's `Range` header against a resource of `size` bytes.
3
+ *
4
+ * A browser plays `<video>` by asking for byte ranges; without a `206` answer it cannot seek, and
5
+ * Safari refuses to play at all. Only a single `bytes=` range is honoured. `null` means "serve the
6
+ * whole resource": no header, a malformed one, or a multi-range request, all of which RFC 9110 lets
7
+ * a server answer with `200`. `'unsatisfiable'` is a well-formed range lying past the end (`416`).
8
+ */
9
+ export function resolveByteRange(header, size) {
10
+ if (header === null)
11
+ return null;
12
+ const match = /^bytes=(\d*)-(\d*)$/.exec(header.trim());
13
+ if (!match)
14
+ return null;
15
+ const [, first = '', last = ''] = match;
16
+ if (first === '' && last === '')
17
+ return null;
18
+ if (first === '') {
19
+ const suffix = Number(last);
20
+ if (suffix === 0 || size === 0)
21
+ return 'unsatisfiable';
22
+ return { start: Math.max(0, size - suffix), end: size - 1 };
23
+ }
24
+ const start = Number(first);
25
+ const end = last === '' ? size - 1 : Math.min(Number(last), size - 1);
26
+ if (last !== '' && Number(last) < start)
27
+ return null;
28
+ if (start >= size)
29
+ return 'unsatisfiable';
30
+ return { start, end };
31
+ }
@@ -6,9 +6,9 @@
6
6
  * the project's real Zod schema. Loading twice would double the I/O on a 1.5k-entry site
7
7
  * and let the two disagree about which files even belong to a collection.
8
8
  */
9
- import type { ParsedConfig } from './content-config-ast';
10
- import type { CollectionKind } from './editor-write-model';
11
- import type { CmsFileSystem } from './fs/types';
9
+ import type { ParsedConfig } from './content-config-ast.ts';
10
+ import type { CollectionKind } from './editor-write-model.ts';
11
+ import type { CmsFileSystem } from './fs/types.ts';
12
12
  export interface LoadedEntry {
13
13
  /** Root-relative path of the source file. */
14
14
  file: string;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-entries.d.ts","sourceRoot":"","sources":["../src/check-entries.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAoB,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAC7E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAE7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAElD,MAAM,WAAW,WAAW;IAC3B,6CAA6C;IAC7C,IAAI,EAAE,MAAM,CAAA;IACZ,0GAA0G;IAC1G,IAAI,EAAE,MAAM,CAAA;IACZ,gEAAgE;IAChE,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACrC,yEAAyE;IACzE,UAAU,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,gBAAgB;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,6CAA6C;IAC7C,IAAI,EAAE,MAAM,CAAA;IACZ,gEAAgE;IAChE,MAAM,EAAE,OAAO,CAAA;IACf,oHAAoH;IACpH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,WAAW,EAAE,CAAA;CACtB;AAED,MAAM,MAAM,iBAAiB,GAAG,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;AAI7D,iFAAiF;AACjF,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,KAAG,MAAuE,CAAA;AAEpH,wGAAwG;AACxG,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,KAAG,MAAmE,CAAA;AAE5G,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAE9E;AAQD,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG;IAAE,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAwBlH;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,GAAG,SAAS,GAAG,cAAc,CAI9G;AAED,+FAA+F;AAC/F,wBAAsB,eAAe,CAAC,EAAE,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAqCzG"}