@brickkit/cli 0.10.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/README.md +1 -1
  2. package/dashboard-dist/CollapsiblePanel-CbUysOp5.js +2 -0
  3. package/dashboard-dist/CompositeRoot-D4sRkYq3.js +1 -0
  4. package/dashboard-dist/Geist-Variable.woff2 +0 -0
  5. package/dashboard-dist/GeistMono-Variable.woff2 +0 -0
  6. package/dashboard-dist/PopoverPopup-CiI2avT_.js +1 -0
  7. package/dashboard-dist/api-reference-B-bZRtNV.js +265 -0
  8. package/dashboard-dist/app.css +2 -2
  9. package/dashboard-dist/app.js +13 -13
  10. package/dashboard-dist/ccount-CcG1m-Yh.js +1 -0
  11. package/dashboard-dist/client-BJJtVSVr.js +1 -0
  12. package/dashboard-dist/core-Z7NJFk0K.js +1 -0
  13. package/dashboard-dist/docs-Dpfc0wJb.js +4 -0
  14. package/dashboard-dist/docs.css +1 -1
  15. package/dashboard-dist/kit.js +1 -0
  16. package/dashboard-dist/popover-BzejBolB.js +1 -0
  17. package/dashboard-dist/react-dom-client.js +3 -0
  18. package/dashboard-dist/react-dom.js +3 -0
  19. package/dashboard-dist/react-jsx-runtime.js +1 -1
  20. package/dashboard-dist/react.js +3 -3
  21. package/dashboard-dist/theme.css +123 -0
  22. package/dist/app-entry2.js +2 -3
  23. package/dist/bin.d.ts +0 -2
  24. package/dist/bin.js +606 -49
  25. package/dist/bin.js.map +1 -1
  26. package/dist/client-contract-file2.js +2 -3
  27. package/dist/client-contract2.js +18 -10
  28. package/dist/client-contract2.js.map +1 -1
  29. package/dist/compiler.d.ts +1 -2
  30. package/dist/compiler.js +1 -1
  31. package/dist/compiler2.js +3 -4
  32. package/dist/config.js +250 -0
  33. package/dist/config.js.map +1 -0
  34. package/dist/dashboard-extension.d.ts +25 -0
  35. package/dist/dashboard.d.ts +2997 -0
  36. package/dist/dev-reporter.d.ts +0 -2
  37. package/dist/dev-reporter.js +1 -2
  38. package/dist/dev-telemetry-store.js +1411 -966
  39. package/dist/dev-telemetry-store.js.map +1 -1
  40. package/dist/dev-telemetry.js +3 -4
  41. package/dist/dev-telemetry.js.map +1 -1
  42. package/dist/dev-worker.js +3 -4
  43. package/dist/emit.d.ts +0 -2
  44. package/dist/index.d.ts +96 -17
  45. package/dist/index.js +4 -5
  46. package/dist/lint/eslint.d.ts +2 -0
  47. package/dist/lint/eslint.js +1 -0
  48. package/dist/lint/oxlint.d.ts +17 -0
  49. package/dist/lint/oxlint.js +18 -0
  50. package/dist/lint/oxlint.js.map +1 -0
  51. package/dist/plugin.d.ts +70 -0
  52. package/dist/plugin.js +64 -0
  53. package/dist/plugin.js.map +1 -0
  54. package/dist/presets.js +1066 -0
  55. package/dist/presets.js.map +1 -0
  56. package/dist/runner.js +114 -32
  57. package/dist/runner.js.map +1 -1
  58. package/dist/vite.d.ts +6 -5
  59. package/dist/vite.js +13 -9
  60. package/dist/vite.js.map +1 -1
  61. package/dist/workflows.d.ts +0 -2
  62. package/dist/workflows2.js +3 -4
  63. package/inspector-dist/client/assets/api.rpc-BvRk9kiK.js +0 -0
  64. package/inspector-dist/client/assets/api.stream._streamId-BvRk9kiK.js +0 -0
  65. package/inspector-dist/client/assets/app-CCzpuUz_.css +2 -0
  66. package/inspector-dist/client/assets/dist-BK8w6xOr.js +3930 -0
  67. package/inspector-dist/client/assets/dist-CG2aVufI.js +197 -0
  68. package/inspector-dist/client/assets/entry.client-D9jbgmTR.js +9391 -0
  69. package/inspector-dist/client/assets/highlighted-body-B3W2YXNL-DYVdwGy2.js +34 -0
  70. package/inspector-dist/client/assets/home-CyjkvtII.js +2883 -0
  71. package/inspector-dist/client/assets/jsx-runtime-CPEah4WQ.js +7084 -0
  72. package/inspector-dist/client/assets/manifest-ba30b52d.js +1 -0
  73. package/inspector-dist/client/assets/mermaid-3ZIDBTTL-Dy6IVqPy.js +1 -0
  74. package/inspector-dist/client/assets/root-8BMab1lL.css +2 -0
  75. package/inspector-dist/client/assets/root-DX9wtogx.js +332 -0
  76. package/inspector-dist/client/assets/run-detail-C69EJGql.js +1549 -0
  77. package/inspector-dist/client/assets/tabs-B6B88IjT.js +75692 -0
  78. package/inspector-dist/client/assets/tabs-L5XKzOpP.css +1 -0
  79. package/inspector-dist/client/assets/world-config-context-C3BqXPIv.js +30 -0
  80. package/inspector-dist/client/assets/zstd-browser-decoder-ByUgcY9H.js +41 -0
  81. package/inspector-dist/server/assets/app-WoDoT62X.js +100155 -0
  82. package/inspector-dist/server/assets/chunk-RLXIAIE6-CbvDIAEa.js +42977 -0
  83. package/inspector-dist/server/assets/dist-BRxZSWUN.js +1140 -0
  84. package/inspector-dist/server/assets/dist-CQnQcIJg.js +199 -0
  85. package/inspector-dist/server/assets/dist-DqRd9pyS.js +1644 -0
  86. package/inspector-dist/server/assets/dist-qR-969AD.js +10327 -0
  87. package/inspector-dist/server/assets/encryption-_PuklZNX.js +888 -0
  88. package/inspector-dist/server/assets/event-metadata-BVakQJ_y.js +147 -0
  89. package/inspector-dist/server/assets/functions-CImcpqNl.js +1172 -0
  90. package/inspector-dist/server/assets/global-singleton-CPirHxFh.js +82 -0
  91. package/inspector-dist/server/assets/highlighted-body-B3W2YXNL-fPMB_t7F.js +36 -0
  92. package/inspector-dist/server/assets/mermaid-3ZIDBTTL-bADXySE3.js +3 -0
  93. package/inspector-dist/server/assets/parse-D9Vvgzt9.js +471 -0
  94. package/inspector-dist/server/assets/rolldown-runtime-CLg409Sh.js +44 -0
  95. package/inspector-dist/server/assets/serialization-format-DDtsVTU1.js +478 -0
  96. package/inspector-dist/server/assets/token-BW4GdQZh.js +62 -0
  97. package/inspector-dist/server/assets/token-D6FXdkJT.js +57 -0
  98. package/inspector-dist/server/assets/token-util-BoNmi-wE.js +457 -0
  99. package/inspector-dist/server/assets/wrapper-wiqsGXcE.js +3626 -0
  100. package/inspector-dist/server/assets/ws-transport-DV7oG4mL.js +29478 -0
  101. package/inspector-dist/server/assets/zstd-browser-decoder-Cswf0KO6.js +40 -0
  102. package/inspector-dist/server/index.js +2 -57
  103. package/package.json +57 -32
  104. package/vite-client.d.ts +1 -1
  105. package/dashboard-dist/CollapsiblePanel-a54TwMKb.js +0 -2
  106. package/dashboard-dist/PopoverPopup-BLzjTqsi.js +0 -1
  107. package/dashboard-dist/api-reference-r893F8zi.js +0 -260
  108. package/dashboard-dist/core-BWAwhSFf.js +0 -1
  109. package/dashboard-dist/docs-CkMy3Y5i.js +0 -4
  110. package/dashboard-dist/preload-helper-CjQDFR0M.js +0 -1
  111. package/dist/bin.d.ts.map +0 -1
  112. package/dist/build.js +0 -119
  113. package/dist/build.js.map +0 -1
  114. package/dist/dev-reporter.d.ts.map +0 -1
  115. package/dist/emit.d.ts.map +0 -1
  116. package/dist/index.d.ts.map +0 -1
  117. package/dist/vite.d.ts.map +0 -1
  118. package/dist/workflows.d.ts.map +0 -1
  119. package/inspector-dist/client/assets/api.rpc-l0sNRNKZ.js +0 -1
  120. package/inspector-dist/client/assets/api.stream._streamId-l0sNRNKZ.js +0 -1
  121. package/inspector-dist/client/assets/app-CY7CQBRo.css +0 -1
  122. package/inspector-dist/client/assets/entry.client-BJ6G3n5t.js +0 -11697
  123. package/inspector-dist/client/assets/highlighted-body-B3W2YXNL-C-3wZnxf.js +0 -19
  124. package/inspector-dist/client/assets/home-CSKAS4P2.js +0 -4979
  125. package/inspector-dist/client/assets/index-DECCyMR0.js +0 -4482
  126. package/inspector-dist/client/assets/index-Dot7CgrA.js +0 -9837
  127. package/inspector-dist/client/assets/index-HqNj_XIX.js +0 -200
  128. package/inspector-dist/client/assets/manifest-4baa7c6f.js +0 -1
  129. package/inspector-dist/client/assets/mermaid-3ZIDBTTL-DC0K8uTy.js +0 -58626
  130. package/inspector-dist/client/assets/mermaid-3ZIDBTTL-F88p7PFX.css +0 -1
  131. package/inspector-dist/client/assets/root-Bmn5n3jF.js +0 -305
  132. package/inspector-dist/client/assets/root-CfCr265_.css +0 -1
  133. package/inspector-dist/client/assets/run-detail-CWoGxu_0.css +0 -1
  134. package/inspector-dist/client/assets/run-detail-Cc7tSGNq.js +0 -6237
  135. package/inspector-dist/client/assets/world-config-context-BAD1QCrR.js +0 -26
  136. package/inspector-dist/client/assets/zstd-browser-decoder-BQoRpP7L.js +0 -28
  137. package/inspector-dist/server/assets/app-C-ZVJtic.js +0 -174880
  138. package/inspector-dist/server/assets/highlighted-body-B3W2YXNL-C8sq8F_D.js +0 -71
  139. package/inspector-dist/server/assets/index-BfLBLRRi.js +0 -204
  140. package/inspector-dist/server/assets/index-BzrGWk7J.js +0 -1164
  141. package/inspector-dist/server/assets/index-CWJr34WJ.js +0 -1296
  142. package/inspector-dist/server/assets/index-CYlmUaKx.js +0 -191
  143. package/inspector-dist/server/assets/mermaid-3ZIDBTTL-Dv5rjfMN.js +0 -58
  144. package/inspector-dist/server/assets/token-DnLp3wBO.js +0 -95
  145. package/inspector-dist/server/assets/token-util-Bpfp-B0w.js +0 -33
  146. package/inspector-dist/server/assets/wrapper-D5LIcZ_u.js +0 -67
  147. package/inspector-dist/server/assets/zstd-browser-decoder-BM8GpVB8.js +0 -77
