@secondlayer/cli 1.10.0 → 1.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -20266,7 +20266,7 @@ import { promises as fs3 } from "fs";
20266
20266
  import path from "path";
20267
20267
  import { isValidAddress as _validateStacksAddress } from "@secondlayer/stacks";
20268
20268
  import { getErrorMessage } from "@secondlayer/shared";
20269
- import { toCamelCase as toCamelCase2 } from "@secondlayer/stacks/clarity";
20269
+ import { toCamelCase as toCamelCase3 } from "@secondlayer/stacks/clarity";
20270
20270
 
20271
20271
  class PluginManager {
20272
20272
  plugins = [];
@@ -20490,7 +20490,7 @@ ${JSON.stringify(content, null, 2)}`;
20490
20490
  }
20491
20491
  createUtils() {
20492
20492
  return {
20493
- toCamelCase: toCamelCase2,
20493
+ toCamelCase: toCamelCase3,
20494
20494
  toKebabCase: (str) => {
20495
20495
  return str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
20496
20496
  },
@@ -20541,7 +20541,7 @@ import {
20541
20541
  isAbiStringAscii as isAbiStringAscii2,
20542
20542
  isAbiStringUtf8 as isAbiStringUtf82,
20543
20543
  isAbiTuple,
20544
- toCamelCase as toCamelCase3
20544
+ toCamelCase as toCamelCase4
20545
20545
  } from "@secondlayer/stacks/clarity";
20546
20546
  function generateClarityConversion(argName, argType) {
20547
20547
  const type = argType.type;
@@ -20632,7 +20632,7 @@ function generateClarityConversion(argName, argType) {
20632
20632
  const requiredFields = type.tuple.map((f) => f.name);
20633
20633
  const fieldNames = JSON.stringify(requiredFields);
20634
20634
  const fields = type.tuple.map((field) => {
20635
- const camelFieldName = toCamelCase3(field.name);
20635
+ const camelFieldName = toCamelCase4(field.name);
20636
20636
  const fieldConversion = generateClarityConversion(`tupleValue.${camelFieldName}`, { type: field.type });
20637
20637
  return `"${field.name}": ${fieldConversion}`;
20638
20638
  }).join(", ");
@@ -20681,7 +20681,7 @@ import {
20681
20681
  isAbiStringAscii as isAbiStringAscii3,
20682
20682
  isAbiStringUtf8 as isAbiStringUtf83,
20683
20683
  isAbiTuple as isAbiTuple2,
20684
- toCamelCase as toCamelCase4
20684
+ toCamelCase as toCamelCase5
20685
20685
  } from "@secondlayer/stacks/clarity";
20686
20686
  function clarityTypeToTS(type) {
20687
20687
  if (typeof type === "string") {
@@ -20733,7 +20733,7 @@ function clarityTypeToTS(type) {
20733
20733
  return `${innerType}[]`;
20734
20734
  }
20735
20735
  if (isAbiTuple2(type)) {
20736
- const fields = type.tuple.map((field) => `${toCamelCase4(field.name)}: ${clarityTypeToTS(field.type)}`).join("; ");
20736
+ const fields = type.tuple.map((field) => `${toCamelCase5(field.name)}: ${clarityTypeToTS(field.type)}`).join("; ");
20737
20737
  return `{ ${fields} }`;
20738
20738
  }
20739
20739
  if (isAbiResponse2(type)) {
@@ -20751,12 +20751,12 @@ var init_type_mapping = () => {};
20751
20751
  // src/utils/generator-helpers.ts
20752
20752
  import {
20753
20753
  isAbiTuple as isAbiTuple3,
20754
- toCamelCase as toCamelCase5
20754
+ toCamelCase as toCamelCase6
20755
20755
  } from "@secondlayer/stacks/clarity";
20756
20756
  function generateMapKeyConversion(keyType) {
20757
20757
  if (isAbiTuple3(keyType)) {
20758
20758
  const fields = keyType.tuple.map((field) => {
20759
- const camelFieldName = toCamelCase5(field.name);
20759
+ const camelFieldName = toCamelCase6(field.name);
20760
20760
  const fieldConversion = generateClarityConversion(`key.${camelFieldName}`, { type: field.type });
20761
20761
  return `"${field.name}": ${fieldConversion}`;
20762
20762
  }).join(", ");
@@ -20771,7 +20771,7 @@ var init_generator_helpers = __esm(() => {
20771
20771
 
20772
20772
  // src/generators/contract.ts
20773
20773
  import {
20774
- toCamelCase as toCamelCase6
20774
+ toCamelCase as toCamelCase7
20775
20775
  } from "@secondlayer/stacks/clarity";
20776
20776
  function generateNetworkUtils() {
20777
20777
  return `/**
@@ -20863,7 +20863,7 @@ function generateAbiConstant(name, abi) {
20863
20863
  return `export const ${name}Abi = ${abiJson} as const`;
20864
20864
  }
20865
20865
  function generateMethod(func, address, contractName) {
20866
- const methodName = toCamelCase6(func.name);
20866
+ const methodName = toCamelCase7(func.name);
20867
20867
  if (func.args.length === 0) {
20868
20868
  return `${methodName}() {
20869
20869
  return {
@@ -20876,7 +20876,7 @@ function generateMethod(func, address, contractName) {
20876
20876
  }
20877
20877
  if (func.args.length === 1) {
20878
20878
  const originalArgName = func.args[0].name;
20879
- const argName = toCamelCase6(originalArgName);
20879
+ const argName = toCamelCase7(originalArgName);
20880
20880
  const argType = getTypeForArg(func.args[0]);
20881
20881
  const clarityConversion = generateClarityConversion(argName, func.args[0]);
20882
20882
  return `${methodName}(...args: [{ ${argName}: ${argType} }] | [${argType}]) {
@@ -20892,17 +20892,17 @@ function generateMethod(func, address, contractName) {
20892
20892
  }
20893
20893
  }`;
20894
20894
  }
20895
- const argsList = func.args.map((arg) => toCamelCase6(arg.name)).join(", ");
20895
+ const argsList = func.args.map((arg) => toCamelCase7(arg.name)).join(", ");
20896
20896
  const argsTypes = func.args.map((arg) => {
20897
- const camelName = toCamelCase6(arg.name);
20897
+ const camelName = toCamelCase7(arg.name);
20898
20898
  return `${camelName}: ${getTypeForArg(arg)}`;
20899
20899
  }).join("; ");
20900
20900
  const argsArray = func.args.map((arg) => {
20901
- const argName = toCamelCase6(arg.name);
20901
+ const argName = toCamelCase7(arg.name);
20902
20902
  return generateClarityConversion(argName, arg);
20903
20903
  }).join(", ");
20904
20904
  const objectAccess = func.args.map((arg) => {
20905
- const camelName = toCamelCase6(arg.name);
20905
+ const camelName = toCamelCase7(arg.name);
20906
20906
  return `args[0].${camelName}`;
20907
20907
  }).join(", ");
20908
20908
  const positionTypes = func.args.map((arg) => getTypeForArg(arg)).join(", ");
@@ -20924,7 +20924,7 @@ function generateMapsObject(maps, address, contractName) {
20924
20924
  return "";
20925
20925
  }
20926
20926
  const mapMethods = maps.map((map) => {
20927
- const methodName = toCamelCase6(map.name);
20927
+ const methodName = toCamelCase7(map.name);
20928
20928
  const keyType = getTypeForArg({ type: map.key });
20929
20929
  const valueType = getTypeForArg({ type: map.value });
20930
20930
  const keyConversion = generateMapKeyConversion(map.key);
@@ -20985,7 +20985,7 @@ function generateVarsObject(variables, address, contractName) {
20985
20985
  return "";
20986
20986
  }
20987
20987
  const varMethods = dataVars.map((variable) => {
20988
- const methodName = toCamelCase6(variable.name);
20988
+ const methodName = toCamelCase7(variable.name);
20989
20989
  const valueType = getTypeForArg({ type: variable.type });
20990
20990
  return `${methodName}: {
20991
20991
  async get(options?: { network?: 'mainnet' | 'testnet' | 'devnet' }): Promise<${valueType}> {
@@ -21030,7 +21030,7 @@ function generateConstantsObject(variables, address, contractName) {
21030
21030
  return "";
21031
21031
  }
21032
21032
  const constMethods = constants.map((constant) => {
21033
- const methodName = toCamelCase6(constant.name);
21033
+ const methodName = toCamelCase7(constant.name);
21034
21034
  const valueType = getTypeForArg({ type: constant.type });
21035
21035
  return `${methodName}: {
21036
21036
  async get(options?: { network?: 'mainnet' | 'testnet' | 'devnet' }): Promise<${valueType}> {
@@ -32314,7 +32314,7 @@ __export(exports_generate, {
32314
32314
  });
32315
32315
  import path10 from "path";
32316
32316
  import { getErrorMessage as getErrorMessage2 } from "@secondlayer/shared";
32317
- import { toCamelCase as toCamelCase7 } from "@secondlayer/stacks/clarity";
32317
+ import { toCamelCase as toCamelCase8 } from "@secondlayer/stacks/clarity";
32318
32318
  function isContractAddress(input4) {
32319
32319
  const contractIdPattern = /^(SP|ST|SM|SN)[A-Z0-9]{38,}\.[a-zA-Z][a-zA-Z0-9-]*$/;
32320
32320
  return contractIdPattern.test(input4);
@@ -32375,7 +32375,7 @@ async function buildConfigFromInputs(parsedInputs, outPath, apiKey, defaultAddre
32375
32375
  const apiClient = new StacksApiClient(network, apiKey);
32376
32376
  const contractInfo = await apiClient.getContractInfo(contractId);
32377
32377
  const abi = parseApiResponse(contractInfo);
32378
- const name = toCamelCase7(contractName);
32378
+ const name = toCamelCase8(contractName);
32379
32379
  contracts.push({
32380
32380
  name,
32381
32381
  address: contractId,
@@ -32620,7 +32620,7 @@ var {
32620
32620
  // package.json
32621
32621
  var package_default = {
32622
32622
  name: "@secondlayer/cli",
32623
- version: "1.10.0",
32623
+ version: "1.10.1",
32624
32624
  description: "CLI for streams, subgraphs, and real-time blockchain indexing on Stacks",
32625
32625
  type: "module",
32626
32626
  bin: {
@@ -32661,10 +32661,10 @@ var package_default = {
32661
32661
  license: "MIT",
32662
32662
  dependencies: {
32663
32663
  "@inquirer/prompts": "^8.2.0",
32664
- "@secondlayer/sdk": "^0.9.0",
32665
- "@secondlayer/shared": "^0.10.0",
32664
+ "@secondlayer/sdk": "^0.9.1",
32665
+ "@secondlayer/shared": "^0.10.1",
32666
32666
  "@secondlayer/stacks": "^0.2.2",
32667
- "@secondlayer/subgraphs": "^0.8.0",
32667
+ "@secondlayer/subgraphs": "^0.9.0",
32668
32668
  "@biomejs/js-api": "^0.7.0",
32669
32669
  "@biomejs/wasm-nodejs": "^1.9.0",
32670
32670
  esbuild: "^0.19.0",
@@ -35226,6 +35226,9 @@ function mapType(abiType, nullable) {
35226
35226
  }
35227
35227
 
35228
35228
  // src/generators/subgraph-scaffold.ts
35229
+ function toCamelCase(str) {
35230
+ return str.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
35231
+ }
35229
35232
  async function generateSubgraphScaffold(input2) {
35230
35233
  const { contractId, functions } = input2;
35231
35234
  const contractParts = contractId.split(".");
@@ -35235,6 +35238,12 @@ async function generateSubgraphScaffold(input2) {
35235
35238
  if (publicFunctions.length === 0) {
35236
35239
  throw new Error(`No public functions found in ${contractId}`);
35237
35240
  }
35241
+ const sourceEntries = publicFunctions.map((fn) => {
35242
+ const sourceName = toCamelCase(fn.name);
35243
+ return ` ${sourceName}: { type: 'contract_call', contractId: '${contractId}', functionName: '${fn.name}' }`;
35244
+ });
35245
+ const sourcesBlock = sourceEntries.join(`,
35246
+ `);
35238
35247
  const tables = publicFunctions.map((fn) => {
35239
35248
  const columns = fn.args.map((arg) => {
35240
35249
  const mapped = clarityTypeToSubgraphColumn(arg.type);
@@ -35251,14 +35260,15 @@ ${columns || " _placeholder: { type: 'text' }"}
35251
35260
  });
35252
35261
  const schemaBlock = tables.join(`,
35253
35262
  `);
35254
- const handlerKeys = publicFunctions.map((fn) => {
35255
- return ` '${contractId}::${fn.name}': async (event, ctx) => {
35263
+ const handlerEntries = publicFunctions.map((fn) => {
35264
+ const sourceName = toCamelCase(fn.name);
35265
+ return ` ${sourceName}: async (event, ctx) => {
35256
35266
  // TODO: implement ${fn.name} handler
35257
35267
  // event.args contains the function arguments
35258
35268
  // ctx.insert('${fn.name.replace(/-/g, "_")}', { ... })
35259
35269
  }`;
35260
35270
  });
35261
- const handlersBlock = handlerKeys.join(`,
35271
+ const handlersBlock = handlerEntries.join(`,
35262
35272
 
35263
35273
  `);
35264
35274
  const code = `
@@ -35266,7 +35276,9 @@ import { defineSubgraph } from '@secondlayer/subgraphs';
35266
35276
 
35267
35277
  export default defineSubgraph({
35268
35278
  name: '${subgraphName}',
35269
- sources: [{ contract: '${contractId}' }],
35279
+ sources: {
35280
+ ${sourcesBlock}
35281
+ },
35270
35282
  schema: {
35271
35283
  ${schemaBlock}
35272
35284
  },
@@ -35279,12 +35291,12 @@ ${handlersBlock}
35279
35291
  }
35280
35292
 
35281
35293
  // src/utils/case-conversion.ts
35282
- import { toCamelCase } from "@secondlayer/stacks/clarity";
35294
+ import { toCamelCase as toCamelCase2 } from "@secondlayer/stacks/clarity";
35283
35295
  function capitalize(str) {
35284
35296
  return str.charAt(0).toUpperCase() + str.slice(1);
35285
35297
  }
35286
35298
  function toPascalCase(str) {
35287
- return capitalize(toCamelCase(str));
35299
+ return capitalize(toCamelCase2(str));
35288
35300
  }
35289
35301
 
35290
35302
  // src/generators/subgraphs.ts
@@ -35378,15 +35390,19 @@ export default defineSubgraph({
35378
35390
  description: "TODO: describe what this subgraph tracks",
35379
35391
 
35380
35392
  // Sources define what blockchain data this subgraph processes.
35381
- // Each source filters transactions/events by contract, type, function, or event.
35382
- // Examples:
35383
- // { contract: "SP000...::my-contract" } — all txs to a contract
35384
- // { contract: "SP000...::my-contract", event: "transfer" } — specific event
35385
- // { type: "stx_transfer", minAmount: 1000000n } — STX transfers >= 1 STX
35386
- // { contract: "*.pox-*" } — wildcard contract match
35387
- sources: [
35388
- { contract: "SP000000000000000000002Q6VF78.pox-4" },
35389
- ],
35393
+ // Each source is named the name becomes the handler key.
35394
+ //
35395
+ // Filter types:
35396
+ // { type: "ft_transfer", assetIdentifier: "SP...token::token-name" }
35397
+ // { type: "ft_mint", assetIdentifier: "SP...token::token-name" }
35398
+ // { type: "contract_call", contractId: "SP...contract", functionName: "swap" }
35399
+ // { type: "contract_deploy" }
35400
+ // { type: "print_event", contractId: "SP...contract", topic: "my-event" }
35401
+ // { type: "stx_transfer", minAmount: 1000000n }
35402
+ // { type: "nft_transfer", assetIdentifier: "SP...nft::nft-name" }
35403
+ sources: {
35404
+ handler: { type: "contract_call", contractId: "SP000000000000000000002Q6VF78.pox-4" },
35405
+ },
35390
35406
 
35391
35407
  // Schema defines the tables this subgraph creates.
35392
35408
  // Each table gets auto-columns: _id, _block_height, _tx_id, _created_at.
@@ -35398,20 +35414,18 @@ export default defineSubgraph({
35398
35414
  amount: { type: "uint" },
35399
35415
  memo: { type: "text", nullable: true },
35400
35416
  },
35401
- // Optional composite indexes
35402
- // indexes: [["sender", "amount"]],
35403
35417
  },
35404
35418
  },
35405
35419
 
35406
- // Handlers process matched events and write to your tables via the context.
35407
- // Keys match source patterns (use sourceKey format), or "*" as catch-all.
35408
- // Context methods: ctx.insert(), ctx.update(), ctx.delete()
35420
+ // Handlers process matched events. Keys must match source names.
35421
+ // Context: ctx.insert(), ctx.update(), ctx.upsert(), ctx.patch(),
35422
+ // ctx.patchOrInsert(), ctx.findOne(), ctx.findMany()
35409
35423
  handlers: {
35410
- "*": async (event, ctx) => {
35411
- await ctx.insert("data", {
35412
- sender: event.sender ?? event.tx?.sender,
35424
+ handler: (event, ctx) => {
35425
+ ctx.insert("data", {
35426
+ sender: ctx.tx.sender,
35413
35427
  amount: event.amount ?? 0,
35414
- memo: event.memo ?? null,
35428
+ memo: null,
35415
35429
  });
35416
35430
  },
35417
35431
  },
@@ -35520,12 +35534,11 @@ Stopped watching.`);
35520
35534
  write: false
35521
35535
  });
35522
35536
  const handlerCode = new TextDecoder().decode(buildResult.outputFiles[0].contents);
35523
- const { sourceKey } = await import("@secondlayer/subgraphs");
35524
35537
  const result = await deploySubgraphApi({
35525
35538
  name: def.name,
35526
35539
  version: def.version,
35527
35540
  description: def.description,
35528
- sources: def.sources.map(sourceKey),
35541
+ sources: def.sources,
35529
35542
  schema: def.schema,
35530
35543
  handlerCode,
35531
35544
  reindex: options2.reindex
@@ -37025,5 +37038,5 @@ registerWhoamiCommand(program);
37025
37038
  registerReceiverCommand(program);
37026
37039
  program.parse();
37027
37040
 
37028
- //# debugId=2406566DC849ADA464756E2164756E21
37041
+ //# debugId=7DCC96BC6E5808DA64756E2164756E21
37029
37042
  //# sourceMappingURL=cli.js.map