arkgate 3.0.5 → 3.2.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/CHANGELOG.md +92 -1
- package/README.md +58 -21
- package/bin/ark-check.mjs +46 -4
- package/bin/ark-mcp.mjs +267 -26
- package/bin/ark.mjs +47 -0
- package/bin/lib/adapter-contract.mjs +27 -1
- package/bin/lib/analysis-engine.mjs +7 -1169
- package/bin/lib/ci-and-commands.mjs +4 -0
- package/bin/lib/contract-smells.mjs +514 -0
- package/bin/lib/doctor-plan.mjs +15 -4
- package/bin/lib/host-support-matrix.mjs +6 -2
- package/bin/lib/policy-delta-io.mjs +161 -0
- package/bin/lib/prepare-change.mjs +186 -0
- package/bin/lib/remediation.mjs +24 -0
- package/bin/lib/violations.mjs +2 -2
- package/bin/lib/write-path-capabilities.mjs +67 -1
- package/bin/lib/write-path-detect.mjs +4 -3
- package/dist/eslint/index.cjs +3 -977
- package/dist/eslint/index.js +3 -931
- package/dist/index.cjs +6 -1960
- package/dist/index.d.cts +152 -5
- package/dist/index.d.ts +152 -5
- package/dist/index.js +6 -1908
- package/docs/agent-guide.md +39 -5
- package/docs/ai-gates.md +17 -15
- package/docs/configuration.md +44 -0
- package/docs/demos/01-write-gate-self-correction.md +2 -2
- package/docs/enthusiast/README.md +5 -1
- package/docs/enthusiast/how-to-agent-gates.md +3 -5
- package/docs/enthusiast/how-to-policy-pack.md +4 -1
- package/docs/enthusiast/reference-archetypes.md +8 -1
- package/docs/enthusiast/reference-commands.md +8 -2
- package/docs/package-surface.md +12 -2
- package/docs/threat-model.md +10 -6
- package/package.json +7 -6
- package/schemas/ark.analysis-result.schema.json +5 -1
- package/schemas/ark.change-map.schema.json +77 -0
- package/server.json +3 -3
- package/docs/ark-check-example.json +0 -87
- package/docs/demos/03-copilot-autopilot.md +0 -93
- package/docs/migrate-from-ark-runtime-kernel.md +0 -174
- package/docs/production-hardening.md +0 -100
package/dist/eslint/index.js
CHANGED
|
@@ -1,931 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import path from "path";
|
|
4
|
-
|
|
5
|
-
// src/domain/layerMatch.ts
|
|
6
|
-
var regexpCache = /* @__PURE__ */ new Map();
|
|
7
|
-
function escapeLiteral(ch) {
|
|
8
|
-
return /[.*+?^${}()|[\]\\]/.test(ch) ? `\\${ch}` : ch;
|
|
9
|
-
}
|
|
10
|
-
function normalizeGlobSeparators(pattern) {
|
|
11
|
-
let out = "";
|
|
12
|
-
for (let i = 0; i < pattern.length; i += 1) {
|
|
13
|
-
const c = pattern[i];
|
|
14
|
-
if (c === "\\" && i + 1 < pattern.length) {
|
|
15
|
-
const next = pattern[i + 1];
|
|
16
|
-
if ("*?{}[],".includes(next) || next === "\\") {
|
|
17
|
-
out += "\\" + next;
|
|
18
|
-
i += 1;
|
|
19
|
-
continue;
|
|
20
|
-
}
|
|
21
|
-
out += "/";
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
out += c;
|
|
25
|
-
}
|
|
26
|
-
return out;
|
|
27
|
-
}
|
|
28
|
-
function bracesBalanced(glob) {
|
|
29
|
-
let depth = 0;
|
|
30
|
-
for (let i = 0; i < glob.length; i += 1) {
|
|
31
|
-
const c = glob[i];
|
|
32
|
-
if (c === "\\") {
|
|
33
|
-
i += 1;
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
if (c === "{") depth += 1;
|
|
37
|
-
else if (c === "}") {
|
|
38
|
-
depth -= 1;
|
|
39
|
-
if (depth < 0) return false;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return depth === 0;
|
|
43
|
-
}
|
|
44
|
-
function globToRegExp(pattern) {
|
|
45
|
-
const cached = regexpCache.get(pattern);
|
|
46
|
-
if (cached) return cached;
|
|
47
|
-
const glob = normalizeGlobSeparators(pattern);
|
|
48
|
-
const useBraces = bracesBalanced(glob);
|
|
49
|
-
let out = "";
|
|
50
|
-
let braceDepth = 0;
|
|
51
|
-
for (let i = 0; i < glob.length; i += 1) {
|
|
52
|
-
const c = glob[i];
|
|
53
|
-
if (c === "\\" && i + 1 < glob.length) {
|
|
54
|
-
out += escapeLiteral(glob[i + 1]);
|
|
55
|
-
i += 1;
|
|
56
|
-
} else if (c === "*") {
|
|
57
|
-
if (glob[i + 1] === "*") {
|
|
58
|
-
if (glob[i + 2] === "/") {
|
|
59
|
-
out += "(?:.*/)?";
|
|
60
|
-
i += 2;
|
|
61
|
-
} else {
|
|
62
|
-
out += ".*";
|
|
63
|
-
i += 1;
|
|
64
|
-
}
|
|
65
|
-
} else {
|
|
66
|
-
out += "[^/]*";
|
|
67
|
-
}
|
|
68
|
-
} else if (c === "?") {
|
|
69
|
-
out += "[^/]";
|
|
70
|
-
} else if (c === "{" && useBraces) {
|
|
71
|
-
out += "(?:";
|
|
72
|
-
braceDepth += 1;
|
|
73
|
-
} else if (c === "}" && useBraces && braceDepth > 0) {
|
|
74
|
-
out += ")";
|
|
75
|
-
braceDepth -= 1;
|
|
76
|
-
} else if (c === "," && useBraces && braceDepth > 0) {
|
|
77
|
-
out += "|";
|
|
78
|
-
} else {
|
|
79
|
-
out += escapeLiteral(c);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
const re = new RegExp(`^${out}$`);
|
|
83
|
-
regexpCache.set(pattern, re);
|
|
84
|
-
return re;
|
|
85
|
-
}
|
|
86
|
-
function patternSpecificity(pattern) {
|
|
87
|
-
const glob = normalizeGlobSeparators(String(pattern));
|
|
88
|
-
const beforeWildcard = glob.split("*")[0];
|
|
89
|
-
const literalSegments = beforeWildcard.split("/").filter(Boolean).length;
|
|
90
|
-
const literalLength = glob.replace(/\*/g, "").length;
|
|
91
|
-
return literalSegments * 1e4 + literalLength;
|
|
92
|
-
}
|
|
93
|
-
function layerForRelativePath(relPath, layers) {
|
|
94
|
-
const rel = String(relPath).split(/[/\\]/).join("/");
|
|
95
|
-
let bestName;
|
|
96
|
-
let bestScore = -1;
|
|
97
|
-
for (const layer of layers ?? []) {
|
|
98
|
-
if ((layer.exclude ?? []).some((pattern) => globToRegExp(pattern).test(rel))) {
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
for (const pattern of layer.patterns ?? []) {
|
|
102
|
-
if (globToRegExp(pattern).test(rel)) {
|
|
103
|
-
const score = patternSpecificity(pattern);
|
|
104
|
-
if (score > bestScore) {
|
|
105
|
-
bestScore = score;
|
|
106
|
-
bestName = layer.name;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return bestName;
|
|
112
|
-
}
|
|
113
|
-
function sliceIdForPath(relPath, sliceFolders) {
|
|
114
|
-
if (!sliceFolders?.length) return void 0;
|
|
115
|
-
const parts = String(relPath).split(/[/\\]/).filter(Boolean);
|
|
116
|
-
const folders = new Set(sliceFolders.map((s) => String(s).toLowerCase()));
|
|
117
|
-
for (let i = 0; i < parts.length - 1; i += 1) {
|
|
118
|
-
if (folders.has(parts[i].toLowerCase())) {
|
|
119
|
-
return `${parts[i]}/${parts[i + 1]}`;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return void 0;
|
|
123
|
-
}
|
|
124
|
-
function inferSliceFoldersFromPatterns(patterns) {
|
|
125
|
-
const out = /* @__PURE__ */ new Set();
|
|
126
|
-
for (const pattern of patterns ?? []) {
|
|
127
|
-
const glob = normalizeGlobSeparators(String(pattern));
|
|
128
|
-
const parts = glob.split("/").filter(Boolean);
|
|
129
|
-
for (let i = 0; i < parts.length; i += 1) {
|
|
130
|
-
const part = parts[i];
|
|
131
|
-
if ((part === "**" || part === "*") && i > 0) {
|
|
132
|
-
const prev = parts[i - 1];
|
|
133
|
-
if (prev && !prev.includes("*") && !prev.includes("{") && !prev.includes("}")) {
|
|
134
|
-
out.add(prev);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return [...out];
|
|
140
|
-
}
|
|
141
|
-
function resolveSliceFolders(rule, layerName, layers) {
|
|
142
|
-
if (Array.isArray(rule.sliceFolders) && rule.sliceFolders.length > 0) {
|
|
143
|
-
return rule.sliceFolders.filter((s) => typeof s === "string" && s.length > 0);
|
|
144
|
-
}
|
|
145
|
-
const layer = (layers ?? []).find((l) => l.name === layerName);
|
|
146
|
-
return inferSliceFoldersFromPatterns(layer?.patterns);
|
|
147
|
-
}
|
|
148
|
-
function findDeniedEdgeRule(rules2, from, to, options) {
|
|
149
|
-
for (const rule of rules2 ?? []) {
|
|
150
|
-
if (rule.from !== from || rule.to !== to) continue;
|
|
151
|
-
if (rule.allowed !== false) continue;
|
|
152
|
-
if (rule.peerIsolation) {
|
|
153
|
-
const fromPath = options?.fromPath;
|
|
154
|
-
const toPath = options?.toPath;
|
|
155
|
-
if (!fromPath || !toPath) continue;
|
|
156
|
-
const folders = resolveSliceFolders(rule, from, options?.layers);
|
|
157
|
-
if (folders.length === 0) continue;
|
|
158
|
-
const fromSlice = sliceIdForPath(fromPath, folders);
|
|
159
|
-
const toSlice = sliceIdForPath(toPath, folders);
|
|
160
|
-
if (!fromSlice || !toSlice) continue;
|
|
161
|
-
if (fromSlice !== toSlice) return rule;
|
|
162
|
-
continue;
|
|
163
|
-
}
|
|
164
|
-
if (from === to) continue;
|
|
165
|
-
return rule;
|
|
166
|
-
}
|
|
167
|
-
return void 0;
|
|
168
|
-
}
|
|
169
|
-
function isEdgeDenied(rules2, from, to, options) {
|
|
170
|
-
return findDeniedEdgeRule(rules2, from, to, options) !== void 0;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// src/domain/configContract.ts
|
|
174
|
-
var ARK_CONFIG_SCHEMA_VERSION = "1.0";
|
|
175
|
-
var ARK_CONFIG_SCHEMA_URL = "https://unpkg.com/arkgate@2/schemas/ark.config.schema.json";
|
|
176
|
-
var DEFAULT_LAYER_NAMES = [
|
|
177
|
-
"DomainModel",
|
|
178
|
-
"ApplicationOrchestration",
|
|
179
|
-
"PersistenceAdapters",
|
|
180
|
-
"IntegrationAdapters",
|
|
181
|
-
"WorkflowSagaEngine",
|
|
182
|
-
"BackgroundJobsScheduling",
|
|
183
|
-
"PresentationAdapters",
|
|
184
|
-
"ReportingReadModels",
|
|
185
|
-
"ExtensibilityMetadata",
|
|
186
|
-
"SecurityAuditObservability",
|
|
187
|
-
"Kernel"
|
|
188
|
-
];
|
|
189
|
-
var DEFAULT_ALLOWED_FLOWS = /* @__PURE__ */ new Set([
|
|
190
|
-
"PresentationAdapters->ApplicationOrchestration",
|
|
191
|
-
"ApplicationOrchestration->DomainModel",
|
|
192
|
-
"WorkflowSagaEngine->ApplicationOrchestration",
|
|
193
|
-
"WorkflowSagaEngine->DomainModel",
|
|
194
|
-
"BackgroundJobsScheduling->ApplicationOrchestration"
|
|
195
|
-
]);
|
|
196
|
-
function createDefaultRules() {
|
|
197
|
-
const rules2 = [];
|
|
198
|
-
for (const from of DEFAULT_LAYER_NAMES) {
|
|
199
|
-
for (const to of DEFAULT_LAYER_NAMES) {
|
|
200
|
-
if (from === to || DEFAULT_ALLOWED_FLOWS.has(`${from}->${to}`)) continue;
|
|
201
|
-
rules2.push({ from, to, allowed: false });
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
return rules2;
|
|
205
|
-
}
|
|
206
|
-
var DEFAULT_ARK_CONFIG_RULES = createDefaultRules();
|
|
207
|
-
var stringArraySchema = {
|
|
208
|
-
type: "array",
|
|
209
|
-
items: { type: "string", minLength: 1 },
|
|
210
|
-
uniqueItems: true
|
|
211
|
-
};
|
|
212
|
-
var ARK_CONFIG_SCHEMA = {
|
|
213
|
-
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
214
|
-
$id: ARK_CONFIG_SCHEMA_URL,
|
|
215
|
-
title: "ArkGate architecture contract",
|
|
216
|
-
description: "Versioned contract consumed identically by ArkGate CLI, MCP, and ESLint surfaces.",
|
|
217
|
-
type: "object",
|
|
218
|
-
additionalProperties: false,
|
|
219
|
-
required: ["$schema", "schemaVersion", "include", "layers", "rules"],
|
|
220
|
-
properties: {
|
|
221
|
-
$schema: {
|
|
222
|
-
type: "string",
|
|
223
|
-
minLength: 1,
|
|
224
|
-
default: ARK_CONFIG_SCHEMA_URL,
|
|
225
|
-
description: "Editor-facing URL or local path for this JSON Schema."
|
|
226
|
-
},
|
|
227
|
-
schemaVersion: {
|
|
228
|
-
type: "string",
|
|
229
|
-
const: ARK_CONFIG_SCHEMA_VERSION,
|
|
230
|
-
default: ARK_CONFIG_SCHEMA_VERSION
|
|
231
|
-
},
|
|
232
|
-
name: { type: "string", minLength: 1 },
|
|
233
|
-
include: { ...stringArraySchema, minItems: 1, default: ["src"] },
|
|
234
|
-
exclude: { ...stringArraySchema, default: [] },
|
|
235
|
-
excludeGenerated: { type: "boolean", default: true },
|
|
236
|
-
frameworkOverlay: { type: "string", minLength: 1 },
|
|
237
|
-
layers: {
|
|
238
|
-
type: "array",
|
|
239
|
-
default: [],
|
|
240
|
-
items: { $ref: "#/$defs/layer" }
|
|
241
|
-
},
|
|
242
|
-
rules: {
|
|
243
|
-
type: "array",
|
|
244
|
-
default: DEFAULT_ARK_CONFIG_RULES,
|
|
245
|
-
items: { $ref: "#/$defs/rule" }
|
|
246
|
-
},
|
|
247
|
-
cyclePolicy: {
|
|
248
|
-
type: "string",
|
|
249
|
-
enum: ["strict", "soft", "framework-soft", "off"],
|
|
250
|
-
default: "strict"
|
|
251
|
-
},
|
|
252
|
-
dynamicImportAllowlist: { ...stringArraySchema, default: [] },
|
|
253
|
-
safety: {
|
|
254
|
-
$ref: "#/$defs/safety",
|
|
255
|
-
default: {
|
|
256
|
-
maxTsSuppressions: 0,
|
|
257
|
-
maxAnyCasts: 0,
|
|
258
|
-
allowInMemory: false,
|
|
259
|
-
allowDisabledPeerIsolation: false
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
},
|
|
263
|
-
$defs: {
|
|
264
|
-
layer: {
|
|
265
|
-
type: "object",
|
|
266
|
-
additionalProperties: false,
|
|
267
|
-
required: ["name", "patterns"],
|
|
268
|
-
properties: {
|
|
269
|
-
name: { type: "string", minLength: 1 },
|
|
270
|
-
patterns: { ...stringArraySchema, minItems: 1 },
|
|
271
|
-
exclude: stringArraySchema,
|
|
272
|
-
intentPrefixes: stringArraySchema,
|
|
273
|
-
description: { type: "string", minLength: 1 },
|
|
274
|
-
forbiddenGlobals: stringArraySchema,
|
|
275
|
-
mayImportInfrastructure: { type: "boolean" },
|
|
276
|
-
optional: { type: "boolean" }
|
|
277
|
-
}
|
|
278
|
-
},
|
|
279
|
-
rule: {
|
|
280
|
-
type: "object",
|
|
281
|
-
additionalProperties: false,
|
|
282
|
-
required: ["from", "to", "allowed"],
|
|
283
|
-
properties: {
|
|
284
|
-
from: { type: "string", minLength: 1 },
|
|
285
|
-
to: { type: "string", minLength: 1 },
|
|
286
|
-
allowed: { type: "boolean" },
|
|
287
|
-
message: { type: "string", minLength: 1 },
|
|
288
|
-
peerIsolation: { type: "boolean" },
|
|
289
|
-
sliceFolders: { ...stringArraySchema, minItems: 1 }
|
|
290
|
-
}
|
|
291
|
-
},
|
|
292
|
-
safety: {
|
|
293
|
-
type: "object",
|
|
294
|
-
additionalProperties: false,
|
|
295
|
-
properties: {
|
|
296
|
-
maxTsSuppressions: { type: "integer", minimum: 0, default: 0 },
|
|
297
|
-
maxAnyCasts: { type: "integer", minimum: 0, default: 0 },
|
|
298
|
-
allowInMemory: { type: "boolean", default: false },
|
|
299
|
-
allowDisabledPeerIsolation: { type: "boolean", default: false }
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
};
|
|
304
|
-
var ArkConfigValidationError = class extends Error {
|
|
305
|
-
issues;
|
|
306
|
-
source;
|
|
307
|
-
constructor(source, issues) {
|
|
308
|
-
super(
|
|
309
|
-
`Invalid ArkGate config (${source}):
|
|
310
|
-
${issues.map((issue) => `- ${issue.path}: ${issue.message}`).join("\n")}`
|
|
311
|
-
);
|
|
312
|
-
this.name = "ArkConfigValidationError";
|
|
313
|
-
this.source = source;
|
|
314
|
-
this.issues = issues;
|
|
315
|
-
}
|
|
316
|
-
};
|
|
317
|
-
function isObject(value) {
|
|
318
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
319
|
-
}
|
|
320
|
-
function propertyPath(parent, key) {
|
|
321
|
-
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) ? `${parent}.${key}` : `${parent}[${JSON.stringify(key)}]`;
|
|
322
|
-
}
|
|
323
|
-
function valueType(value) {
|
|
324
|
-
if (value === null) return "null";
|
|
325
|
-
if (Array.isArray(value)) return "array";
|
|
326
|
-
return typeof value;
|
|
327
|
-
}
|
|
328
|
-
function resolveSchemaRef(ref, root) {
|
|
329
|
-
const prefix = "#/$defs/";
|
|
330
|
-
if (!ref.startsWith(prefix)) return void 0;
|
|
331
|
-
return root.$defs[ref.slice(prefix.length)];
|
|
332
|
-
}
|
|
333
|
-
function validateNode(value, schema, path2, root, issues) {
|
|
334
|
-
if (schema.$ref) {
|
|
335
|
-
const referenced = resolveSchemaRef(schema.$ref, root);
|
|
336
|
-
if (!referenced) {
|
|
337
|
-
issues.push({ path: path2, message: `schema reference ${schema.$ref} cannot be resolved` });
|
|
338
|
-
return;
|
|
339
|
-
}
|
|
340
|
-
validateNode(value, referenced, path2, root, issues);
|
|
341
|
-
return;
|
|
342
|
-
}
|
|
343
|
-
if (schema.const !== void 0 && !Object.is(value, schema.const)) {
|
|
344
|
-
issues.push({ path: path2, message: `must equal ${JSON.stringify(schema.const)}` });
|
|
345
|
-
return;
|
|
346
|
-
}
|
|
347
|
-
if (schema.enum && !schema.enum.some((candidate) => Object.is(candidate, value))) {
|
|
348
|
-
issues.push({ path: path2, message: `must be one of ${schema.enum.map(String).join(", ")}` });
|
|
349
|
-
return;
|
|
350
|
-
}
|
|
351
|
-
if (schema.type === "object") {
|
|
352
|
-
if (!isObject(value)) {
|
|
353
|
-
issues.push({ path: path2, message: `must be an object; received ${valueType(value)}` });
|
|
354
|
-
return;
|
|
355
|
-
}
|
|
356
|
-
const properties = schema.properties ?? {};
|
|
357
|
-
for (const key of schema.required ?? []) {
|
|
358
|
-
if (value[key] === void 0) {
|
|
359
|
-
issues.push({ path: propertyPath(path2, key), message: "is required" });
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
if (schema.additionalProperties === false) {
|
|
363
|
-
for (const key of Object.keys(value)) {
|
|
364
|
-
if (!(key in properties)) {
|
|
365
|
-
issues.push({ path: propertyPath(path2, key), message: "unknown field" });
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
for (const [key, childSchema] of Object.entries(properties)) {
|
|
370
|
-
if (value[key] !== void 0) {
|
|
371
|
-
validateNode(value[key], childSchema, propertyPath(path2, key), root, issues);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
return;
|
|
375
|
-
}
|
|
376
|
-
if (schema.type === "array") {
|
|
377
|
-
if (!Array.isArray(value)) {
|
|
378
|
-
issues.push({ path: path2, message: `must be an array; received ${valueType(value)}` });
|
|
379
|
-
return;
|
|
380
|
-
}
|
|
381
|
-
if (schema.minItems !== void 0 && value.length < schema.minItems) {
|
|
382
|
-
issues.push({ path: path2, message: `must contain at least ${schema.minItems} item(s)` });
|
|
383
|
-
}
|
|
384
|
-
if (schema.uniqueItems) {
|
|
385
|
-
const serialized = value.map((entry) => JSON.stringify(entry));
|
|
386
|
-
if (new Set(serialized).size !== serialized.length) {
|
|
387
|
-
issues.push({ path: path2, message: "must not contain duplicate items" });
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
if (schema.items) {
|
|
391
|
-
value.forEach(
|
|
392
|
-
(entry, index) => validateNode(entry, schema.items, `${path2}[${index}]`, root, issues)
|
|
393
|
-
);
|
|
394
|
-
}
|
|
395
|
-
return;
|
|
396
|
-
}
|
|
397
|
-
if (schema.type === "string") {
|
|
398
|
-
if (typeof value !== "string") {
|
|
399
|
-
issues.push({ path: path2, message: `must be a string; received ${valueType(value)}` });
|
|
400
|
-
return;
|
|
401
|
-
}
|
|
402
|
-
if (schema.minLength !== void 0 && value.length < schema.minLength) {
|
|
403
|
-
issues.push({ path: path2, message: `must contain at least ${schema.minLength} character(s)` });
|
|
404
|
-
}
|
|
405
|
-
return;
|
|
406
|
-
}
|
|
407
|
-
if (schema.type === "boolean") {
|
|
408
|
-
if (typeof value !== "boolean") {
|
|
409
|
-
issues.push({ path: path2, message: `must be a boolean; received ${valueType(value)}` });
|
|
410
|
-
}
|
|
411
|
-
return;
|
|
412
|
-
}
|
|
413
|
-
if (schema.type === "integer") {
|
|
414
|
-
if (!Number.isInteger(value)) {
|
|
415
|
-
issues.push({ path: path2, message: `must be an integer; received ${valueType(value)}` });
|
|
416
|
-
return;
|
|
417
|
-
}
|
|
418
|
-
if (schema.minimum !== void 0 && value < schema.minimum) {
|
|
419
|
-
issues.push({ path: path2, message: `must be at least ${schema.minimum}` });
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
function defaultedConfig(input) {
|
|
424
|
-
return {
|
|
425
|
-
...input,
|
|
426
|
-
$schema: input.$schema === void 0 ? ARK_CONFIG_SCHEMA_URL : input.$schema,
|
|
427
|
-
schemaVersion: input.schemaVersion === void 0 ? ARK_CONFIG_SCHEMA_VERSION : input.schemaVersion,
|
|
428
|
-
include: input.include === void 0 ? ["src"] : input.include,
|
|
429
|
-
layers: input.layers === void 0 ? [] : input.layers,
|
|
430
|
-
rules: input.rules === void 0 ? DEFAULT_ARK_CONFIG_RULES.map((rule) => ({ ...rule })) : input.rules
|
|
431
|
-
};
|
|
432
|
-
}
|
|
433
|
-
function migrateArkConfig(input, source = "ark.config.json") {
|
|
434
|
-
if (!isObject(input)) {
|
|
435
|
-
throw new ArkConfigValidationError(source, [
|
|
436
|
-
{ path: "$", message: `must be an object; received ${valueType(input)}` }
|
|
437
|
-
]);
|
|
438
|
-
}
|
|
439
|
-
const migratedFrom = input.schemaVersion === void 0 ? "unversioned" : null;
|
|
440
|
-
if (input.schemaVersion !== void 0 && input.schemaVersion !== ARK_CONFIG_SCHEMA_VERSION) {
|
|
441
|
-
throw new ArkConfigValidationError(source, [
|
|
442
|
-
{
|
|
443
|
-
path: "$.schemaVersion",
|
|
444
|
-
message: `unsupported version ${JSON.stringify(input.schemaVersion)}; expected ${ARK_CONFIG_SCHEMA_VERSION}`
|
|
445
|
-
}
|
|
446
|
-
]);
|
|
447
|
-
}
|
|
448
|
-
return { candidate: defaultedConfig(input), migratedFrom };
|
|
449
|
-
}
|
|
450
|
-
function loadArkConfigContract(input, source = "ark.config.json") {
|
|
451
|
-
const { candidate, migratedFrom } = migrateArkConfig(input, source);
|
|
452
|
-
const issues = [];
|
|
453
|
-
validateNode(
|
|
454
|
-
candidate,
|
|
455
|
-
ARK_CONFIG_SCHEMA,
|
|
456
|
-
"$",
|
|
457
|
-
ARK_CONFIG_SCHEMA,
|
|
458
|
-
issues
|
|
459
|
-
);
|
|
460
|
-
if (issues.length > 0) throw new ArkConfigValidationError(source, issues);
|
|
461
|
-
return { config: candidate, migratedFrom };
|
|
462
|
-
}
|
|
463
|
-
function parseArkConfigJson(json, source = "ark.config.json") {
|
|
464
|
-
let input;
|
|
465
|
-
try {
|
|
466
|
-
input = JSON.parse(json);
|
|
467
|
-
} catch (error) {
|
|
468
|
-
throw new ArkConfigValidationError(source, [
|
|
469
|
-
{
|
|
470
|
-
path: "$",
|
|
471
|
-
message: `invalid JSON: ${error instanceof Error ? error.message : String(error)}`
|
|
472
|
-
}
|
|
473
|
-
]);
|
|
474
|
-
}
|
|
475
|
-
return loadArkConfigContract(input, source);
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
// src/domain/adapterContract.ts
|
|
479
|
-
function text(value) {
|
|
480
|
-
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
481
|
-
}
|
|
482
|
-
function positiveInteger(value, fallback) {
|
|
483
|
-
return Number.isInteger(value) && Number(value) > 0 ? Number(value) : fallback;
|
|
484
|
-
}
|
|
485
|
-
function toAdapterDiagnostic(violation, fallbackSeverity = "error") {
|
|
486
|
-
const ruleId = text(violation.ruleId) ?? text(violation.code) ?? "ARK_UNKNOWN";
|
|
487
|
-
const severity = violation.severity === "warning" ? "warning" : fallbackSeverity;
|
|
488
|
-
const evidence = {
|
|
489
|
-
...text(violation.target) ? { target: text(violation.target) } : {},
|
|
490
|
-
...text(violation.fromLayer) ? { fromLayer: text(violation.fromLayer) } : {},
|
|
491
|
-
...text(violation.toLayer) ? { toLayer: text(violation.toLayer) } : {},
|
|
492
|
-
...typeof violation.typeOnly === "boolean" ? { typeOnly: violation.typeOnly } : {}
|
|
493
|
-
};
|
|
494
|
-
return {
|
|
495
|
-
ruleId,
|
|
496
|
-
severity,
|
|
497
|
-
message: text(violation.message) ?? ruleId,
|
|
498
|
-
location: {
|
|
499
|
-
file: text(violation.file) ?? "<unknown>",
|
|
500
|
-
line: positiveInteger(violation.line, 1),
|
|
501
|
-
column: positiveInteger(violation.column, 1)
|
|
502
|
-
},
|
|
503
|
-
evidence
|
|
504
|
-
};
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
// src/domain/sourcePolicy.ts
|
|
508
|
-
var SOURCE_POLICY_MESSAGES = {
|
|
509
|
-
RAW_EVENT_PUBLISH: "Publish through a registered intent creator; raw event objects or intent strings bypass Ark contracts and tooling.",
|
|
510
|
-
PUBLISH_MISSING_SOURCE: "Strict Ark publish calls must include metadata.source."
|
|
511
|
-
};
|
|
512
|
-
function looksLikeArkIntent(value) {
|
|
513
|
-
return /^(Domain|Application|Adapter|Workflow|Job|Presentation|Reporting|Metadata|Security|Audit|Observability|Kernel)\.[A-Za-z0-9_.]+$/.test(
|
|
514
|
-
value
|
|
515
|
-
);
|
|
516
|
-
}
|
|
517
|
-
function classifyPublishFacts(facts) {
|
|
518
|
-
if (!facts.publishCall) return [];
|
|
519
|
-
const findings = [];
|
|
520
|
-
if (facts.rawIntentName !== void 0 && looksLikeArkIntent(facts.rawIntentName) || facts.objectHasIntent) {
|
|
521
|
-
findings.push({
|
|
522
|
-
ruleId: "RAW_EVENT_PUBLISH",
|
|
523
|
-
message: SOURCE_POLICY_MESSAGES.RAW_EVENT_PUBLISH
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
if (facts.arkPublishCandidate && !facts.hasSource) {
|
|
527
|
-
findings.push({
|
|
528
|
-
ruleId: "PUBLISH_MISSING_SOURCE",
|
|
529
|
-
message: SOURCE_POLICY_MESSAGES.PUBLISH_MISSING_SOURCE
|
|
530
|
-
});
|
|
531
|
-
}
|
|
532
|
-
return findings;
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
// src/eslint/index.ts
|
|
536
|
-
function lintedFilename(context) {
|
|
537
|
-
if (typeof context.physicalFilename === "string" && context.physicalFilename.length > 0) {
|
|
538
|
-
return context.physicalFilename;
|
|
539
|
-
}
|
|
540
|
-
if (typeof context.filename === "string" && context.filename.length > 0) {
|
|
541
|
-
return context.filename;
|
|
542
|
-
}
|
|
543
|
-
if (typeof context.getFilename === "function") {
|
|
544
|
-
try {
|
|
545
|
-
const name = context.getFilename();
|
|
546
|
-
if (typeof name === "string" && name.length > 0) return name;
|
|
547
|
-
} catch {
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
return "";
|
|
551
|
-
}
|
|
552
|
-
function reportAdapterDiagnostic(context, node, messageId, violation, data) {
|
|
553
|
-
const diagnostic = toAdapterDiagnostic({
|
|
554
|
-
...violation,
|
|
555
|
-
line: violation.line ?? node.loc?.start?.line,
|
|
556
|
-
column: violation.column ?? (typeof node.loc?.start?.column === "number" ? node.loc.start.column + 1 : void 0)
|
|
557
|
-
});
|
|
558
|
-
context.report({ node, messageId, ...data ? { data } : {}, diagnostic });
|
|
559
|
-
return diagnostic;
|
|
560
|
-
}
|
|
561
|
-
function findConfigPath(startFile) {
|
|
562
|
-
if (!startFile || startFile === "<input>" || startFile.startsWith("stdin")) return null;
|
|
563
|
-
let dir = path.dirname(path.resolve(startFile));
|
|
564
|
-
for (; ; ) {
|
|
565
|
-
const candidate = path.join(dir, "ark.config.json");
|
|
566
|
-
if (fs.existsSync(candidate)) return candidate;
|
|
567
|
-
const parent = path.dirname(dir);
|
|
568
|
-
if (parent === dir) return null;
|
|
569
|
-
dir = parent;
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
var _configCache = /* @__PURE__ */ new Map();
|
|
573
|
-
function loadArkConfig(configPath) {
|
|
574
|
-
if (_configCache.has(configPath)) return _configCache.get(configPath) ?? null;
|
|
575
|
-
if (!fs.existsSync(configPath)) return null;
|
|
576
|
-
const config = parseArkConfigJson(fs.readFileSync(configPath, "utf8"), configPath).config;
|
|
577
|
-
_configCache.set(configPath, config);
|
|
578
|
-
return config;
|
|
579
|
-
}
|
|
580
|
-
function resolveRelativeImport(fromFile, specifier) {
|
|
581
|
-
if (!specifier.startsWith(".")) return null;
|
|
582
|
-
const base = path.resolve(path.dirname(fromFile), specifier);
|
|
583
|
-
const candidates = [
|
|
584
|
-
base,
|
|
585
|
-
`${base}.ts`,
|
|
586
|
-
`${base}.tsx`,
|
|
587
|
-
`${base}.mts`,
|
|
588
|
-
`${base}.cts`,
|
|
589
|
-
`${base}.js`,
|
|
590
|
-
`${base}.jsx`,
|
|
591
|
-
path.join(base, "index.ts"),
|
|
592
|
-
path.join(base, "index.tsx"),
|
|
593
|
-
path.join(base, "index.js")
|
|
594
|
-
];
|
|
595
|
-
for (const c of candidates) {
|
|
596
|
-
try {
|
|
597
|
-
if (fs.existsSync(c) && fs.statSync(c).isFile()) return c;
|
|
598
|
-
} catch {
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
return `${base}.ts`;
|
|
602
|
-
}
|
|
603
|
-
function stringValue(node) {
|
|
604
|
-
return typeof node?.value === "string" ? node.value : void 0;
|
|
605
|
-
}
|
|
606
|
-
function propertyName(node) {
|
|
607
|
-
return node?.name ?? stringValue(node);
|
|
608
|
-
}
|
|
609
|
-
function sourceCodeFor(context) {
|
|
610
|
-
return context.sourceCode ?? context.getSourceCode?.();
|
|
611
|
-
}
|
|
612
|
-
function referenceFor(context, node) {
|
|
613
|
-
let scope = sourceCodeFor(context)?.getScope?.(node);
|
|
614
|
-
while (scope) {
|
|
615
|
-
const reference = scope.references?.find((candidate) => candidate.identifier === node);
|
|
616
|
-
if (reference) return reference;
|
|
617
|
-
scope = scope.upper ?? void 0;
|
|
618
|
-
}
|
|
619
|
-
return void 0;
|
|
620
|
-
}
|
|
621
|
-
function isLocallyBound(context, node, name) {
|
|
622
|
-
const reference = referenceFor(context, node);
|
|
623
|
-
if (reference?.resolved) return (reference.resolved.defs?.length ?? 0) > 0;
|
|
624
|
-
let scope = sourceCodeFor(context)?.getScope?.(node);
|
|
625
|
-
while (scope) {
|
|
626
|
-
const variable = scope.set?.get(name);
|
|
627
|
-
if (variable) return (variable.defs?.length ?? 0) > 0;
|
|
628
|
-
scope = scope.upper ?? void 0;
|
|
629
|
-
}
|
|
630
|
-
return false;
|
|
631
|
-
}
|
|
632
|
-
function isValueIdentifierReference(context, node) {
|
|
633
|
-
const reference = referenceFor(context, node);
|
|
634
|
-
if (reference) return reference.isValueReference !== false;
|
|
635
|
-
return node.parent?.type === "VariableDeclarator" && node.parent.init === node;
|
|
636
|
-
}
|
|
637
|
-
function memberExpressionPath(node) {
|
|
638
|
-
if (node?.type === "Identifier" && node.name) {
|
|
639
|
-
return { root: node, segments: [node.name] };
|
|
640
|
-
}
|
|
641
|
-
if (!node) return void 0;
|
|
642
|
-
const memberLike = node.type === "MemberExpression" || Boolean(node.object && node.property);
|
|
643
|
-
if (!memberLike || node.computed === true) return void 0;
|
|
644
|
-
const base = memberExpressionPath(node.object);
|
|
645
|
-
const property = propertyName(node.property);
|
|
646
|
-
if (!base || !property) return void 0;
|
|
647
|
-
return { root: base.root, segments: [...base.segments, property] };
|
|
648
|
-
}
|
|
649
|
-
function calleePropertyName(node) {
|
|
650
|
-
return propertyName(node.callee?.property);
|
|
651
|
-
}
|
|
652
|
-
function objectProperty(node, name) {
|
|
653
|
-
return node?.properties?.find((property) => propertyName(property.key) === name);
|
|
654
|
-
}
|
|
655
|
-
function objectHasProperty(node, name) {
|
|
656
|
-
return objectProperty(node, name) !== void 0;
|
|
657
|
-
}
|
|
658
|
-
function objectHasMetadataSource(node) {
|
|
659
|
-
const metadata = objectProperty(node, "metadata")?.value;
|
|
660
|
-
return objectHasProperty(metadata, "source");
|
|
661
|
-
}
|
|
662
|
-
function isPublishCall(node) {
|
|
663
|
-
return calleePropertyName(node) === "publish";
|
|
664
|
-
}
|
|
665
|
-
var noDomainInfraImports = {
|
|
666
|
-
meta: {
|
|
667
|
-
type: "problem",
|
|
668
|
-
docs: {
|
|
669
|
-
description: "Disallow imports that violate ark.config.json layer rules (same contract as arkgate-check)."
|
|
670
|
-
},
|
|
671
|
-
messages: {
|
|
672
|
-
forbiddenImport: "Architecture: {{fromLayer}} must not import {{toLayer}} (ark.config.json). Specifier: {{specifier}}",
|
|
673
|
-
forbiddenImportHeuristic: "Domain code must not import infrastructure, adapters, repositories, or database modules."
|
|
674
|
-
},
|
|
675
|
-
schema: []
|
|
676
|
-
},
|
|
677
|
-
create(context) {
|
|
678
|
-
const filename = lintedFilename(context);
|
|
679
|
-
const configPath = findConfigPath(filename);
|
|
680
|
-
const config = configPath ? loadArkConfig(configPath) : null;
|
|
681
|
-
const root = configPath ? path.dirname(configPath) : null;
|
|
682
|
-
const check = (node) => {
|
|
683
|
-
const source = stringValue(node.source);
|
|
684
|
-
if (!source) return;
|
|
685
|
-
if (config && root && filename) {
|
|
686
|
-
const absFile = path.isAbsolute(filename) ? filename : path.resolve(filename);
|
|
687
|
-
const relFile = path.relative(root, absFile).split(path.sep).join("/");
|
|
688
|
-
const fromLayer = layerForRelativePath(relFile, config.layers);
|
|
689
|
-
if (!fromLayer) return;
|
|
690
|
-
const targetAbs = resolveRelativeImport(absFile, source);
|
|
691
|
-
if (!targetAbs) return;
|
|
692
|
-
const relTarget = path.relative(root, targetAbs).split(path.sep).join("/");
|
|
693
|
-
if (relTarget.startsWith("..")) return;
|
|
694
|
-
const toLayer = layerForRelativePath(relTarget, config.layers);
|
|
695
|
-
if (!toLayer) return;
|
|
696
|
-
if (isEdgeDenied(config.rules, fromLayer, toLayer, {
|
|
697
|
-
fromPath: relFile,
|
|
698
|
-
toPath: relTarget,
|
|
699
|
-
layers: config.layers
|
|
700
|
-
})) {
|
|
701
|
-
reportAdapterDiagnostic(
|
|
702
|
-
context,
|
|
703
|
-
node,
|
|
704
|
-
"forbiddenImport",
|
|
705
|
-
{
|
|
706
|
-
ruleId: "LAYER_IMPORT_VIOLATION",
|
|
707
|
-
file: relFile,
|
|
708
|
-
fromLayer,
|
|
709
|
-
toLayer,
|
|
710
|
-
target: relTarget,
|
|
711
|
-
...node.importKind === "type" ? { typeOnly: true } : {},
|
|
712
|
-
message: `${fromLayer} must not import ${toLayer}.`
|
|
713
|
-
},
|
|
714
|
-
{ fromLayer, toLayer, specifier: source }
|
|
715
|
-
);
|
|
716
|
-
}
|
|
717
|
-
return;
|
|
718
|
-
}
|
|
719
|
-
};
|
|
720
|
-
return {
|
|
721
|
-
ImportDeclaration: check,
|
|
722
|
-
ExportNamedDeclaration: check,
|
|
723
|
-
ExportAllDeclaration: check
|
|
724
|
-
};
|
|
725
|
-
}
|
|
726
|
-
};
|
|
727
|
-
var noRawEventPublish = {
|
|
728
|
-
meta: {
|
|
729
|
-
type: "problem",
|
|
730
|
-
docs: {
|
|
731
|
-
description: "Require event bus publish calls to use registered intent creators instead of raw event objects or intent strings."
|
|
732
|
-
},
|
|
733
|
-
messages: {
|
|
734
|
-
rawPublish: "Publish through a registered intent creator; raw event objects or intent strings bypass Ark contracts."
|
|
735
|
-
},
|
|
736
|
-
schema: []
|
|
737
|
-
},
|
|
738
|
-
create(context) {
|
|
739
|
-
return {
|
|
740
|
-
CallExpression(node) {
|
|
741
|
-
const firstArg = node.arguments?.[0];
|
|
742
|
-
const firstValue = stringValue(firstArg);
|
|
743
|
-
const findings = classifyPublishFacts({
|
|
744
|
-
publishCall: isPublishCall(node),
|
|
745
|
-
rawIntentName: firstValue,
|
|
746
|
-
objectHasIntent: objectHasProperty(firstArg, "intent"),
|
|
747
|
-
arkPublishCandidate: false,
|
|
748
|
-
hasSource: true
|
|
749
|
-
});
|
|
750
|
-
if (findings.some((finding) => finding.ruleId === "RAW_EVENT_PUBLISH")) {
|
|
751
|
-
const finding = findings.find((item) => item.ruleId === "RAW_EVENT_PUBLISH");
|
|
752
|
-
reportAdapterDiagnostic(context, node, "rawPublish", {
|
|
753
|
-
...finding,
|
|
754
|
-
file: lintedFilename(context)
|
|
755
|
-
});
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
};
|
|
759
|
-
}
|
|
760
|
-
};
|
|
761
|
-
var requirePublishSource = {
|
|
762
|
-
meta: {
|
|
763
|
-
type: "problem",
|
|
764
|
-
docs: {
|
|
765
|
-
description: "Require event bus publish calls to include source metadata."
|
|
766
|
-
},
|
|
767
|
-
messages: {
|
|
768
|
-
missingSource: "Strict Ark publish calls must include metadata.source."
|
|
769
|
-
},
|
|
770
|
-
schema: []
|
|
771
|
-
},
|
|
772
|
-
create(context) {
|
|
773
|
-
return {
|
|
774
|
-
CallExpression(node) {
|
|
775
|
-
const firstArg = node.arguments?.[0];
|
|
776
|
-
const metadataArg = node.arguments?.[2];
|
|
777
|
-
const findings = classifyPublishFacts({
|
|
778
|
-
publishCall: isPublishCall(node),
|
|
779
|
-
rawIntentName: stringValue(firstArg),
|
|
780
|
-
objectHasIntent: objectHasProperty(firstArg, "intent"),
|
|
781
|
-
arkPublishCandidate: true,
|
|
782
|
-
hasSource: objectHasMetadataSource(firstArg) || objectHasProperty(metadataArg, "source")
|
|
783
|
-
});
|
|
784
|
-
const finding = findings.find((item) => item.ruleId === "PUBLISH_MISSING_SOURCE");
|
|
785
|
-
if (finding) {
|
|
786
|
-
reportAdapterDiagnostic(context, node, "missingSource", {
|
|
787
|
-
...finding,
|
|
788
|
-
file: lintedFilename(context)
|
|
789
|
-
});
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
};
|
|
793
|
-
}
|
|
794
|
-
};
|
|
795
|
-
var noForbiddenGlobals = {
|
|
796
|
-
meta: {
|
|
797
|
-
type: "problem",
|
|
798
|
-
docs: {
|
|
799
|
-
description: "Disallow ambient globals from the layer\u2019s forbiddenGlobals in ark.config.json (same purity surface as ark-check). Option `globals` explicitly overrides."
|
|
800
|
-
},
|
|
801
|
-
messages: {
|
|
802
|
-
forbiddenGlobal: 'Ambient global "{{name}}" is forbidden in {{layer}} (ark.config.json); inject the capability through a port instead.',
|
|
803
|
-
forbiddenGlobalDefault: 'Ambient global "{{name}}" is forbidden here; inject the capability through a port instead.'
|
|
804
|
-
},
|
|
805
|
-
schema: [
|
|
806
|
-
{
|
|
807
|
-
type: "object",
|
|
808
|
-
properties: {
|
|
809
|
-
globals: { type: "array", items: { type: "string" } }
|
|
810
|
-
},
|
|
811
|
-
additionalProperties: false
|
|
812
|
-
}
|
|
813
|
-
]
|
|
814
|
-
},
|
|
815
|
-
create(context) {
|
|
816
|
-
const filename = lintedFilename(context);
|
|
817
|
-
const option = context.options?.[0];
|
|
818
|
-
const configPath = findConfigPath(filename);
|
|
819
|
-
const config = configPath ? loadArkConfig(configPath) : null;
|
|
820
|
-
const root = configPath ? path.dirname(configPath) : null;
|
|
821
|
-
let globals = null;
|
|
822
|
-
let layerName = "this layer";
|
|
823
|
-
if (option?.globals) {
|
|
824
|
-
globals = new Set(option.globals);
|
|
825
|
-
} else if (config && root && filename) {
|
|
826
|
-
const absFile = path.isAbsolute(filename) ? filename : path.resolve(filename);
|
|
827
|
-
const relFile = path.relative(root, absFile).split(path.sep).join("/");
|
|
828
|
-
const layer = config.layers?.find(
|
|
829
|
-
(l) => l.name === layerForRelativePath(relFile, config.layers)
|
|
830
|
-
);
|
|
831
|
-
if (layer?.forbiddenGlobals?.length) {
|
|
832
|
-
globals = new Set(layer.forbiddenGlobals);
|
|
833
|
-
layerName = layer.name;
|
|
834
|
-
} else {
|
|
835
|
-
globals = null;
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
if (!globals) {
|
|
839
|
-
return {};
|
|
840
|
-
}
|
|
841
|
-
const scopeAware = typeof sourceCodeFor(context)?.getScope === "function";
|
|
842
|
-
const report = (node, name) => {
|
|
843
|
-
const absFile = path.isAbsolute(filename) ? filename : path.resolve(filename);
|
|
844
|
-
const reportFile = root ? path.relative(root, absFile).split(path.sep).join("/") : filename;
|
|
845
|
-
reportAdapterDiagnostic(
|
|
846
|
-
context,
|
|
847
|
-
node,
|
|
848
|
-
config ? "forbiddenGlobal" : "forbiddenGlobalDefault",
|
|
849
|
-
{
|
|
850
|
-
ruleId: "FORBIDDEN_GLOBAL",
|
|
851
|
-
file: reportFile,
|
|
852
|
-
fromLayer: layerName,
|
|
853
|
-
target: name,
|
|
854
|
-
message: `${layerName} must not use the ambient global "${name}".`
|
|
855
|
-
},
|
|
856
|
-
{ name, layer: layerName }
|
|
857
|
-
);
|
|
858
|
-
};
|
|
859
|
-
return {
|
|
860
|
-
MemberExpression(node) {
|
|
861
|
-
if (node.parent?.type === "MemberExpression" && node.parent.object === node) return;
|
|
862
|
-
const path2 = memberExpressionPath(node);
|
|
863
|
-
if (!path2 || isLocallyBound(context, path2.root, path2.segments[0])) return;
|
|
864
|
-
const explicitGlobalThis = path2.segments[0] === "globalThis";
|
|
865
|
-
const normalized = explicitGlobalThis ? path2.segments.slice(1) : path2.segments;
|
|
866
|
-
let match;
|
|
867
|
-
for (let length = normalized.length; length >= (explicitGlobalThis ? 1 : 2); length -= 1) {
|
|
868
|
-
const candidate = normalized.slice(0, length).join(".");
|
|
869
|
-
if (globals.has(candidate)) {
|
|
870
|
-
match = candidate;
|
|
871
|
-
break;
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
if (match) report(node, match);
|
|
875
|
-
else if (!scopeAware && globals.has(path2.segments[0])) {
|
|
876
|
-
report(node, path2.segments[0]);
|
|
877
|
-
}
|
|
878
|
-
},
|
|
879
|
-
CallExpression(node) {
|
|
880
|
-
if (scopeAware) return;
|
|
881
|
-
const callee = node.callee?.type === "Identifier" ? node.callee.name : void 0;
|
|
882
|
-
if (callee && globals.has(callee)) report(node, callee);
|
|
883
|
-
},
|
|
884
|
-
NewExpression(node) {
|
|
885
|
-
if (scopeAware) return;
|
|
886
|
-
const callee = node.callee?.type === "Identifier" ? node.callee.name : void 0;
|
|
887
|
-
if (callee && globals.has(callee)) report(node, callee);
|
|
888
|
-
},
|
|
889
|
-
Identifier(node) {
|
|
890
|
-
if (!scopeAware || !node.name || !globals.has(node.name) || !isValueIdentifierReference(context, node) || isLocallyBound(context, node, node.name)) {
|
|
891
|
-
return;
|
|
892
|
-
}
|
|
893
|
-
report(node, node.name);
|
|
894
|
-
}
|
|
895
|
-
};
|
|
896
|
-
}
|
|
897
|
-
};
|
|
898
|
-
var rules = {
|
|
899
|
-
"no-domain-infra-imports": noDomainInfraImports,
|
|
900
|
-
"no-raw-event-publish": noRawEventPublish,
|
|
901
|
-
"require-publish-source": requirePublishSource,
|
|
902
|
-
"no-forbidden-globals": noForbiddenGlobals
|
|
903
|
-
};
|
|
904
|
-
var plugin = { rules };
|
|
905
|
-
plugin.configs = {
|
|
906
|
-
recommended: {
|
|
907
|
-
plugins: { ark: plugin },
|
|
908
|
-
rules: {
|
|
909
|
-
"ark/no-domain-infra-imports": "error",
|
|
910
|
-
"ark/no-raw-event-publish": "error",
|
|
911
|
-
"ark/require-publish-source": "error",
|
|
912
|
-
"ark/no-forbidden-globals": "error"
|
|
913
|
-
}
|
|
914
|
-
}
|
|
915
|
-
};
|
|
916
|
-
var eslint_default = plugin;
|
|
917
|
-
export {
|
|
918
|
-
eslint_default as default,
|
|
919
|
-
findConfigPath,
|
|
920
|
-
globToRegExp,
|
|
921
|
-
isEdgeDenied,
|
|
922
|
-
layerForRelativePath,
|
|
923
|
-
loadArkConfig,
|
|
924
|
-
noDomainInfraImports,
|
|
925
|
-
noForbiddenGlobals,
|
|
926
|
-
noRawEventPublish,
|
|
927
|
-
patternSpecificity,
|
|
928
|
-
plugin,
|
|
929
|
-
requirePublishSource,
|
|
930
|
-
resolveRelativeImport
|
|
931
|
-
};
|
|
1
|
+
import A from"fs";import u from"path";var G=new Map;function D(e){return/[.*+?^${}()|[\]\\]/.test(e)?`\\${e}`:e}function L(e){let n="";for(let t=0;t<e.length;t+=1){let i=e[t];if(i==="\\"&&t+1<e.length){let r=e[t+1];if("*?{}[],".includes(r)||r==="\\"){n+="\\"+r,t+=1;continue}n+="/";continue}n+=i}return n}function ie(e){let n=0;for(let t=0;t<e.length;t+=1){let i=e[t];if(i==="\\"){t+=1;continue}if(i==="{")n+=1;else if(i==="}"&&(n-=1,n<0))return!1}return n===0}function w(e){let n=G.get(e);if(n)return n;let t=L(e),i=ie(t),r="",o=0;for(let a=0;a<t.length;a+=1){let d=t[a];d==="\\"&&a+1<t.length?(r+=D(t[a+1]),a+=1):d==="*"?t[a+1]==="*"?t[a+2]==="/"?(r+="(?:.*/)?",a+=2):(r+=".*",a+=1):r+="[^/]*":d==="?"?r+="[^/]":d==="{"&&i?(r+="(?:",o+=1):d==="}"&&i&&o>0?(r+=")",o-=1):d===","&&i&&o>0?r+="|":r+=D(d)}let s=new RegExp(`^${r}$`);return G.set(e,s),s}function H(e){let n=L(String(e)),i=n.split("*")[0].split("/").filter(Boolean).length,r=n.replace(/\*/g,"").length;return i*1e4+r}function S(e,n){let t=String(e).split(/[/\\]/).join("/"),i,r=-1;for(let o of n??[])if(!(o.exclude??[]).some(s=>w(s).test(t))){for(let s of o.patterns??[])if(w(s).test(t)){let a=H(s);a>r&&(r=a,i=o.name)}}return i}function T(e,n){if(!n?.length)return;let t=String(e).split(/[/\\]/).filter(Boolean),i=new Set(n.map(r=>String(r).toLowerCase()));for(let r=0;r<t.length-1;r+=1)if(i.has(t[r].toLowerCase()))return`${t[r]}/${t[r+1]}`}function oe(e){let n=new Set;for(let t of e??[]){let r=L(String(t)).split("/").filter(Boolean);for(let o=0;o<r.length;o+=1){let s=r[o];if((s==="**"||s==="*")&&o>0){let a=r[o-1];a&&!a.includes("*")&&!a.includes("{")&&!a.includes("}")&&n.add(a)}}}return[...n]}function se(e,n,t){if(Array.isArray(e.sliceFolders)&&e.sliceFolders.length>0)return e.sliceFolders.filter(r=>typeof r=="string"&&r.length>0);let i=(t??[]).find(r=>r.name===n);return oe(i?.patterns)}function ae(e,n,t,i){for(let r of e??[])if(!(r.from!==n||r.to!==t)&&r.allowed===!1){if(r.peerIsolation){let o=i?.fromPath,s=i?.toPath;if(!o||!s)continue;let a=se(r,n,i?.layers);if(a.length===0)continue;let d=T(o,a),p=T(s,a);if(!d||!p)continue;if(d!==p)return r;continue}if(n!==t)return r}}function v(e,n,t,i){return ae(e,n,t,i)!==void 0}var O="https://unpkg.com/arkgate@2/schemas/ark.config.schema.json",U=["DomainModel","ApplicationOrchestration","PersistenceAdapters","IntegrationAdapters","WorkflowSagaEngine","BackgroundJobsScheduling","PresentationAdapters","ReportingReadModels","ExtensibilityMetadata","SecurityAuditObservability","Kernel"],le=new Set(["PresentationAdapters->ApplicationOrchestration","ApplicationOrchestration->DomainModel","WorkflowSagaEngine->ApplicationOrchestration","WorkflowSagaEngine->DomainModel","BackgroundJobsScheduling->ApplicationOrchestration"]);function ce(){let e=[];for(let n of U)for(let t of U)n===t||le.has(`${n}->${t}`)||e.push({from:n,to:t,allowed:!1});return e}var K=ce();var y={type:"array",items:{type:"string",minLength:1},uniqueItems:!0},B={$schema:"https://json-schema.org/draft/2020-12/schema",$id:O,title:"ArkGate architecture contract",description:"Versioned contract consumed identically by ArkGate CLI, MCP, and ESLint surfaces.",type:"object",additionalProperties:!1,required:["$schema","schemaVersion","include","layers","rules"],properties:{$schema:{type:"string",minLength:1,default:O,description:"Editor-facing URL or local path for this JSON Schema."},schemaVersion:{type:"string",const:"1.0",default:"1.0"},name:{type:"string",minLength:1},include:{...y,minItems:1,default:["src"]},exclude:{...y,default:[]},excludeGenerated:{type:"boolean",default:!0},frameworkOverlay:{type:"string",minLength:1},layers:{type:"array",default:[],items:{$ref:"#/$defs/layer"}},rules:{type:"array",default:K,items:{$ref:"#/$defs/rule"}},cyclePolicy:{type:"string",enum:["strict","soft","framework-soft","off"],default:"strict"},dynamicImportAllowlist:{...y,default:[]},safety:{$ref:"#/$defs/safety",default:{maxTsSuppressions:0,maxAnyCasts:0,allowInMemory:!1,allowDisabledPeerIsolation:!1}}},$defs:{layer:{type:"object",additionalProperties:!1,required:["name","patterns"],properties:{name:{type:"string",minLength:1},patterns:{...y,minItems:1},exclude:y,intentPrefixes:y,description:{type:"string",minLength:1},forbiddenGlobals:y,mayImportInfrastructure:{type:"boolean"},optional:{type:"boolean"}}},rule:{type:"object",additionalProperties:!1,required:["from","to","allowed"],properties:{from:{type:"string",minLength:1},to:{type:"string",minLength:1},allowed:{type:"boolean"},message:{type:"string",minLength:1},peerIsolation:{type:"boolean"},sliceFolders:{...y,minItems:1}}},safety:{type:"object",additionalProperties:!1,properties:{maxTsSuppressions:{type:"integer",minimum:0,default:0},maxAnyCasts:{type:"integer",minimum:0,default:0},allowInMemory:{type:"boolean",default:!1},allowDisabledPeerIsolation:{type:"boolean",default:!1}}}}},h=class extends Error{issues;source;constructor(n,t){super(`Invalid ArkGate config (${n}):
|
|
2
|
+
${t.map(i=>`- ${i.path}: ${i.message}`).join(`
|
|
3
|
+
`)}`),this.name="ArkConfigValidationError",this.source=n,this.issues=t}};function W(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function _(e,n){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(n)?`${e}.${n}`:`${e}[${JSON.stringify(n)}]`}function b(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function ue(e,n){let t="#/$defs/";if(e.startsWith(t))return n.$defs[e.slice(t.length)]}function k(e,n,t,i,r){if(n.$ref){let o=ue(n.$ref,i);if(!o){r.push({path:t,message:`schema reference ${n.$ref} cannot be resolved`});return}k(e,o,t,i,r);return}if(n.const!==void 0&&!Object.is(e,n.const)){r.push({path:t,message:`must equal ${JSON.stringify(n.const)}`});return}if(n.enum&&!n.enum.some(o=>Object.is(o,e))){r.push({path:t,message:`must be one of ${n.enum.map(String).join(", ")}`});return}if(n.type==="object"){if(!W(e)){r.push({path:t,message:`must be an object; received ${b(e)}`});return}let o=n.properties??{};for(let s of n.required??[])e[s]===void 0&&r.push({path:_(t,s),message:"is required"});if(n.additionalProperties===!1)for(let s of Object.keys(e))s in o||r.push({path:_(t,s),message:"unknown field"});for(let[s,a]of Object.entries(o))e[s]!==void 0&&k(e[s],a,_(t,s),i,r);return}if(n.type==="array"){if(!Array.isArray(e)){r.push({path:t,message:`must be an array; received ${b(e)}`});return}if(n.minItems!==void 0&&e.length<n.minItems&&r.push({path:t,message:`must contain at least ${n.minItems} item(s)`}),n.uniqueItems){let o=e.map(s=>JSON.stringify(s));new Set(o).size!==o.length&&r.push({path:t,message:"must not contain duplicate items"})}n.items&&e.forEach((o,s)=>k(o,n.items,`${t}[${s}]`,i,r));return}if(n.type==="string"){if(typeof e!="string"){r.push({path:t,message:`must be a string; received ${b(e)}`});return}n.minLength!==void 0&&e.length<n.minLength&&r.push({path:t,message:`must contain at least ${n.minLength} character(s)`});return}if(n.type==="boolean"){typeof e!="boolean"&&r.push({path:t,message:`must be a boolean; received ${b(e)}`});return}if(n.type==="integer"){if(!Number.isInteger(e)){r.push({path:t,message:`must be an integer; received ${b(e)}`});return}n.minimum!==void 0&&e<n.minimum&&r.push({path:t,message:`must be at least ${n.minimum}`})}}function de(e){return{...e,$schema:e.$schema===void 0?O:e.$schema,schemaVersion:e.schemaVersion===void 0?"1.0":e.schemaVersion,include:e.include===void 0?["src"]:e.include,layers:e.layers===void 0?[]:e.layers,rules:e.rules===void 0?K.map(n=>({...n})):e.rules}}function fe(e,n="ark.config.json"){if(!W(e))throw new h(n,[{path:"$",message:`must be an object; received ${b(e)}`}]);let t=e.schemaVersion===void 0?"unversioned":null;if(e.schemaVersion!==void 0&&e.schemaVersion!=="1.0")throw new h(n,[{path:"$.schemaVersion",message:`unsupported version ${JSON.stringify(e.schemaVersion)}; expected 1.0`}]);return{candidate:de(e),migratedFrom:t}}function pe(e,n="ark.config.json"){let{candidate:t,migratedFrom:i}=fe(e,n),r=[];if(k(t,B,"$",B,r),r.length>0)throw new h(n,r);return{config:t,migratedFrom:i}}function q(e,n="ark.config.json"){let t;try{t=JSON.parse(e)}catch(i){throw new h(n,[{path:"$",message:`invalid JSON: ${i instanceof Error?i.message:String(i)}`}])}return pe(t,n)}function m(e){return typeof e=="string"&&e.length>0?e:void 0}function J(e,n){return Number.isInteger(e)&&Number(e)>0?Number(e):n}function ge(e,n,t){return e==="LAYER_IMPORT_VIOLATION"?n.typeOnly||t.targetTypeOnlyExports===!0||t.namedBindingsTypeOnly===!0?"Move the referenced type to a mutually allowed layer, use `import type`, then preflight again.":t.peerIsolation===!0?"Extract the shared dependency to a shared layer, then preflight again.":`Define a port in ${n.fromLayer??"the source layer"}, inject the ${n.toLayer??"outer-layer"} implementation, then preflight again.`:e==="FORBIDDEN_GLOBAL"?`Inject ${n.target??"the capability"} through a port, then preflight again.`:e==="CIRCULAR_DEPENDENCY"?"Extract the shared dependency into a third module, then preflight again.":e==="RAW_EVENT_PUBLISH"?"Publish through a registered intent creator, then run Ark again.":e==="PUBLISH_MISSING_SOURCE"?"Add metadata.source to the publish call, then run Ark again.":`Resolve ${e} without weakening ark.config.json, then run Ark again.`}function Y(e,n="error"){let t=m(e.ruleId)??m(e.code)??"ARK_UNKNOWN",i=e.severity==="warning"?"warning":n,r={...m(e.target)?{target:m(e.target)}:{},...m(e.fromLayer)?{fromLayer:m(e.fromLayer)}:{},...m(e.toLayer)?{toLayer:m(e.toLayer)}:{},...typeof e.typeOnly=="boolean"?{typeOnly:e.typeOnly}:{}};return{ruleId:t,severity:i,message:m(e.message)??t,location:{file:m(e.file)??"<unknown>",line:J(e.line,1),column:J(e.column,1)},evidence:r,nextAction:m(e.nextAction)??ge(t,r,e)}}var z={RAW_EVENT_PUBLISH:"Publish through a registered intent creator; raw event objects or intent strings bypass Ark contracts and tooling.",PUBLISH_MISSING_SOURCE:"Strict Ark publish calls must include metadata.source."};function me(e){return/^(Domain|Application|Adapter|Workflow|Job|Presentation|Reporting|Metadata|Security|Audit|Observability|Kernel)\.[A-Za-z0-9_.]+$/.test(e)}function $(e){if(!e.publishCall)return[];let n=[];return(e.rawIntentName!==void 0&&me(e.rawIntentName)||e.objectHasIntent)&&n.push({ruleId:"RAW_EVENT_PUBLISH",message:z.RAW_EVENT_PUBLISH}),e.arkPublishCandidate&&!e.hasSource&&n.push({ruleId:"PUBLISH_MISSING_SOURCE",message:z.PUBLISH_MISSING_SOURCE}),n}function R(e){if(typeof e.physicalFilename=="string"&&e.physicalFilename.length>0)return e.physicalFilename;if(typeof e.filename=="string"&&e.filename.length>0)return e.filename;if(typeof e.getFilename=="function")try{let n=e.getFilename();if(typeof n=="string"&&n.length>0)return n}catch{}return""}function C(e,n,t,i,r){let o=Y({...i,line:i.line??n.loc?.start?.line,column:i.column??(typeof n.loc?.start?.column=="number"?n.loc.start.column+1:void 0)});return e.report({node:n,messageId:t,...r?{data:r}:{},diagnostic:o}),o}function Q(e){if(!e||e==="<input>"||e.startsWith("stdin"))return null;let n=u.dirname(u.resolve(e));for(;;){let t=u.join(n,"ark.config.json");if(A.existsSync(t))return t;let i=u.dirname(n);if(i===n)return null;n=i}}var P=new Map;function X(e){if(P.has(e))return P.get(e)??null;if(!A.existsSync(e))return null;let n=q(A.readFileSync(e,"utf8"),e).config;return P.set(e,n),n}function ye(e,n){if(!n.startsWith("."))return null;let t=u.resolve(u.dirname(e),n),i=[t,`${t}.ts`,`${t}.tsx`,`${t}.mts`,`${t}.cts`,`${t}.js`,`${t}.jsx`,u.join(t,"index.ts"),u.join(t,"index.tsx"),u.join(t,"index.js")];for(let r of i)try{if(A.existsSync(r)&&A.statSync(r).isFile())return r}catch{}return`${t}.ts`}function E(e){return typeof e?.value=="string"?e.value:void 0}function F(e){return e?.name??E(e)}function V(e){return e.sourceCode??e.getSourceCode?.()}function ee(e,n){let t=V(e)?.getScope?.(n);for(;t;){let i=t.references?.find(r=>r.identifier===n);if(i)return i;t=t.upper??void 0}}function Z(e,n,t){let i=ee(e,n);if(i?.resolved)return(i.resolved.defs?.length??0)>0;let r=V(e)?.getScope?.(n);for(;r;){let o=r.set?.get(t);if(o)return(o.defs?.length??0)>0;r=r.upper??void 0}return!1}function be(e,n){let t=ee(e,n);return t?t.isValueReference!==!1:n.parent?.type==="VariableDeclarator"&&n.parent.init===n}function ne(e){if(e?.type==="Identifier"&&e.name)return{root:e,segments:[e.name]};if(!e||!(e.type==="MemberExpression"||!!(e.object&&e.property))||e.computed===!0)return;let t=ne(e.object),i=F(e.property);if(!(!t||!i))return{root:t.root,segments:[...t.segments,i]}}function he(e){return F(e.callee?.property)}function te(e,n){return e?.properties?.find(t=>F(t.key)===n)}function I(e,n){return te(e,n)!==void 0}function Ae(e){let n=te(e,"metadata")?.value;return I(n,"source")}function re(e){return he(e)==="publish"}var Se={meta:{type:"problem",docs:{description:"Disallow imports that violate ark.config.json layer rules (same contract as arkgate-check)."},messages:{forbiddenImport:"Architecture: {{fromLayer}} must not import {{toLayer}} (ark.config.json). Specifier: {{specifier}}",forbiddenImportHeuristic:"Domain code must not import infrastructure, adapters, repositories, or database modules."},schema:[]},create(e){let n=R(e),t=Q(n),i=t?X(t):null,r=t?u.dirname(t):null,o=s=>{let a=E(s.source);if(a&&i&&r&&n){let d=u.isAbsolute(n)?n:u.resolve(n),p=u.relative(r,d).split(u.sep).join("/"),l=S(p,i.layers);if(!l)return;let c=ye(d,a);if(!c)return;let f=u.relative(r,c).split(u.sep).join("/");if(f.startsWith(".."))return;let g=S(f,i.layers);if(!g)return;v(i.rules,l,g,{fromPath:p,toPath:f,layers:i.layers})&&C(e,s,"forbiddenImport",{ruleId:"LAYER_IMPORT_VIOLATION",file:p,fromLayer:l,toLayer:g,target:f,...s.importKind==="type"?{typeOnly:!0}:{},message:`${l} must not import ${g}.`},{fromLayer:l,toLayer:g,specifier:a});return}};return{ImportDeclaration:o,ExportNamedDeclaration:o,ExportAllDeclaration:o}}},ke={meta:{type:"problem",docs:{description:"Require event bus publish calls to use registered intent creators instead of raw event objects or intent strings."},messages:{rawPublish:"Publish through a registered intent creator; raw event objects or intent strings bypass Ark contracts."},schema:[]},create(e){return{CallExpression(n){let t=n.arguments?.[0],i=E(t),r=$({publishCall:re(n),rawIntentName:i,objectHasIntent:I(t,"intent"),arkPublishCandidate:!1,hasSource:!0});if(r.some(o=>o.ruleId==="RAW_EVENT_PUBLISH")){let o=r.find(s=>s.ruleId==="RAW_EVENT_PUBLISH");C(e,n,"rawPublish",{...o,file:R(e)})}}}}},Ie={meta:{type:"problem",docs:{description:"Require event bus publish calls to include source metadata."},messages:{missingSource:"Strict Ark publish calls must include metadata.source."},schema:[]},create(e){return{CallExpression(n){let t=n.arguments?.[0],i=n.arguments?.[2],o=$({publishCall:re(n),rawIntentName:E(t),objectHasIntent:I(t,"intent"),arkPublishCandidate:!0,hasSource:Ae(t)||I(i,"source")}).find(s=>s.ruleId==="PUBLISH_MISSING_SOURCE");o&&C(e,n,"missingSource",{...o,file:R(e)})}}}},Re={meta:{type:"problem",docs:{description:"Disallow ambient globals from the layer\u2019s forbiddenGlobals in ark.config.json (same purity surface as ark-check). Option `globals` explicitly overrides."},messages:{forbiddenGlobal:'Ambient global "{{name}}" is forbidden in {{layer}} (ark.config.json); inject the capability through a port instead.',forbiddenGlobalDefault:'Ambient global "{{name}}" is forbidden here; inject the capability through a port instead.'},schema:[{type:"object",properties:{globals:{type:"array",items:{type:"string"}}},additionalProperties:!1}]},create(e){let n=R(e),t=e.options?.[0],i=Q(n),r=i?X(i):null,o=i?u.dirname(i):null,s=null,a="this layer";if(t?.globals)s=new Set(t.globals);else if(r&&o&&n){let l=u.isAbsolute(n)?n:u.resolve(n),c=u.relative(o,l).split(u.sep).join("/"),f=r.layers?.find(g=>g.name===S(c,r.layers));f?.forbiddenGlobals?.length?(s=new Set(f.forbiddenGlobals),a=f.name):s=null}if(!s)return{};let d=typeof V(e)?.getScope=="function",p=(l,c)=>{let f=u.isAbsolute(n)?n:u.resolve(n),g=o?u.relative(o,f).split(u.sep).join("/"):n;C(e,l,r?"forbiddenGlobal":"forbiddenGlobalDefault",{ruleId:"FORBIDDEN_GLOBAL",file:g,fromLayer:a,target:c,message:`${a} must not use the ambient global "${c}".`},{name:c,layer:a})};return{MemberExpression(l){if(l.parent?.type==="MemberExpression"&&l.parent.object===l)return;let c=ne(l);if(!c||Z(e,c.root,c.segments[0]))return;let f=c.segments[0]==="globalThis",g=f?c.segments.slice(1):c.segments,x;for(let N=g.length;N>=(f?1:2);N-=1){let M=g.slice(0,N).join(".");if(s.has(M)){x=M;break}}x?p(l,x):!d&&s.has(c.segments[0])&&p(l,c.segments[0])},CallExpression(l){if(d)return;let c=l.callee?.type==="Identifier"?l.callee.name:void 0;c&&s.has(c)&&p(l,c)},NewExpression(l){if(d)return;let c=l.callee?.type==="Identifier"?l.callee.name:void 0;c&&s.has(c)&&p(l,c)},Identifier(l){!d||!l.name||!s.has(l.name)||!be(e,l)||Z(e,l,l.name)||p(l,l.name)}}}},Ce={"no-domain-infra-imports":Se,"no-raw-event-publish":ke,"require-publish-source":Ie,"no-forbidden-globals":Re},j={rules:Ce};j.configs={recommended:{plugins:{ark:j},rules:{"ark/no-domain-infra-imports":"error","ark/no-raw-event-publish":"error","ark/require-publish-source":"error","ark/no-forbidden-globals":"error"}}};var Fe=j;export{Fe as default,Q as findConfigPath,w as globToRegExp,v as isEdgeDenied,S as layerForRelativePath,X as loadArkConfig,Se as noDomainInfraImports,Re as noForbiddenGlobals,ke as noRawEventPublish,H as patternSpecificity,j as plugin,Ie as requirePublishSource,ye as resolveRelativeImport};
|