@@ -0,0 +1,1066 @@
1
+ import { basename, dirname, relative, resolve, sep } from "node:path";
2
+ import { readdirSync } from "node:fs";
3
+ const SUFFIX = new RegExp(`^(.*)\\.(${[
4
+ "service",
5
+ "events",
6
+ "resource",
7
+ "table",
8
+ "action",
9
+ "command",
10
+ "tool",
11
+ "socket",
12
+ "listener",
13
+ "workflow",
14
+ "step"
15
+ ].join("|")})\\.(ts|tsx|mts|js|jsx|mjs)$`);
16
+ const posix$1 = (path) => path.split(sep).join("/");
17
+ function brickSettings(context) {
18
+ const given = context.settings?.brick ?? {};
19
+ return {
20
+ root: given.root ?? context.cwd ?? process.cwd(),
21
+ services: given.services ?? "src/services",
22
+ entry: given.entry ?? "src/app.ts",
23
+ generated: given.generated ?? "_brick",
24
+ web: given.web ?? "web"
25
+ };
26
+ }
27
+ function fileInfo(context) {
28
+ const settings = brickSettings(context);
29
+ const rel = posix$1(relative(settings.root, context.filename));
30
+ const servicesDir = posix$1(relative(settings.root, resolve(settings.root, settings.services)));
31
+ const generated = posix$1(relative(settings.root, resolve(settings.root, settings.generated)));
32
+ const base = basename(rel);
33
+ const inServices = rel.startsWith(`${servicesDir}/`);
34
+ const parts = inServices ? rel.slice(servicesDir.length + 1).split("/") : [];
35
+ const match = SUFFIX.exec(base);
36
+ const segments = rel.split("/");
37
+ return {
38
+ settings,
39
+ rel,
40
+ base,
41
+ servicesDir,
42
+ inServices,
43
+ service: parts.length > 1 ? parts[0] : void 0,
44
+ rest: parts.slice(1),
45
+ kind: match?.[2],
46
+ stem: match?.[1],
47
+ exempt: /\.(test|spec)\.[cm]?[jt]sx?$/.test(base) || segments.includes("test") || segments.includes("tests") || segments.includes("__tests__") || segments.includes("plugins") || segments.includes("node_modules") || rel.startsWith(`${generated}/`)
48
+ };
49
+ }
50
+ function kebab(name) {
51
+ return name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/[_\s.]+/g, "-").toLowerCase();
52
+ }
53
+ /** A string literal's value, or a template literal's text when it has no expressions. */
54
+ function stringValue(node) {
55
+ if (node?.type === "Literal" && typeof node.value === "string") return node.value;
56
+ if (node?.type === "TemplateLiteral" && node.expressions.length === 0) return node.quasis[0]?.value.cooked ?? void 0;
57
+ }
58
+ function propertyName(property) {
59
+ if (property?.type !== "Property" || property.computed) return void 0;
60
+ const key = property.key;
61
+ if (key.type === "Identifier") return key.name;
62
+ return typeof key.value === "string" ? key.value : void 0;
63
+ }
64
+ function getProperty(object, name) {
65
+ if (object?.type !== "ObjectExpression") return void 0;
66
+ return object.properties.find((property) => propertyName(property) === name);
67
+ }
68
+ function objectKeys(object) {
69
+ if (object?.type !== "ObjectExpression") return void 0;
70
+ const keys = [];
71
+ for (const property of object.properties) {
72
+ const name = propertyName(property);
73
+ if (name === void 0) return void 0;
74
+ keys.push(name);
75
+ }
76
+ return keys;
77
+ }
78
+ /** `t.Object(...)` or `Type.Object(...)`. */
79
+ function isSchemaCall(node, kind) {
80
+ return node?.type === "CallExpression" && node.callee.type === "MemberExpression" && !node.callee.computed && node.callee.object.type === "Identifier" && (node.callee.object.name === "t" || node.callee.object.name === "Type") && (kind === void 0 || node.callee.property.name === kind);
81
+ }
82
+ const DEFINE_FUNCTIONS = {
83
+ defineService: "service",
84
+ defineAction: "action",
85
+ defineTool: "tool",
86
+ defineListener: "listener",
87
+ definePlugin: "plugin",
88
+ crud: "crud",
89
+ sqliteTable: "table",
90
+ pgTable: "table",
91
+ mysqlTable: "table"
92
+ };
93
+ const ATTACH_METHODS = {
94
+ action: "action",
95
+ tool: "tool",
96
+ socket: "socket",
97
+ resource: "resource",
98
+ command: "command"
99
+ };
100
+ /** What a call defines, matching the call shapes in the project structure. */
101
+ function definitionOf(call) {
102
+ if (call?.type !== "CallExpression") return void 0;
103
+ const [first, second] = call.arguments;
104
+ const callee = call.callee;
105
+ if (callee.type === "Identifier" && DEFINE_FUNCTIONS[callee.name]) {
106
+ const kind = DEFINE_FUNCTIONS[callee.name];
107
+ if (kind === "service" || kind === "table") {
108
+ const name = stringValue(first);
109
+ if (name === void 0) return void 0;
110
+ return {
111
+ kind,
112
+ call,
113
+ name,
114
+ nameNode: first,
115
+ config: second
116
+ };
117
+ }
118
+ if (first?.type !== "ObjectExpression") return void 0;
119
+ const nameNode = getProperty(first, "name")?.value;
120
+ return {
121
+ kind,
122
+ call,
123
+ config: first,
124
+ name: stringValue(nameNode),
125
+ nameNode
126
+ };
127
+ }
128
+ if (callee.type !== "MemberExpression" || callee.computed || callee.object.type !== "Identifier") return void 0;
129
+ const kind = ATTACH_METHODS[callee.property.name];
130
+ if (!kind) return void 0;
131
+ const owner = callee.object.name;
132
+ if (kind === "command") {
133
+ const name = stringValue(first);
134
+ if (name === void 0 || second?.type !== "ObjectExpression") return void 0;
135
+ return {
136
+ kind,
137
+ call,
138
+ owner,
139
+ name,
140
+ nameNode: first,
141
+ config: second
142
+ };
143
+ }
144
+ if (first?.type !== "ObjectExpression") return void 0;
145
+ const nameNode = getProperty(first, "name")?.value;
146
+ const name = stringValue(nameNode);
147
+ if (kind === "resource" && name === void 0) return void 0;
148
+ return {
149
+ kind,
150
+ call,
151
+ owner,
152
+ config: first,
153
+ name,
154
+ nameNode
155
+ };
156
+ }
157
+ /** The nearest enclosing definition of one of `kinds`. */
158
+ function enclosingDefinition(node, kinds) {
159
+ for (let current = node.parent; current; current = current.parent) {
160
+ const definition = definitionOf(current);
161
+ if (definition && (!kinds || kinds.includes(definition.kind))) return definition;
162
+ }
163
+ }
164
+ function isFunction(node) {
165
+ return node?.type === "FunctionDeclaration" || node?.type === "FunctionExpression" || node?.type === "ArrowFunctionExpression";
166
+ }
167
+ function enclosingFunction(node) {
168
+ for (let current = node.parent; current; current = current.parent) if (isFunction(current)) return current;
169
+ }
170
+ /** Directives at the top of a function body or of the program. */
171
+ function directivesOf(node) {
172
+ const body = node?.type === "Program" ? node.body : node?.body?.type === "BlockStatement" ? node.body.body : [];
173
+ const directives = [];
174
+ for (const statement of body) {
175
+ if (statement.type !== "ExpressionStatement" || typeof statement.directive !== "string") break;
176
+ directives.push(statement.directive);
177
+ }
178
+ return directives;
179
+ }
180
+ function programOf(node) {
181
+ let current = node;
182
+ while (current.parent) current = current.parent;
183
+ return current;
184
+ }
185
+ /** Local name to import source, for the file's import declarations. */
186
+ function importSources(program) {
187
+ const sources = /* @__PURE__ */ new Map();
188
+ for (const statement of program.body) if (statement.type === "ImportDeclaration") for (const specifier of statement.specifiers) sources.set(specifier.local.name, statement.source.value);
189
+ return sources;
190
+ }
191
+ /** An import source resolved to a project-relative path; undefined for packages. */
192
+ function resolveImport(info, context, source) {
193
+ if (!source.startsWith(".")) return void 0;
194
+ return posix$1(relative(info.settings.root, resolve(dirname(context.filename), source)));
195
+ }
196
+ /** `name.method(...)` with a non-computed property. */
197
+ function memberCall(node) {
198
+ if (node?.type !== "CallExpression") return void 0;
199
+ const callee = node.callee;
200
+ if (callee.type === "Identifier") return { property: callee.name };
201
+ if (callee.type !== "MemberExpression" || callee.computed) return void 0;
202
+ return {
203
+ object: callee.object.type === "Identifier" ? callee.object.name : void 0,
204
+ property: callee.property.name
205
+ };
206
+ }
207
+ // src/lint/rules/checks.ts
208
+ function rule$1(description, create, options = {}) {
209
+ return {
210
+ meta: {
211
+ type: "problem",
212
+ docs: { description },
213
+ fixable: options.fixable,
214
+ schema: options.schema ?? []
215
+ },
216
+ create
217
+ };
218
+ }
219
+ /** Skip tests and generated files; local plugins are checked like app code. */
220
+ function skip(context) {
221
+ const info = fileInfo(context);
222
+ return info.exempt && !info.rel.split("/").includes("plugins");
223
+ }
224
+ const HANDLERS = [
225
+ "action",
226
+ "command",
227
+ "tool"
228
+ ];
229
+ const BUILT_IN_ERRORS = /* @__PURE__ */ new Set([
230
+ "BAD_REQUEST",
231
+ "UNAUTHORIZED",
232
+ "FORBIDDEN",
233
+ "NOT_FOUND",
234
+ "CONFLICT",
235
+ "INTERNAL_SERVER_ERROR"
236
+ ]);
237
+ /** `error.NAME(...)`, the error helper handlers receive. */
238
+ function errorHelper(node) {
239
+ const call = memberCall(node);
240
+ return call?.object === "error" ? call.property : void 0;
241
+ }
242
+ function isEmit(node) {
243
+ const call = memberCall(node);
244
+ if (!call) return void 0;
245
+ if (call.property === "emitEvent" && call.object === void 0) return "emitEvent";
246
+ if (call.property === "emit" && call.object && node.arguments.length >= 3) return "emit";
247
+ }
248
+ const WRITE_METHODS = /* @__PURE__ */ new Set([
249
+ "insert",
250
+ "update",
251
+ "delete"
252
+ ]);
253
+ const VERBS = new Set(`get list find search query count read load fetch check validate verify preview render export download
254
+ create add insert import upload register invite book place submit send post publish issue open start schedule
255
+ update set edit change rename move copy clone merge assign attach link mark toggle enable disable approve reject
256
+ accept confirm complete cancel close finish stop end archive restore refund pay charge ship track sync refresh
257
+ reset delete remove detach unlink clear purge run process handle compute calculate generate build apply sign
258
+ login logout subscribe unsubscribe notify ping upsert transfer resend retry lock unlock save write report`.split(/\s+/));
259
+ const IRREGULAR_PAST = new Set(`sent paid built made sold bought won lost begun done held kept left met read run set shut spent taken given
260
+ written chosen frozen broken spoken stolen hidden driven fallen forgotten known shown thrown drawn grown seen
261
+ put cut hit quit split spread cast cost let upset rebuilt resent undone withdrawn`.split(/\s+/));
262
+ /** definePlugin's parts that run while the plugin installs. */
263
+ const SETUP_PARTS = [
264
+ "app",
265
+ "service",
266
+ "resource",
267
+ "tables"
268
+ ];
269
+ const CONNECTION_CLASS = /(Client|Pool|Redis|Connection|Socket)$/;
270
+ const CONNECTION_CALL = /^(connect|createClient|createPool|createConnection)$/;
271
+ const isPastTense = (word) => word.endsWith("ed") || IRREGULAR_PAST.has(word);
272
+ const lastWord = (name) => (name.match(/[A-Z]?[a-z0-9]+$/)?.[0] ?? name).toLowerCase();
273
+ const firstWord = (name) => name.match(/^[a-z0-9]+/)?.[0] ?? "";
274
+ const ROOM = /^[a-z][a-zA-Z0-9_-]*:./;
275
+ const checkRules = {
276
+ "no-server-in-client": rule$1("Browser code imports only @brickkit/core/client and the generated contract.", (context) => {
277
+ const info = fileInfo(context);
278
+ const web = info.settings.web.replace(/\/$/, "");
279
+ if (!info.rel.startsWith(`${web}/`)) return {};
280
+ const generated = info.settings.generated.replace(/\/$/, "");
281
+ const check = (node, source) => {
282
+ if (typeof source !== "string") return;
283
+ let allowed;
284
+ if (source.startsWith(".")) {
285
+ const path = resolveImport(info, context, source);
286
+ allowed = path.startsWith(`${web}/`) || path.startsWith(`${generated}/`) && !path.endsWith("services.gen") && !path.endsWith("services.gen.ts");
287
+ } else allowed = !/^(@brickkit\/|bun:|node:)/.test(source) || source === "@brickkit/core/client" || source === "@brickkit/core/tanstack-query";
288
+ if (!allowed) context.report({
289
+ node,
290
+ message: `Browser code imports only @brickkit/core/client and the generated contract, not "${source}".`
291
+ });
292
+ };
293
+ return {
294
+ ImportDeclaration: (node) => {
295
+ if (node.importKind !== "type") check(node.source, node.source.value);
296
+ },
297
+ ExportNamedDeclaration: (node) => node.source && check(node.source, node.source.value),
298
+ ExportAllDeclaration: (node) => check(node.source, node.source.value),
299
+ ImportExpression: (node) => check(node.source, stringValue(node.source))
300
+ };
301
+ }),
302
+ "no-global-context": rule$1("No module-level mutable singletons for dependencies (the setOrdersContext pattern); use deps.", (context) => {
303
+ if (skip(context)) return {};
304
+ const mutable = /* @__PURE__ */ new Set();
305
+ const reported = /* @__PURE__ */ new Set();
306
+ return {
307
+ Program(program) {
308
+ for (let statement of program.body) {
309
+ if (statement.type === "ExportNamedDeclaration") statement = statement.declaration;
310
+ if (statement?.type === "VariableDeclaration" && statement.kind !== "const") {
311
+ for (const declarator of statement.declarations) if (declarator.id.type === "Identifier") mutable.add(declarator.id.name);
312
+ }
313
+ }
314
+ },
315
+ AssignmentExpression(node) {
316
+ const name = node.left.type === "Identifier" ? node.left.name : void 0;
317
+ if (!name || !mutable.has(name) || reported.has(name)) return;
318
+ if (!enclosingFunction(node)) return;
319
+ reported.add(name);
320
+ context.report({
321
+ node,
322
+ message: `Module-level "${name}" is set from a function, a global context. Declare it in the service's deps (port<T>()) and read ctx.deps, or useDeps() in listeners and workflow steps.`
323
+ });
324
+ }
325
+ };
326
+ }),
327
+ "no-env-outside-secrets": rule$1("process.env and Bun.env are read only through defineSecret or config files.", (context) => {
328
+ const info = fileInfo(context);
329
+ if (info.exempt || /(^|\.)secrets\.[cm]?[jt]s$/.test(info.base) || /\.config\.[cm]?[jt]s$/.test(info.base)) return {};
330
+ return { MemberExpression(node) {
331
+ const object = node.object;
332
+ const property = node.computed ? void 0 : node.property.name;
333
+ if (object.type === "Identifier" && (object.name === "process" || object.name === "Bun") && property === "env" || object.type === "MetaProperty" && property === "env") context.report({
334
+ node,
335
+ message: "Read configuration through defineSecret() in secrets.ts, not from the environment directly."
336
+ });
337
+ } };
338
+ }),
339
+ "action-schemas": rule$1("Every action, command and tool declares input and output.", (context) => {
340
+ if (skip(context)) return {};
341
+ return { CallExpression(node) {
342
+ const definition = definitionOf(node);
343
+ if (!definition || !HANDLERS.includes(definition.kind)) return;
344
+ const missing = ["input", "output"].filter((key) => !getProperty(definition.config, key));
345
+ if (missing.length) context.report({
346
+ node: definition.nameNode ?? node,
347
+ message: `${definition.kind} ${definition.name ? `"${definition.name}" ` : ""}declares no ${missing.join(" or ")}.`
348
+ });
349
+ } };
350
+ }),
351
+ "declared-errors": rule$1("Every error.X() names an entry in that action's errors or a built-in error.", (context) => {
352
+ if (skip(context)) return {};
353
+ return { CallExpression(node) {
354
+ const name = errorHelper(node);
355
+ if (!name) return;
356
+ const definition = enclosingDefinition(node, HANDLERS);
357
+ if (!definition) return;
358
+ const errors = getProperty(definition.config, "errors")?.value;
359
+ const declared = errors ? objectKeys(errors) : [];
360
+ if (declared === void 0) return;
361
+ if (!BUILT_IN_ERRORS.has(name) && !declared.includes(name)) context.report({
362
+ node: node.callee.property,
363
+ message: `error.${name} is not in this ${definition.kind}'s errors or the built-in errors.`
364
+ });
365
+ } };
366
+ }),
367
+ "return-error": rule$1("Error helpers are returned (return error.NOT_FOUND()), so TypeScript narrows the value after them.", (context) => {
368
+ if (skip(context)) return {};
369
+ return { CallExpression(node) {
370
+ const name = errorHelper(node);
371
+ if (!name || node.parent?.type !== "ExpressionStatement") return;
372
+ if (!enclosingDefinition(node, [
373
+ ...HANDLERS,
374
+ "crud",
375
+ "socket"
376
+ ])) return;
377
+ context.report({
378
+ node,
379
+ message: `Return the error: return error.${name}(...).`,
380
+ fix: (fixer) => fixer.insertTextBefore(node, "return ")
381
+ });
382
+ } };
383
+ }, { fixable: "code" }),
384
+ "path-params-in-input": rule$1("Each :param in path is a field of input.", (context) => {
385
+ if (skip(context)) return {};
386
+ return { CallExpression(node) {
387
+ const definition = definitionOf(node);
388
+ if (!definition || !HANDLERS.includes(definition.kind)) return;
389
+ const pathNode = getProperty(definition.config, "path")?.value;
390
+ const path = stringValue(pathNode);
391
+ if (!path) return;
392
+ const input = getProperty(definition.config, "input")?.value;
393
+ const fields = isSchemaCall(input, "Object") ? objectKeys(input.arguments[0]) : input ? void 0 : [];
394
+ if (!fields) return;
395
+ const record = getProperty(definition.config, "record")?.value?.value;
396
+ for (const [, param] of path.matchAll(/:([A-Za-z_$][\w$]*)/g)) if (!fields.includes(param) && !(record === true && param === "id")) context.report({
397
+ node: pathNode,
398
+ message: `Path parameter :${param} is not a field of input.`
399
+ });
400
+ } };
401
+ }),
402
+ "get-is-read-only": rule$1("GET actions don't insert, update, delete or emit.", (context) => {
403
+ if (skip(context)) return {};
404
+ return { CallExpression(node) {
405
+ const call = memberCall(node);
406
+ if (!call) return;
407
+ if (!(node.callee.type === "MemberExpression" && WRITE_METHODS.has(call.property) && /\b(db|tx)\b/.test(context.sourceCode.getText(node.callee.object))) && !isEmit(node)) return;
408
+ const definition = enclosingDefinition(node, HANDLERS);
409
+ if (stringValue(getProperty(definition?.config, "method")?.value) === "GET") context.report({
410
+ node,
411
+ message: `A GET ${definition.kind} only reads; ${call.property}() writes. Use POST.`
412
+ });
413
+ } };
414
+ }),
415
+ "emit-in-transaction": rule$1("emitEvent or live.emit inside a transaction callback passes { tx } or { after: tx }.", (context) => {
416
+ if (skip(context)) return {};
417
+ return { CallExpression(node) {
418
+ const kind = isEmit(node);
419
+ if (!kind) return;
420
+ let tx;
421
+ let inside = false;
422
+ for (let fn = enclosingFunction(node); fn; fn = enclosingFunction(fn)) {
423
+ const parent = fn.parent;
424
+ if (parent?.type === "CallExpression" && parent.arguments[0] === fn && memberCall(parent)?.property === "transaction") {
425
+ inside = true;
426
+ if (fn.params[0]?.type === "Identifier") tx = fn.params[0].name;
427
+ break;
428
+ }
429
+ }
430
+ if (!inside) return;
431
+ const options = node.arguments[3];
432
+ const keys = objectKeys(options);
433
+ if (options && (!keys || keys.includes("tx") || keys.includes("after"))) return;
434
+ const option = kind === "emitEvent" ? "tx" : "after";
435
+ context.report({
436
+ node,
437
+ message: `Inside a transaction, pass { ${option}: ${tx ?? "tx"} } so the ${kind === "emitEvent" ? "event is recorded in it" : "message is sent on commit"}.`,
438
+ fix: tx && !options && node.arguments.length === 3 ? (fixer) => fixer.insertTextAfter(node.arguments[2], `, { ${option}: ${tx} }`) : void 0
439
+ });
440
+ } };
441
+ }, { fixable: "code" }),
442
+ "deterministic-workflow": rule$1("No Date.now, Math.random, fetch or database access in a workflow function outside its steps.", (context) => {
443
+ if (skip(context)) return {};
444
+ const inWorkflow = (node) => {
445
+ for (let fn = enclosingFunction(node); fn; fn = enclosingFunction(fn)) {
446
+ const directives = directivesOf(fn);
447
+ if (directives.includes("use step")) return false;
448
+ if (directives.includes("use workflow")) return true;
449
+ }
450
+ return directivesOf(programOf(node)).includes("use workflow");
451
+ };
452
+ const report = (node, what) => {
453
+ if (inWorkflow(node)) context.report({
454
+ node,
455
+ message: `${what} in a workflow function is not replayed the same way; move it into a step.`
456
+ });
457
+ };
458
+ return {
459
+ CallExpression(node) {
460
+ const call = memberCall(node);
461
+ if (!call) return;
462
+ if (call.object === "Date" && call.property === "now") report(node, "Date.now()");
463
+ else if (call.object === "Math" && call.property === "random") report(node, "Math.random()");
464
+ else if (call.object === void 0 && call.property === "fetch") report(node, "fetch()");
465
+ },
466
+ NewExpression(node) {
467
+ if (node.callee.name === "Date" && node.arguments.length === 0) report(node, "new Date()");
468
+ },
469
+ MemberExpression(node) {
470
+ if (!node.computed && node.property.name === "db") report(node, "Database access");
471
+ }
472
+ };
473
+ }),
474
+ "idempotent-listener": rule$1("Listener writes are keyed by deliveryId or use onConflictDoNothing, because delivery is at least once.", (context) => {
475
+ if (skip(context)) return {};
476
+ return { CallExpression(node) {
477
+ const definition = definitionOf(node);
478
+ if (definition?.kind !== "listener") return;
479
+ const text = context.sourceCode.getText(definition.config);
480
+ if (/\.(insert|update|delete)\s*\(/.test(text) && !/deliveryId|onConflictDo(Nothing|Update)/.test(text)) context.report({
481
+ node: definition.nameNode ?? node,
482
+ message: "This listener writes without deliveryId or onConflictDoNothing; a redelivered event would write twice."
483
+ });
484
+ } };
485
+ }),
486
+ "socket-schemas": rule$1("Socket schemas have no format or transforms, and event names don't start with $.", (context) => {
487
+ if (skip(context)) return {};
488
+ return { CallExpression(node) {
489
+ const definition = definitionOf(node);
490
+ if (definition?.kind !== "socket") return;
491
+ for (const key of ["input", "output"]) {
492
+ const schemas = getProperty(definition.config, key)?.value;
493
+ if (schemas?.type !== "ObjectExpression") continue;
494
+ for (const property of schemas.properties) {
495
+ const name = propertyName(property);
496
+ if (name?.startsWith("$")) context.report({
497
+ node: property.key,
498
+ message: `Socket ${key} event "${name}" starts with $, which is reserved for control messages.`
499
+ });
500
+ const text = context.sourceCode.getText(property.value);
501
+ if (/\bformat\s*:|\b(Transform|Decode|Encode)\s*\(/.test(text)) context.report({
502
+ node: property.value,
503
+ message: `Socket ${key} "${name}" uses a format or transform, which sockets cannot check.`
504
+ });
505
+ }
506
+ }
507
+ } };
508
+ }),
509
+ "no-unregistered-format": rule$1("A TypeBox format is used only when it is registered with FormatRegistry.", (context) => {
510
+ if (skip(context)) return {};
511
+ const options = context.options?.[0] ?? {};
512
+ const registered = new Set(options.formats ?? []);
513
+ const used = [];
514
+ return {
515
+ CallExpression(node) {
516
+ const call = memberCall(node);
517
+ if (call?.object === "FormatRegistry" && call.property === "Set") {
518
+ const name = stringValue(node.arguments[0]);
519
+ if (name) registered.add(name);
520
+ }
521
+ if (!isSchemaCall(node)) return;
522
+ for (const argument of node.arguments) {
523
+ const format = getProperty(argument, "format");
524
+ if (stringValue(format?.value)) used.push(format.value);
525
+ }
526
+ },
527
+ "Program:exit"() {
528
+ for (const node of used) if (!registered.has(node.value)) context.report({
529
+ node,
530
+ message: `Format "${node.value}" is not registered; call FormatRegistry.Set("${node.value}", ...) or list it in this rule's formats option.`
531
+ });
532
+ }
533
+ };
534
+ }, { schema: [{
535
+ type: "object",
536
+ properties: { formats: {
537
+ type: "array",
538
+ items: { type: "string" }
539
+ } },
540
+ additionalProperties: false
541
+ }] }),
542
+ "no-floating-calls": rule$1("Promises from service calls and emitEvent are awaited.", (context) => {
543
+ if (skip(context)) return {};
544
+ const proxies = /* @__PURE__ */ new Set();
545
+ const candidates = [];
546
+ return {
547
+ VariableDeclarator(node) {
548
+ const call = memberCall(node.init);
549
+ if (node.id.type === "Identifier" && call?.property === "useService") proxies.add(node.id.name);
550
+ },
551
+ ExpressionStatement(node) {
552
+ if (node.expression.type === "CallExpression") candidates.push(node.expression);
553
+ },
554
+ "Program:exit"() {
555
+ for (const call of candidates) {
556
+ const target = memberCall(call);
557
+ if (!(target?.property === "emitEvent" && !target.object || target?.object !== void 0 && proxies.has(target.object))) continue;
558
+ const async = enclosingFunction(call)?.async === true;
559
+ context.report({
560
+ node: call,
561
+ message: `Await this call (or mark it with void): an unawaited promise loses its errors.`,
562
+ fix: async ? (fixer) => fixer.insertTextBefore(call, "await ") : void 0
563
+ });
564
+ }
565
+ }
566
+ };
567
+ }, { fixable: "code" }),
568
+ "explicit-access": rule$1("Every action and CRUD resource sets access, and record actions and commands set `access`; nothing is public by omission.", (context) => {
569
+ if (skip(context)) return {};
570
+ return { CallExpression(node) {
571
+ const definition = definitionOf(node);
572
+ if (!definition) return;
573
+ if ((definition.kind === "command" || definition.kind === "action" && getProperty(definition.config, "record")?.value?.value === true) && !getProperty(definition.config, "access")) context.report({
574
+ node: definition.nameNode ?? node,
575
+ message: `Set access on this ${definition.kind === "command" ? "command" : "record action"}: access: { scope } or "public"; it decides which rows it can load.`
576
+ });
577
+ else if (definition.kind === "action" && !getProperty(definition.config, "authorize") && !getProperty(definition.config, "access")) context.report({
578
+ node: definition.nameNode ?? node,
579
+ message: `Set access on this action: authorize, or access: "public" when anyone may call it.`
580
+ });
581
+ if (definition.kind === "crud" && !getProperty(definition.config, "access")) context.report({
582
+ node,
583
+ message: "Set access on this CRUD resource ({ authorize, scope } or \"public\")."
584
+ });
585
+ } };
586
+ }),
587
+ "socket-authorize": rule$1("Sockets declare authorize and join.", (context) => {
588
+ if (skip(context)) return {};
589
+ return { CallExpression(node) {
590
+ const definition = definitionOf(node);
591
+ if (definition?.kind !== "socket") return;
592
+ const missing = ["authorize", "join"].filter((key) => !getProperty(definition.config, key));
593
+ if (missing.length) context.report({
594
+ node: definition.nameNode ?? node,
595
+ message: `Socket declares no ${missing.join(" or ")}; add ${missing.length > 1 ? "them" : "it"}.`
596
+ });
597
+ } };
598
+ }),
599
+ "no-wildcard-origins": rule$1("No \"*\" in allowedOrigins or trustedOrigins.", (context) => {
600
+ if (skip(context)) return {};
601
+ return { Property(node) {
602
+ const name = propertyName(node);
603
+ if (name !== "allowedOrigins" && name !== "trustedOrigins") return;
604
+ const values = node.value.type === "ArrayExpression" ? node.value.elements : [node.value];
605
+ for (const value of values) if (stringValue(value) === "*") context.report({
606
+ node: value,
607
+ message: `"*" in ${name} lets any site in; list the origins.`
608
+ });
609
+ } };
610
+ }),
611
+ "strict-input": rule$1("Input objects set additionalProperties: false.", (context) => {
612
+ if (skip(context)) return {};
613
+ return { CallExpression(node) {
614
+ const definition = definitionOf(node);
615
+ if (!definition || !HANDLERS.includes(definition.kind)) return;
616
+ const input = getProperty(definition.config, "input")?.value;
617
+ if (!isSchemaCall(input, "Object")) return;
618
+ const [fields, options] = input.arguments;
619
+ const strict = getProperty(options, "additionalProperties")?.value;
620
+ if (strict?.type === "Literal" && strict.value === false) return;
621
+ if (options && options.type !== "ObjectExpression") return;
622
+ context.report({
623
+ node: input,
624
+ message: "Set additionalProperties: false on this input object.",
625
+ fix: strict ? void 0 : !options ? (fixer) => fixer.insertTextAfter(fields, ", { additionalProperties: false }") : options.properties.length === 0 ? (fixer) => fixer.replaceText(options, "{ additionalProperties: false }") : (fixer) => fixer.insertTextAfter(options.properties.at(-1), ", additionalProperties: false")
626
+ });
627
+ } };
628
+ }, { fixable: "code" }),
629
+ "description-required": rule$1("Actions, commands, tools, sockets and events have a description, which feeds OpenAPI, MCP and the dashboard.", (context) => {
630
+ if (skip(context)) return {};
631
+ return { CallExpression(node) {
632
+ const definition = definitionOf(node);
633
+ if (!definition) return;
634
+ if ([
635
+ "action",
636
+ "command",
637
+ "tool",
638
+ "socket"
639
+ ].includes(definition.kind) && !getProperty(definition.config, "description")) context.report({
640
+ node: definition.nameNode ?? node,
641
+ message: `Describe this ${definition.kind}: the description feeds OpenAPI, MCP and the dashboard.`
642
+ });
643
+ const events = definition.kind === "service" || definition.kind === "plugin" ? getProperty(definition.config, "events")?.value : void 0;
644
+ for (const event of events?.properties ?? []) {
645
+ const schema = event.value;
646
+ if (!isSchemaCall(schema)) continue;
647
+ if (!schema.arguments.some((argument) => getProperty(argument, "description"))) context.report({
648
+ node: event.key,
649
+ message: `Describe event "${propertyName(event)}" with { description } on its schema.`
650
+ });
651
+ }
652
+ } };
653
+ }),
654
+ naming: rule$1("Actions are camelCase verbs (getUser), events are service.pastTense (orders.shipped), and rooms are prefix:value.", (context) => {
655
+ if (skip(context)) return {};
656
+ const checkRoom = (node) => {
657
+ const text = node?.type === "TemplateLiteral" ? node.quasis[0].value.cooked + (node.expressions.length ? "x" : "") : stringValue(node);
658
+ if (text !== void 0 && !ROOM.test(text)) context.report({
659
+ node,
660
+ message: `Room "${text}" should be prefix:value, such as doc:42 or user:7.`
661
+ });
662
+ };
663
+ return { CallExpression(node) {
664
+ const definition = definitionOf(node);
665
+ if ((definition?.kind === "action" || definition?.kind === "command") && definition.name) {
666
+ const name = definition.name;
667
+ if (!/^[a-z][a-zA-Z0-9]*$/.test(name) || !VERBS.has(firstWord(name))) context.report({
668
+ node: definition.nameNode,
669
+ message: `${definition.kind} "${name}" should be a camelCase verb, such as getUser or archive.`
670
+ });
671
+ }
672
+ if (definition?.kind === "service") {
673
+ const events = getProperty(definition.config, "events")?.value;
674
+ for (const name of objectKeys(events) ?? []) if (!/^[a-z][a-zA-Z0-9]*$/.test(name) || !isPastTense(lastWord(name))) context.report({
675
+ node: getProperty(events, name).key,
676
+ message: `Event "${name}" should be camelCase past tense, such as shipped or itemAdded.`
677
+ });
678
+ }
679
+ if (definition?.kind === "socket") {
680
+ const rooms = getProperty(definition.config, "rooms")?.value;
681
+ const list = isFunction(rooms) ? rooms.body : rooms;
682
+ if (list?.type === "ArrayExpression") for (const element of list.elements) checkRoom(element);
683
+ }
684
+ const kind = isEmit(node);
685
+ if (kind === "emitEvent") {
686
+ const name = stringValue(node.arguments[1]);
687
+ if (name !== void 0 && (!/^[a-z][a-zA-Z0-9]*\.[a-z][a-zA-Z0-9]*$/.test(name) || !isPastTense(lastWord(name)))) context.report({
688
+ node: node.arguments[1],
689
+ message: `Event "${name}" should be service.pastTense, such as orders.shipped.`
690
+ });
691
+ }
692
+ if (kind === "emit") {
693
+ const room = node.arguments[0];
694
+ if (room.type === "ArrayExpression") room.elements.forEach(checkRoom);
695
+ else checkRoom(room);
696
+ }
697
+ } };
698
+ }),
699
+ "no-console": rule$1("Handlers log through the request logger, so lines carry the request and trace ids.", (context) => {
700
+ if (skip(context)) return {};
701
+ return { CallExpression(node) {
702
+ if (memberCall(node)?.object !== "console") return;
703
+ if (!enclosingDefinition(node, [
704
+ ...HANDLERS,
705
+ "socket",
706
+ "listener",
707
+ "crud"
708
+ ])) return;
709
+ context.report({
710
+ node,
711
+ message: "Log through ctx.logger, so the line carries the request and trace ids."
712
+ });
713
+ } };
714
+ }),
715
+ "plugin-manifest": rule$1("definePlugin has a scoped name, a brick range and declared options with descriptions; its setup functions are synchronous and open no connections outside on(\"start\").", (context) => {
716
+ if (skip(context)) return {};
717
+ const connection = (node) => {
718
+ if (!(node.type === "NewExpression" ? node.callee.type === "Identifier" && CONNECTION_CLASS.test(node.callee.name) : CONNECTION_CALL.test(memberCall(node)?.property ?? ""))) return;
719
+ for (let current = node.parent; current; current = current.parent) {
720
+ if (memberCall(current)?.property === "on" && stringValue(current.arguments[0]) === "start") return;
721
+ if (current.type === "Property" && SETUP_PARTS.includes(propertyName(current) ?? "") && definitionOf(current.parent?.parent)?.kind === "plugin") return context.report({
722
+ node,
723
+ message: "Open connections in on(\"start\") (and close them in on(\"stop\")), not while the plugin installs."
724
+ });
725
+ }
726
+ };
727
+ return {
728
+ NewExpression: connection,
729
+ CallExpression(node) {
730
+ connection(node);
731
+ const definition = definitionOf(node);
732
+ if (definition?.kind !== "plugin") return;
733
+ const config = definition.config;
734
+ if (!definition.name || !/^@[^/\s]+\/[^/\s]+$/.test(definition.name)) context.report({
735
+ node: definition.nameNode ?? node,
736
+ message: "Give the plugin a scoped package name, such as \"@acme/brick-comments\"."
737
+ });
738
+ if (!stringValue(getProperty(config, "brick")?.value)) context.report({
739
+ node: node.callee,
740
+ message: "Declare the Brick versions this plugin supports: brick: \"^0.11.0\"."
741
+ });
742
+ const options = getProperty(config, "options")?.value;
743
+ if (!options) context.report({
744
+ node: node.callee,
745
+ message: "Declare the plugin's options as a TypeBox schema (options: t.Object({ ... }))."
746
+ });
747
+ else if (isSchemaCall(options, "Object") && options.arguments[0]?.type === "ObjectExpression") for (const option of options.arguments[0].properties) {
748
+ const schema = option.value;
749
+ if (!getProperty(isSchemaCall(schema) ? schema.arguments.at(-1) : void 0, "description")) context.report({
750
+ node: option,
751
+ message: `Describe option "${propertyName(option) ?? "?"}": add { description: "..." } to its schema.`
752
+ });
753
+ }
754
+ for (const key of ["setup", ...SETUP_PARTS]) {
755
+ const setup = getProperty(config, key)?.value;
756
+ if (isFunction(setup) && setup.async) context.report({
757
+ node: setup,
758
+ message: `${key} must be synchronous; open connections in on("start").`
759
+ });
760
+ }
761
+ }
762
+ };
763
+ })
764
+ };
765
+ // src/lint/rules/layout.ts
766
+ function rule(description, create, fixable) {
767
+ return {
768
+ meta: {
769
+ type: "suggestion",
770
+ docs: { description },
771
+ fixable,
772
+ schema: []
773
+ },
774
+ create
775
+ };
776
+ }
777
+ /** Collect every definition in the file, then check them once the file is read. */
778
+ function onDefinitions(check) {
779
+ const definitions = [];
780
+ return {
781
+ CallExpression(node) {
782
+ const definition = definitionOf(node);
783
+ if (definition) definitions.push(definition);
784
+ },
785
+ "Program:exit"(program) {
786
+ check(definitions, program);
787
+ }
788
+ };
789
+ }
790
+ const SERVICE_FOLDERS = {
791
+ action: "actions",
792
+ tool: "tools",
793
+ socket: "sockets",
794
+ listener: "listeners",
795
+ workflow: "workflows",
796
+ step: "workflows",
797
+ table: "tables"
798
+ };
799
+ // src/lint/presets.ts
800
+ /** Rules that check one file at a time, in ESLint, oxlint or brick lint. */
801
+ const rules = {
802
+ "one-action-per-file": rule("A *.action.ts file defines exactly one action, and actions are defined nowhere else.", (context) => {
803
+ const info = fileInfo(context);
804
+ if (info.exempt) return {};
805
+ return onDefinitions((definitions, program) => {
806
+ const actions = definitions.filter((d) => d.kind === "action");
807
+ if (info.kind !== "action") {
808
+ for (const action of actions) context.report({
809
+ node: action.call,
810
+ message: `Define this action in its own *.action.ts file.`
811
+ });
812
+ return;
813
+ }
814
+ if (actions.length === 0) context.report({
815
+ node: program,
816
+ message: `${info.base} defines no action; a *.action.ts file defines exactly one.`
817
+ });
818
+ for (const extra of actions.slice(1)) context.report({
819
+ node: extra.call,
820
+ message: `${info.base} already defines an action; move this one to its own *.action.ts file.`
821
+ });
822
+ });
823
+ }),
824
+ "file-suffixes": rule("Each kind of definition goes in a file with its suffix: .service, .action, .command, .tool, .socket, .listener, .workflow, .step, .resource, .table, .events.", (context) => {
825
+ const info = fileInfo(context);
826
+ if (info.exempt) return {};
827
+ return onDefinitions((definitions) => {
828
+ for (const definition of definitions) {
829
+ const kind = definition.kind;
830
+ if (kind === "action" || kind === "plugin" || kind === "crud") continue;
831
+ if (kind === "table" && info.kind === "resource") continue;
832
+ if (info.kind !== kind) context.report({
833
+ node: definition.call,
834
+ message: `Define this ${kind} in a *.${kind}.ts file.`
835
+ });
836
+ }
837
+ });
838
+ }),
839
+ "kind-folders": rule("Files sit in their kind's folder, as in the project structure.", (context) => {
840
+ const info = fileInfo(context);
841
+ if (info.exempt || !info.kind) return {};
842
+ return { Program(program) {
843
+ const report = (where) => context.report({
844
+ node: program,
845
+ message: `Move ${info.base} to ${where}.`
846
+ });
847
+ const kind = info.kind;
848
+ if (!info.inServices || !info.service) return report(`${info.servicesDir}/<service>/, where it is registered`);
849
+ const service = `${info.servicesDir}/${info.service}`;
850
+ const rest = info.rest;
851
+ if (kind === "service" || kind === "events") {
852
+ if (rest.length !== 1) report(`${service}/`);
853
+ return;
854
+ }
855
+ if (rest[0] === "resources") {
856
+ const resource = `${service}/resources/${rest[1]}`;
857
+ if ((kind === "resource" || kind === "table") && rest.length === 3) return;
858
+ if (kind === "action" && rest.length === 4 && rest[2] === "actions") return;
859
+ if (kind === "command" && rest.length === 4 && rest[2] === "commands") return;
860
+ if (kind === "resource" || kind === "table") return report(`${resource}/`);
861
+ if (kind === "action" || kind === "command") return report(`${resource}/${kind}s/`);
862
+ return report(`${service}/${SERVICE_FOLDERS[kind]}/`);
863
+ }
864
+ if (kind === "command" || kind === "resource") return report(`${service}/resources/<resource>/`);
865
+ const folder = SERVICE_FOLDERS[kind];
866
+ if (rest.length !== 2 || rest[0] !== folder) report(`${service}/${folder}/`);
867
+ } };
868
+ }),
869
+ "resource-folder": rule("Each .resource.ts is alone in resources/<name>/, and resource actions and commands attach to their own folder's resource.", (context) => {
870
+ const info = fileInfo(context);
871
+ if (info.exempt || !info.inServices) return {};
872
+ const folder = info.rest[0] === "resources" && info.rest.length >= 3 ? info.rest[1] : void 0;
873
+ return onDefinitions((definitions, program) => {
874
+ const imports = importSources(program);
875
+ for (const definition of definitions) {
876
+ if (definition.kind === "resource" && info.kind === "resource") {
877
+ if (!folder || info.rest.length !== 3) continue;
878
+ if (definition.name && kebab(definition.name) !== folder) context.report({
879
+ node: definition.nameNode,
880
+ message: `Resource "${definition.name}" lives in resources/${kebab(definition.name)}/, not resources/${folder}/.`
881
+ });
882
+ const siblings = readdirSync(dirname(context.filename)).filter((file) => /\.resource\.[cm]?[jt]sx?$/.test(file));
883
+ if (siblings.length > 1) context.report({
884
+ node: definition.call,
885
+ message: `resources/${folder}/ holds ${siblings.length} resources; give each its own folder.`
886
+ });
887
+ }
888
+ if (definition.kind === "command" && !(folder && info.rest[2] === "commands")) context.report({
889
+ node: definition.call,
890
+ message: "Commands exist only inside a resource folder: resources/<name>/commands/."
891
+ });
892
+ if (folder && (definition.kind === "action" || definition.kind === "command") && definition.owner) {
893
+ const source = imports.get(definition.owner);
894
+ const owner = source?.split("/").pop()?.replace(/\.[cm]?[jt]sx?$/, "");
895
+ if (source && owner !== `${folder}.resource`) context.report({
896
+ node: definition.call.callee,
897
+ message: `Files in resources/${folder}/ attach to the ${folder} resource (import it from "../${folder}.resource").`
898
+ });
899
+ }
900
+ }
901
+ });
902
+ }),
903
+ "file-name-matches": rule("The file name is the kebab-case of the definition's name, without its owner.", (context) => {
904
+ const info = fileInfo(context);
905
+ if (info.exempt || !info.kind) return {};
906
+ return onDefinitions((definitions) => {
907
+ for (const definition of definitions) {
908
+ if (definition.kind !== info.kind || !definition.name) continue;
909
+ const expected = kebab(definition.name.split(".").pop());
910
+ if (expected !== info.stem) context.report({
911
+ node: definition.nameNode,
912
+ message: `"${definition.name}" belongs in ${expected}.${info.kind}.ts, not ${info.base}.`
913
+ });
914
+ }
915
+ });
916
+ }),
917
+ "service-folder": rule("One defineService per *.service.ts, inside services/<name>/, where the folder name is the service name.", (context) => {
918
+ const info = fileInfo(context);
919
+ if (info.exempt || info.kind !== "service") return {};
920
+ return onDefinitions((definitions, program) => {
921
+ const services = definitions.filter((d) => d.kind === "service");
922
+ if (services.length === 0) context.report({
923
+ node: program,
924
+ message: `${info.base} has no defineService(); a *.service.ts file defines exactly one.`
925
+ });
926
+ for (const extra of services.slice(1)) context.report({
927
+ node: extra.call,
928
+ message: `${info.base} already defines a service; give this one its own folder.`
929
+ });
930
+ const service = services[0];
931
+ if (!service?.name || !info.inServices) return;
932
+ const folder = info.rest.length === 1 ? info.service : void 0;
933
+ if (folder !== kebab(service.name) && folder !== service.name) context.report({
934
+ node: service.nameNode,
935
+ message: `Service "${service.name}" lives in ${info.servicesDir}/${kebab(service.name)}/${kebab(service.name)}.service.ts.`
936
+ });
937
+ });
938
+ }),
939
+ "colocate-in-service": rule("Everything under services/<name>/ attaches to that service, or to one of its resources.", (context) => {
940
+ const info = fileInfo(context);
941
+ if (info.exempt || !info.service) return {};
942
+ return onDefinitions((definitions, program) => {
943
+ const imports = importSources(program);
944
+ for (const definition of definitions) {
945
+ if (!definition.owner) continue;
946
+ const source = imports.get(definition.owner);
947
+ const path = source && resolveImport(info, context, source);
948
+ if (!path?.startsWith(`${info.servicesDir}/`)) continue;
949
+ const owner = path.slice(info.servicesDir.length + 1).split("/")[0];
950
+ if (owner !== info.service) context.report({
951
+ node: definition.call.callee,
952
+ message: `This file is in ${info.service}/ but attaches to ${owner}; move it to ${info.servicesDir}/${owner}/.`
953
+ });
954
+ }
955
+ });
956
+ }),
957
+ "workflow-directive": rule("Workflow files use \"use workflow\", step files \"use step\", and the directives appear nowhere else.", (context) => {
958
+ const info = fileInfo(context);
959
+ if (info.exempt) return {};
960
+ const found = [];
961
+ return {
962
+ ExpressionStatement(node) {
963
+ if (node.directive === "use workflow" || node.directive === "use step") found.push(node);
964
+ },
965
+ "Program:exit"(program) {
966
+ const own = info.kind === "workflow" ? "use workflow" : info.kind === "step" ? "use step" : void 0;
967
+ for (const node of found) if (node.directive !== own) context.report({
968
+ node,
969
+ message: `"${node.directive}" belongs in a *.${node.directive === "use step" ? "step" : "workflow"}.ts file.`
970
+ });
971
+ if (own && !found.some((node) => node.directive === own)) context.report({
972
+ node: program,
973
+ message: `${info.base} must start with "${own}".`,
974
+ fix: (fixer) => fixer.insertTextBeforeRange([0, 0], `"${own}";\n\n`)
975
+ });
976
+ }
977
+ };
978
+ }, "code"),
979
+ ...checkRules
980
+ };
981
+ /** Rules that need the loaded app; only `brick lint` runs them. */
982
+ const APP_RULES = [
983
+ "single-app-entry",
984
+ "no-cross-service-tables",
985
+ "unique-names",
986
+ "declared-events",
987
+ "test-colocated"
988
+ ];
989
+ /** Always an error: no preset or rule setting turns it down. */
990
+ const ALWAYS_ERROR = "no-cross-service-tables";
991
+ const RECOMMENDED = {
992
+ "workflow-directive": "error",
993
+ "no-cross-service-tables": "error",
994
+ "unique-names": "error",
995
+ "no-server-in-client": "error",
996
+ "action-schemas": "error",
997
+ "declared-errors": "error",
998
+ "return-error": "error",
999
+ "path-params-in-input": "error",
1000
+ "get-is-read-only": "error",
1001
+ "emit-in-transaction": "error",
1002
+ "declared-events": "error",
1003
+ "deterministic-workflow": "error",
1004
+ "idempotent-listener": "warn",
1005
+ "socket-schemas": "error",
1006
+ "no-unregistered-format": "error",
1007
+ "no-floating-calls": "error",
1008
+ "explicit-access": "error",
1009
+ "socket-authorize": "error",
1010
+ "no-wildcard-origins": "error"
1011
+ };
1012
+ /** Every preset, with app rules, by bare rule name. */
1013
+ const PRESETS = {
1014
+ recommended: RECOMMENDED,
1015
+ layout: {
1016
+ "one-action-per-file": "error",
1017
+ "file-suffixes": "error",
1018
+ "kind-folders": "error",
1019
+ "resource-folder": "error",
1020
+ "file-name-matches": "error",
1021
+ "service-folder": "error",
1022
+ "colocate-in-service": "error",
1023
+ "single-app-entry": "error"
1024
+ },
1025
+ strict: {
1026
+ ...RECOMMENDED,
1027
+ "no-global-context": "error",
1028
+ "no-env-outside-secrets": "error",
1029
+ "strict-input": "error",
1030
+ "description-required": "error",
1031
+ naming: "error",
1032
+ "no-console": "error",
1033
+ "test-colocated": "error"
1034
+ },
1035
+ plugin: {
1036
+ "plugin-manifest": "error",
1037
+ "explicit-access": "error",
1038
+ "description-required": "error"
1039
+ }
1040
+ };
1041
+ const KNOWN = /* @__PURE__ */ new Set([...Object.keys(rules), ...APP_RULES]);
1042
+ /**
1043
+ * Severity of every rule, keyed `brick/<rule>`, from presets then per-rule
1044
+ * settings. Throws on an unknown rule, or on turning down no-cross-service-tables.
1045
+ */
1046
+ function resolveRules(presets = ["recommended"], overrides = {}) {
1047
+ const resolved = {};
1048
+ for (const preset of presets) {
1049
+ if (!PRESETS[preset]) throw new Error(`Brick: unknown preset "${preset}"`);
1050
+ for (const [name, severity] of Object.entries(PRESETS[preset])) resolved[`brick/${name}`] = severity;
1051
+ }
1052
+ for (const [key, severity] of Object.entries(overrides)) {
1053
+ const name = key.replace(/^brick\//, "");
1054
+ if (!KNOWN.has(name)) throw new Error(`Brick: unknown rule "${key}"`);
1055
+ if (name === "no-cross-service-tables" && severity !== "error") throw new Error(`Brick: brick/${ALWAYS_ERROR} is always an error and cannot be turned off`);
1056
+ resolved[`brick/${name}`] = severity;
1057
+ }
1058
+ return resolved;
1059
+ }
1060
+ /** The file rules of a resolved rule set, as ESLint and oxlint take them. */
1061
+ function fileRules(resolved) {
1062
+ return Object.fromEntries(Object.entries(resolved).filter(([key]) => key.replace(/^brick\//, "") in rules));
1063
+ }
1064
+ export { rules as a, resolveRules as i, PRESETS as n, fileRules as r, ALWAYS_ERROR as t };
1065
+
1066
+ //# sourceMappingURL=presets.js.map