pasika 0.10.75 → 0.10.77

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.
@@ -5096,6 +5096,15 @@ var ContractOwnershipIndex = class {
5096
5096
  if (typeDeclarations.length === 0) return { kind: "missing", ownership: "unknown" };
5097
5097
  return this.endpointFromDeclarations(typeDeclarations);
5098
5098
  }
5099
+ sourceBinding(node, name) {
5100
+ if (!ts7.isVariableDeclaration(node) || !node.initializer) {
5101
+ return { kind: "missing", ownership: "unknown" };
5102
+ }
5103
+ const sourceType = this.checker.getTypeAtLocation(node.initializer);
5104
+ const declarations = this.propertyDeclarations(sourceType, name);
5105
+ if (declarations.length === 0) return { kind: "missing", ownership: "unknown" };
5106
+ return this.endpointFromDeclarations(declarations);
5107
+ }
5099
5108
  targetProperty(node, name) {
5100
5109
  if (!ts7.isPropertyAssignment(node) && !ts7.isShorthandPropertyAssignment(node)) {
5101
5110
  return { kind: "missing", ownership: "unknown" };
@@ -5314,6 +5323,10 @@ function contractOwnershipResolver(context) {
5314
5323
  const tsNode = nodeMap.get(node);
5315
5324
  return tsNode ? index.sourceMember(tsNode) : { kind: "missing", ownership: "unknown" };
5316
5325
  },
5326
+ sourceBinding(node, name) {
5327
+ const tsNode = nodeMap.get(node);
5328
+ return tsNode ? index.sourceBinding(tsNode, name) : { kind: "missing", ownership: "unknown" };
5329
+ },
5317
5330
  targetProperty(node, name) {
5318
5331
  const tsNode = nodeMap.get(node);
5319
5332
  return tsNode ? index.targetProperty(tsNode, name) : { kind: "missing", ownership: "unknown" };
@@ -5398,6 +5411,48 @@ function semanticMappingMessage(propertyName5, sourcePropertyName) {
5398
5411
  function unknownContractOwnershipMessage(propertyName5, sourcePropertyName) {
5399
5412
  return `Cannot determine contract ownership for mapping "${propertyName5}" from "${sourcePropertyName}". Define or propagate a concrete contract, make the boundary schema explicit, or connect a mirrored external schema to its defineApiContract. ${DOC4}`;
5400
5413
  }
5414
+ function destructuredBindingSource(context, identifier) {
5415
+ const initialScope = context.sourceCode.getScope(identifier);
5416
+ for (let scope = initialScope; scope !== null; scope = scope.upper) {
5417
+ const variable = scope.variables.find(({ name }) => name === identifier.name);
5418
+ if (!variable) continue;
5419
+ for (const definition of variable.defs) {
5420
+ if (definition.type !== "Variable") continue;
5421
+ const declarator = definition.node;
5422
+ if (declarator.id.type !== "ObjectPattern") continue;
5423
+ for (const property of declarator.id.properties) {
5424
+ if (property.type !== "Property" || property.computed || property.key.type !== "Identifier") continue;
5425
+ let binding;
5426
+ if (property.value.type === "Identifier") binding = property.value;
5427
+ if (property.value.type === "AssignmentPattern" && property.value.left.type === "Identifier") {
5428
+ binding = property.value.left;
5429
+ }
5430
+ if (binding?.name === identifier.name) {
5431
+ return { declarator, propertyName: property.key.name };
5432
+ }
5433
+ }
5434
+ }
5435
+ return void 0;
5436
+ }
5437
+ return void 0;
5438
+ }
5439
+ function contractMappingViolation(propertyName5, sourcePropertyName, sourceResolution, targetResolution) {
5440
+ if (sourceResolution.kind === "non-contract" || targetResolution.kind === "non-contract") return void 0;
5441
+ if ((sourceResolution.ownership === "third-party" || sourceResolution.ownership === "platform") && targetResolution.kind !== "missing") {
5442
+ return void 0;
5443
+ }
5444
+ if ((targetResolution.ownership === "third-party" || targetResolution.ownership === "platform") && sourceResolution.kind !== "missing") {
5445
+ return void 0;
5446
+ }
5447
+ const hasDataContract = sourceResolution.kind === "data-contract" || targetResolution.kind === "data-contract";
5448
+ if (!hasDataContract) return void 0;
5449
+ if (sourceResolution.kind === "missing" || targetResolution.kind === "missing" || sourceResolution.ownership === "unknown" || targetResolution.ownership === "unknown") {
5450
+ return unknownContractOwnershipMessage(propertyName5, sourcePropertyName);
5451
+ }
5452
+ if (sourceResolution.kind !== "data-contract") return void 0;
5453
+ if (sourceResolution.ownership !== "first-party" || targetResolution.ownership !== "first-party") return void 0;
5454
+ return semanticMappingMessage(propertyName5, sourcePropertyName);
5455
+ }
5401
5456
  var noRedundantAliasRule = {
5402
5457
  meta: {
5403
5458
  schema: [],
@@ -5464,12 +5519,28 @@ var noRedundantAliasRule = {
5464
5519
  if (node.value.type === "Identifier") {
5465
5520
  if (node.shorthand) return;
5466
5521
  const source = node.value.name;
5522
+ if (propertyName5 === source) {
5523
+ context.report({
5524
+ node,
5525
+ message: objectPropertyMessage(propertyName5, source),
5526
+ fix(fixer) {
5527
+ return fixer.replaceText(node, propertyName5);
5528
+ }
5529
+ });
5530
+ return;
5531
+ }
5532
+ const bindingSource = destructuredBindingSource(context, node.value);
5533
+ if (!bindingSource || !ownershipResolver) return;
5534
+ const sourcePropertyName2 = bindingSource.propertyName;
5535
+ if (normalizePropertyName(propertyName5) === normalizePropertyName(sourcePropertyName2)) return;
5536
+ if (FRAMEWORK_MAPPING_KEYS.has(propertyName5) || isNamedMemberValue(sourcePropertyName2)) return;
5537
+ const sourceResolution2 = ownershipResolver.sourceBinding(bindingSource.declarator, sourcePropertyName2);
5538
+ const targetResolution2 = ownershipResolver.targetProperty(node, propertyName5);
5539
+ const hasDataContract = sourceResolution2.kind === "data-contract" || targetResolution2.kind === "data-contract";
5540
+ if (!hasDataContract) return;
5467
5541
  context.report({
5468
5542
  node,
5469
- message: objectPropertyMessage(propertyName5, source),
5470
- fix(fixer) {
5471
- return propertyName5 === source ? fixer.replaceText(node, propertyName5) : null;
5472
- }
5543
+ message: contractMappingViolation(propertyName5, sourcePropertyName2, sourceResolution2, targetResolution2) ?? objectPropertyMessage(propertyName5, source)
5473
5544
  });
5474
5545
  return;
5475
5546
  }
@@ -5482,27 +5553,16 @@ var noRedundantAliasRule = {
5482
5553
  if (!ownershipResolver) return;
5483
5554
  const sourceResolution = ownershipResolver.sourceMember(node.value);
5484
5555
  const targetResolution = ownershipResolver.targetProperty(node, propertyName5);
5485
- if (sourceResolution.kind === "non-contract" || targetResolution.kind === "non-contract") return;
5486
- if ((sourceResolution.ownership === "third-party" || sourceResolution.ownership === "platform") && targetResolution.kind !== "missing") {
5487
- return;
5488
- }
5489
- if ((targetResolution.ownership === "third-party" || targetResolution.ownership === "platform") && sourceResolution.kind !== "missing") {
5490
- return;
5491
- }
5492
- const hasDataContract = sourceResolution.kind === "data-contract" || targetResolution.kind === "data-contract";
5493
- if (!hasDataContract) return;
5494
- if (sourceResolution.kind === "missing" || targetResolution.kind === "missing" || sourceResolution.ownership === "unknown" || targetResolution.ownership === "unknown") {
5495
- context.report({
5496
- node,
5497
- message: unknownContractOwnershipMessage(propertyName5, sourcePropertyName)
5498
- });
5499
- return;
5500
- }
5501
- if (sourceResolution.kind !== "data-contract") return;
5502
- if (sourceResolution.ownership !== "first-party" || targetResolution.ownership !== "first-party") return;
5556
+ const violation = contractMappingViolation(
5557
+ propertyName5,
5558
+ sourcePropertyName,
5559
+ sourceResolution,
5560
+ targetResolution
5561
+ );
5562
+ if (!violation) return;
5503
5563
  context.report({
5504
5564
  node,
5505
- message: semanticMappingMessage(propertyName5, sourcePropertyName)
5565
+ message: violation
5506
5566
  });
5507
5567
  },
5508
5568
  TSTypeAliasDeclaration(node) {
@@ -6073,6 +6133,7 @@ function directPropertyBinding(context, declarator) {
6073
6133
  if (declarator.init?.type !== "MemberExpression") return void 0;
6074
6134
  const member = declarator.init;
6075
6135
  if (member.computed || member.optional || member.property.type !== "Identifier") return void 0;
6136
+ if (!memberCanBecomeLocal(member)) return void 0;
6076
6137
  if (context.sourceCode.getCommentsInside(declarator).length > 0) return void 0;
6077
6138
  const propertyName5 = member.property.name;
6078
6139
  const localName = declarator.id.name;
@@ -6098,10 +6159,56 @@ function isStableObjectSource(source) {
6098
6159
  if (source.computed || source.optional || source.property.type !== "Identifier") return false;
6099
6160
  return isStableObjectSource(source.object);
6100
6161
  }
6162
+ function rootIdentifierName(node) {
6163
+ if (node.type === "Identifier") return node.name;
6164
+ if (node.type !== "MemberExpression" || node.object.type === "Super") return void 0;
6165
+ return rootIdentifierName(node.object);
6166
+ }
6167
+ function isCompliantLocalName(propertyName5) {
6168
+ return !propertyName5.includes("_");
6169
+ }
6170
+ function propertyNameOf(node) {
6171
+ if (node.type !== "Property" || node.computed) return void 0;
6172
+ if (node.key.type === "Identifier") return node.key.name;
6173
+ if (node.key.type === "Literal" && typeof node.key.value === "string") return node.key.value;
6174
+ return void 0;
6175
+ }
6176
+ function renamedDirectMapping(context, member) {
6177
+ let current = member;
6178
+ const ancestors = context.sourceCode.getAncestors(member);
6179
+ for (let index = ancestors.length - 1; index >= 0; index -= 1) {
6180
+ const parent = ancestors[index];
6181
+ if (!parent) break;
6182
+ if (parent.type === "MemberExpression" && parent.object === current) {
6183
+ current = parent;
6184
+ continue;
6185
+ }
6186
+ if (parent.type !== "Property" || parent.value !== current) return void 0;
6187
+ const targetName = propertyNameOf(parent);
6188
+ const sourceName = !current.computed && current.property.type === "Identifier" ? current.property.name : void 0;
6189
+ if (targetName === void 0 || sourceName === void 0 || targetName === sourceName) return void 0;
6190
+ return { property: parent, sourceMember: current, targetName };
6191
+ }
6192
+ return void 0;
6193
+ }
6194
+ function memberCanBecomeLocal(member) {
6195
+ if (rootIdentifierName(member) === "locales") return false;
6196
+ return member.property.type === "Identifier" && isCompliantLocalName(member.property.name);
6197
+ }
6198
+ function directMappingRequiresQualifiedAccess(context, ownershipResolver, member) {
6199
+ const mapping = renamedDirectMapping(context, member);
6200
+ if (!mapping || !ownershipResolver) return false;
6201
+ const sourceResolution = ownershipResolver.sourceMember(mapping.sourceMember);
6202
+ const targetResolution = ownershipResolver.targetProperty(mapping.property, mapping.targetName);
6203
+ return sourceResolution.kind === "data-contract" || targetResolution.kind === "data-contract";
6204
+ }
6205
+ function memberCanBeDestructured(context, ownershipResolver, member) {
6206
+ return memberCanBecomeLocal(member) && !directMappingRequiresQualifiedAccess(context, ownershipResolver, member);
6207
+ }
6101
6208
  function objectUsage(scope, sourceText) {
6102
6209
  let usage = scope.objects.get(sourceText);
6103
6210
  if (!usage) {
6104
- usage = { propertyNames: /* @__PURE__ */ new Set(), directMembers: /* @__PURE__ */ new Map() };
6211
+ usage = { propertyNames: /* @__PURE__ */ new Set(), directMembers: [] };
6105
6212
  scope.objects.set(sourceText, usage);
6106
6213
  }
6107
6214
  return usage;
@@ -6121,33 +6228,60 @@ function memberIsDirectVariableInitializer(context, member) {
6121
6228
  const parent = context.sourceCode.getAncestors(member).at(-1);
6122
6229
  return parent?.type === "VariableDeclarator" && parent.init === member;
6123
6230
  }
6124
- function recordMemberUsage(context, scope, member) {
6231
+ function recordMemberUsage(context, scope, ownershipResolver, member) {
6125
6232
  if (!scope || member.computed || member.optional || member.property.type !== "Identifier") return;
6233
+ if (!memberCanBeDestructured(context, ownershipResolver, member)) return;
6126
6234
  if (!isStableObjectSource(member.object) || !memberIsRead(context, member)) return;
6127
6235
  const sourceText = context.sourceCode.getText(member.object);
6128
6236
  const usage = objectUsage(scope, sourceText);
6129
6237
  const propertyName5 = member.property.name;
6130
6238
  usage.propertyNames.add(propertyName5);
6131
- if (!memberIsDirectVariableInitializer(context, member) && !usage.directMembers.has(propertyName5)) {
6132
- usage.directMembers.set(propertyName5, member);
6239
+ if (!memberIsDirectVariableInitializer(context, member)) {
6240
+ usage.directMembers.push({ member, propertyName: propertyName5 });
6133
6241
  }
6134
6242
  }
6135
6243
  function recordDestructuringUsage(context, scope, declaration) {
6136
6244
  if (!scope) return;
6137
6245
  for (const declarator of declaration.declarations) {
6138
6246
  if (declarator.id.type !== "ObjectPattern" || !declarator.init || !isStableObjectSource(declarator.init)) continue;
6247
+ if (rootIdentifierName(declarator.init) === "locales") continue;
6139
6248
  const sourceText = context.sourceCode.getText(declarator.init);
6140
6249
  const usage = objectUsage(scope, sourceText);
6250
+ const propertyNames = /* @__PURE__ */ new Set();
6141
6251
  for (const property of declarator.id.properties) {
6142
6252
  if (property.type !== "Property" || property.computed || property.key.type !== "Identifier") continue;
6253
+ if (!isCompliantLocalName(property.key.name)) continue;
6254
+ propertyNames.add(property.key.name);
6143
6255
  usage.propertyNames.add(property.key.name);
6144
6256
  }
6257
+ usage.destructuring ??= { pattern: declarator.id, propertyNames };
6145
6258
  }
6146
6259
  }
6147
6260
  function scopeUsageMessage(sourceText, propertyNames) {
6148
6261
  const names = [...propertyNames].map((name) => `"${name}"`).join(", ");
6149
6262
  return `${names} are read from "${sourceText}" in the same block. Destructure them together in one declaration. ${DOC5}`;
6150
6263
  }
6264
+ function hasBinding(context, node, name) {
6265
+ const initialScope = context.sourceCode.getScope(node);
6266
+ if (initialScope.variables.some((variable) => variable.name === name)) return true;
6267
+ for (let scope = initialScope.upper; scope !== null; scope = scope.upper) {
6268
+ if (scope.variables.some((variable) => variable.name === name)) return true;
6269
+ }
6270
+ return false;
6271
+ }
6272
+ function containingStatement(context, scopeNode, node) {
6273
+ if (scopeNode.type !== "Program" && scopeNode.type !== "BlockStatement") return void 0;
6274
+ const [nodeStart, nodeEnd] = context.sourceCode.getRange(node);
6275
+ return scopeNode.body.find((statement) => {
6276
+ const [statementStart, statementEnd] = context.sourceCode.getRange(statement);
6277
+ return statementStart <= nodeStart && statementEnd >= nodeEnd;
6278
+ });
6279
+ }
6280
+ function statementIndentation(context, statement) {
6281
+ const [start] = context.sourceCode.getRange(statement);
6282
+ const lineStart = context.sourceCode.text.lastIndexOf("\n", start - 1) + 1;
6283
+ return context.sourceCode.text.slice(lineStart, start);
6284
+ }
6151
6285
  function whitespaceKeepsStatementsAdjacent(text) {
6152
6286
  if (text.trim() !== "") return false;
6153
6287
  return (text.match(/\n/gu) ?? []).length <= 1;
@@ -6188,12 +6322,13 @@ function destructuringSelection(context, declaration) {
6188
6322
  if (declaration.declarations.length !== 1) return void 0;
6189
6323
  const declarator = declaration.declarations[0];
6190
6324
  if (declarator?.id.type !== "ObjectPattern" || !declarator.init) return void 0;
6325
+ if (rootIdentifierName(declarator.init) === "locales") return void 0;
6191
6326
  if (context.sourceCode.getCommentsInside(declarator).length > 0) return void 0;
6192
6327
  const bindingTexts = [];
6193
6328
  const localNames = [];
6194
6329
  const propertyNames = [];
6195
6330
  for (const property of declarator.id.properties) {
6196
- if (property.type !== "Property" || property.computed || property.key.type !== "Identifier" || property.value.type !== "Identifier" || property.key.name !== property.value.name) {
6331
+ if (property.type !== "Property" || property.computed || property.key.type !== "Identifier" || !isCompliantLocalName(property.key.name) || property.value.type !== "Identifier" || property.key.name !== property.value.name) {
6197
6332
  return void 0;
6198
6333
  }
6199
6334
  bindingTexts.push(context.sourceCode.getText(property));
@@ -6262,22 +6397,53 @@ var preferObjectDestructuringRule = {
6262
6397
  }
6263
6398
  },
6264
6399
  create(context) {
6400
+ const ownershipResolver = contractOwnershipResolver(context);
6265
6401
  const grouped = /* @__PURE__ */ new Set();
6266
6402
  const usageScopes = [];
6267
6403
  const currentUsageScope = () => usageScopes.at(-1);
6268
- const enterUsageScope = () => {
6269
- usageScopes.push({ objects: /* @__PURE__ */ new Map() });
6404
+ const enterUsageScope = (node) => {
6405
+ usageScopes.push({ node, objects: /* @__PURE__ */ new Map() });
6270
6406
  };
6271
6407
  const exitUsageScope = () => {
6272
6408
  const scope = usageScopes.pop();
6273
6409
  if (!scope) return;
6274
6410
  for (const [sourceText, usage] of scope.objects) {
6275
- if (usage.propertyNames.size < 2 || usage.directMembers.size === 0) continue;
6276
- const firstDirectMember = usage.directMembers.values().next().value;
6277
- if (!firstDirectMember) continue;
6411
+ if (usage.propertyNames.size < 2 || usage.directMembers.length === 0) continue;
6412
+ const firstDirectUsage = usage.directMembers[0];
6413
+ if (!firstDirectUsage) continue;
6414
+ const { member: firstDirectMember } = firstDirectUsage;
6278
6415
  context.report({
6279
6416
  node: firstDirectMember,
6280
- message: scopeUsageMessage(sourceText, usage.propertyNames)
6417
+ message: scopeUsageMessage(sourceText, usage.propertyNames),
6418
+ fix(fixer) {
6419
+ const propertyNames = [...usage.propertyNames];
6420
+ const missingPropertyNames = propertyNames.filter(
6421
+ (propertyName5) => !usage.destructuring?.propertyNames.has(propertyName5)
6422
+ );
6423
+ if (missingPropertyNames.some((propertyName5) => hasBinding(context, firstDirectMember, propertyName5))) {
6424
+ return null;
6425
+ }
6426
+ const memberFixes = usage.directMembers.map(
6427
+ ({ member, propertyName: propertyName5 }) => fixer.replaceText(member, propertyName5)
6428
+ );
6429
+ if (usage.destructuring) {
6430
+ if (missingPropertyNames.length === 0) return memberFixes;
6431
+ const patternText = context.sourceCode.getText(usage.destructuring.pattern);
6432
+ const closeIndex = patternText.lastIndexOf("}");
6433
+ const beforeClose = patternText.slice(0, closeIndex);
6434
+ const contentEnd = beforeClose.trimEnd().length;
6435
+ const trailingWhitespace = beforeClose.slice(contentEnd);
6436
+ const separator = usage.destructuring.propertyNames.size > 0 ? ", " : "";
6437
+ const replacement = `${beforeClose.slice(0, contentEnd)}${separator}${missingPropertyNames.join(", ")}${trailingWhitespace}${patternText.slice(closeIndex)}`;
6438
+ return [fixer.replaceText(usage.destructuring.pattern, replacement), ...memberFixes];
6439
+ }
6440
+ const statement = containingStatement(context, scope.node, firstDirectMember);
6441
+ if (!statement) return null;
6442
+ const indentation = statementIndentation(context, statement);
6443
+ const declaration = `const { ${propertyNames.join(", ")} } = ${sourceText};
6444
+ ${indentation}`;
6445
+ return [fixer.insertTextBefore(statement, declaration), ...memberFixes];
6446
+ }
6281
6447
  });
6282
6448
  }
6283
6449
  };
@@ -6293,7 +6459,7 @@ var preferObjectDestructuringRule = {
6293
6459
  ArrowFunctionExpression: enterUsageScope,
6294
6460
  "ArrowFunctionExpression:exit": exitUsageScope,
6295
6461
  MemberExpression(node) {
6296
- recordMemberUsage(context, currentUsageScope(), node);
6462
+ recordMemberUsage(context, currentUsageScope(), ownershipResolver, node);
6297
6463
  },
6298
6464
  VariableDeclaration(node) {
6299
6465
  recordDestructuringUsage(context, currentUsageScope(), node);
@@ -7057,7 +7223,7 @@ import path49 from "path";
7057
7223
  function isCamelCase(name) {
7058
7224
  return /^[a-z][a-zA-Z0-9]*$/.test(name);
7059
7225
  }
7060
- function rootIdentifierName(node) {
7226
+ function rootIdentifierName2(node) {
7061
7227
  let current = node;
7062
7228
  for (; ; ) {
7063
7229
  if (current.type === "Identifier") return current.name;
@@ -7102,7 +7268,7 @@ var schemaCasingRule = {
7102
7268
  const container = declaration.parent;
7103
7269
  const isModuleLevel = container.type === "Program" || container.type === "ExportNamedDeclaration" && container.parent.type === "Program";
7104
7270
  if (!isModuleLevel) return;
7105
- if (!node.init || rootIdentifierName(node.init) !== zodLocalName) return;
7271
+ if (!node.init || rootIdentifierName2(node.init) !== zodLocalName) return;
7106
7272
  const { name } = node.id;
7107
7273
  if (isCamelCase(name)) return;
7108
7274
  context.report({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pasika",
3
- "version": "0.10.75",
3
+ "version": "0.10.77",
4
4
  "description": "Reusable agent setup package",
5
5
  "repository": {
6
6
  "type": "git",