@mastra/codemod 0.0.0-feat-add-query-option-to-playground-20251209160219 → 0.0.0-feat-8782-cf-bindings-20260102164434
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/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @mastra/codemod
|
|
2
2
|
|
|
3
|
-
## 0.0.0-feat-
|
|
3
|
+
## 0.0.0-feat-8782-cf-bindings-20260102164434
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
@@ -10,6 +10,44 @@
|
|
|
10
10
|
|
|
11
11
|
- Fixed a bug where `[native code]` was incorrectly added to the output ([#10971](https://github.com/mastra-ai/mastra/pull/10971))
|
|
12
12
|
|
|
13
|
+
- **Breaking Change:** `memory.readOnly` has been moved to `memory.options.readOnly` ([#11523](https://github.com/mastra-ai/mastra/pull/11523))
|
|
14
|
+
|
|
15
|
+
The `readOnly` option now lives inside `memory.options` alongside other memory configuration like `lastMessages` and `semanticRecall`.
|
|
16
|
+
|
|
17
|
+
**Before:**
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
agent.stream('Hello', {
|
|
21
|
+
memory: {
|
|
22
|
+
thread: threadId,
|
|
23
|
+
resource: resourceId,
|
|
24
|
+
readOnly: true,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**After:**
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
agent.stream('Hello', {
|
|
33
|
+
memory: {
|
|
34
|
+
thread: threadId,
|
|
35
|
+
resource: resourceId,
|
|
36
|
+
options: {
|
|
37
|
+
readOnly: true,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**Migration:** Run the codemod to update your code automatically:
|
|
44
|
+
|
|
45
|
+
```shell
|
|
46
|
+
npx @mastra/codemod@beta v1/memory-readonly-to-options .
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
This also fixes issue #11519 where `readOnly: true` was being ignored and messages were saved to memory anyway.
|
|
50
|
+
|
|
13
51
|
- Add `v1/workflow-stream-vnext` codemod. This codemod renames `streamVNext()`, `resumeStreamVNext()`, and `observeStreamVNext()` to their "non-VNext" counterparts. ([#10802](https://github.com/mastra-ai/mastra/pull/10802))
|
|
14
52
|
|
|
15
53
|
- Fix `mastra-required-id`, `mcp-get-toolsets`, and `mcp-get-tools` codemods to add missing imports and instances. ([#10221](https://github.com/mastra-ai/mastra/pull/10221))
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createTransformer
|
|
3
|
+
} from "../chunk-JNFQ6J6B.js";
|
|
4
|
+
|
|
5
|
+
// src/codemods/v1/memory-readonly-to-options.ts
|
|
6
|
+
var memory_readonly_to_options_default = createTransformer((_fileInfo, _api, _options, context) => {
|
|
7
|
+
const { j, root } = context;
|
|
8
|
+
root.find(j.ObjectExpression).forEach((path) => {
|
|
9
|
+
const memoryProp = path.value.properties.find(
|
|
10
|
+
(prop) => (prop.type === "Property" || prop.type === "ObjectProperty") && prop.key && prop.key.type === "Identifier" && prop.key.name === "memory"
|
|
11
|
+
);
|
|
12
|
+
if (!memoryProp || !memoryProp.value || memoryProp.value.type !== "ObjectExpression") {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const memoryObj = memoryProp.value;
|
|
16
|
+
const properties = memoryObj.properties;
|
|
17
|
+
const readOnlyPropIndex = properties.findIndex(
|
|
18
|
+
(prop) => (prop.type === "Property" || prop.type === "ObjectProperty") && prop.key && prop.key.type === "Identifier" && prop.key.name === "readOnly"
|
|
19
|
+
);
|
|
20
|
+
if (readOnlyPropIndex === -1) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const readOnlyProp = properties[readOnlyPropIndex];
|
|
24
|
+
const readOnlyValue = readOnlyProp.value;
|
|
25
|
+
properties.splice(readOnlyPropIndex, 1);
|
|
26
|
+
let optionsProp = properties.find(
|
|
27
|
+
(prop) => (prop.type === "Property" || prop.type === "ObjectProperty") && prop.key && prop.key.type === "Identifier" && prop.key.name === "options"
|
|
28
|
+
);
|
|
29
|
+
if (optionsProp && optionsProp.value && optionsProp.value.type === "ObjectExpression") {
|
|
30
|
+
optionsProp.value.properties.push(j.property("init", j.identifier("readOnly"), readOnlyValue));
|
|
31
|
+
} else {
|
|
32
|
+
const newOptionsProp = j.property(
|
|
33
|
+
"init",
|
|
34
|
+
j.identifier("options"),
|
|
35
|
+
j.objectExpression([j.property("init", j.identifier("readOnly"), readOnlyValue)])
|
|
36
|
+
);
|
|
37
|
+
properties.push(newOptionsProp);
|
|
38
|
+
}
|
|
39
|
+
context.hasChanges = true;
|
|
40
|
+
});
|
|
41
|
+
if (context.hasChanges) {
|
|
42
|
+
context.messages.push("Moved memory.readOnly to memory.options.readOnly");
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
export {
|
|
46
|
+
memory_readonly_to_options_default as default
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=memory-readonly-to-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/codemods/v1/memory-readonly-to-options.ts"],"sourcesContent":["import { createTransformer } from '../lib/create-transformer';\n\n/**\n * Moves memory.readOnly to memory.options.readOnly in agent.stream() and agent.generate() calls.\n * The top-level readOnly property has been removed in favor of options.readOnly.\n *\n * Before:\n * agent.stream('Hello', {\n * memory: {\n * thread: threadId,\n * resource: resourceId,\n * readOnly: true,\n * },\n * });\n *\n * After:\n * agent.stream('Hello', {\n * memory: {\n * thread: threadId,\n * resource: resourceId,\n * options: {\n * readOnly: true,\n * },\n * },\n * });\n */\nexport default createTransformer((_fileInfo, _api, _options, context) => {\n const { j, root } = context;\n\n // Find all object expressions that have a 'memory' property\n root.find(j.ObjectExpression).forEach(path => {\n const memoryProp = path.value.properties.find(\n (prop: any) =>\n (prop.type === 'Property' || prop.type === 'ObjectProperty') &&\n prop.key &&\n prop.key.type === 'Identifier' &&\n prop.key.name === 'memory',\n ) as any;\n\n if (!memoryProp || !memoryProp.value || memoryProp.value.type !== 'ObjectExpression') {\n return;\n }\n\n const memoryObj = memoryProp.value;\n const properties = memoryObj.properties;\n\n // Find readOnly property\n const readOnlyPropIndex = properties.findIndex(\n (prop: any) =>\n (prop.type === 'Property' || prop.type === 'ObjectProperty') &&\n prop.key &&\n prop.key.type === 'Identifier' &&\n prop.key.name === 'readOnly',\n );\n\n if (readOnlyPropIndex === -1) {\n return;\n }\n\n const readOnlyProp = properties[readOnlyPropIndex] as any;\n const readOnlyValue = readOnlyProp.value;\n\n // Remove readOnly from top level\n properties.splice(readOnlyPropIndex, 1);\n\n // Find or create options property\n let optionsProp = properties.find(\n (prop: any) =>\n (prop.type === 'Property' || prop.type === 'ObjectProperty') &&\n prop.key &&\n prop.key.type === 'Identifier' &&\n prop.key.name === 'options',\n ) as any;\n\n if (optionsProp && optionsProp.value && optionsProp.value.type === 'ObjectExpression') {\n // Add readOnly to existing options\n optionsProp.value.properties.push(j.property('init', j.identifier('readOnly'), readOnlyValue));\n } else {\n // Create new options object with readOnly\n const newOptionsProp = j.property(\n 'init',\n j.identifier('options'),\n j.objectExpression([j.property('init', j.identifier('readOnly'), readOnlyValue)]),\n );\n properties.push(newOptionsProp);\n }\n\n context.hasChanges = true;\n });\n\n if (context.hasChanges) {\n context.messages.push('Moved memory.readOnly to memory.options.readOnly');\n }\n});\n"],"mappings":";;;;;AA0BA,IAAO,qCAAQ,kBAAkB,CAAC,WAAW,MAAM,UAAU,YAAY;AACvE,QAAM,EAAE,GAAG,KAAK,IAAI;AAGpB,OAAK,KAAK,EAAE,gBAAgB,EAAE,QAAQ,UAAQ;AAC5C,UAAM,aAAa,KAAK,MAAM,WAAW;AAAA,MACvC,CAAC,UACE,KAAK,SAAS,cAAc,KAAK,SAAS,qBAC3C,KAAK,OACL,KAAK,IAAI,SAAS,gBAClB,K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
122
|
"v1/memory-message-v2-type",
|
|
123
|
+
"v1/memory-readonly-to-options",
|
|
123
124
|
"v1/storage-get-threads-by-resource",
|
|
124
125
|
"v1/storage-list-messages-by-id",
|
|
125
126
|
"v1/storage-postgres-schema-name",
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/transform.ts","../src/lib/bundle.ts","../src/lib/upgrade.ts","../src/index.ts"],"names":["transform","log","debug","error"],"mappings":";;;;;;;;;;AAOA,IAAM,IAAA,GAAO,IAAA,CAAK,SAAA,CAAU,aAAA,CAAc,IAAI,CAAA;AAS9C,IAAM,GAAA,GAAM,MAAM,mBAAmB,CAAA;AACrC,IAAM,KAAA,GAAQ,MAAM,yBAAyB,CAAA;AAC7C,IAAM,UAAA,GAAa,aAAA,CAAc,MAAA,CAAA,IAAA,CAAY,GAAG,CAAA;AAChD,IAAM,SAAA,GAAY,IAAA,CAAK,OAAA,CAAQ,UAAU,CAAA;AAEzC,SAAS,cAAA,GAAyB;AAChC,EAAA,MAAM,gBAAA,GAAmB,IAAA,CAAK,OAAA,CAAQ,SAAA,EAAW,kCAAkC,CAAA;AACnF,EAAA,OAAO,EAAA,CAAG,UAAA,CAAW,gBAAgB,CAAA,GAAI,gBAAA,GAAmB,aAAA;AAC9D;AAEA,SAAS,YAAA,CAAa,WAAA,EAAqB,UAAA,EAAoB,WAAA,EAAqB,OAAA,EAAmC;AAGrH,EAAA,IAAI,UAAU,CAAA,EAAG,WAAW,CAAA,IAAA,EAAO,WAAW,IAAI,UAAU,CAAA,yOAAA,CAAA;AAS5D,EAAA,IAAI,QAAQ,GAAA,EAAK;AACf,IAAA,OAAA,IAAW,QAAA;AAAA,EACb;AAEA,EAAA,IAAI,QAAQ,KAAA,EAAO;AACjB,IAAA,OAAA,IAAW,UAAA;AAAA,EACb;AAEA,EAAA,IAAI,QAAQ,OAAA,EAAS;AACnB,IAAA,OAAA,IAAW,YAAA;AAAA,EACb;AAEA,E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AI,CAAA,CACZ,WAAA,CAAY,oCAAoC,EAChD,MAAA,CAAO,WAAA,EAAa,wCAAwC,CAAA,CAC5D,MAAA,CAAO,aAAA,EAAe,mCAAmC,CAAA,CACzD,MAAA,CAAO,WAAA,EAAa,mDAAmD,CAAA,CACvE,MAAA,CAAO,+BAA+B,sCAAsC,CAAA,CAC5E,MAAA,CAAO,OAAM,OAAA,KAAW;AACvB,EAAA,IAAI;AACF,IAAA,MAAM,UAAU,OAAO,CAAA;AAAA,EACzB,SAAS,GAAA,EAAU;AACjB,IAAAA,MAAAA,CAAM,CAAA,oBAAA,EAAuB,GAAG,CAAA,CAAE,CAAA;AAClC,IAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,EAChB;AACF,CAAC,CAAA;AAEH,OAAA,CAAQ,KAAA,CAAM,QAAQ,IAAI,CAAA","file":"index.js","sourcesContent":["import child_process from 'node:child_process';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport util from 'node:util';\nimport debug from 'debug';\n\nconst exec = util.promisify(child_process.exec);\n\ninterface TransformOptions {\n dry?: boolean;\n print?: boolean;\n verbose?: boolean;\n jscodeshift?: string;\n}\n\nconst log = debug('codemod:transform');\nconst error = debug('codemod:transform:error');\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\nfunction getJscodeshift(): string {\n const localJscodeshift = path.resolve(__dirname, '../node_modules/.bin/jscodeshift');\n return fs.existsSync(localJscodeshift) ? localJscodeshift : 'jscodeshift';\n}\n\nfunction buildCommand(codemodPath: string, targetPath: string, jscodeshift: string, options: TransformOptions): string {\n // Ignoring everything under `.*/` covers `.mastra/` along with any other\n // framework build related or otherwise intended-to-be-hidden directories.\n let command = `${jscodeshift} -t ${codemodPath} ${targetPath} \\\n --parser tsx \\\n --ignore-pattern=\"**/node_modules/**\" \\\n --ignore-pattern=\"**/.*/**\" \\\n --ignore-pattern=\"**/dist/**\" \\\n --ignore-pattern=\"**/build/**\" \\\n --ignore-pattern=\"**/*.min.js\" \\\n --ignore-pattern=\"**/*.bundle.js\"`;\n\n if (options.dry) {\n command += ' --dry';\n }\n\n if (options.print) {\n command += ' --print';\n }\n\n if (options.verbose) {\n command += ' --verbose';\n }\n\n if (options.jscodeshift) {\n command += ` ${options.jscodeshift}`;\n }\n\n return command;\n}\n\nexport type TransformErrors = {\n transform: string;\n filename: string;\n summary: string;\n}[];\n\nfunction parseErrors(transform: string, output: string): TransformErrors {\n const errors: TransformErrors = [];\n const errorRegex = /ERR (.+) Transformation error/g;\n const syntaxErrorRegex = /SyntaxError: .+/g;\n\n let match;\n while ((match = errorRegex.exec(output)) !== null) {\n const filename = match[1]!;\n const syntaxErrorMatch = syntaxErrorRegex.exec(output);\n if (syntaxErrorMatch) {\n const summary = syntaxErrorMatch[0];\n errors.push({ transform, filename, summary });\n }\n }\n\n return errors;\n}\n\nfunction parseNotImplementedErrors(transform: string, output: string): TransformErrors {\n const notImplementedErrors: TransformErrors = [];\n const notImplementedRegex = /Not Implemented (.+): (.+)/g;\n\n let match;\n while ((match = notImplementedRegex.exec(output)) !== null) {\n const filename = match[1]!;\n const summary = match[2]!;\n notImplementedErrors.push({ transform, filename, summary });\n }\n\n return notImplementedErrors;\n}\n\nexport async function transform(\n codemod: string,\n source: string,\n transformOptions: TransformOptions,\n options: { logStatus: boolean } = { logStatus: true },\n): Promise<{ errors: TransformErrors; notImplementedErrors: TransformErrors }> {\n if (options.logStatus) {\n log(`Applying codemod '${codemod}': ${source}`);\n }\n const codemodPath = path.resolve(__dirname, `./codemods/${codemod}.js`);\n const targetPath = path.resolve(source);\n const jscodeshift = getJscodeshift();\n const command = buildCommand(codemodPath, targetPath, jscodeshift, transformOptions);\n const { stdout } = await exec(command, { encoding: 'utf8' });\n const errors = parseErrors(codemod, stdout);\n const notImplementedErrors = parseNotImplementedErrors(codemod, stdout);\n if (options.logStatus) {\n if (errors.length > 0) {\n errors.forEach(({ transform, filename, summary }) => {\n error(`Error applying codemod [codemod=${transform}, path=${filename}, summary=${summary}]`);\n });\n }\n\n if (notImplementedErrors.length > 0) {\n log(\n `Some files require manual changes. Please search your codebase for \\`FIXME(mastra): \\` comments and follow the instructions to complete the upgrade.`,\n );\n notImplementedErrors.forEach(({ transform, filename, summary }) => {\n log(`Not Implemented [codemod=${transform}, path=${filename}, summary=${summary}]`);\n });\n }\n }\n\n return { errors, notImplementedErrors };\n}\n","// List of all codemods\nexport const BUNDLE = [\n 'v1/mastra-core-imports',\n 'v1/runtime-context',\n 'v1/not-implemented/mastra-memory',\n 'v1/mastra-plural-apis',\n 'v1/not-implemented/mastra-required-id',\n 'v1/agent-property-access',\n 'v1/agent-voice',\n 'v1/agent-processor-methods',\n 'v1/agent-generate-stream-v-next',\n 'v1/agent-abort-signal',\n 'v1/not-implemented/agent-format-parameter',\n 'v1/not-implemented/agent-to-step',\n 'v1/voice-property-names',\n 'v1/mcp-get-tools',\n 'v1/mcp-get-toolsets',\n 'v1/client-sdk-types',\n 'v1/client-to-ai-sdk-format',\n 'v1/client-offset-limit',\n 'v1/client-get-memory-thread',\n 'v1/experimental-auth',\n 'v1/evals-run-experiment',\n 'v1/evals-scorer-by-name',\n 'v1/evals-prebuilt-imports',\n 'v1/workflow-create-run-async',\n 'v1/workflow-run-count',\n 'v1/workflow-list-runs',\n 'v1/workflow-stream-vnext',\n 'v1/memory-query-to-recall',\n 'v1/memory-vector-search-param',\n 'v1/memory-message-v2-type',\n 'v1/storage-get-threads-by-resource',\n 'v1/storage-list-messages-by-id',\n 'v1/storage-postgres-schema-name',\n 'v1/storage-get-messages-paginated',\n 'v1/storage-list-workflow-runs',\n 'v1/vector-pg-constructor',\n];\n","import { spinner, intro, outro } from '@clack/prompts';\nimport debug from 'debug';\nimport { BUNDLE } from './bundle';\nimport type { TransformErrors } from './transform';\nimport { transform } from './transform';\n\ninterface TransformOptions {\n dry?: true;\n print?: true;\n verbose?: true;\n jscodeshift?: string;\n}\n\nconst log = debug('codemod:upgrade');\nconst error = debug('codemod:upgrade:error');\n\n// Extract v1 codemods from the bundle\nconst v1Bundle = BUNDLE.filter(codemod => codemod.startsWith('v1/'));\n\nasync function runCodemods(codemods: string[], options: TransformOptions, versionLabel: string) {\n const cwd = process.cwd();\n intro(`Starting ${versionLabel} codemods`);\n const modCount = codemods.length;\n const s = spinner();\n\n s.start(`Running ${modCount} ${versionLabel} codemods`);\n\n const allErrors: TransformErrors = [];\n let notImplementedAvailable = false;\n let count = 0;\n for (const [_, codemod] of codemods.entries()) {\n const { errors, notImplementedErrors } = await transform(codemod, cwd, options, {\n logStatus: false,\n });\n allErrors.push(...errors);\n if (notImplementedErrors.length > 0) {\n notImplementedAvailable = true;\n }\n count++;\n s.message(`Codemod ${count}/${modCount} (${codemod})`);\n }\n s.stop(`Ran ${count}/${modCount} codemods.`);\n\n if (allErrors.length > 0) {\n log(`Some ${versionLabel} codemods did not apply successfully to all files. Details:`);\n allErrors.forEach(({ transform, filename, summary }) => {\n error(`codemod=${transform}, path=${filename}, summary=${summary}`);\n });\n }\n\n if (notImplementedAvailable) {\n log(\n `Some ${versionLabel} codemods require manual changes. Please search your codebase for \\`FIXME(mastra): \\` comments and follow the instructions to complete the upgrade.`,\n );\n }\n\n outro(`${versionLabel} codemods complete.`);\n}\n\nexport async function upgradeV1(options: TransformOptions) {\n await runCodemods(v1Bundle, options, 'v1');\n}\n","#! /usr/bin/env node\n\nimport { Command } from 'commander';\nimport debug from 'debug';\nimport { transform } from './lib/transform';\nimport { upgradeV1 } from './lib/upgrade';\n\nconst error = debug('codemod:error');\ndebug.enable('codemod:*');\n\nconst program = new Command();\n\nprogram\n .name('codemod')\n .description('CLI for running Mastra codemods')\n .argument('<codemod>', 'Codemod to run')\n .argument('<source>', 'Path to source files or directory')\n .option('-d, --dry', 'Dry run (no changes are made to files)')\n .option('-p, --print', 'Print transformed files to stdout')\n .option('--verbose', 'Show more information about the transform process')\n .option('-j, --jscodeshift <options>', 'Pass options directly to jscodeshift')\n .action(async (codemod, source, options) => {\n try {\n await transform(codemod, source, options);\n } catch (err: any) {\n error(`Error transforming: ${err}`);\n process.exit(1);\n }\n });\n\nprogram\n .command('v1')\n .description('Apply all v1 codemods (v0.x to v1)')\n .option('-d, --dry', 'Dry run (no changes are made to files)')\n .option('-p, --print', 'Print transformed files to stdout')\n .option('--verbose', 'Show more information about the transform process')\n .option('-j, --jscodeshift <options>', 'Pass options directly to jscodeshift')\n .action(async options => {\n try {\n await upgradeV1(options);\n } catch (err: any) {\n error(`Error transforming: ${err}`);\n process.exit(1);\n }\n });\n\nprogram.parse(process.argv);\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/lib/transform.ts","../src/lib/bundle.ts","../src/lib/upgrade.ts","../src/index.ts"],"names":["transform","log","debug","error"],"mappings":";;;;;;;;;;AAOA,IAAM,IAAA,GAAO,IAAA,CAAK,SAAA,CAAU,aAAA,CAAc,IAAI,CAAA;AAS9C,IAAM,GAAA,GAAM,MAAM,mBAAmB,CAAA;AACrC,IAAM,KAAA,GAAQ,MAAM,yBAAyB,CAAA;AAC7C,IAAM,UAAA,GAAa,aAAA,CAAc,MAAA,CAAA,IAAA,CAAY,GAAG,CAAA;AAChD,IAAM,SAAA,GAAY,IAAA,CAAK,OAAA,CAAQ,UAAU,CAAA;AAEzC,SAAS,cAAA,GAAyB;AAChC,EAAA,MAAM,gBAAA,GAAmB,IAAA,CAAK,OAAA,CAAQ,SAAA,EAAW,kCAAkC,CAAA;AACnF,EAAA,OAAO,EAAA,CAAG,UAAA,CAAW,gBAAgB,CAAA,GAAI,gBAAA,GAAmB,aAAA;AAC9D;AAEA,SAAS,YAAA,CAAa,WAAA,EAAqB,UAAA,EAAoB,WAAA,EAAqB,OAAA,EAAmC;AAGrH,EAAA,IAAI,UAAU,CAAA,EAAG,WAAW,CAAA,IAAA,EAAO,WAAW,IAAI,UAAU,CAAA,yOAAA,CAAA;AAS5D,EAAA,IAAI,QAAQ,GAAA,EAAK;AACf,IAAA,OAAA,IAAW,QAAA;AA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S,GAAA,EAAU;AACjB,IAAAC,MAAAA,CAAM,CAAA,oBAAA,EAAuB,GAAG,CAAA,CAAE,CAAA;AAClC,IAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,EAChB;AACF,CAAC,CAAA;AAEH,OAAA,CACG,OAAA,CAAQ,IAAI,CAAA,CACZ,WAAA,CAAY,oCAAoC,EAChD,MAAA,CAAO,WAAA,EAAa,wCAAwC,CAAA,CAC5D,MAAA,CAAO,aAAA,EAAe,mCAAmC,CAAA,CACzD,MAAA,CAAO,WAAA,EAAa,mDAAmD,CAAA,CACvE,MAAA,CAAO,+BAA+B,sCAAsC,CAAA,CAC5E,MAAA,CAAO,OAAM,OAAA,KAAW;AACvB,EAAA,IAAI;AACF,IAAA,MAAM,UAAU,OAAO,CAAA;AAAA,EACzB,SAAS,GAAA,EAAU;AACjB,IAAAA,MAAAA,CAAM,CAAA,oBAAA,EAAuB,GAAG,CAAA,CAAE,CAAA;AAClC,IAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,EAChB;AACF,CAAC,CAAA;AAEH,OAAA,CAAQ,KAAA,CAAM,QAAQ,IAAI,CAAA","file":"index.js","sourcesContent":["import child_process from 'node:child_process';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport util from 'node:util';\nimport debug from 'debug';\n\nconst exec = util.promisify(child_process.exec);\n\ninterface TransformOptions {\n dry?: boolean;\n print?: boolean;\n verbose?: boolean;\n jscodeshift?: string;\n}\n\nconst log = debug('codemod:transform');\nconst error = debug('codemod:transform:error');\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\nfunction getJscodeshift(): string {\n const localJscodeshift = path.resolve(__dirname, '../node_modules/.bin/jscodeshift');\n return fs.existsSync(localJscodeshift) ? localJscodeshift : 'jscodeshift';\n}\n\nfunction buildCommand(codemodPath: string, targetPath: string, jscodeshift: string, options: TransformOptions): string {\n // Ignoring everything under `.*/` covers `.mastra/` along with any other\n // framework build related or otherwise intended-to-be-hidden directories.\n let command = `${jscodeshift} -t ${codemodPath} ${targetPath} \\\n --parser tsx \\\n --ignore-pattern=\"**/node_modules/**\" \\\n --ignore-pattern=\"**/.*/**\" \\\n --ignore-pattern=\"**/dist/**\" \\\n --ignore-pattern=\"**/build/**\" \\\n --ignore-pattern=\"**/*.min.js\" \\\n --ignore-pattern=\"**/*.bundle.js\"`;\n\n if (options.dry) {\n command += ' --dry';\n }\n\n if (options.print) {\n command += ' --print';\n }\n\n if (options.verbose) {\n command += ' --verbose';\n }\n\n if (options.jscodeshift) {\n command += ` ${options.jscodeshift}`;\n }\n\n return command;\n}\n\nexport type TransformErrors = {\n transform: string;\n filename: string;\n summary: string;\n}[];\n\nfunction parseErrors(transform: string, output: string): TransformErrors {\n const errors: TransformErrors = [];\n const errorRegex = /ERR (.+) Transformation error/g;\n const syntaxErrorRegex = /SyntaxError: .+/g;\n\n let match;\n while ((match = errorRegex.exec(output)) !== null) {\n const filename = match[1]!;\n const syntaxErrorMatch = syntaxErrorRegex.exec(output);\n if (syntaxErrorMatch) {\n const summary = syntaxErrorMatch[0];\n errors.push({ transform, filename, summary });\n }\n }\n\n return errors;\n}\n\nfunction parseNotImplementedErrors(transform: string, output: string): TransformErrors {\n const notImplementedErrors: TransformErrors = [];\n const notImplementedRegex = /Not Implemented (.+): (.+)/g;\n\n let match;\n while ((match = notImplementedRegex.exec(output)) !== null) {\n const filename = match[1]!;\n const summary = match[2]!;\n notImplementedErrors.push({ transform, filename, summary });\n }\n\n return notImplementedErrors;\n}\n\nexport async function transform(\n codemod: string,\n source: string,\n transformOptions: TransformOptions,\n options: { logStatus: boolean } = { logStatus: true },\n): Promise<{ errors: TransformErrors; notImplementedErrors: TransformErrors }> {\n if (options.logStatus) {\n log(`Applying codemod '${codemod}': ${source}`);\n }\n const codemodPath = path.resolve(__dirname, `./codemods/${codemod}.js`);\n const targetPath = path.resolve(source);\n const jscodeshift = getJscodeshift();\n const command = buildCommand(codemodPath, targetPath, jscodeshift, transformOptions);\n const { stdout } = await exec(command, { encoding: 'utf8' });\n const errors = parseErrors(codemod, stdout);\n const notImplementedErrors = parseNotImplementedErrors(codemod, stdout);\n if (options.logStatus) {\n if (errors.length > 0) {\n errors.forEach(({ transform, filename, summary }) => {\n error(`Error applying codemod [codemod=${transform}, path=${filename}, summary=${summary}]`);\n });\n }\n\n if (notImplementedErrors.length > 0) {\n log(\n `Some files require manual changes. Please search your codebase for \\`FIXME(mastra): \\` comments and follow the instructions to complete the upgrade.`,\n );\n notImplementedErrors.forEach(({ transform, filename, summary }) => {\n log(`Not Implemented [codemod=${transform}, path=${filename}, summary=${summary}]`);\n });\n }\n }\n\n return { errors, notImplementedErrors };\n}\n","// List of all codemods\nexport const BUNDLE = [\n 'v1/mastra-core-imports',\n 'v1/runtime-context',\n 'v1/not-implemented/mastra-memory',\n 'v1/mastra-plural-apis',\n 'v1/not-implemented/mastra-required-id',\n 'v1/agent-property-access',\n 'v1/agent-voice',\n 'v1/agent-processor-methods',\n 'v1/agent-generate-stream-v-next',\n 'v1/agent-abort-signal',\n 'v1/not-implemented/agent-format-parameter',\n 'v1/not-implemented/agent-to-step',\n 'v1/voice-property-names',\n 'v1/mcp-get-tools',\n 'v1/mcp-get-toolsets',\n 'v1/client-sdk-types',\n 'v1/client-to-ai-sdk-format',\n 'v1/client-offset-limit',\n 'v1/client-get-memory-thread',\n 'v1/experimental-auth',\n 'v1/evals-run-experiment',\n 'v1/evals-scorer-by-name',\n 'v1/evals-prebuilt-imports',\n 'v1/workflow-create-run-async',\n 'v1/workflow-run-count',\n 'v1/workflow-list-runs',\n 'v1/workflow-stream-vnext',\n 'v1/memory-query-to-recall',\n 'v1/memory-vector-search-param',\n 'v1/memory-message-v2-type',\n 'v1/memory-readonly-to-options',\n 'v1/storage-get-threads-by-resource',\n 'v1/storage-list-messages-by-id',\n 'v1/storage-postgres-schema-name',\n 'v1/storage-get-messages-paginated',\n 'v1/storage-list-workflow-runs',\n 'v1/vector-pg-constructor',\n];\n","import { spinner, intro, outro } from '@clack/prompts';\nimport debug from 'debug';\nimport { BUNDLE } from './bundle';\nimport type { TransformErrors } from './transform';\nimport { transform } from './transform';\n\ninterface TransformOptions {\n dry?: true;\n print?: true;\n verbose?: true;\n jscodeshift?: string;\n}\n\nconst log = debug('codemod:upgrade');\nconst error = debug('codemod:upgrade:error');\n\n// Extract v1 codemods from the bundle\nconst v1Bundle = BUNDLE.filter(codemod => codemod.startsWith('v1/'));\n\nasync function runCodemods(codemods: string[], options: TransformOptions, versionLabel: string) {\n const cwd = process.cwd();\n intro(`Starting ${versionLabel} codemods`);\n const modCount = codemods.length;\n const s = spinner();\n\n s.start(`Running ${modCount} ${versionLabel} codemods`);\n\n const allErrors: TransformErrors = [];\n let notImplementedAvailable = false;\n let count = 0;\n for (const [_, codemod] of codemods.entries()) {\n const { errors, notImplementedErrors } = await transform(codemod, cwd, options, {\n logStatus: false,\n });\n allErrors.push(...errors);\n if (notImplementedErrors.length > 0) {\n notImplementedAvailable = true;\n }\n count++;\n s.message(`Codemod ${count}/${modCount} (${codemod})`);\n }\n s.stop(`Ran ${count}/${modCount} codemods.`);\n\n if (allErrors.length > 0) {\n log(`Some ${versionLabel} codemods did not apply successfully to all files. Details:`);\n allErrors.forEach(({ transform, filename, summary }) => {\n error(`codemod=${transform}, path=${filename}, summary=${summary}`);\n });\n }\n\n if (notImplementedAvailable) {\n log(\n `Some ${versionLabel} codemods require manual changes. Please search your codebase for \\`FIXME(mastra): \\` comments and follow the instructions to complete the upgrade.`,\n );\n }\n\n outro(`${versionLabel} codemods complete.`);\n}\n\nexport async function upgradeV1(options: TransformOptions) {\n await runCodemods(v1Bundle, options, 'v1');\n}\n","#! /usr/bin/env node\n\nimport { Command } from 'commander';\nimport debug from 'debug';\nimport { transform } from './lib/transform';\nimport { upgradeV1 } from './lib/upgrade';\n\nconst error = debug('codemod:error');\ndebug.enable('codemod:*');\n\nconst program = new Command();\n\nprogram\n .name('codemod')\n .description('CLI for running Mastra codemods')\n .argument('<codemod>', 'Codemod to run')\n .argument('<source>', 'Path to source files or directory')\n .option('-d, --dry', 'Dry run (no changes are made to files)')\n .option('-p, --print', 'Print transformed files to stdout')\n .option('--verbose', 'Show more information about the transform process')\n .option('-j, --jscodeshift <options>', 'Pass options directly to jscodeshift')\n .action(async (codemod, source, options) => {\n try {\n await transform(codemod, source, options);\n } catch (err: any) {\n error(`Error transforming: ${err}`);\n process.exit(1);\n }\n });\n\nprogram\n .command('v1')\n .description('Apply all v1 codemods (v0.x to v1)')\n .option('-d, --dry', 'Dry run (no changes are made to files)')\n .option('-p, --print', 'Print transformed files to stdout')\n .option('--verbose', 'Show more information about the transform process')\n .option('-j, --jscodeshift <options>', 'Pass options directly to jscodeshift')\n .action(async options => {\n try {\n await upgradeV1(options);\n } catch (err: any) {\n error(`Error transforming: ${err}`);\n process.exit(1);\n }\n });\n\nprogram.parse(process.argv);\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/codemod",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-feat-
|
|
4
|
+
"version": "0.0.0-feat-8782-cf-bindings-20260102164434",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"description": "Codemod CLI for Mastra",
|
|
7
7
|
"bin": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"tsup": "^8.5.0",
|
|
35
35
|
"typescript": "^5.8.3",
|
|
36
36
|
"vitest": "4.0.12",
|
|
37
|
-
"@internal/lint": "0.0.0-feat-
|
|
37
|
+
"@internal/lint": "0.0.0-feat-8782-cf-bindings-20260102164434"
|
|
38
38
|
},
|
|
39
39
|
"homepage": "https://mastra.ai",
|
|
40
40
|
"repository": {
|