pasika 0.10.34 → 0.10.36

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.
@@ -3875,40 +3875,70 @@ var hookComplexityRule = {
3875
3875
  if (relative.startsWith("..")) return {};
3876
3876
  const segments = relative.split(path28.sep);
3877
3877
  const sourceText = context.sourceCode.text;
3878
- function checkHook(node, name, body, exported) {
3879
- if (!exported) return;
3880
- if (!name || !isHookName3(name)) return;
3881
- if (!body) return;
3882
- const score = computeExtractionScore(body, sourceText);
3878
+ const index = getProjectIndex(sourceRoot);
3879
+ const localHookCalls = /* @__PURE__ */ new Set();
3880
+ const hooks = [];
3881
+ function registerHook(node, name, body, exported) {
3882
+ if (!name || !isHookName3(name) || !body) return;
3883
+ hooks.push({ node, name, body, exported });
3884
+ }
3885
+ function reportHooks() {
3883
3886
  const parentFolder = segments.length >= 2 ? segments[segments.length - 2] : void 0;
3884
3887
  const inSupportFolder = parentFolder === "hooks";
3885
- if (score >= 2 && !inSupportFolder) {
3886
- context.report({
3887
- node,
3888
- message: `Hook "${name}" has an extraction score of ${String(score)} and must be extracted to a hooks/ folder. See docs/next-codebase-guide/rules/hook-extraction-rule.md`
3889
- });
3890
- } else if (score < 2 && inSupportFolder) {
3891
- context.report({
3892
- node,
3893
- message: `Hook "${name}" has an extraction score below two and must stay inline in its consumer file. See docs/next-codebase-guide/rules/hook-extraction-rule.md`
3894
- });
3888
+ for (const { node, name, body, exported } of hooks) {
3889
+ const score = computeExtractionScore(body, sourceText);
3890
+ const hasLocalConsumer = localHookCalls.has(name);
3891
+ const externalConsumerCount = exported ? index?.symbolConsumers.get(symbolKey(filename, name))?.size ?? 0 : 0;
3892
+ if (score >= 2) {
3893
+ if (!inSupportFolder && (exported || hasLocalConsumer)) {
3894
+ context.report({
3895
+ node,
3896
+ message: `Hook "${name}" has an extraction score of ${String(score)} and must be extracted to a hooks/ folder. See docs/next-codebase-guide/rules/hook-extraction-rule.md`
3897
+ });
3898
+ }
3899
+ continue;
3900
+ }
3901
+ const consumerCount = externalConsumerCount + (hasLocalConsumer ? 1 : 0);
3902
+ if (inSupportFolder && exported) {
3903
+ if (consumerCount < 2) {
3904
+ context.report({
3905
+ node,
3906
+ message: `Hook "${name}" has an extraction score below two and must be inlined directly into its sole consumer instead of remaining a custom hook. See docs/next-codebase-guide/rules/hook-extraction-rule.md`
3907
+ });
3908
+ }
3909
+ continue;
3910
+ }
3911
+ const isSingleLocalConsumer = hasLocalConsumer && externalConsumerCount === 0;
3912
+ if (isSingleLocalConsumer) {
3913
+ context.report({
3914
+ node,
3915
+ message: `Hook "${name}" has one local consumer and an extraction score below two; inline its React primitives and handlers directly into the consumer instead of keeping a custom hook. See docs/next-codebase-guide/rules/hook-extraction-rule.md`
3916
+ });
3917
+ }
3895
3918
  }
3896
3919
  }
3897
3920
  return {
3898
3921
  FunctionDeclaration(node) {
3899
3922
  const exported = node.parent?.type === "ExportNamedDeclaration";
3900
- checkHook(node, node.id?.name, node.body, exported);
3923
+ registerHook(node, node.id?.name, node.body, exported);
3901
3924
  },
3902
3925
  VariableDeclarator(node) {
3903
3926
  if (node.id.type !== "Identifier") return;
3904
- const exported = node.parent.parent?.type === "ExportNamedDeclaration";
3905
- if (!exported) return;
3906
3927
  const init = node.init;
3907
3928
  if (!init || init.type !== "ArrowFunctionExpression" && init.type !== "FunctionExpression") {
3908
3929
  return;
3909
3930
  }
3910
3931
  if (init.body.type !== "BlockStatement") return;
3911
- checkHook(node, node.id.name, init.body, true);
3932
+ const exported = node.parent.parent?.type === "ExportNamedDeclaration";
3933
+ registerHook(node, node.id.name, init.body, exported);
3934
+ },
3935
+ CallExpression(node) {
3936
+ if (node.callee.type === "Identifier" && isHookName3(node.callee.name)) {
3937
+ localHookCalls.add(node.callee.name);
3938
+ }
3939
+ },
3940
+ "Program:exit"() {
3941
+ reportHooks();
3912
3942
  }
3913
3943
  };
3914
3944
  }
@@ -0,0 +1,14 @@
1
+ /** Standard HTTP request methods for runtime use. */
2
+ declare enum HttpMethod {
3
+ Get = "GET",
4
+ Head = "HEAD",
5
+ Post = "POST",
6
+ Put = "PUT",
7
+ Delete = "DELETE",
8
+ Connect = "CONNECT",
9
+ Options = "OPTIONS",
10
+ Trace = "TRACE",
11
+ Patch = "PATCH"
12
+ }
13
+
14
+ export { HttpMethod };
@@ -0,0 +1,16 @@
1
+ // helpers/http-method.ts
2
+ var HttpMethod = /* @__PURE__ */ ((HttpMethod2) => {
3
+ HttpMethod2["Get"] = "GET";
4
+ HttpMethod2["Head"] = "HEAD";
5
+ HttpMethod2["Post"] = "POST";
6
+ HttpMethod2["Put"] = "PUT";
7
+ HttpMethod2["Delete"] = "DELETE";
8
+ HttpMethod2["Connect"] = "CONNECT";
9
+ HttpMethod2["Options"] = "OPTIONS";
10
+ HttpMethod2["Trace"] = "TRACE";
11
+ HttpMethod2["Patch"] = "PATCH";
12
+ return HttpMethod2;
13
+ })(HttpMethod || {});
14
+ export {
15
+ HttpMethod
16
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pasika",
3
- "version": "0.10.34",
3
+ "version": "0.10.36",
4
4
  "description": "Reusable agent setup package",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,6 +21,10 @@
21
21
  "types": "./dist/helpers/http-error.d.ts",
22
22
  "import": "./dist/helpers/http-error.js"
23
23
  },
24
+ "./http-method": {
25
+ "types": "./dist/helpers/http-method.d.ts",
26
+ "import": "./dist/helpers/http-method.js"
27
+ },
24
28
  "./response-envelope": {
25
29
  "types": "./dist/helpers/response-envelope.d.ts",
26
30
  "import": "./dist/helpers/response-envelope.js"