pasika 0.10.76 → 0.10.78

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;
@@ -6092,11 +6153,54 @@ function directPropertyBinding(context, declarator) {
6092
6153
  function canGroupSource(source) {
6093
6154
  return source.type === "Identifier" || source.type === "ThisExpression";
6094
6155
  }
6095
- function isStableObjectSource(source) {
6096
- if (source.type === "Identifier" || source.type === "ThisExpression") return true;
6097
- if (source.type !== "MemberExpression") return false;
6098
- if (source.computed || source.optional || source.property.type !== "Identifier") return false;
6099
- return isStableObjectSource(source.object);
6156
+ function isGroupedUsageSource(source) {
6157
+ return source.type === "Identifier" || source.type === "ThisExpression";
6158
+ }
6159
+ function rootIdentifierName(node) {
6160
+ if (node.type === "Identifier") return node.name;
6161
+ if (node.type !== "MemberExpression" || node.object.type === "Super") return void 0;
6162
+ return rootIdentifierName(node.object);
6163
+ }
6164
+ function isCompliantLocalName(propertyName5) {
6165
+ return !propertyName5.includes("_");
6166
+ }
6167
+ function propertyNameOf(node) {
6168
+ if (node.type !== "Property" || node.computed) return void 0;
6169
+ if (node.key.type === "Identifier") return node.key.name;
6170
+ if (node.key.type === "Literal" && typeof node.key.value === "string") return node.key.value;
6171
+ return void 0;
6172
+ }
6173
+ function renamedDirectMapping(context, member) {
6174
+ let current = member;
6175
+ const ancestors = context.sourceCode.getAncestors(member);
6176
+ for (let index = ancestors.length - 1; index >= 0; index -= 1) {
6177
+ const parent = ancestors[index];
6178
+ if (!parent) break;
6179
+ if (parent.type === "MemberExpression" && parent.object === current) {
6180
+ current = parent;
6181
+ continue;
6182
+ }
6183
+ if (parent.type !== "Property" || parent.value !== current) return void 0;
6184
+ const targetName = propertyNameOf(parent);
6185
+ const sourceName = !current.computed && current.property.type === "Identifier" ? current.property.name : void 0;
6186
+ if (targetName === void 0 || sourceName === void 0 || targetName === sourceName) return void 0;
6187
+ return { property: parent, sourceMember: current, targetName };
6188
+ }
6189
+ return void 0;
6190
+ }
6191
+ function memberCanBecomeLocal(member) {
6192
+ if (rootIdentifierName(member) === "locales") return false;
6193
+ return member.property.type === "Identifier" && isCompliantLocalName(member.property.name);
6194
+ }
6195
+ function directMappingRequiresQualifiedAccess(context, ownershipResolver, member) {
6196
+ const mapping = renamedDirectMapping(context, member);
6197
+ if (!mapping || !ownershipResolver) return false;
6198
+ const sourceResolution = ownershipResolver.sourceMember(mapping.sourceMember);
6199
+ const targetResolution = ownershipResolver.targetProperty(mapping.property, mapping.targetName);
6200
+ return sourceResolution.kind === "data-contract" || targetResolution.kind === "data-contract";
6201
+ }
6202
+ function memberCanBeDestructured(context, ownershipResolver, member) {
6203
+ return memberCanBecomeLocal(member) && !directMappingRequiresQualifiedAccess(context, ownershipResolver, member);
6100
6204
  }
6101
6205
  function objectUsage(scope, sourceText) {
6102
6206
  let usage = scope.objects.get(sourceText);
@@ -6121,9 +6225,10 @@ function memberIsDirectVariableInitializer(context, member) {
6121
6225
  const parent = context.sourceCode.getAncestors(member).at(-1);
6122
6226
  return parent?.type === "VariableDeclarator" && parent.init === member;
6123
6227
  }
6124
- function recordMemberUsage(context, scope, member) {
6228
+ function recordMemberUsage(context, scope, ownershipResolver, member) {
6125
6229
  if (!scope || member.computed || member.optional || member.property.type !== "Identifier") return;
6126
- if (!isStableObjectSource(member.object) || !memberIsRead(context, member)) return;
6230
+ if (!memberCanBeDestructured(context, ownershipResolver, member)) return;
6231
+ if (!isGroupedUsageSource(member.object) || !memberIsRead(context, member)) return;
6127
6232
  const sourceText = context.sourceCode.getText(member.object);
6128
6233
  const usage = objectUsage(scope, sourceText);
6129
6234
  const propertyName5 = member.property.name;
@@ -6135,12 +6240,15 @@ function recordMemberUsage(context, scope, member) {
6135
6240
  function recordDestructuringUsage(context, scope, declaration) {
6136
6241
  if (!scope) return;
6137
6242
  for (const declarator of declaration.declarations) {
6138
- if (declarator.id.type !== "ObjectPattern" || !declarator.init || !isStableObjectSource(declarator.init)) continue;
6243
+ if (declarator.id.type !== "ObjectPattern" || !declarator.init || !isGroupedUsageSource(declarator.init)) continue;
6244
+ if (rootIdentifierName(declarator.init) === "locales") continue;
6139
6245
  const sourceText = context.sourceCode.getText(declarator.init);
6140
6246
  const usage = objectUsage(scope, sourceText);
6247
+ if (usage.directMembers.length > 0) continue;
6141
6248
  const propertyNames = /* @__PURE__ */ new Set();
6142
6249
  for (const property of declarator.id.properties) {
6143
6250
  if (property.type !== "Property" || property.computed || property.key.type !== "Identifier") continue;
6251
+ if (!isCompliantLocalName(property.key.name)) continue;
6144
6252
  propertyNames.add(property.key.name);
6145
6253
  usage.propertyNames.add(property.key.name);
6146
6254
  }
@@ -6212,12 +6320,13 @@ function destructuringSelection(context, declaration) {
6212
6320
  if (declaration.declarations.length !== 1) return void 0;
6213
6321
  const declarator = declaration.declarations[0];
6214
6322
  if (declarator?.id.type !== "ObjectPattern" || !declarator.init) return void 0;
6323
+ if (rootIdentifierName(declarator.init) === "locales") return void 0;
6215
6324
  if (context.sourceCode.getCommentsInside(declarator).length > 0) return void 0;
6216
6325
  const bindingTexts = [];
6217
6326
  const localNames = [];
6218
6327
  const propertyNames = [];
6219
6328
  for (const property of declarator.id.properties) {
6220
- if (property.type !== "Property" || property.computed || property.key.type !== "Identifier" || property.value.type !== "Identifier" || property.key.name !== property.value.name) {
6329
+ if (property.type !== "Property" || property.computed || property.key.type !== "Identifier" || !isCompliantLocalName(property.key.name) || property.value.type !== "Identifier" || property.key.name !== property.value.name) {
6221
6330
  return void 0;
6222
6331
  }
6223
6332
  bindingTexts.push(context.sourceCode.getText(property));
@@ -6286,12 +6395,16 @@ var preferObjectDestructuringRule = {
6286
6395
  }
6287
6396
  },
6288
6397
  create(context) {
6398
+ const ownershipResolver = contractOwnershipResolver(context);
6289
6399
  const grouped = /* @__PURE__ */ new Set();
6290
6400
  const usageScopes = [];
6291
6401
  const currentUsageScope = () => usageScopes.at(-1);
6292
6402
  const enterUsageScope = (node) => {
6293
6403
  usageScopes.push({ node, objects: /* @__PURE__ */ new Map() });
6294
6404
  };
6405
+ const enterUsageBarrier = () => {
6406
+ usageScopes.push(void 0);
6407
+ };
6295
6408
  const exitUsageScope = () => {
6296
6409
  const scope = usageScopes.pop();
6297
6410
  if (!scope) return;
@@ -6300,17 +6413,17 @@ var preferObjectDestructuringRule = {
6300
6413
  const firstDirectUsage = usage.directMembers[0];
6301
6414
  if (!firstDirectUsage) continue;
6302
6415
  const { member: firstDirectMember } = firstDirectUsage;
6416
+ const propertyNames = [...usage.propertyNames];
6417
+ const missingPropertyNames = propertyNames.filter(
6418
+ (propertyName5) => !usage.destructuring?.propertyNames.has(propertyName5)
6419
+ );
6420
+ if (missingPropertyNames.some((propertyName5) => hasBinding(context, firstDirectMember, propertyName5))) {
6421
+ continue;
6422
+ }
6303
6423
  context.report({
6304
6424
  node: firstDirectMember,
6305
6425
  message: scopeUsageMessage(sourceText, usage.propertyNames),
6306
6426
  fix(fixer) {
6307
- const propertyNames = [...usage.propertyNames];
6308
- const missingPropertyNames = propertyNames.filter(
6309
- (propertyName5) => !usage.destructuring?.propertyNames.has(propertyName5)
6310
- );
6311
- if (missingPropertyNames.some((propertyName5) => hasBinding(context, firstDirectMember, propertyName5))) {
6312
- return null;
6313
- }
6314
6427
  const memberFixes = usage.directMembers.map(
6315
6428
  ({ member, propertyName: propertyName5 }) => fixer.replaceText(member, propertyName5)
6316
6429
  );
@@ -6340,14 +6453,14 @@ ${indentation}`;
6340
6453
  "Program:exit": exitUsageScope,
6341
6454
  BlockStatement: enterUsageScope,
6342
6455
  "BlockStatement:exit": exitUsageScope,
6343
- FunctionDeclaration: enterUsageScope,
6456
+ FunctionDeclaration: enterUsageBarrier,
6344
6457
  "FunctionDeclaration:exit": exitUsageScope,
6345
- FunctionExpression: enterUsageScope,
6458
+ FunctionExpression: enterUsageBarrier,
6346
6459
  "FunctionExpression:exit": exitUsageScope,
6347
- ArrowFunctionExpression: enterUsageScope,
6460
+ ArrowFunctionExpression: enterUsageBarrier,
6348
6461
  "ArrowFunctionExpression:exit": exitUsageScope,
6349
6462
  MemberExpression(node) {
6350
- recordMemberUsage(context, currentUsageScope(), node);
6463
+ recordMemberUsage(context, currentUsageScope(), ownershipResolver, node);
6351
6464
  },
6352
6465
  VariableDeclaration(node) {
6353
6466
  recordDestructuringUsage(context, currentUsageScope(), node);
@@ -7111,7 +7224,7 @@ import path49 from "path";
7111
7224
  function isCamelCase(name) {
7112
7225
  return /^[a-z][a-zA-Z0-9]*$/.test(name);
7113
7226
  }
7114
- function rootIdentifierName(node) {
7227
+ function rootIdentifierName2(node) {
7115
7228
  let current = node;
7116
7229
  for (; ; ) {
7117
7230
  if (current.type === "Identifier") return current.name;
@@ -7156,7 +7269,7 @@ var schemaCasingRule = {
7156
7269
  const container = declaration.parent;
7157
7270
  const isModuleLevel = container.type === "Program" || container.type === "ExportNamedDeclaration" && container.parent.type === "Program";
7158
7271
  if (!isModuleLevel) return;
7159
- if (!node.init || rootIdentifierName(node.init) !== zodLocalName) return;
7272
+ if (!node.init || rootIdentifierName2(node.init) !== zodLocalName) return;
7160
7273
  const { name } = node.id;
7161
7274
  if (isCamelCase(name)) return;
7162
7275
  context.report({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pasika",
3
- "version": "0.10.76",
3
+ "version": "0.10.78",
4
4
  "description": "Reusable agent setup package",
5
5
  "repository": {
6
6
  "type": "git",