@platformos/platformos-common 0.0.15 → 0.0.17

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.
@@ -1,6 +1,6 @@
1
1
  import yaml from 'js-yaml';
2
2
  import { AbstractFileSystem, FileType } from '../AbstractFileSystem';
3
- import { getAppPaths, getModulePaths, PlatformOSFileType } from '../path-utils';
3
+ import { getAppPaths, getModulePaths, parseModulePrefix, PlatformOSFileType } from '../path-utils';
4
4
  import { URI, Utils } from 'vscode-uri';
5
5
 
6
6
  export type DocumentType =
@@ -34,9 +34,8 @@ export async function loadSearchPaths(
34
34
  }
35
35
  }
36
36
 
37
- type ModulePathInfo =
38
- | { isModule: false; key: string }
39
- | { isModule: true; moduleName: string; key: string };
37
+ /** Maximum number of concrete paths generated by a single dynamic search-path expansion. */
38
+ const MAX_DYNAMIC_PATH_EXPANSIONS = 100;
40
39
 
41
40
  export class DocumentsLocator {
42
41
  constructor(private readonly fs: AbstractFileSystem) {}
@@ -49,17 +48,6 @@ export class DocumentsLocator {
49
48
  }
50
49
  }
51
50
 
52
- private parseModulePath(fileName: string): ModulePathInfo {
53
- if (!fileName.startsWith('modules/')) {
54
- return { isModule: false, key: fileName };
55
- }
56
-
57
- const [, moduleName, ...rest] = fileName.split('/');
58
- const key = rest.join('/');
59
-
60
- return moduleName ? { isModule: true, moduleName, key } : { isModule: false, key: fileName };
61
- }
62
-
63
51
  private getSearchPaths(type: 'partial' | 'graphql' | 'asset', moduleName?: string): string[] {
64
52
  const fileType: PlatformOSFileType = {
65
53
  partial: PlatformOSFileType.Partial,
@@ -75,7 +63,7 @@ export class DocumentsLocator {
75
63
  fileName: string,
76
64
  type: 'partial' | 'graphql' | 'asset',
77
65
  ): Promise<string | undefined> {
78
- const parsed = this.parseModulePath(fileName);
66
+ const parsed = parseModulePrefix(fileName);
79
67
  const searchPaths = this.getSearchPaths(type, parsed.isModule ? parsed.moduleName : undefined);
80
68
 
81
69
  let targetFile = parsed.key;
@@ -101,7 +89,7 @@ export class DocumentsLocator {
101
89
  filePrefix: string,
102
90
  type: 'partial' | 'graphql' | 'asset',
103
91
  ): Promise<string[]> {
104
- const parsed = this.parseModulePath(filePrefix);
92
+ const parsed = parseModulePrefix(filePrefix);
105
93
  const searchPaths = this.getSearchPaths(type, parsed.isModule ? parsed.moduleName : undefined);
106
94
 
107
95
  const results = new Set<string>();
@@ -185,7 +173,8 @@ export class DocumentsLocator {
185
173
  * concrete directory prefixes by enumerating subdirectories at each dynamic
186
174
  * segment. Static segments pass through unchanged.
187
175
  *
188
- * Results are cached per (rootUri, searchPath) and capped at 100 entries.
176
+ * Results are cached per (rootUri, searchPath) and capped at
177
+ * MAX_DYNAMIC_PATH_EXPANSIONS entries per dynamic segment.
189
178
  */
190
179
  private async expandDynamicPath(rootUri: URI, searchPath: string): Promise<string[]> {
191
180
  const segments = searchPath.split('/');
@@ -211,9 +200,9 @@ export class DocumentsLocator {
211
200
  }
212
201
  for (const sub of subdirs) {
213
202
  nextPrefixes.push(prefix ? `${prefix}/${sub}` : sub);
214
- if (nextPrefixes.length >= 100) break;
203
+ if (nextPrefixes.length >= MAX_DYNAMIC_PATH_EXPANSIONS) break;
215
204
  }
216
- if (nextPrefixes.length >= 100) break;
205
+ if (nextPrefixes.length >= MAX_DYNAMIC_PATH_EXPANSIONS) break;
217
206
  }
218
207
  prefixes = nextPrefixes;
219
208
  }
@@ -269,7 +258,7 @@ export class DocumentsLocator {
269
258
  * Returns undefined for theme_render_rc (ambiguous search path) and asset.
270
259
  */
271
260
  locateDefault(rootUri: URI, nodeName: DocumentType, fileName: string): string | undefined {
272
- const parsed = this.parseModulePath(fileName);
261
+ const parsed = parseModulePrefix(fileName);
273
262
 
274
263
  let basePath: string;
275
264
  let ext: string;
@@ -0,0 +1,533 @@
1
+ /**
2
+ * Frontmatter schema definitions for platformOS Liquid file types.
3
+ *
4
+ * Each Liquid file type in platformOS has a YAML frontmatter section at the
5
+ * top of the file that configures server-side behaviour. The schema for each
6
+ * type is different — Pages have slug/layout, Emails have to/from/subject, etc.
7
+ *
8
+ * This module provides:
9
+ * - FrontmatterFieldSchema — type definition for a single field
10
+ * - FrontmatterSchema — type definition for a complete schema
11
+ * - FRONTMATTER_SCHEMAS — per-type schemas keyed by PlatformOSFileType
12
+ * - getFrontmatterSchema() — convenience lookup that returns undefined for
13
+ * types without a frontmatter schema
14
+ */
15
+
16
+ import { FILE_TYPE_DIRS, PlatformOSFileType } from './path-utils';
17
+
18
+ // ─── Types ────────────────────────────────────────────────────────────────────
19
+
20
+ export type FrontmatterFieldType = 'string' | 'boolean' | 'integer' | 'number' | 'array' | 'object';
21
+
22
+ export interface FrontmatterFieldSchema {
23
+ /** The expected YAML type(s) for this field's value. */
24
+ type: FrontmatterFieldType | FrontmatterFieldType[];
25
+ /** Whether this field must be present. */
26
+ required?: boolean;
27
+ /** Human-readable description of this field. */
28
+ description?: string;
29
+ /** Whether this field name is deprecated in favour of a newer one. */
30
+ deprecated?: boolean;
31
+ /** Message shown when this deprecated field is used. */
32
+ deprecatedMessage?: string;
33
+ /**
34
+ * Allowed values for this field. When set, a validator should warn if the
35
+ * field value is not one of these entries.
36
+ */
37
+ enumValues?: (string | number)[];
38
+ }
39
+
40
+ export interface FrontmatterSchema {
41
+ /** Human-readable name of the file type, used in diagnostics. */
42
+ name: string;
43
+ /**
44
+ * Known frontmatter fields.
45
+ * Checks can use this to surface unknown keys or missing required keys.
46
+ * Any key not listed here will produce an "unknown field" warning.
47
+ */
48
+ fields: Record<string, FrontmatterFieldSchema>;
49
+ }
50
+
51
+ // ─── Schemas ──────────────────────────────────────────────────────────────────
52
+
53
+ /**
54
+ * Per-type frontmatter schemas.
55
+ *
56
+ * Only Liquid file types are present here — GraphQL, YAML, and Asset types
57
+ * do not use frontmatter.
58
+ *
59
+ * Field lists are derived from the server-side converter files in
60
+ * app/services/app_builder/converters/. Enum constraints mirror server validations.
61
+ * Unknown keys always produce a warning; file types with arbitrary frontmatter
62
+ * (e.g. Migration) are omitted so no validation runs for them.
63
+ */
64
+ export const FRONTMATTER_SCHEMAS: Partial<Record<PlatformOSFileType, FrontmatterSchema>> = {
65
+ // ── Page ─────────────────────────────────────────────────────────────────────
66
+ [PlatformOSFileType.Page]: {
67
+ name: 'Page',
68
+ fields: {
69
+ slug: {
70
+ type: 'string',
71
+ description: 'URL slug for this page. Supports dynamic segments (e.g. users/:id).',
72
+ },
73
+ layout: {
74
+ type: 'string',
75
+ description: 'Layout template to wrap this page (path relative to app root, no extension).',
76
+ },
77
+ layout_name: {
78
+ type: 'string',
79
+ description: 'Alias for layout.',
80
+ deprecated: true,
81
+ deprecatedMessage: 'Use `layout` instead of `layout_name`.',
82
+ },
83
+ method: {
84
+ type: 'string',
85
+ description: 'HTTP method this page responds to.',
86
+ enumValues: ['delete', 'get', 'patch', 'post', 'put', 'options'],
87
+ },
88
+ redirect_to: {
89
+ type: 'string',
90
+ description: 'URL to redirect to.',
91
+ },
92
+ redirect_url: {
93
+ type: 'string',
94
+ description: 'Alias for redirect_to.',
95
+ deprecated: true,
96
+ deprecatedMessage: 'Use `redirect_to` instead of `redirect_url`.',
97
+ },
98
+ redirect_code: {
99
+ type: 'integer',
100
+ description: 'HTTP redirect status code.',
101
+ enumValues: [301, 302, 307],
102
+ },
103
+ authorization_policies: {
104
+ type: 'array',
105
+ description: 'List of authorization policy names that must pass before rendering.',
106
+ },
107
+ response_headers: {
108
+ type: 'string',
109
+ description: 'Liquid template that renders a JSON object of HTTP response headers.',
110
+ },
111
+ metadata: {
112
+ type: 'object',
113
+ description: 'Arbitrary metadata object (e.g. SEO title/description, robots directives).',
114
+ },
115
+ max_deep_level: {
116
+ type: 'integer',
117
+ description: 'Maximum number of dynamic URL segments to capture.',
118
+ },
119
+ searchable: {
120
+ type: 'boolean',
121
+ description: 'Whether this page is included in platformOS search indexes.',
122
+ },
123
+ format: {
124
+ type: 'string',
125
+ description: 'Response format (html, json, xml, csv, …). Often encoded in the filename.',
126
+ },
127
+ default_layout: {
128
+ type: 'boolean',
129
+ description: 'Use the instance default layout.',
130
+ },
131
+ handler: {
132
+ type: 'string',
133
+ description: 'Template handler type.',
134
+ },
135
+ converter: {
136
+ type: 'string',
137
+ description: 'Content converter, e.g. `markdown`.',
138
+ },
139
+ dynamic_cache: {
140
+ type: 'object',
141
+ description: 'Dynamic cache settings: { key, layout, expire }.',
142
+ },
143
+ static_cache: {
144
+ type: 'object',
145
+ description: 'Static cache settings: { expire }.',
146
+ },
147
+ cache_for: {
148
+ type: 'integer',
149
+ description: 'Static cache expiration in seconds.',
150
+ },
151
+ subdomain: {
152
+ type: 'string',
153
+ description: 'Subdomain routing.',
154
+ },
155
+ require_verified_user: {
156
+ type: 'boolean',
157
+ },
158
+ admin_page: {
159
+ type: 'boolean',
160
+ },
161
+ enable_profiler: {
162
+ type: 'boolean',
163
+ },
164
+ metadata_title: {
165
+ type: 'string',
166
+ description: 'SEO <title> shorthand (alias for metadata.title).',
167
+ },
168
+ metadata_meta_description: {
169
+ type: 'string',
170
+ description: 'SEO meta description shorthand (alias for metadata.meta_description).',
171
+ },
172
+ metadata_canonical_url: {
173
+ type: 'string',
174
+ description: 'Canonical URL shorthand (alias for metadata.canonical_url).',
175
+ },
176
+ },
177
+ },
178
+
179
+ // ── Layout ───────────────────────────────────────────────────────────────────
180
+ // liquid_view_converter.rb: primary_key derived from physical_file_path; no `name` property.
181
+ [PlatformOSFileType.Layout]: {
182
+ name: 'Layout',
183
+ fields: {
184
+ converter: {
185
+ type: 'string',
186
+ description: 'Content converter, e.g. `markdown`.',
187
+ },
188
+ metadata: {
189
+ type: 'object',
190
+ },
191
+ },
192
+ },
193
+
194
+ // ── Partial ──────────────────────────────────────────────────────────────────
195
+ [PlatformOSFileType.Partial]: {
196
+ name: 'Partial',
197
+ fields: {
198
+ metadata: {
199
+ type: 'object',
200
+ description:
201
+ 'Partial metadata. `metadata.params` declares accepted parameters; `metadata.name` is a human-readable label for the style guide.',
202
+ },
203
+ converter: {
204
+ type: 'string',
205
+ description: 'Content converter, e.g. `markdown`.',
206
+ },
207
+ },
208
+ },
209
+
210
+ // ── AuthorizationPolicy ──────────────────────────────────────────────────────
211
+ // authorization_policy_converter.rb: name, content, flash_alert, redirect_to, http_status, metadata.
212
+ // Note: only flash_alert is supported — flash_notice is NOT a valid property here.
213
+ [PlatformOSFileType.Authorization]: {
214
+ name: 'AuthorizationPolicy',
215
+ fields: {
216
+ name: {
217
+ type: 'string',
218
+ description: 'Unique identifier for this authorization policy.',
219
+ },
220
+ redirect_to: {
221
+ type: 'string',
222
+ description: 'URL to redirect the user to when the policy fails.',
223
+ },
224
+ flash_alert: {
225
+ type: 'string',
226
+ description: 'Flash alert message shown after a failed authorization redirect.',
227
+ },
228
+ http_status: {
229
+ type: 'integer',
230
+ description: 'HTTP status code returned on policy failure.',
231
+ enumValues: [403, 404],
232
+ },
233
+ metadata: {
234
+ type: 'object',
235
+ },
236
+ },
237
+ },
238
+
239
+ // ── Email ────────────────────────────────────────────────────────────────────
240
+ [PlatformOSFileType.Email]: {
241
+ name: 'Email',
242
+ fields: {
243
+ name: {
244
+ type: 'string',
245
+ description: 'Unique identifier for this email notification.',
246
+ },
247
+ to: {
248
+ type: 'string',
249
+ description: 'Recipient email address (may use Liquid).',
250
+ },
251
+ from: {
252
+ type: 'string',
253
+ description: 'Sender email address.',
254
+ },
255
+ reply_to: {
256
+ type: 'string',
257
+ description: 'Reply-to email address.',
258
+ },
259
+ cc: {
260
+ type: 'string',
261
+ description: 'Carbon-copy recipients.',
262
+ },
263
+ bcc: {
264
+ type: 'string',
265
+ description: 'Blind carbon-copy recipients.',
266
+ },
267
+ subject: {
268
+ type: 'string',
269
+ description: 'Email subject line (may use Liquid).',
270
+ },
271
+ layout: {
272
+ type: 'string',
273
+ description: 'Layout partial to wrap the email body.',
274
+ },
275
+ layout_path: {
276
+ type: 'string',
277
+ description: 'Alias for layout.',
278
+ deprecated: true,
279
+ deprecatedMessage: 'Use `layout` instead of `layout_path`.',
280
+ },
281
+ delay: {
282
+ type: 'integer',
283
+ description: 'Seconds to delay delivery after being triggered.',
284
+ },
285
+ enabled: {
286
+ type: 'boolean',
287
+ description: 'When false, this email is never sent. Defaults to true.',
288
+ },
289
+ trigger_condition: {
290
+ type: ['boolean', 'string'],
291
+ description:
292
+ 'Liquid expression or boolean; email is only sent when this evaluates to true.',
293
+ },
294
+ locale: {
295
+ type: 'string',
296
+ description: 'Locale for the email.',
297
+ },
298
+ forced: {
299
+ type: 'boolean',
300
+ },
301
+ attachments: {
302
+ type: 'string',
303
+ },
304
+ unique_args: {
305
+ type: 'object',
306
+ description: 'Extra key/value pairs passed to the email delivery provider.',
307
+ },
308
+ metadata: {
309
+ type: 'object',
310
+ },
311
+ },
312
+ },
313
+
314
+ // ── ApiCall ──────────────────────────────────────────────────────────────────
315
+ [PlatformOSFileType.ApiCall]: {
316
+ name: 'ApiCall',
317
+ fields: {
318
+ name: {
319
+ type: 'string',
320
+ description: 'Unique identifier for this API call notification.',
321
+ },
322
+ to: {
323
+ type: 'string',
324
+ description: 'Target URL for the HTTP request (may use Liquid).',
325
+ },
326
+ request_type: {
327
+ type: 'string',
328
+ description: 'HTTP method: GET, POST, PUT, PATCH, or DELETE.',
329
+ enumValues: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'],
330
+ },
331
+ request_headers: {
332
+ type: 'string',
333
+ description: 'Liquid template rendering a JSON object of request headers.',
334
+ },
335
+ headers: {
336
+ type: 'string',
337
+ description: 'Alias for request_headers.',
338
+ deprecated: true,
339
+ deprecatedMessage: 'Use `request_headers` instead of `headers`.',
340
+ },
341
+ callback: {
342
+ type: 'string',
343
+ description: 'Liquid template executed after the HTTP response is received.',
344
+ },
345
+ delay: {
346
+ type: 'integer',
347
+ description: 'Seconds to delay the request after being triggered.',
348
+ },
349
+ enabled: {
350
+ type: 'boolean',
351
+ description: 'When false, this API call is never executed. Defaults to true.',
352
+ },
353
+ trigger_condition: {
354
+ type: ['boolean', 'string'],
355
+ description: 'Liquid expression or boolean; call is only made when this evaluates to true.',
356
+ },
357
+ format: {
358
+ type: 'string',
359
+ description: 'Request body encoding format (http, json, …).',
360
+ },
361
+ locale: {
362
+ type: 'string',
363
+ },
364
+ metadata: {
365
+ type: 'object',
366
+ },
367
+ },
368
+ },
369
+
370
+ // ── Sms ──────────────────────────────────────────────────────────────────────
371
+ [PlatformOSFileType.Sms]: {
372
+ name: 'SMS',
373
+ fields: {
374
+ name: {
375
+ type: 'string',
376
+ description: 'Unique identifier for this SMS notification.',
377
+ },
378
+ to: {
379
+ type: 'string',
380
+ description: 'Recipient phone number in E.164 format (may use Liquid).',
381
+ },
382
+ content: {
383
+ type: 'string',
384
+ description: 'SMS body (may use Liquid).',
385
+ },
386
+ delay: {
387
+ type: 'integer',
388
+ description: 'Seconds to delay sending after being triggered.',
389
+ },
390
+ enabled: {
391
+ type: 'boolean',
392
+ description: 'When false, this SMS is never sent. Defaults to true.',
393
+ },
394
+ trigger_condition: {
395
+ type: ['boolean', 'string'],
396
+ description: 'Liquid expression or boolean; SMS is only sent when this evaluates to true.',
397
+ },
398
+ locale: {
399
+ type: 'string',
400
+ },
401
+ metadata: {
402
+ type: 'object',
403
+ },
404
+ },
405
+ },
406
+
407
+ // ── FormConfiguration ────────────────────────────────────────────────────────
408
+ [PlatformOSFileType.FormConfiguration]: {
409
+ name: 'FormConfiguration',
410
+ fields: {
411
+ name: {
412
+ type: 'string',
413
+ description: 'Unique identifier for this form, used in include_form / function calls.',
414
+ },
415
+ resource: {
416
+ type: ['string', 'object'],
417
+ description: 'Model or resource type this form operates on.',
418
+ },
419
+ resource_owner: {
420
+ type: 'string',
421
+ description: 'Who owns the resource being created/updated.',
422
+ },
423
+ fields: {
424
+ type: 'object',
425
+ description: 'Field definitions — what data this form accepts and validates.',
426
+ },
427
+ configuration: {
428
+ type: 'object',
429
+ description: 'Alias for fields.',
430
+ },
431
+ redirect_to: {
432
+ type: 'string',
433
+ description: 'URL to redirect to after a successful form submission.',
434
+ },
435
+ return_to: {
436
+ type: 'string',
437
+ description: 'Alias for redirect_to.',
438
+ deprecated: true,
439
+ deprecatedMessage: 'Use `redirect_to` instead of `return_to`.',
440
+ },
441
+ flash_notice: {
442
+ type: 'string',
443
+ description: 'Flash notice message shown after a successful submission.',
444
+ },
445
+ flash_alert: {
446
+ type: 'string',
447
+ description: 'Flash alert message shown after a failed submission.',
448
+ },
449
+ spam_protection: {
450
+ type: 'string',
451
+ description: 'Spam protection mechanism to use.',
452
+ enumValues: ['recaptcha', 'recaptcha_v2', 'recaptcha_v3', 'hcaptcha'],
453
+ },
454
+ request_allowed: {
455
+ type: 'boolean',
456
+ description: 'Whether the request is allowed. Default: true.',
457
+ },
458
+ live_reindex: {
459
+ type: 'boolean',
460
+ },
461
+ default_payload: {
462
+ type: ['string', 'object'],
463
+ },
464
+ callback_actions: {
465
+ type: 'string',
466
+ description: 'Liquid template with GraphQL mutations to run after submission.',
467
+ },
468
+ async_callback_actions: {
469
+ type: 'object',
470
+ description: 'Async callback settings: { content, delay, max_attempts, priority }.',
471
+ },
472
+ email_notifications: {
473
+ type: 'array',
474
+ description: 'Email notification names to trigger after successful form submission.',
475
+ },
476
+ sms_notifications: {
477
+ type: 'array',
478
+ description: 'SMS notification names to trigger after successful form submission.',
479
+ },
480
+ api_call_notifications: {
481
+ type: 'array',
482
+ description: 'API call notification names to trigger after successful form submission.',
483
+ },
484
+ response_headers: {
485
+ type: ['string', 'object'],
486
+ },
487
+ metadata: {
488
+ type: 'object',
489
+ },
490
+ },
491
+ },
492
+ };
493
+
494
+ // ─── Lookup helper ────────────────────────────────────────────────────────────
495
+
496
+ /**
497
+ * Returns the frontmatter schema for a given file type, or undefined if no
498
+ * schema is defined for that type (e.g. GraphQL, YAML, Asset types).
499
+ */
500
+ export function getFrontmatterSchema(
501
+ fileType: PlatformOSFileType | undefined,
502
+ ): FrontmatterSchema | undefined {
503
+ if (fileType === undefined) return undefined;
504
+ return FRONTMATTER_SCHEMAS[fileType];
505
+ }
506
+
507
+ // ─── Frontmatter association directories ──────────────────────────────────────
508
+
509
+ /**
510
+ * Maps frontmatter list-field names to their canonical app-relative directory.
511
+ *
512
+ * Derived from FILE_TYPE_DIRS[type][0] so it always stays in sync with the
513
+ * single source of truth in path-utils.ts.
514
+ *
515
+ * Used by both the ValidFrontmatter check (file-existence validation) and the
516
+ * FrontmatterDefinitionProvider (go-to-definition) to resolve association paths.
517
+ */
518
+ export const FRONTMATTER_ASSOCIATION_DIRS: Readonly<Record<string, string>> = {
519
+ authorization_policies: FILE_TYPE_DIRS[PlatformOSFileType.Authorization][0],
520
+ email_notifications: FILE_TYPE_DIRS[PlatformOSFileType.Email][0],
521
+ sms_notifications: FILE_TYPE_DIRS[PlatformOSFileType.Sms][0],
522
+ api_call_notifications: FILE_TYPE_DIRS[PlatformOSFileType.ApiCall][0],
523
+ };
524
+
525
+ // ─── Liquid expression detection ──────────────────────────────────────────────
526
+
527
+ /**
528
+ * Returns true if the value contains a Liquid output tag (`{{`) or tag (`{%`).
529
+ * Used to skip static validation of dynamic frontmatter values.
530
+ */
531
+ export function containsLiquid(value: string): boolean {
532
+ return value.includes('{{') || value.includes('{%');
533
+ }
package/src/index.ts CHANGED
@@ -3,3 +3,4 @@ export * from './translation-provider/TranslationProvider';
3
3
  export * from './route-table';
4
4
  export * from './AbstractFileSystem';
5
5
  export * from './path-utils';
6
+ export * from './frontmatter';
package/src/path-utils.ts CHANGED
@@ -220,6 +220,19 @@ export function isKnownLiquidFile(uri: UriString): boolean {
220
220
  return type !== undefined && LIQUID_FILE_TYPES.has(type);
221
221
  }
222
222
 
223
+ /**
224
+ * Returns true if the URI has a `.liquid` extension but does not match any
225
+ * recognized platformOS directory. Useful for detecting misplaced files that
226
+ * the server will silently ignore.
227
+ *
228
+ * @example
229
+ * isUnclassifiedLiquidFile('file:///project/scripts/helper.liquid') // → true
230
+ * isUnclassifiedLiquidFile('file:///project/app/views/pages/home.liquid') // → false (Page)
231
+ */
232
+ export function isUnclassifiedLiquidFile(uri: UriString): boolean {
233
+ return uri.endsWith('.liquid') && getFileType(uri) === undefined;
234
+ }
235
+
223
236
  /**
224
237
  * Returns true if the URI belongs to a recognized platformOS GraphQL directory
225
238
  * and should be linted. Files outside known directories (e.g. generator
@@ -264,3 +277,45 @@ export function isMigration(uri: UriString): boolean {
264
277
  export function isFormConfiguration(uri: UriString): boolean {
265
278
  return getFileType(uri) === PlatformOSFileType.FormConfiguration;
266
279
  }
280
+
281
+ // ─── Module prefix utilities ──────────────────────────────────────────────────
282
+
283
+ /**
284
+ * Result of parsing a `modules/{name}/...` prefix from a path or key.
285
+ * Used by DocumentsLocator and TranslationProvider to route lookups to the
286
+ * correct module directory.
287
+ */
288
+ export type ModulePrefix =
289
+ | { isModule: false; key: string }
290
+ | { isModule: true; moduleName: string; key: string };
291
+
292
+ /**
293
+ * Parse a `modules/{name}/{rest}` prefix from a path or translation key.
294
+ * Returns the module name and the remaining key, or marks it as non-module.
295
+ *
296
+ * @example
297
+ * parseModulePrefix('modules/community/components/card') // → { isModule: true, moduleName: 'community', key: 'components/card' }
298
+ * parseModulePrefix('modules/community/hello.world') // → { isModule: true, moduleName: 'community', key: 'hello.world' }
299
+ * parseModulePrefix('app/views/partials/card') // → { isModule: false, key: 'app/views/partials/card' }
300
+ * parseModulePrefix('modules/community') // → { isModule: false, key: 'modules/community' } (no key segment)
301
+ */
302
+ export function parseModulePrefix(path: string): ModulePrefix {
303
+ if (!path.startsWith('modules/')) {
304
+ return { isModule: false, key: path };
305
+ }
306
+
307
+ const withoutPrefix = path.slice('modules/'.length);
308
+ const slashIdx = withoutPrefix.indexOf('/');
309
+
310
+ if (slashIdx === -1) {
311
+ // Just "modules/name" with no key segment
312
+ return { isModule: false, key: path };
313
+ }
314
+
315
+ const moduleName = withoutPrefix.slice(0, slashIdx);
316
+ const key = withoutPrefix.slice(slashIdx + 1);
317
+
318
+ // moduleName must be non-empty to be a valid module prefix.
319
+ // key may be empty (e.g. 'modules/users/') — that means "all files in the module".
320
+ return moduleName ? { isModule: true, moduleName, key } : { isModule: false, key: path };
321
+ }