@platformos/platformos-check-common 0.0.17 → 0.0.18
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/CHANGELOG.md +8 -0
- package/dist/checks/index.d.ts +1 -1
- package/dist/checks/index.js +6 -2
- package/dist/checks/index.js.map +1 -1
- package/dist/checks/json-literal-quote-style/index.d.ts +2 -0
- package/dist/checks/json-literal-quote-style/index.js +42 -0
- package/dist/checks/json-literal-quote-style/index.js.map +1 -0
- package/dist/checks/liquid-html-syntax-error/checks/InvalidAssignSyntax.d.ts +21 -0
- package/dist/checks/liquid-html-syntax-error/checks/InvalidAssignSyntax.js +60 -0
- package/dist/checks/liquid-html-syntax-error/checks/InvalidAssignSyntax.js.map +1 -0
- package/dist/checks/liquid-html-syntax-error/checks/InvalidOutputPush.d.ts +17 -0
- package/dist/checks/liquid-html-syntax-error/checks/InvalidOutputPush.js +37 -0
- package/dist/checks/liquid-html-syntax-error/checks/InvalidOutputPush.js.map +1 -0
- package/dist/checks/liquid-html-syntax-error/checks/InvalidTagSyntax.js +1 -1
- package/dist/checks/liquid-html-syntax-error/index.js +17 -0
- package/dist/checks/liquid-html-syntax-error/index.js.map +1 -1
- package/dist/checks/partial-call-arguments/extract-undefined-variables.d.ts +14 -0
- package/dist/checks/partial-call-arguments/extract-undefined-variables.js +234 -0
- package/dist/checks/partial-call-arguments/extract-undefined-variables.js.map +1 -0
- package/dist/checks/partial-call-arguments/index.d.ts +2 -0
- package/dist/checks/partial-call-arguments/index.js +117 -0
- package/dist/checks/partial-call-arguments/index.js.map +1 -0
- package/dist/checks/valid-frontmatter/index.d.ts +2 -0
- package/dist/checks/valid-frontmatter/index.js +279 -0
- package/dist/checks/valid-frontmatter/index.js.map +1 -0
- package/dist/frontmatter/index.d.ts +1 -59
- package/dist/frontmatter/index.js +6 -298
- package/dist/frontmatter/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/checks/index.ts +6 -2
- package/src/checks/json-literal-quote-style/index.spec.ts +129 -0
- package/src/checks/json-literal-quote-style/index.ts +45 -0
- package/src/checks/liquid-html-syntax-error/checks/InvalidAssignSyntax.spec.ts +422 -0
- package/src/checks/liquid-html-syntax-error/checks/InvalidAssignSyntax.ts +63 -0
- package/src/checks/liquid-html-syntax-error/checks/InvalidOutputPush.spec.ts +104 -0
- package/src/checks/liquid-html-syntax-error/checks/InvalidOutputPush.ts +39 -0
- package/src/checks/liquid-html-syntax-error/checks/InvalidTagSyntax.spec.ts +86 -2
- package/src/checks/liquid-html-syntax-error/checks/InvalidTagSyntax.ts +1 -1
- package/src/checks/liquid-html-syntax-error/index.ts +19 -0
- package/src/checks/partial-call-arguments/extract-undefined-variables.spec.ts +218 -0
- package/src/checks/{metadata-params → partial-call-arguments}/extract-undefined-variables.ts +31 -6
- package/src/checks/partial-call-arguments/index.spec.ts +436 -0
- package/src/checks/{metadata-params → partial-call-arguments}/index.ts +18 -11
- package/src/checks/undefined-object/index.spec.ts +101 -0
- package/src/checks/valid-frontmatter/index.spec.ts +666 -0
- package/src/checks/valid-frontmatter/index.ts +344 -0
- package/src/frontmatter/index.ts +9 -344
- package/src/checks/metadata-params/extract-undefined-variables.spec.ts +0 -115
- package/src/checks/metadata-params/index.spec.ts +0 -257
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PartialCallArguments = void 0;
|
|
4
|
+
const types_1 = require("../../types");
|
|
5
|
+
const platformos_common_1 = require("@platformos/platformos-common");
|
|
6
|
+
const vscode_uri_1 = require("vscode-uri");
|
|
7
|
+
const path_1 = require("../../path");
|
|
8
|
+
const extract_undefined_variables_1 = require("./extract-undefined-variables");
|
|
9
|
+
exports.PartialCallArguments = {
|
|
10
|
+
meta: {
|
|
11
|
+
code: 'PartialCallArguments',
|
|
12
|
+
aliases: ['MetadataParamsCheck'],
|
|
13
|
+
name: 'Partial Call Arguments',
|
|
14
|
+
docs: {
|
|
15
|
+
description: 'Ensures that all required arguments are passed at render/function call sites, and that no unknown arguments are passed. Required vs optional is determined from the {% doc %} block when present, or inferred from undefined variables in the partial source otherwise. Variables used with | default are treated as optional.',
|
|
16
|
+
recommended: true,
|
|
17
|
+
url: 'https://documentation.platformos.com/developer-guide/platformos-check/checks/partial-call-arguments',
|
|
18
|
+
},
|
|
19
|
+
type: types_1.SourceCodeType.LiquidHtml,
|
|
20
|
+
severity: types_1.Severity.ERROR,
|
|
21
|
+
schema: {},
|
|
22
|
+
targets: [],
|
|
23
|
+
},
|
|
24
|
+
create(context) {
|
|
25
|
+
const locator = new platformos_common_1.DocumentsLocator(context.fs);
|
|
26
|
+
const validate = async (nodeType, targetFile, args, position) => {
|
|
27
|
+
const locatedFile = await locator.locate(vscode_uri_1.URI.parse(context.config.rootUri), nodeType, targetFile);
|
|
28
|
+
if (!locatedFile) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const source = await context.fs.readFile(locatedFile);
|
|
32
|
+
const relativePath = (0, path_1.relative)(locatedFile, context.config.rootUri);
|
|
33
|
+
let requiredParams;
|
|
34
|
+
let allowedParams;
|
|
35
|
+
// Check for @doc tag first — if present, it's the complete param list
|
|
36
|
+
const docDef = context.getDocDefinition
|
|
37
|
+
? await context.getDocDefinition(relativePath)
|
|
38
|
+
: undefined;
|
|
39
|
+
if (docDef?.liquidDoc?.parameters) {
|
|
40
|
+
const globalObjectNames = [];
|
|
41
|
+
if (context.platformosDocset) {
|
|
42
|
+
const objects = await context.platformosDocset.objects();
|
|
43
|
+
for (const obj of objects) {
|
|
44
|
+
if (!obj.access || obj.access.global === true || obj.access.template.length > 0) {
|
|
45
|
+
globalObjectNames.push(obj.name);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const { required: undefinedRequiredVars, optional: undefinedOptionalVars } = (0, extract_undefined_variables_1.extractUndefinedVariables)(source, globalObjectNames);
|
|
50
|
+
const undefinedVars = [...undefinedRequiredVars, ...undefinedOptionalVars];
|
|
51
|
+
const docRequiredNames = docDef.liquidDoc.parameters
|
|
52
|
+
.filter((p) => p.required)
|
|
53
|
+
.map((p) => p.name);
|
|
54
|
+
requiredParams = docRequiredNames.filter((name) => undefinedVars.includes(name));
|
|
55
|
+
allowedParams = docDef.liquidDoc.parameters.map((p) => p.name);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
// No @doc — infer required vs optional from undefined variables in the source.
|
|
59
|
+
// Variables used with `| default` are treated as optional.
|
|
60
|
+
const globalObjectNames = [];
|
|
61
|
+
if (context.platformosDocset) {
|
|
62
|
+
const objects = await context.platformosDocset.objects();
|
|
63
|
+
for (const obj of objects) {
|
|
64
|
+
if (!obj.access || obj.access.global === true || obj.access.template.length > 0) {
|
|
65
|
+
globalObjectNames.push(obj.name);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (relativePath.includes('views/partials/') || relativePath.includes('/lib/')) {
|
|
70
|
+
if (!globalObjectNames.includes('app')) {
|
|
71
|
+
globalObjectNames.push('app');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const { required: requiredVars, optional: optionalVars } = (0, extract_undefined_variables_1.extractUndefinedVariables)(source, globalObjectNames);
|
|
75
|
+
if (requiredVars.length === 0 && optionalVars.length === 0)
|
|
76
|
+
return;
|
|
77
|
+
requiredParams = requiredVars;
|
|
78
|
+
allowedParams = [...requiredVars, ...optionalVars];
|
|
79
|
+
}
|
|
80
|
+
args
|
|
81
|
+
.filter((arg) => !allowedParams.includes(arg.name))
|
|
82
|
+
.forEach((arg) => {
|
|
83
|
+
context.report({
|
|
84
|
+
message: `Unknown parameter ${arg.name} passed to ${nodeType} call`,
|
|
85
|
+
startIndex: arg.position.start,
|
|
86
|
+
endIndex: arg.position.end,
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
requiredParams
|
|
90
|
+
.filter((param) => !args.find((arg) => arg.name === param))
|
|
91
|
+
.forEach((param) => {
|
|
92
|
+
context.report({
|
|
93
|
+
message: `Required parameter ${param} must be passed to ${nodeType} call`,
|
|
94
|
+
startIndex: position.start,
|
|
95
|
+
endIndex: position.end,
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
return {
|
|
100
|
+
async RenderMarkup(node) {
|
|
101
|
+
const targetFile = 'value' in node.partial ? node.partial.value : node.partial.name;
|
|
102
|
+
if (!targetFile) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
await validate('render', targetFile, node.args, node.position);
|
|
106
|
+
},
|
|
107
|
+
async FunctionMarkup(node) {
|
|
108
|
+
const targetFile = 'value' in node.partial ? node.partial.value : node.partial.name;
|
|
109
|
+
if (!targetFile) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
await validate('function', targetFile, node.args, node.position);
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/checks/partial-call-arguments/index.ts"],"names":[],"mappings":";;;AAAA,uCAA8E;AAC9E,qEAA+E;AAC/E,2CAAiC;AAEjC,qCAAsC;AACtC,+EAA0E;AAE7D,QAAA,oBAAoB,GAA0B;IACzD,IAAI,EAAE;QACJ,IAAI,EAAE,sBAAsB;QAC5B,OAAO,EAAE,CAAC,qBAAqB,CAAC;QAChC,IAAI,EAAE,wBAAwB;QAC9B,IAAI,EAAE;YACJ,WAAW,EACT,gUAAgU;YAClU,WAAW,EAAE,IAAI;YACjB,GAAG,EAAE,qGAAqG;SAC3G;QACD,IAAI,EAAE,sBAAc,CAAC,UAAU;QAC/B,QAAQ,EAAE,gBAAQ,CAAC,KAAK;QACxB,MAAM,EAAE,EAAE;QACV,OAAO,EAAE,EAAE;KACZ;IAED,MAAM,CAAC,OA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,EAAE,EAAE;gBACjB,OAAO,CAAC,MAAM,CAAC;oBACb,OAAO,EAAE,sBAAsB,KAAK,sBAAsB,QAAQ,OAAO;oBACzE,UAAU,EAAE,QAAQ,CAAC,KAAK;oBAC1B,QAAQ,EAAE,QAAQ,CAAC,GAAG;iBACvB,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACP,CAAC,CAAC;QAEF,OAAO;YACL,KAAK,CAAC,YAAY,CAAC,IAAI;gBACrB,MAAM,UAAU,GAAG,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;gBACpF,IAAI,CAAC,UAAU,EAAE,CAAC;oBAChB,OAAO;gBACT,CAAC;gBAED,MAAM,QAAQ,CAAC,QAAQ,EAAE,UAAU,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;YACjE,CAAC;YACD,KAAK,CAAC,cAAc,CAAC,IAAI;gBACvB,MAAM,UAAU,GAAG,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;gBACpF,IAAI,CAAC,UAAU,EAAE,CAAC;oBAChB,OAAO;gBACT,CAAC;gBAED,MAAM,QAAQ,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;YACnE,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValidFrontmatter = void 0;
|
|
4
|
+
const yaml_1 = require("yaml");
|
|
5
|
+
const types_1 = require("../../types");
|
|
6
|
+
const platformos_common_1 = require("@platformos/platformos-common");
|
|
7
|
+
const file_utils_1 = require("../../utils/file-utils");
|
|
8
|
+
exports.ValidFrontmatter = {
|
|
9
|
+
meta: {
|
|
10
|
+
code: 'ValidFrontmatter',
|
|
11
|
+
name: 'Valid Frontmatter',
|
|
12
|
+
docs: {
|
|
13
|
+
description: 'Validates YAML frontmatter properties (required fields, allowed values, deprecated keys) for known platformOS file types.',
|
|
14
|
+
recommended: true,
|
|
15
|
+
url: undefined,
|
|
16
|
+
},
|
|
17
|
+
type: types_1.SourceCodeType.LiquidHtml,
|
|
18
|
+
severity: types_1.Severity.WARNING,
|
|
19
|
+
schema: {},
|
|
20
|
+
targets: [],
|
|
21
|
+
},
|
|
22
|
+
create(context) {
|
|
23
|
+
return {
|
|
24
|
+
async onCodePathStart(file) {
|
|
25
|
+
const source = file.source;
|
|
26
|
+
if (/(?:^|\/)home\.html\.liquid$/.test(file.uri)) {
|
|
27
|
+
context.report({
|
|
28
|
+
message: "'home.html.liquid' is deprecated. Rename to 'index.html.liquid' to serve as the root page.",
|
|
29
|
+
startIndex: 0,
|
|
30
|
+
endIndex: 0,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
// Locate the frontmatter block — may be preceded by whitespace
|
|
34
|
+
const trimmed = source.trimStart();
|
|
35
|
+
if (!trimmed.startsWith('---'))
|
|
36
|
+
return;
|
|
37
|
+
const leadingLen = source.length - trimmed.length;
|
|
38
|
+
const firstNewline = trimmed.indexOf('\n');
|
|
39
|
+
if (firstNewline === -1)
|
|
40
|
+
return;
|
|
41
|
+
const afterOpening = trimmed.slice(firstNewline + 1);
|
|
42
|
+
// The closing `---` may be the very first line of afterOpening (empty frontmatter)
|
|
43
|
+
// or may follow a newline (normal frontmatter with content).
|
|
44
|
+
let yamlBody;
|
|
45
|
+
if (afterOpening.startsWith('---')) {
|
|
46
|
+
yamlBody = '';
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
const closeIdx = afterOpening.indexOf('\n---');
|
|
50
|
+
if (closeIdx === -1)
|
|
51
|
+
return;
|
|
52
|
+
yamlBody = afterOpening.slice(0, closeIdx);
|
|
53
|
+
}
|
|
54
|
+
// Absolute offset of the first character of yamlBody in source
|
|
55
|
+
const bodyOffset = leadingLen + firstNewline + 1;
|
|
56
|
+
const fileType = (0, platformos_common_1.getFileType)(file.uri);
|
|
57
|
+
const schema = (0, platformos_common_1.getFrontmatterSchema)(fileType);
|
|
58
|
+
if (!schema)
|
|
59
|
+
return;
|
|
60
|
+
// Parse YAML with position tracking (yaml v2 provides range arrays).
|
|
61
|
+
// Continue even when the document has parse errors — parseDocument is
|
|
62
|
+
// lenient and still builds a partial map for the valid pairs it finds.
|
|
63
|
+
// Normalize CRLF → LF so YAML values don't contain stray \r characters.
|
|
64
|
+
const doc = (0, yaml_1.parseDocument)(yamlBody.replace(/\r\n/g, '\n').replace(/\r/g, '\n'));
|
|
65
|
+
const entries = new Map();
|
|
66
|
+
// Only populate entries when the document parsed to a map (non-empty frontmatter).
|
|
67
|
+
// When frontmatter is empty (`---\n---\n`) doc.contents is null — entries stays empty
|
|
68
|
+
// and required-field validation below will still fire correctly.
|
|
69
|
+
if ((0, yaml_1.isMap)(doc.contents)) {
|
|
70
|
+
for (const pair of doc.contents.items) {
|
|
71
|
+
const keyNode = pair.key;
|
|
72
|
+
if (!(0, yaml_1.isScalar)(keyNode) || typeof keyNode.value !== 'string')
|
|
73
|
+
continue;
|
|
74
|
+
const [ks = 0, ke = 0] = keyNode.range ?? [];
|
|
75
|
+
const valNode = (0, yaml_1.isScalar)(pair.value) ? pair.value : undefined;
|
|
76
|
+
const jsValue = valNode?.value;
|
|
77
|
+
const [vs = 0, ve = 0] = valNode?.range ?? [];
|
|
78
|
+
entries.set(keyNode.value, {
|
|
79
|
+
jsValue,
|
|
80
|
+
absStart: bodyOffset + ks,
|
|
81
|
+
absEnd: bodyOffset + ke,
|
|
82
|
+
valueAbsStart: bodyOffset + vs,
|
|
83
|
+
valueAbsEnd: bodyOffset + ve,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const frontmatterStart = leadingLen; // position of opening `---`
|
|
88
|
+
// 1. Required field validation
|
|
89
|
+
for (const [fieldName, fieldSchema] of Object.entries(schema.fields)) {
|
|
90
|
+
if (fieldSchema.required && !entries.has(fieldName)) {
|
|
91
|
+
context.report({
|
|
92
|
+
message: `Missing required frontmatter field '${fieldName}' in ${schema.name} file`,
|
|
93
|
+
startIndex: frontmatterStart,
|
|
94
|
+
endIndex: frontmatterStart + 3,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// 2. Unrecognized key warnings
|
|
99
|
+
for (const [key, entry] of entries) {
|
|
100
|
+
if (!(key in schema.fields)) {
|
|
101
|
+
context.report({
|
|
102
|
+
message: `Unknown frontmatter field '${key}' in ${schema.name} file`,
|
|
103
|
+
startIndex: entry.absStart,
|
|
104
|
+
endIndex: entry.absEnd,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// 3. Deprecated field warnings
|
|
109
|
+
for (const [key, entry] of entries) {
|
|
110
|
+
const fieldSchema = schema.fields[key];
|
|
111
|
+
if (fieldSchema?.deprecated) {
|
|
112
|
+
context.report({
|
|
113
|
+
message: fieldSchema.deprecatedMessage ?? `'${key}' is deprecated`,
|
|
114
|
+
startIndex: entry.absStart,
|
|
115
|
+
endIndex: entry.absEnd,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// 4. Enum validation — allowed values are defined in the schema.
|
|
120
|
+
// Comparison is case-insensitive for string values: both the field value and
|
|
121
|
+
// each enum entry are lowercased before comparing, so `GET` matches `get` etc.
|
|
122
|
+
for (const [key, entry] of entries) {
|
|
123
|
+
const fieldSchema = schema.fields[key];
|
|
124
|
+
if (!fieldSchema?.enumValues)
|
|
125
|
+
continue;
|
|
126
|
+
const { jsValue, absStart, absEnd } = entry;
|
|
127
|
+
// Skip enum validation for Liquid expressions — they're dynamic and can't be statically checked.
|
|
128
|
+
if (typeof jsValue === 'string' && (0, platformos_common_1.containsLiquid)(jsValue))
|
|
129
|
+
continue;
|
|
130
|
+
const normalizedValue = typeof jsValue === 'string' ? jsValue.toLowerCase() : jsValue;
|
|
131
|
+
const matches = fieldSchema.enumValues.some((allowed) => typeof allowed === 'string'
|
|
132
|
+
? allowed.toLowerCase() === normalizedValue
|
|
133
|
+
: allowed === normalizedValue);
|
|
134
|
+
if (!matches) {
|
|
135
|
+
context.report({
|
|
136
|
+
message: `Invalid value '${jsValue}' for '${key}'. Must be one of: ${fieldSchema.enumValues.join(', ')}`,
|
|
137
|
+
startIndex: absStart,
|
|
138
|
+
endIndex: absEnd,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// 5. Layout association validation (Page and Email).
|
|
143
|
+
// Both types share the primary `layout` key; deprecated aliases differ per type.
|
|
144
|
+
if (fileType === platformos_common_1.PlatformOSFileType.Page || fileType === platformos_common_1.PlatformOSFileType.Email) {
|
|
145
|
+
const deprecatedAlias = fileType === platformos_common_1.PlatformOSFileType.Page ? 'layout_name' : 'layout_path';
|
|
146
|
+
const layoutEntry = entries.get('layout') ?? entries.get(deprecatedAlias);
|
|
147
|
+
if (layoutEntry) {
|
|
148
|
+
if (layoutEntry.jsValue === false) {
|
|
149
|
+
// `layout: false` (YAML boolean) does NOT disable the layout — it falls back to the
|
|
150
|
+
// instance default. Use `layout: ''` to explicitly disable layout rendering.
|
|
151
|
+
context.report({
|
|
152
|
+
message: "`layout: false` falls back to the default layout. Use `layout: ''` to disable layout rendering.",
|
|
153
|
+
startIndex: layoutEntry.valueAbsStart,
|
|
154
|
+
endIndex: layoutEntry.valueAbsEnd,
|
|
155
|
+
suggest: [
|
|
156
|
+
{
|
|
157
|
+
message: "Replace with `layout: ''`",
|
|
158
|
+
fix: (corrector) => {
|
|
159
|
+
corrector.replace(layoutEntry.valueAbsStart, layoutEntry.valueAbsEnd, "''");
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
],
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
else if (typeof layoutEntry.jsValue === 'string' &&
|
|
166
|
+
layoutEntry.jsValue !== '' &&
|
|
167
|
+
!(0, platformos_common_1.containsLiquid)(layoutEntry.jsValue)) {
|
|
168
|
+
await checkLayoutExists(layoutEntry.jsValue, layoutEntry, context);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// 6. Authorization policy association validation (Page)
|
|
173
|
+
if (fileType === platformos_common_1.PlatformOSFileType.Page) {
|
|
174
|
+
await checkNotificationArray(doc, bodyOffset, 'authorization_policies', `app/${platformos_common_1.FRONTMATTER_ASSOCIATION_DIRS['authorization_policies']}`, 'Authorization policy', context);
|
|
175
|
+
}
|
|
176
|
+
// 7. Notification association validation (FormConfiguration)
|
|
177
|
+
if (fileType === platformos_common_1.PlatformOSFileType.FormConfiguration) {
|
|
178
|
+
for (const [field, dir] of Object.entries(platformos_common_1.FRONTMATTER_ASSOCIATION_DIRS)) {
|
|
179
|
+
if (field === 'authorization_policies')
|
|
180
|
+
continue; // only on Page, handled above
|
|
181
|
+
await checkNotificationArray(doc, bodyOffset, field, `app/${dir}`, fieldLabel(field), context);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* Checks each string item of a YAML sequence field against the filesystem.
|
|
190
|
+
*
|
|
191
|
+
* App-level items (e.g. `require_login`) are looked up at `{dir}/{name}.liquid`.
|
|
192
|
+
* Module-prefixed items (e.g. `modules/community/require_login`) are looked up
|
|
193
|
+
* at modules/{mod}/{public|private}/{moduleDir}/{name}.liquid where moduleDir
|
|
194
|
+
* is derived from dir by stripping the leading `app/` segment.
|
|
195
|
+
*/
|
|
196
|
+
async function checkNotificationArray(doc, bodyOffset, fieldName, dir, label, context) {
|
|
197
|
+
if (!(0, yaml_1.isMap)(doc.contents))
|
|
198
|
+
return;
|
|
199
|
+
const pair = doc.contents.items.find((p) => (0, yaml_1.isScalar)(p.key) && p.key.value === fieldName);
|
|
200
|
+
if (!pair || !(0, yaml_1.isSeq)(pair.value))
|
|
201
|
+
return;
|
|
202
|
+
// Module-relative dir: strip leading 'app/' (e.g. 'app/authorization_policies' → 'authorization_policies')
|
|
203
|
+
const moduleDir = dir.slice('app/'.length);
|
|
204
|
+
for (const item of pair.value.items) {
|
|
205
|
+
if (!(0, yaml_1.isScalar)(item) || typeof item.value !== 'string')
|
|
206
|
+
continue;
|
|
207
|
+
const name = item.value;
|
|
208
|
+
if ((0, platformos_common_1.containsLiquid)(name))
|
|
209
|
+
continue;
|
|
210
|
+
const [is = 0, ie = 0] = item.range ?? [];
|
|
211
|
+
let exists;
|
|
212
|
+
if (name.startsWith('modules/')) {
|
|
213
|
+
const match = name.match(/^modules\/([^/]+)\/(.+)$/);
|
|
214
|
+
if (!match) {
|
|
215
|
+
exists = false;
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
const [, mod, rest] = match;
|
|
219
|
+
exists =
|
|
220
|
+
(await (0, file_utils_1.doesFileExist)(context, `modules/${mod}/public/${moduleDir}/${rest}.liquid`)) ||
|
|
221
|
+
(await (0, file_utils_1.doesFileExist)(context, `modules/${mod}/private/${moduleDir}/${rest}.liquid`));
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
exists = await (0, file_utils_1.doesFileExist)(context, `${dir}/${name}.liquid`);
|
|
226
|
+
}
|
|
227
|
+
if (!exists) {
|
|
228
|
+
context.report({
|
|
229
|
+
message: `${label} '${name}' does not exist`,
|
|
230
|
+
startIndex: bodyOffset + is,
|
|
231
|
+
endIndex: bodyOffset + ie,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Tries both `{base}.liquid` and `{base}.html.liquid` since layout files may
|
|
238
|
+
* carry a format extension (e.g. `application.html.liquid`).
|
|
239
|
+
*/
|
|
240
|
+
async function layoutFileExists(context, base) {
|
|
241
|
+
return ((await (0, file_utils_1.doesFileExist)(context, `${base}.liquid`)) ||
|
|
242
|
+
(await (0, file_utils_1.doesFileExist)(context, `${base}.html.liquid`)));
|
|
243
|
+
}
|
|
244
|
+
async function checkLayoutExists(layoutName, entry, context) {
|
|
245
|
+
let exists;
|
|
246
|
+
if (layoutName.startsWith('modules/')) {
|
|
247
|
+
// modules/{mod}/rest → modules/{mod}/{public,private}/views/layouts/{rest}.{html.}liquid
|
|
248
|
+
const match = layoutName.match(/^modules\/([^/]+)\/(.+)$/);
|
|
249
|
+
if (!match)
|
|
250
|
+
return;
|
|
251
|
+
const [, mod, rest] = match;
|
|
252
|
+
exists =
|
|
253
|
+
(await layoutFileExists(context, `modules/${mod}/public/views/layouts/${rest}`)) ||
|
|
254
|
+
(await layoutFileExists(context, `modules/${mod}/private/views/layouts/${rest}`));
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
exists = await layoutFileExists(context, `app/views/layouts/${layoutName}`);
|
|
258
|
+
}
|
|
259
|
+
if (!exists) {
|
|
260
|
+
context.report({
|
|
261
|
+
message: `Layout '${layoutName}' does not exist`,
|
|
262
|
+
startIndex: entry.absStart,
|
|
263
|
+
endIndex: entry.absEnd,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
function fieldLabel(field) {
|
|
268
|
+
switch (field) {
|
|
269
|
+
case 'email_notifications':
|
|
270
|
+
return 'Email notification';
|
|
271
|
+
case 'sms_notifications':
|
|
272
|
+
return 'SMS notification';
|
|
273
|
+
case 'api_call_notifications':
|
|
274
|
+
return 'API call notification';
|
|
275
|
+
default:
|
|
276
|
+
return field;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","source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,CAAC;gBAChF,CAAC,MAAM,gBAAgB,CAAC,OAAO,EAAE,WAAW,GAAG,0BAA0B,IAAI,EAAE,CAAC,CAAC,CAAC;IACtF,CAAC;SAAM,CAAC;QACN,MAAM,GAAG,MAAM,gBAAgB,CAAC,OAAO,EAAE,qBAAqB,UAAU,EAAE,CAAC,CAAC;IAC9E,CAAC;IAED,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,CAAC,MAAM,CAAC;YACb,OAAO,EAAE,WAAW,UAAU,kBAAkB;YAChD,UAAU,EAAE,KAAK,CAAC,QAAQ;YAC1B,QAAQ,EAAE,KAAK,CAAC,MAAM;SACvB,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC/B,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,qBAAqB;YACxB,OAAO,oBAAoB,CAAC;QAC9B,KAAK,mBAAmB;YACtB,OAAO,kBAAkB,CAAC;QAC5B,KAAK,wBAAwB;YAC3B,OAAO,uBAAuB,CAAC;QACjC;YACE,OAAO,KAAK,CAAC;IACjB,CAAC;AACH,CAAC"}
|
|
@@ -1,59 +1 @@
|
|
|
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
|
-
import { PlatformOSFileType } from '@platformos/platformos-common';
|
|
16
|
-
export type FrontmatterFieldType = 'string' | 'boolean' | 'integer' | 'number' | 'array' | 'object';
|
|
17
|
-
export interface FrontmatterFieldSchema {
|
|
18
|
-
/** The expected YAML type(s) for this field's value. */
|
|
19
|
-
type: FrontmatterFieldType | FrontmatterFieldType[];
|
|
20
|
-
/** Whether this field must be present. */
|
|
21
|
-
required?: boolean;
|
|
22
|
-
/** Human-readable description of this field. */
|
|
23
|
-
description?: string;
|
|
24
|
-
/** Whether this field name is deprecated in favour of a newer one. */
|
|
25
|
-
deprecated?: boolean;
|
|
26
|
-
/** Message shown when this deprecated field is used. */
|
|
27
|
-
deprecatedMessage?: string;
|
|
28
|
-
}
|
|
29
|
-
export interface FrontmatterSchema {
|
|
30
|
-
/** Human-readable name of the file type, used in diagnostics. */
|
|
31
|
-
name: string;
|
|
32
|
-
/**
|
|
33
|
-
* Known frontmatter fields.
|
|
34
|
-
* Checks can use this to surface unknown keys or missing required keys.
|
|
35
|
-
*/
|
|
36
|
-
fields: Record<string, FrontmatterFieldSchema>;
|
|
37
|
-
/**
|
|
38
|
-
* Whether fields not listed in `fields` are allowed without a warning.
|
|
39
|
-
* Defaults to true — schemas are additive and may not be exhaustive.
|
|
40
|
-
*/
|
|
41
|
-
allowAdditionalFields?: boolean;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Per-type frontmatter schemas.
|
|
45
|
-
*
|
|
46
|
-
* Only Liquid file types are present here — GraphQL, YAML, and Asset types
|
|
47
|
-
* do not use frontmatter.
|
|
48
|
-
*
|
|
49
|
-
* Field lists are based on real-world usage in platformOS apps. Set
|
|
50
|
-
* `allowAdditionalFields: true` (the default) everywhere so that apps using
|
|
51
|
-
* custom/undocumented keys don't get false-positive warnings until the schemas
|
|
52
|
-
* are finalised.
|
|
53
|
-
*/
|
|
54
|
-
export declare const FRONTMATTER_SCHEMAS: Partial<Record<PlatformOSFileType, FrontmatterSchema>>;
|
|
55
|
-
/**
|
|
56
|
-
* Returns the frontmatter schema for a given file type, or undefined if no
|
|
57
|
-
* schema is defined for that type (e.g. GraphQL, YAML, Asset types).
|
|
58
|
-
*/
|
|
59
|
-
export declare function getFrontmatterSchema(fileType: PlatformOSFileType | undefined): FrontmatterSchema | undefined;
|
|
1
|
+
export { type FrontmatterFieldType, type FrontmatterFieldSchema, type FrontmatterSchema, FRONTMATTER_SCHEMAS, getFrontmatterSchema, } from '@platformos/platformos-common';
|