@crombolo/server 0.48.1 → 0.49.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crombolo/server",
3
- "version": "0.48.1",
3
+ "version": "0.49.0",
4
4
  "description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. The crombolo HTTP server: routing, configuration, media stores and background jobs.",
5
5
  "license": "MIT",
6
6
  "author": "Crombolo",
@@ -31,18 +31,18 @@
31
31
  "access": "public"
32
32
  },
33
33
  "dependencies": {
34
- "@crombolo/api-delivery": "0.48.1",
35
- "@crombolo/api-management": "0.48.1",
36
- "@crombolo/auth": "0.48.1",
37
- "@crombolo/backoffice-host": "0.48.1",
38
- "@crombolo/common": "0.48.1",
39
- "@crombolo/content": "0.48.1",
40
- "@crombolo/contracts": "0.48.1",
41
- "@crombolo/core": "0.48.1",
42
- "@crombolo/data": "0.48.1",
43
- "@crombolo/render": "0.48.1",
44
- "@crombolo/schema": "0.48.1",
45
- "@crombolo/transfer": "0.48.1",
34
+ "@crombolo/api-delivery": "0.49.0",
35
+ "@crombolo/api-management": "0.49.0",
36
+ "@crombolo/auth": "0.49.0",
37
+ "@crombolo/backoffice-host": "0.49.0",
38
+ "@crombolo/common": "0.49.0",
39
+ "@crombolo/content": "0.49.0",
40
+ "@crombolo/contracts": "0.49.0",
41
+ "@crombolo/core": "0.49.0",
42
+ "@crombolo/data": "0.49.0",
43
+ "@crombolo/render": "0.49.0",
44
+ "@crombolo/schema": "0.49.0",
45
+ "@crombolo/transfer": "0.49.0",
46
46
  "@logtape/logtape": "^2.3.8",
47
47
  "@opentelemetry/api": "1.10.0",
48
48
  "@opentelemetry/context-async-hooks": "3.0.0",
package/src/components.ts CHANGED
@@ -83,6 +83,8 @@ export interface ComponentCheckReport {
83
83
  problems: ComponentProblem[]
84
84
  /** Whether types were checked, and what the compiler said. */
85
85
  types: { checked: boolean; problems: string[]; note?: string }
86
+ /** The gaps marked in the templates: work left, never a problem. */
87
+ gaps: ComponentGap[]
86
88
  }
87
89
 
88
90
  /**
@@ -182,9 +184,108 @@ export async function checkComponents(options: {
182
184
  declared: declared.filter((alias) => present.has(alias)),
183
185
  problems,
184
186
  types: await checkTypes(options.siteDir),
187
+ gaps: findGaps(options.componentsDir, options.siteDir),
185
188
  }
186
189
  }
187
190
 
191
+ /** A `<Gap>` in a file. A reason or `was` worked out in code cannot be read, so is null. */
192
+ export interface GapMark {
193
+ line: number
194
+ reason: string | null
195
+ was: string | null
196
+ }
197
+
198
+ export interface ComponentGap extends GapMark {
199
+ /** Relative to the site, as a problem's is. */
200
+ file: string
201
+ }
202
+
203
+ const PACKAGE_IMPORT = /import\s*\{([^}]*)\}\s*from\s*['"]@crombolo\/crombolo['"]/g
204
+ const COMMENT = /\/\*[\s\S]*?\*\/|^[ \t]*\/\/.*$/gm
205
+ const ENTITIES: Record<string, string> = { quot: '"', amp: '&', lt: '<', gt: '>', apos: "'" }
206
+
207
+ const decodeEntities = (text: string) =>
208
+ text.replace(/&(?:#(\d+)|#x([\da-f]+)|(\w+));/gi, (entity, decimal, hex, name) => {
209
+ if (decimal) return String.fromCodePoint(Number(decimal))
210
+ if (hex) return String.fromCodePoint(Number.parseInt(hex, 16))
211
+ return ENTITIES[name] ?? entity
212
+ })
213
+
214
+ /** What a site calls `Gap` here: undefined when it comes from anywhere but crombolo. */
215
+ function gapName(source: string): string | undefined {
216
+ for (const match of source.matchAll(PACKAGE_IMPORT))
217
+ for (const part of (match[1] as string).split(',')) {
218
+ const name = /^\s*Gap(?:\s+as\s+([\w$]+))?\s*$/.exec(part)
219
+ if (name) return name[1] ?? 'Gap'
220
+ }
221
+ return undefined
222
+ }
223
+
224
+ /** The index just past the brace that closes the one at `from`, strings skipped. */
225
+ function closingBrace(source: string, from: number): number {
226
+ let depth = 0
227
+ for (let at = from; at < source.length; at++) {
228
+ const c = source[at] as string
229
+ if (c === '"' || c === "'" || c === '`') {
230
+ for (at++; at < source.length && source[at] !== c; at++) if (source[at] === '\\') at++
231
+ } else if (c === '{') depth += 1
232
+ else if (c === '}' && --depth === 0) return at + 1
233
+ }
234
+ return source.length
235
+ }
236
+
237
+ /** The string in an attribute's `{…}`, when it is only a string. */
238
+ function literal(expression: string): string | null {
239
+ const string = /^\s*(["'`])((?:\\[\s\S]|(?!\1)[^\\])*)\1\s*$/.exec(expression)
240
+ if (!string || (string[1] === '`' && (string[2] as string).includes('${'))) return null
241
+ return (string[2] as string).replace(/\\([\s\S])/g, (_, c) => (c === 'n' ? '\n' : c))
242
+ }
243
+
244
+ /** `reason` and `was` from the tag whose attributes start at `from`. */
245
+ function gapAttributes(source: string, from: number): Pick<GapMark, 'reason' | 'was'> {
246
+ const found: Record<string, string | null> = {}
247
+ let at = from
248
+ while (at < source.length) {
249
+ const rest = /^\s*(?:([\w-]+)\s*(=\s*)?)?/.exec(source.slice(at)) as RegExpExecArray
250
+ at += rest[0].length
251
+ const quote = source[at]
252
+ if (rest[2] && (quote === '"' || quote === "'")) {
253
+ const end = source.indexOf(quote, at + 1)
254
+ if (end < 0) break
255
+ found[rest[1] as string] = decodeEntities(source.slice(at + 1, end))
256
+ at = end + 1
257
+ } else if (quote === '{') {
258
+ const end = closingBrace(source, at)
259
+ if (rest[2]) found[rest[1] as string] = literal(source.slice(at + 1, end - 1))
260
+ at = end
261
+ } else if (!rest[1]) break
262
+ }
263
+ return { reason: found.reason ?? null, was: found.was ?? null }
264
+ }
265
+
266
+ /** Every `<Gap>` in a file's source, read rather than compiled. Pure. */
267
+ export function gapsIn(source: string): GapMark[] {
268
+ const name = gapName(source)
269
+ if (!name) return []
270
+ // Blanked rather than removed, so what is left keeps its lines.
271
+ const code = source.replace(COMMENT, (comment) => comment.replace(/[^\n]/g, ' '))
272
+ const tag = new RegExp(`<${name.replace(/\$/g, '\\$')}(?=[\\s/>])`, 'g')
273
+ return [...code.matchAll(tag)].map((match) => ({
274
+ line: code.slice(0, match.index).split('\n').length,
275
+ ...gapAttributes(code, match.index + match[0].length),
276
+ }))
277
+ }
278
+
279
+ /** The gaps marked across `components/`, without compiling anything. */
280
+ export function findGaps(componentsDir: string, siteDir: string): ComponentGap[] {
281
+ return listComponents(componentsDir).flatMap((component) =>
282
+ gapsIn(readFileSync(component.path, 'utf8')).map((gap) => ({
283
+ file: relative(siteDir, component.path),
284
+ ...gap,
285
+ })),
286
+ )
287
+ }
288
+
188
289
  const MEDIA_CALL = /(\bawait\s+)?((?:[A-Za-z_$][\w$]*)(?:\??\.[A-Za-z_$][\w$]*)*)\.media\(/g
189
290
 
190
291
  /** The index just past the parenthesis that closes the one opened before `from`. */
package/src/config.ts CHANGED
@@ -1086,7 +1086,7 @@ export function describeDatabase(
1086
1086
  }
1087
1087
  }
1088
1088
 
1089
- export const VERSION = '0.48.1'
1089
+ export const VERSION = '0.49.0'
1090
1090
 
1091
1091
  /** A whole number of seconds from the environment; undefined when unset or not one. */
1092
1092
  /** A positive number from a setting, else the default. */