convex 1.47.0 → 1.48.0-alpha.0
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/browser.bundle.js +1 -1
- package/dist/browser.bundle.js.map +1 -1
- package/dist/cjs/bundler/context.js +7 -5
- package/dist/cjs/bundler/context.js.map +2 -2
- package/dist/cjs/bundler/fs.js +47 -6
- package/dist/cjs/bundler/fs.js.map +2 -2
- package/dist/cjs/cli/account.js +237 -0
- package/dist/cjs/cli/account.js.map +7 -0
- package/dist/cjs/cli/configure.js +15 -2
- package/dist/cjs/cli/configure.js.map +2 -2
- package/dist/cjs/cli/lib/deployKeyWarning.js +43 -0
- package/dist/cjs/cli/lib/deployKeyWarning.js.map +7 -0
- package/dist/cjs/cli/lib/deployment.js +2 -0
- package/dist/cjs/cli/lib/deployment.js.map +2 -2
- package/dist/cjs/cli/lib/deploymentSelection.js +27 -18
- package/dist/cjs/cli/lib/deploymentSelection.js.map +2 -2
- package/dist/cjs/cli/lib/envvars.js +32 -0
- package/dist/cjs/cli/lib/envvars.js.map +2 -2
- package/dist/cjs/cli/lib/fsUtils.js +1 -1
- package/dist/cjs/cli/lib/fsUtils.js.map +2 -2
- package/dist/cjs/cli/lib/generateDocs.js +1 -1
- package/dist/cjs/cli/lib/generateDocs.js.map +1 -1
- package/dist/cjs/cli/lib/login.js +28 -4
- package/dist/cjs/cli/lib/login.js.map +2 -2
- package/dist/cjs/cli/lib/mcp/requestContext.js +5 -1
- package/dist/cjs/cli/lib/mcp/requestContext.js.map +2 -2
- package/dist/cjs/cli/lib/profileManagement.js +196 -0
- package/dist/cjs/cli/lib/profileManagement.js.map +7 -0
- package/dist/cjs/cli/lib/profiles.js +333 -0
- package/dist/cjs/cli/lib/profiles.js.map +7 -0
- package/dist/cjs/cli/lib/utils/utils.js +18 -9
- package/dist/cjs/cli/lib/utils/utils.js.map +2 -2
- package/dist/cjs/cli/login.js +213 -114
- package/dist/cjs/cli/login.js.map +3 -3
- package/dist/cjs/cli/logout.js +113 -12
- package/dist/cjs/cli/logout.js.map +3 -3
- package/dist/cjs/cli/mcp.js +43 -10
- package/dist/cjs/cli/mcp.js.map +3 -3
- package/dist/cjs/cli/program.js +2 -1
- package/dist/cjs/cli/program.js.map +2 -2
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs-types/bundler/context.d.ts +5 -0
- package/dist/cjs-types/bundler/context.d.ts.map +1 -1
- package/dist/cjs-types/bundler/fs.d.ts +7 -2
- package/dist/cjs-types/bundler/fs.d.ts.map +1 -1
- package/dist/cjs-types/cli/account.d.ts +6 -0
- package/dist/cjs-types/cli/account.d.ts.map +1 -0
- package/dist/cjs-types/cli/configure.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/deployKeyWarning.d.ts +3 -0
- package/dist/cjs-types/cli/lib/deployKeyWarning.d.ts.map +1 -0
- package/dist/cjs-types/cli/lib/deployment.d.ts +2 -0
- package/dist/cjs-types/cli/lib/deployment.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/deploymentSelection.d.ts +2 -1
- package/dist/cjs-types/cli/lib/deploymentSelection.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/envvars.d.ts +6 -0
- package/dist/cjs-types/cli/lib/envvars.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/fsUtils.d.ts +1 -0
- package/dist/cjs-types/cli/lib/fsUtils.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/login.d.ts +3 -1
- package/dist/cjs-types/cli/lib/login.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/mcp/requestContext.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/mcp/tools/insights.d.ts +2 -2
- package/dist/cjs-types/cli/lib/profileManagement.d.ts +10 -0
- package/dist/cjs-types/cli/lib/profileManagement.d.ts.map +1 -0
- package/dist/cjs-types/cli/lib/profiles.d.ts +59 -0
- package/dist/cjs-types/cli/lib/profiles.d.ts.map +1 -0
- package/dist/cjs-types/cli/lib/utils/utils.d.ts +5 -0
- package/dist/cjs-types/cli/lib/utils/utils.d.ts.map +1 -1
- package/dist/cjs-types/cli/login.d.ts +21 -0
- package/dist/cjs-types/cli/login.d.ts.map +1 -1
- package/dist/cjs-types/cli/logout.d.ts +8 -1
- package/dist/cjs-types/cli/logout.d.ts.map +1 -1
- package/dist/cjs-types/cli/mcp.d.ts.map +1 -1
- package/dist/cjs-types/cli/program.d.ts.map +1 -1
- package/dist/cjs-types/index.d.ts +1 -1
- package/dist/cjs-types/index.d.ts.map +1 -1
- package/dist/cli.bundle.cjs +2118 -1096
- package/dist/cli.bundle.cjs.map +4 -4
- package/dist/esm/bundler/context.js +7 -5
- package/dist/esm/bundler/context.js.map +2 -2
- package/dist/esm/bundler/fs.js +47 -6
- package/dist/esm/bundler/fs.js.map +2 -2
- package/dist/esm/cli/account.js +221 -0
- package/dist/esm/cli/account.js.map +7 -0
- package/dist/esm/cli/configure.js +15 -2
- package/dist/esm/cli/configure.js.map +2 -2
- package/dist/esm/cli/lib/deployKeyWarning.js +27 -0
- package/dist/esm/cli/lib/deployKeyWarning.js.map +7 -0
- package/dist/esm/cli/lib/deployment.js +2 -2
- package/dist/esm/cli/lib/deployment.js.map +2 -2
- package/dist/esm/cli/lib/deploymentSelection.js +35 -20
- package/dist/esm/cli/lib/deploymentSelection.js.map +2 -2
- package/dist/esm/cli/lib/envvars.js +35 -1
- package/dist/esm/cli/lib/envvars.js.map +2 -2
- package/dist/esm/cli/lib/fsUtils.js +1 -1
- package/dist/esm/cli/lib/fsUtils.js.map +2 -2
- package/dist/esm/cli/lib/generateDocs.js +1 -1
- package/dist/esm/cli/lib/generateDocs.js.map +1 -1
- package/dist/esm/cli/lib/login.js +36 -4
- package/dist/esm/cli/lib/login.js.map +2 -2
- package/dist/esm/cli/lib/mcp/requestContext.js +5 -1
- package/dist/esm/cli/lib/mcp/requestContext.js.map +2 -2
- package/dist/esm/cli/lib/profileManagement.js +179 -0
- package/dist/esm/cli/lib/profileManagement.js.map +7 -0
- package/dist/esm/cli/lib/profiles.js +288 -0
- package/dist/esm/cli/lib/profiles.js.map +7 -0
- package/dist/esm/cli/lib/utils/utils.js +16 -9
- package/dist/esm/cli/lib/utils/utils.js.map +2 -2
- package/dist/esm/cli/login.js +225 -112
- package/dist/esm/cli/login.js.map +3 -3
- package/dist/esm/cli/logout.js +110 -13
- package/dist/esm/cli/logout.js.map +2 -2
- package/dist/esm/cli/mcp.js +34 -10
- package/dist/esm/cli/mcp.js.map +2 -2
- package/dist/esm/cli/program.js +2 -1
- package/dist/esm/cli/program.js.map +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm-types/bundler/context.d.ts +5 -0
- package/dist/esm-types/bundler/context.d.ts.map +1 -1
- package/dist/esm-types/bundler/fs.d.ts +7 -2
- package/dist/esm-types/bundler/fs.d.ts.map +1 -1
- package/dist/esm-types/cli/account.d.ts +6 -0
- package/dist/esm-types/cli/account.d.ts.map +1 -0
- package/dist/esm-types/cli/configure.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/deployKeyWarning.d.ts +3 -0
- package/dist/esm-types/cli/lib/deployKeyWarning.d.ts.map +1 -0
- package/dist/esm-types/cli/lib/deployment.d.ts +2 -0
- package/dist/esm-types/cli/lib/deployment.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/deploymentSelection.d.ts +2 -1
- package/dist/esm-types/cli/lib/deploymentSelection.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/envvars.d.ts +6 -0
- package/dist/esm-types/cli/lib/envvars.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/fsUtils.d.ts +1 -0
- package/dist/esm-types/cli/lib/fsUtils.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/login.d.ts +3 -1
- package/dist/esm-types/cli/lib/login.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/mcp/requestContext.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/mcp/tools/insights.d.ts +2 -2
- package/dist/esm-types/cli/lib/profileManagement.d.ts +10 -0
- package/dist/esm-types/cli/lib/profileManagement.d.ts.map +1 -0
- package/dist/esm-types/cli/lib/profiles.d.ts +59 -0
- package/dist/esm-types/cli/lib/profiles.d.ts.map +1 -0
- package/dist/esm-types/cli/lib/utils/utils.d.ts +5 -0
- package/dist/esm-types/cli/lib/utils/utils.d.ts.map +1 -1
- package/dist/esm-types/cli/login.d.ts +21 -0
- package/dist/esm-types/cli/login.d.ts.map +1 -1
- package/dist/esm-types/cli/logout.d.ts +8 -1
- package/dist/esm-types/cli/logout.d.ts.map +1 -1
- package/dist/esm-types/cli/mcp.d.ts.map +1 -1
- package/dist/esm-types/cli/program.d.ts.map +1 -1
- package/dist/esm-types/index.d.ts +1 -1
- package/dist/esm-types/index.d.ts.map +1 -1
- package/dist/react.bundle.js +1 -1
- package/dist/react.bundle.js.map +1 -1
- package/package.json +1 -1
- package/src/bundler/context.ts +9 -5
- package/src/bundler/fs.ts +54 -5
- package/src/cli/account.ts +320 -0
- package/src/cli/configure.ts +18 -2
- package/src/cli/lib/deployKeyWarning.ts +43 -0
- package/src/cli/lib/deployment.ts +2 -2
- package/src/cli/lib/deploymentSelection.ts +37 -18
- package/src/cli/lib/envvars.ts +43 -1
- package/src/cli/lib/fsUtils.ts +5 -2
- package/src/cli/lib/generateDocs.ts +1 -1
- package/src/cli/lib/login.ts +47 -3
- package/src/cli/lib/mcp/requestContext.ts +7 -1
- package/src/cli/lib/profileManagement.ts +262 -0
- package/src/cli/lib/profiles.ts +398 -0
- package/src/cli/lib/utils/utils.ts +19 -15
- package/src/cli/login.ts +293 -168
- package/src/cli/logout.ts +142 -17
- package/src/cli/mcp.ts +48 -11
- package/src/cli/program.ts +2 -0
- package/src/index.ts +1 -1
|
@@ -118,11 +118,13 @@ const oneoffContext = async (args) => {
|
|
|
118
118
|
ctx,
|
|
119
119
|
!!process.env.CONVEX_IGNORE_SUSPICIOUS_ENV_VARS
|
|
120
120
|
);
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
121
|
+
if (!args.skipAuth) {
|
|
122
|
+
await (0, import_deploymentSelection.initializeBigBrainAuth)(ctx, {
|
|
123
|
+
url: args.url,
|
|
124
|
+
adminKey: args.adminKey,
|
|
125
|
+
envFile: args.envFile
|
|
126
|
+
});
|
|
127
|
+
}
|
|
126
128
|
return ctx;
|
|
127
129
|
};
|
|
128
130
|
//# sourceMappingURL=context.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/bundler/context.ts"],
|
|
4
|
-
"sourcesContent": ["import * as Sentry from \"@sentry/node\";\nimport { Ora } from \"ora\";\nimport { Filesystem, nodeFs } from \"./fs.js\";\nimport { initializeBigBrainAuth } from \"../cli/lib/deploymentSelection.js\";\nimport { detectSuspiciousEnvironmentVariables } from \"../cli/lib/envvars.js\";\nimport { logFailure, logVerbose } from \"./log.js\";\n// How the error should be handled when running `npx convex dev`.\nexport type ErrorType =\n // The error was likely caused by the state of the developer's local\n // file system (e.g. `tsc` fails due to a syntax error). The `convex dev`\n // command will then print out the error and wait for the file to change before\n // retrying.\n | \"invalid filesystem data\"\n // The error was caused by either the local state (ie schema.ts content)\n // or the state of the db (ie documents not matching the new schema).\n // The `convex dev` command will wait for either file OR table data change\n // to retry (if a table name is specified as the value in this Object).\n | {\n \"invalid filesystem or db data\": {\n tableName: string;\n componentPath?: string;\n } | null;\n }\n // The error was caused by either the local state (ie schema.ts content)\n // or the state of the deployment environment variables.\n // The `convex dev` command will wait for either file OR env var change\n // before retrying.\n | \"invalid filesystem or env vars\"\n // The error was some transient issue (e.g. a network\n // error). This will then cause a retry after an exponential backoff.\n | \"transient\"\n // This error was caught, handled, and now all that needs to happen\n // is for the proces to restart. No error is logged or reported.\n | \"already handled\"\n // This error is truly permanent. Exit `npx convex dev` because the\n // developer will need to take a manual commandline action.\n | \"fatal\";\n\nexport type BigBrainAuth = {\n header: string;\n} & (\n | {\n kind: \"projectKey\";\n projectKey: string;\n }\n | {\n kind: \"deploymentKey\";\n deploymentKey: string;\n }\n | {\n kind: \"previewDeployKey\";\n previewDeployKey: string;\n }\n | {\n kind: \"accessToken\";\n accessToken: string;\n }\n);\n\nexport interface Context {\n fs: Filesystem;\n deprecationMessagePrinted: boolean;\n // Reports to Sentry and either throws FatalError or exits the process.\n // Prints the `printedMessage` if provided\n crash(args: {\n exitCode: number;\n errorType: ErrorType;\n errForSentry?: any;\n printedMessage: string | null;\n }): Promise<never>;\n registerCleanup(fn: (exitCode: number, err?: any) => Promise<void>): string;\n removeCleanup(\n handle: string,\n ): (exitCode: number, err?: any) => Promise<void> | null;\n bigBrainAuth(): BigBrainAuth | null;\n /**\n * Prefer using `updateBigBrainAuthAfterLogin` in `deploymentSelection.ts` instead\n */\n _updateBigBrainAuth(auth: BigBrainAuth | null): void;\n}\n\nasync function flushAndExit(exitCode: number, err?: any) {\n if (err) {\n Sentry.captureException(err);\n }\n await Sentry.close();\n return process.exit(exitCode);\n}\n\nexport type OneoffCtx = Context & {\n // Generally `ctx.crash` is better to use since it handles printing a message\n // for the user, and then calls this.\n //\n // This function reports to Sentry + exits the process, but does not handle\n // printing a message for the user.\n flushAndExit: (exitCode: number, err?: any) => Promise<never>;\n};\n\nclass OneoffContextImpl {\n private _cleanupFns: Record<\n string,\n (exitCode: number, err?: any) => Promise<void>\n > = {};\n public fs: Filesystem = nodeFs;\n public deprecationMessagePrinted: boolean = false;\n public spinner: Ora | undefined = undefined;\n private _bigBrainAuth: BigBrainAuth | null = null;\n\n crash = async (args: {\n exitCode: number;\n errorType?: ErrorType;\n errForSentry?: any;\n printedMessage: string | null;\n }) => {\n if (args.printedMessage !== null) {\n logFailure(args.printedMessage);\n }\n return await this.flushAndExit(args.exitCode, args.errForSentry);\n };\n flushAndExit = async (exitCode: number, err?: any) => {\n logVerbose(\"Flushing and exiting, error:\", err);\n if (err) {\n logVerbose(err.stack);\n }\n const cleanupFns = this._cleanupFns;\n // Clear the cleanup functions so that there's no risk of running them twice\n // if this somehow gets triggered twice.\n this._cleanupFns = {};\n const fns = Object.values(cleanupFns);\n logVerbose(`Running ${fns.length} cleanup functions`);\n for (const fn of fns) {\n await fn(exitCode, err);\n }\n logVerbose(\"All cleanup functions ran\");\n return flushAndExit(exitCode, err);\n };\n registerCleanup(fn: (exitCode: number, err?: any) => Promise<void>) {\n const handle = Math.random().toString(36).slice(2);\n this._cleanupFns[handle] = fn;\n return handle;\n }\n removeCleanup(handle: string) {\n const value = this._cleanupFns[handle];\n delete this._cleanupFns[handle];\n return value ?? null;\n }\n bigBrainAuth(): BigBrainAuth | null {\n return this._bigBrainAuth;\n }\n _updateBigBrainAuth(auth: BigBrainAuth | null): void {\n logVerbose(`Updating big brain auth to ${auth?.kind ?? \"null\"}`);\n this._bigBrainAuth = auth;\n }\n}\n\n/**\n * Install a SIGINT handler that gracefully exits via ctx.flushAndExit.\n *\n * `bun run` and `npm run` can deliver a duplicate SIGINT to the child\n * process immediately while the first handler is still starting cleanup:\n * bun: https://github.com/oven-sh/bun/issues/14799\n * https://github.com/oven-sh/bun/issues/11400\n * npm: https://github.com/npm/cli/issues/5021\n * https://github.com/npm/cli/issues/8164\n * https://github.com/npm/cli/issues/7693\n * We ignore a second signal within 500ms of the first to avoid\n * double-cleanup, but treat a later Ctrl+C as a force-exit escape hatch.\n */\nexport function installSigintHandler(ctx: OneoffCtx) {\n const DUPLICATE_GRACE_MS = 500;\n let cleanupStartTime: number | null = null;\n process.on(\"SIGINT\", async () => {\n if (cleanupStartTime !== null) {\n if (Date.now() - cleanupStartTime < DUPLICATE_GRACE_MS) {\n logVerbose(\n \"Received SIGINT during cleanup, ignoring duplicate signal...\",\n );\n return;\n }\n logVerbose(\"Received SIGINT during cleanup, exiting immediately...\");\n process.exit(130);\n }\n cleanupStartTime = Date.now();\n logVerbose(\"Received SIGINT, cleaning up...\");\n await ctx.flushAndExit(130);\n });\n}\n\nexport const oneoffContext: (args: {\n url?: string | undefined;\n adminKey?: string | undefined;\n envFile?: string | undefined;\n}) => Promise<OneoffCtx> = async (args) => {\n const ctx = new OneoffContextImpl();\n await detectSuspiciousEnvironmentVariables(\n ctx,\n !!process.env.CONVEX_IGNORE_SUSPICIOUS_ENV_VARS,\n );\n await initializeBigBrainAuth(ctx, {\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,aAAwB;AAExB,gBAAmC;AACnC,iCAAuC;AACvC,qBAAqD;AACrD,iBAAuC;
|
|
4
|
+
"sourcesContent": ["import * as Sentry from \"@sentry/node\";\nimport { Ora } from \"ora\";\nimport { Filesystem, nodeFs } from \"./fs.js\";\nimport { initializeBigBrainAuth } from \"../cli/lib/deploymentSelection.js\";\nimport { detectSuspiciousEnvironmentVariables } from \"../cli/lib/envvars.js\";\nimport { logFailure, logVerbose } from \"./log.js\";\n// How the error should be handled when running `npx convex dev`.\nexport type ErrorType =\n // The error was likely caused by the state of the developer's local\n // file system (e.g. `tsc` fails due to a syntax error). The `convex dev`\n // command will then print out the error and wait for the file to change before\n // retrying.\n | \"invalid filesystem data\"\n // The error was caused by either the local state (ie schema.ts content)\n // or the state of the db (ie documents not matching the new schema).\n // The `convex dev` command will wait for either file OR table data change\n // to retry (if a table name is specified as the value in this Object).\n | {\n \"invalid filesystem or db data\": {\n tableName: string;\n componentPath?: string;\n } | null;\n }\n // The error was caused by either the local state (ie schema.ts content)\n // or the state of the deployment environment variables.\n // The `convex dev` command will wait for either file OR env var change\n // before retrying.\n | \"invalid filesystem or env vars\"\n // The error was some transient issue (e.g. a network\n // error). This will then cause a retry after an exponential backoff.\n | \"transient\"\n // This error was caught, handled, and now all that needs to happen\n // is for the proces to restart. No error is logged or reported.\n | \"already handled\"\n // This error is truly permanent. Exit `npx convex dev` because the\n // developer will need to take a manual commandline action.\n | \"fatal\";\n\nexport type BigBrainAuth = {\n header: string;\n} & (\n | {\n kind: \"projectKey\";\n projectKey: string;\n }\n | {\n kind: \"deploymentKey\";\n deploymentKey: string;\n }\n | {\n kind: \"previewDeployKey\";\n previewDeployKey: string;\n }\n | {\n kind: \"accessToken\";\n accessToken: string;\n profile?: { name: string; source: string } | null;\n }\n);\n\nexport interface Context {\n fs: Filesystem;\n deprecationMessagePrinted: boolean;\n // Reports to Sentry and either throws FatalError or exits the process.\n // Prints the `printedMessage` if provided\n crash(args: {\n exitCode: number;\n errorType: ErrorType;\n errForSentry?: any;\n printedMessage: string | null;\n }): Promise<never>;\n registerCleanup(fn: (exitCode: number, err?: any) => Promise<void>): string;\n removeCleanup(\n handle: string,\n ): (exitCode: number, err?: any) => Promise<void> | null;\n bigBrainAuth(): BigBrainAuth | null;\n /**\n * Prefer using `updateBigBrainAuthAfterLogin` in `deploymentSelection.ts` instead\n */\n _updateBigBrainAuth(auth: BigBrainAuth | null): void;\n}\n\nasync function flushAndExit(exitCode: number, err?: any) {\n if (err) {\n Sentry.captureException(err);\n }\n await Sentry.close();\n return process.exit(exitCode);\n}\n\nexport type OneoffCtx = Context & {\n // Generally `ctx.crash` is better to use since it handles printing a message\n // for the user, and then calls this.\n //\n // This function reports to Sentry + exits the process, but does not handle\n // printing a message for the user.\n flushAndExit: (exitCode: number, err?: any) => Promise<never>;\n};\n\nclass OneoffContextImpl {\n private _cleanupFns: Record<\n string,\n (exitCode: number, err?: any) => Promise<void>\n > = {};\n public fs: Filesystem = nodeFs;\n public deprecationMessagePrinted: boolean = false;\n public spinner: Ora | undefined = undefined;\n private _bigBrainAuth: BigBrainAuth | null = null;\n\n crash = async (args: {\n exitCode: number;\n errorType?: ErrorType;\n errForSentry?: any;\n printedMessage: string | null;\n }) => {\n if (args.printedMessage !== null) {\n logFailure(args.printedMessage);\n }\n return await this.flushAndExit(args.exitCode, args.errForSentry);\n };\n flushAndExit = async (exitCode: number, err?: any) => {\n logVerbose(\"Flushing and exiting, error:\", err);\n if (err) {\n logVerbose(err.stack);\n }\n const cleanupFns = this._cleanupFns;\n // Clear the cleanup functions so that there's no risk of running them twice\n // if this somehow gets triggered twice.\n this._cleanupFns = {};\n const fns = Object.values(cleanupFns);\n logVerbose(`Running ${fns.length} cleanup functions`);\n for (const fn of fns) {\n await fn(exitCode, err);\n }\n logVerbose(\"All cleanup functions ran\");\n return flushAndExit(exitCode, err);\n };\n registerCleanup(fn: (exitCode: number, err?: any) => Promise<void>) {\n const handle = Math.random().toString(36).slice(2);\n this._cleanupFns[handle] = fn;\n return handle;\n }\n removeCleanup(handle: string) {\n const value = this._cleanupFns[handle];\n delete this._cleanupFns[handle];\n return value ?? null;\n }\n bigBrainAuth(): BigBrainAuth | null {\n return this._bigBrainAuth;\n }\n _updateBigBrainAuth(auth: BigBrainAuth | null): void {\n logVerbose(`Updating big brain auth to ${auth?.kind ?? \"null\"}`);\n this._bigBrainAuth = auth;\n }\n}\n\n/**\n * Install a SIGINT handler that gracefully exits via ctx.flushAndExit.\n *\n * `bun run` and `npm run` can deliver a duplicate SIGINT to the child\n * process immediately while the first handler is still starting cleanup:\n * bun: https://github.com/oven-sh/bun/issues/14799\n * https://github.com/oven-sh/bun/issues/11400\n * npm: https://github.com/npm/cli/issues/5021\n * https://github.com/npm/cli/issues/8164\n * https://github.com/npm/cli/issues/7693\n * We ignore a second signal within 500ms of the first to avoid\n * double-cleanup, but treat a later Ctrl+C as a force-exit escape hatch.\n */\nexport function installSigintHandler(ctx: OneoffCtx) {\n const DUPLICATE_GRACE_MS = 500;\n let cleanupStartTime: number | null = null;\n process.on(\"SIGINT\", async () => {\n if (cleanupStartTime !== null) {\n if (Date.now() - cleanupStartTime < DUPLICATE_GRACE_MS) {\n logVerbose(\n \"Received SIGINT during cleanup, ignoring duplicate signal...\",\n );\n return;\n }\n logVerbose(\"Received SIGINT during cleanup, exiting immediately...\");\n process.exit(130);\n }\n cleanupStartTime = Date.now();\n logVerbose(\"Received SIGINT, cleaning up...\");\n await ctx.flushAndExit(130);\n });\n}\n\nexport const oneoffContext: (args: {\n url?: string | undefined;\n adminKey?: string | undefined;\n envFile?: string | undefined;\n skipAuth?: boolean;\n}) => Promise<OneoffCtx> = async (args) => {\n const ctx = new OneoffContextImpl();\n await detectSuspiciousEnvironmentVariables(\n ctx,\n !!process.env.CONVEX_IGNORE_SUSPICIOUS_ENV_VARS,\n );\n if (!args.skipAuth) {\n await initializeBigBrainAuth(ctx, {\n url: args.url,\n adminKey: args.adminKey,\n envFile: args.envFile,\n });\n }\n return ctx;\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,aAAwB;AAExB,gBAAmC;AACnC,iCAAuC;AACvC,qBAAqD;AACrD,iBAAuC;AA6EvC,eAAe,aAAa,UAAkB,KAAW;AACvD,MAAI,KAAK;AACP,WAAO,iBAAiB,GAAG;AAAA,EAC7B;AACA,QAAM,OAAO,MAAM;AACnB,SAAO,QAAQ,KAAK,QAAQ;AAC9B;AAWA,MAAM,kBAAkB;AAAA,EAAxB;AACE,wBAAQ,eAGJ,CAAC;AACL,wBAAO,MAAiB;AACxB,wBAAO,6BAAqC;AAC5C,wBAAO;AACP,wBAAQ,iBAAqC;AAE7C,iCAAQ,OAAO,SAKT;AACJ,UAAI,KAAK,mBAAmB,MAAM;AAChC,mCAAW,KAAK,cAAc;AAAA,MAChC;AACA,aAAO,MAAM,KAAK,aAAa,KAAK,UAAU,KAAK,YAAY;AAAA,IACjE;AACA,wCAAe,OAAO,UAAkB,QAAc;AACpD,iCAAW,gCAAgC,GAAG;AAC9C,UAAI,KAAK;AACP,mCAAW,IAAI,KAAK;AAAA,MACtB;AACA,YAAM,aAAa,KAAK;AAGxB,WAAK,cAAc,CAAC;AACpB,YAAM,MAAM,OAAO,OAAO,UAAU;AACpC,iCAAW,WAAW,IAAI,MAAM,oBAAoB;AACpD,iBAAW,MAAM,KAAK;AACpB,cAAM,GAAG,UAAU,GAAG;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|
package/dist/cjs/bundler/fs.js
CHANGED
|
@@ -117,6 +117,9 @@ class NodeFs {
|
|
|
117
117
|
stat(path2) {
|
|
118
118
|
return import_fs.default.statSync(path2);
|
|
119
119
|
}
|
|
120
|
+
lstat(path2) {
|
|
121
|
+
return import_fs.default.lstatSync(path2);
|
|
122
|
+
}
|
|
120
123
|
readUtf8File(path2) {
|
|
121
124
|
return import_fs.default.readFileSync(path2, { encoding: "utf-8" });
|
|
122
125
|
}
|
|
@@ -197,6 +200,8 @@ class RecordingFs {
|
|
|
197
200
|
__publicField(this, "observedDirectories", /* @__PURE__ */ new Map());
|
|
198
201
|
// Absolute path -> observed stat (or null if observed nonexistent)
|
|
199
202
|
__publicField(this, "observedFiles", /* @__PURE__ */ new Map());
|
|
203
|
+
// lstat observes the link itself, while stat observes its target.
|
|
204
|
+
__publicField(this, "observedLstats", /* @__PURE__ */ new Map());
|
|
200
205
|
// Have we noticed that files have changed while recording?
|
|
201
206
|
__publicField(this, "invalidated", false);
|
|
202
207
|
__publicField(this, "traceEvents");
|
|
@@ -229,6 +234,19 @@ class RecordingFs {
|
|
|
229
234
|
this.observedDirectories.set(absDirPath, observedNames);
|
|
230
235
|
return entries;
|
|
231
236
|
}
|
|
237
|
+
lstat(filePath) {
|
|
238
|
+
const absPath = import_path.default.resolve(filePath);
|
|
239
|
+
try {
|
|
240
|
+
const st = nodeFs.lstat(filePath);
|
|
241
|
+
this.registerNormalized(absPath, st, this.observedLstats);
|
|
242
|
+
return st;
|
|
243
|
+
} catch (err) {
|
|
244
|
+
if (err.code === "ENOENT") {
|
|
245
|
+
this.registerNormalized(absPath, null, this.observedLstats);
|
|
246
|
+
}
|
|
247
|
+
throw err;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
232
250
|
exists(path2) {
|
|
233
251
|
try {
|
|
234
252
|
const st = nodeFs.stat(path2);
|
|
@@ -327,6 +345,8 @@ class RecordingFs {
|
|
|
327
345
|
updateOnWrite(absPath) {
|
|
328
346
|
const newSt = nodeFs.stat(absPath);
|
|
329
347
|
this.observedFiles.set(absPath, newSt);
|
|
348
|
+
if (this.observedLstats.has(absPath))
|
|
349
|
+
this.observedLstats.set(absPath, nodeFs.lstat(absPath));
|
|
330
350
|
const parentPath = import_path.default.resolve(import_path.default.dirname(absPath));
|
|
331
351
|
const observedParent = this.observedDirectories.get(parentPath);
|
|
332
352
|
if (observedParent !== void 0) {
|
|
@@ -335,6 +355,8 @@ class RecordingFs {
|
|
|
335
355
|
}
|
|
336
356
|
updateOnDelete(absPath) {
|
|
337
357
|
this.observedFiles.set(absPath, null);
|
|
358
|
+
if (this.observedLstats.has(absPath))
|
|
359
|
+
this.observedLstats.set(absPath, null);
|
|
338
360
|
const parentPath = import_path.default.resolve(import_path.default.dirname(absPath));
|
|
339
361
|
const observedParent = this.observedDirectories.get(parentPath);
|
|
340
362
|
if (observedParent !== void 0) {
|
|
@@ -348,8 +370,8 @@ class RecordingFs {
|
|
|
348
370
|
invalidate() {
|
|
349
371
|
this.invalidated = true;
|
|
350
372
|
}
|
|
351
|
-
registerNormalized(absPath, observed) {
|
|
352
|
-
const existing =
|
|
373
|
+
registerNormalized(absPath, observed, observations = this.observedFiles) {
|
|
374
|
+
const existing = observations.get(absPath);
|
|
353
375
|
if (existing !== void 0) {
|
|
354
376
|
const stMatch = stMatches(observed, existing);
|
|
355
377
|
if (!stMatch.matches) {
|
|
@@ -365,17 +387,22 @@ class RecordingFs {
|
|
|
365
387
|
this.invalidated = true;
|
|
366
388
|
}
|
|
367
389
|
}
|
|
368
|
-
|
|
390
|
+
observations.set(absPath, observed);
|
|
369
391
|
}
|
|
370
392
|
finalize() {
|
|
371
393
|
if (this.invalidated) {
|
|
372
394
|
return "invalidated";
|
|
373
395
|
}
|
|
374
|
-
return new Observations(
|
|
396
|
+
return new Observations(
|
|
397
|
+
this.observedDirectories,
|
|
398
|
+
this.observedFiles,
|
|
399
|
+
this.observedLstats
|
|
400
|
+
);
|
|
375
401
|
}
|
|
376
402
|
}
|
|
377
403
|
class Observations {
|
|
378
|
-
constructor(directories, files) {
|
|
404
|
+
constructor(directories, files, lstats = /* @__PURE__ */ new Map()) {
|
|
405
|
+
this.lstats = lstats;
|
|
379
406
|
__publicField(this, "directories");
|
|
380
407
|
__publicField(this, "files");
|
|
381
408
|
this.directories = directories;
|
|
@@ -389,7 +416,8 @@ class Observations {
|
|
|
389
416
|
for (const path2 of this.files.keys()) {
|
|
390
417
|
out.push(path2);
|
|
391
418
|
}
|
|
392
|
-
|
|
419
|
+
for (const path2 of this.lstats.keys()) out.push(path2);
|
|
420
|
+
return [...new Set(out)];
|
|
393
421
|
}
|
|
394
422
|
overlaps({
|
|
395
423
|
absPath
|
|
@@ -412,6 +440,19 @@ class Observations {
|
|
|
412
440
|
return { overlaps: true, reason };
|
|
413
441
|
}
|
|
414
442
|
}
|
|
443
|
+
const observedLstat = this.lstats.get(absPath);
|
|
444
|
+
if (observedLstat !== void 0) {
|
|
445
|
+
let currentLstat;
|
|
446
|
+
try {
|
|
447
|
+
currentLstat = nodeFs.lstat(absPath);
|
|
448
|
+
} catch (err) {
|
|
449
|
+
if (err.code !== "ENOENT") throw err;
|
|
450
|
+
currentLstat = null;
|
|
451
|
+
}
|
|
452
|
+
const match = stMatches(observedLstat, currentLstat);
|
|
453
|
+
if (!match.matches)
|
|
454
|
+
return { overlaps: true, reason: `modified (${match.reason})` };
|
|
455
|
+
}
|
|
415
456
|
const parentPath = import_path.default.resolve(import_path.default.dirname(absPath));
|
|
416
457
|
const observedParent = this.directories.get(parentPath);
|
|
417
458
|
if (observedParent !== void 0) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/bundler/fs.ts"],
|
|
4
|
-
"sourcesContent": ["// Disable our restriction on `throw` because these aren't developer-facing\n// error messages.\n/* eslint-disable no-restricted-imports */\n/* eslint-disable no-restricted-syntax */\nimport { chalkStderr } from \"chalk\";\nimport stdFs, { Dirent, Mode, ReadStream, Stats } from \"fs\";\nimport * as fsPromises from \"fs/promises\";\nimport os from \"os\";\nimport path from \"path\";\nimport crypto from \"crypto\";\nimport { Readable } from \"stream\";\n\nexport type NormalizedPath = string;\n\nconst tmpDirOverrideVar = \"CONVEX_TMPDIR\";\nfunction tmpDirPath() {\n // Allow users to override the temporary directory path with an environment variable.\n // This override needs to (1) be project-specific, since the user may have projects\n // on different filesystems, but also (2) be device-specific and not checked in, since\n // it's dependent on where the user has checked out their project. So, we don't want\n // this state in the project-specific `convex.json`, which is shared across all\n // devices, or in the top-level `~/.convex` directory, which is shared across all\n // projects on the local machine.\n //\n // Therefore, just let advanced users configure this behavior with an environment\n // variable that they're responsible for managing themselves for now.\n const envTmpDir = process.env[tmpDirOverrideVar];\n return envTmpDir ?? os.tmpdir();\n}\nconst tmpDirRoot = tmpDirPath();\n\nlet warned = false;\nfunction warnCrossFilesystem(dstPath: string) {\n const dstDir = path.dirname(dstPath);\n if (!warned) {\n // It's hard for these to use `logMessage` without creating a circular dependency, so just log directly.\n // eslint-disable-next-line no-console\n console.warn(\n chalkStderr.yellow(\n `Temporary directory '${tmpDirRoot}' and project directory '${dstDir}' are on different filesystems.`,\n ),\n );\n // eslint-disable-next-line no-console\n console.warn(\n chalkStderr.gray(\n ` If you're running into errors with other tools watching the project directory, override the temporary directory location with the ${chalkStderr.bold(\n tmpDirOverrideVar,\n )} environment variable.`,\n ),\n );\n // eslint-disable-next-line no-console\n console.warn(\n chalkStderr.gray(\n ` Be sure to pick a temporary directory that's on the same filesystem as your project.`,\n ),\n );\n warned = true;\n }\n}\n\nexport interface Filesystem {\n listDir(dirPath: string): Dirent[];\n\n exists(path: string): boolean;\n stat(path: string): Stats;\n readUtf8File(path: string): string;\n // createReadStream returns a stream for which [Symbol.asyncIterator]\n // yields chunks of size highWaterMark (until the last one), or 64KB if\n // highWaterMark isn't specified.\n // https://nodejs.org/api/stream.html#readablesymbolasynciterator\n createReadStream(\n path: string,\n options: { highWaterMark?: number },\n ): ReadStream;\n access(path: string): void;\n\n writeUtf8File(path: string, contents: string, mode?: Mode): void;\n mkdir(\n dirPath: string,\n options?: { allowExisting?: boolean; recursive?: boolean },\n ): void;\n rmdir(path: string): void;\n unlink(path: string): void;\n swapTmpFile(fromPath: TempPath, toPath: string): void;\n\n registerPath(path: string, st: Stats | null): void;\n invalidate(): void;\n}\n\nexport type TempPath = string & { __tempPath: \"tempPath\" };\n\nexport interface TempDir {\n writeUtf8File(contents: string): TempPath;\n writeFileStream(\n path: TempPath,\n stream: Readable,\n onData?: (chunk: any) => void,\n ): Promise<void>;\n registerTempPath(st: Stats | null): TempPath;\n path: TempPath;\n}\n\nexport async function withTmpDir(\n callback: (tmpDir: TempDir) => Promise<void>,\n): Promise<void> {\n // Create temporary directories inside `tmpDirRoot` of the form `convex-<random>`.\n const tmpPath = stdFs.mkdtempSync(path.join(tmpDirRoot, \"convex\"));\n const tmpDir = {\n writeUtf8File(contents: string): TempPath {\n const filePath = path.join(tmpPath, crypto.randomUUID());\n nodeFs.writeUtf8File(filePath, contents);\n return filePath as TempPath;\n },\n registerTempPath(st: Stats | null): TempPath {\n const filePath = path.join(tmpPath, crypto.randomUUID());\n nodeFs.registerPath(filePath, st);\n return filePath as TempPath;\n },\n writeFileStream(\n path: TempPath,\n stream: Readable,\n onData?: (chunk: any) => void,\n ): Promise<void> {\n return nodeFs.writeFileStream(path, stream, onData);\n },\n path: tmpPath as TempPath,\n };\n try {\n await callback(tmpDir);\n } finally {\n stdFs.rmSync(tmpPath, { force: true, recursive: true });\n }\n}\n\n// Use `nodeFs` when you just want to read and write to the local filesystem\n// and don't care about collecting the paths touched. One-off commands\n// should use the singleton `nodeFs`.\nexport class NodeFs implements Filesystem {\n listDir(dirPath: string) {\n return stdFs.readdirSync(dirPath, { withFileTypes: true });\n }\n exists(path: string) {\n try {\n stdFs.statSync(path);\n return true;\n } catch (e: any) {\n if (e.code === \"ENOENT\") {\n return false;\n }\n throw e;\n }\n }\n stat(path: string) {\n return stdFs.statSync(path);\n }\n readUtf8File(path: string) {\n return stdFs.readFileSync(path, { encoding: \"utf-8\" });\n }\n createReadStream(\n path: string,\n options: { highWaterMark?: number },\n ): ReadStream {\n return stdFs.createReadStream(path, options);\n }\n // To avoid issues with filesystem events triggering for our own streamed file\n // writes, writeFileStream is intentionally not on the Filesystem interface\n // and not implemented by RecordingFs.\n async writeFileStream(\n path: string,\n stream: Readable,\n onData?: (chunk: any) => void,\n ): Promise<void> {\n // 'wx' means O_CREAT | O_EXCL | O_WRONLY\n // 0o644 means owner has readwrite access, everyone else has read access.\n const fileHandle = await fsPromises.open(path, \"wx\", 0o644);\n try {\n for await (const chunk of stream) {\n // For some reason, adding `stream.on(\"data\", onData)` causes issues with\n // the stream, but calling a callback here works.\n if (onData) {\n onData(chunk);\n }\n await fileHandle.write(chunk);\n }\n } finally {\n await fileHandle.close();\n }\n }\n access(path: string) {\n return stdFs.accessSync(path);\n }\n writeUtf8File(path: string, contents: string, mode?: Mode) {\n const fd = stdFs.openSync(path, \"w\", mode);\n try {\n stdFs.writeFileSync(fd, contents, { encoding: \"utf-8\" });\n try {\n stdFs.fsyncSync(fd);\n } catch (e: any) {\n // fsync(2) returns EINVAL on file descriptors that don't support\n // synchronization, e.g. FIFOs/pipes. Some integrations (such as\n // 1Password's Local Environment File) expose `.env.local` as a\n // FIFO so secrets can be streamed on demand; the write itself\n // succeeded, so treat the missing sync as best-effort.\n if (e?.code !== \"EINVAL\") {\n throw e;\n }\n }\n } finally {\n stdFs.closeSync(fd);\n }\n }\n mkdir(\n dirPath: string,\n options?: { allowExisting?: boolean; recursive?: boolean },\n ): void {\n try {\n stdFs.mkdirSync(dirPath, { recursive: options?.recursive });\n } catch (e: any) {\n if (options?.allowExisting && e.code === \"EEXIST\") {\n return;\n }\n throw e;\n }\n }\n rmdir(path: string) {\n stdFs.rmdirSync(path);\n }\n unlink(path: string) {\n return stdFs.unlinkSync(path);\n }\n swapTmpFile(fromPath: TempPath, toPath: string) {\n try {\n return stdFs.renameSync(fromPath, toPath);\n } catch (e: any) {\n // Fallback to copying the file if we're on different volumes.\n if (e.code === \"EXDEV\") {\n warnCrossFilesystem(toPath);\n stdFs.copyFileSync(fromPath, toPath);\n return;\n }\n throw e;\n }\n }\n registerPath(_path: string, _st: Stats | null) {\n // The node filesystem doesn't track reads, so we don't need to do anything here.\n }\n invalidate() {\n // We don't track invalidations for the node filesystem either.\n }\n}\nexport const nodeFs = new NodeFs();\n\n// Filesystem implementation that records all paths observed. This is useful\n// for implementing continuous watch commands that need to manage a filesystem\n// watcher and know when a command's inputs were invalidated.\nexport class RecordingFs implements Filesystem {\n // Absolute path -> Set of observed child names\n private observedDirectories: Map<string, Set<string>> = new Map();\n\n // Absolute path -> observed stat (or null if observed nonexistent)\n private observedFiles: Map<string, Stats | null> = new Map();\n\n // Have we noticed that files have changed while recording?\n private invalidated = false;\n\n private traceEvents: boolean;\n\n constructor(traceEvents: boolean) {\n this.traceEvents = traceEvents;\n }\n\n listDir(dirPath: string): Dirent[] {\n const absDirPath = path.resolve(dirPath);\n\n // Register observing the directory itself.\n const dirSt = nodeFs.stat(absDirPath);\n this.registerNormalized(absDirPath, dirSt);\n\n // List the directory and register observing all of its children.\n const entries = nodeFs.listDir(dirPath);\n for (const entry of entries) {\n const childPath = path.join(absDirPath, entry.name);\n const childSt = nodeFs.stat(childPath);\n this.registerPath(childPath, childSt);\n }\n\n // Register observing the directory's children.\n const observedNames = new Set(entries.map((e) => e.name));\n const existingNames = this.observedDirectories.get(absDirPath);\n if (existingNames) {\n if (!setsEqual(observedNames, existingNames)) {\n if (this.traceEvents) {\n // eslint-disable-next-line no-console\n console.log(\n \"Invalidating due to directory children mismatch\",\n observedNames,\n existingNames,\n );\n }\n this.invalidated = true;\n }\n }\n this.observedDirectories.set(absDirPath, observedNames);\n\n return entries;\n }\n\n exists(path: string): boolean {\n try {\n const st = nodeFs.stat(path);\n this.registerPath(path, st);\n return true;\n } catch (err: any) {\n if (err.code === \"ENOENT\") {\n this.registerPath(path, null);\n return false;\n }\n throw err;\n }\n }\n stat(path: string): Stats {\n try {\n const st = nodeFs.stat(path);\n this.registerPath(path, st);\n return st;\n } catch (err: any) {\n if (err.code === \"ENOENT\") {\n this.registerPath(path, null);\n }\n throw err;\n }\n }\n readUtf8File(path: string): string {\n try {\n const st = nodeFs.stat(path);\n this.registerPath(path, st);\n return nodeFs.readUtf8File(path);\n } catch (err: any) {\n if (err.code === \"ENOENT\") {\n this.registerPath(path, null);\n }\n throw err;\n }\n }\n createReadStream(\n path: string,\n options: { highWaterMark?: number },\n ): ReadStream {\n try {\n const st = nodeFs.stat(path);\n this.registerPath(path, st);\n return nodeFs.createReadStream(path, options);\n } catch (err: any) {\n if (err.code === \"ENOENT\") {\n this.registerPath(path, null);\n }\n throw err;\n }\n }\n access(path: string) {\n try {\n const st = nodeFs.stat(path);\n this.registerPath(path, st);\n return nodeFs.access(path);\n } catch (err: any) {\n if (err.code === \"ENOENT\") {\n this.registerPath(path, null);\n }\n throw err;\n }\n }\n\n writeUtf8File(filePath: string, contents: string, mode?: Mode) {\n const absPath = path.resolve(filePath);\n\n nodeFs.writeUtf8File(filePath, contents, mode);\n\n this.updateOnWrite(absPath);\n }\n\n mkdir(\n dirPath: string,\n options?: { allowExisting?: boolean; recursive?: boolean },\n ): void {\n const absPath = path.resolve(dirPath);\n try {\n stdFs.mkdirSync(absPath, { recursive: options?.recursive });\n } catch (e: any) {\n if (options?.allowExisting && e.code === \"EEXIST\") {\n const st = nodeFs.stat(absPath);\n this.registerNormalized(absPath, st);\n return;\n }\n throw e;\n }\n this.updateOnWrite(absPath);\n }\n\n rmdir(dirPath: string) {\n const absPath = path.resolve(dirPath);\n stdFs.rmdirSync(absPath);\n this.updateOnDelete(absPath);\n }\n unlink(filePath: string) {\n const absPath = path.resolve(filePath);\n stdFs.unlinkSync(absPath);\n this.updateOnDelete(absPath);\n }\n swapTmpFile(fromPath: TempPath, toPath: string) {\n const absToPath = path.resolve(toPath);\n nodeFs.swapTmpFile(fromPath, absToPath);\n this.updateOnWrite(absToPath);\n }\n\n private updateOnWrite(absPath: string) {\n // Stat the file or dir after writing and make it our expected observation. If we read the file after\n // writing it and it doesn't match this stat (implying a subsequent write), we'll invalidate\n // the current reader.\n const newSt = nodeFs.stat(absPath);\n // Skip invalidation checking since we don't want to conflict if we previously read this file.\n this.observedFiles.set(absPath, newSt);\n\n // If we observed the parent, add our newly created file.\n const parentPath = path.resolve(path.dirname(absPath));\n const observedParent = this.observedDirectories.get(parentPath);\n if (observedParent !== undefined) {\n observedParent.add(path.basename(absPath));\n }\n }\n private updateOnDelete(absPath: string) {\n // Expect this file to be gone.\n this.observedFiles.set(absPath, null);\n\n // Unlink it from our parent if observed.\n const parentPath = path.resolve(path.dirname(absPath));\n const observedParent = this.observedDirectories.get(parentPath);\n if (observedParent !== undefined) {\n observedParent.delete(path.basename(absPath));\n }\n }\n\n registerPath(p: string, st: Stats | null) {\n const absPath = path.resolve(p);\n this.registerNormalized(absPath, st);\n }\n\n invalidate() {\n this.invalidated = true;\n }\n\n registerNormalized(absPath: string, observed: Stats | null): void {\n const existing = this.observedFiles.get(absPath);\n if (existing !== undefined) {\n const stMatch = stMatches(observed, existing);\n if (!stMatch.matches) {\n if (this.traceEvents) {\n // eslint-disable-next-line no-console\n console.log(\n \"Invalidating due to st mismatch\",\n absPath,\n observed,\n existing,\n stMatch.reason,\n );\n }\n this.invalidated = true;\n }\n }\n this.observedFiles.set(absPath, observed);\n }\n\n finalize(): Observations | \"invalidated\" {\n if (this.invalidated) {\n return \"invalidated\";\n }\n return new Observations(this.observedDirectories, this.observedFiles);\n }\n}\n\nexport type WatchEvent = {\n name: \"add\" | \"addDir\" | \"change\" | \"unlink\" | \"unlinkDir\";\n absPath: string;\n};\n\nexport class Observations {\n directories: Map<string, Set<string>>;\n files: Map<string, Stats | null>;\n\n constructor(\n directories: Map<string, Set<string>>,\n files: Map<string, Stats | null>,\n ) {\n this.directories = directories;\n this.files = files;\n }\n\n paths(): string[] {\n const out = [];\n for (const path of this.directories.keys()) {\n out.push(path);\n }\n for (const path of this.files.keys()) {\n out.push(path);\n }\n return out;\n }\n\n overlaps({\n absPath,\n }: WatchEvent): { overlaps: false } | { overlaps: true; reason: string } {\n let currentSt: null | Stats;\n try {\n currentSt = nodeFs.stat(absPath);\n } catch (e: any) {\n if (e.code === \"ENOENT\") {\n currentSt = null;\n } else {\n throw e;\n }\n }\n\n // First, check to see if we observed `absPath` as a file.\n const observedSt = this.files.get(absPath);\n if (observedSt !== undefined) {\n const stMatch = stMatches(observedSt, currentSt);\n if (!stMatch.matches) {\n const reason = `modified (${stMatch.reason})`;\n return { overlaps: true, reason };\n }\n }\n\n // Second, check if we listed the directory this file is in.\n const parentPath = path.resolve(path.dirname(absPath));\n const observedParent = this.directories.get(parentPath);\n if (observedParent !== undefined) {\n const filename = path.basename(absPath);\n\n // If the file is gone now, but we observed it in its directory, then\n // it was deleted.\n if (currentSt === null && observedParent.has(filename)) {\n return { overlaps: true, reason: \"deleted\" };\n }\n\n // If the file exists now, but we didn't see it when listing its directory,\n // then it was added.\n if (currentSt !== null && !observedParent.has(filename)) {\n return { overlaps: true, reason: \"added\" };\n }\n }\n\n return { overlaps: false };\n }\n}\n\nfunction setsEqual<T>(a: Set<T>, b: Set<T>): boolean {\n if (a.size !== b.size) {\n return false;\n }\n for (const elem of a.keys()) {\n if (!b.has(elem)) {\n return false;\n }\n }\n return true;\n}\n\nexport function stMatches(\n a: Stats | null,\n b: Stats | null,\n): { matches: true } | { matches: false; reason: string } {\n if (a === null && b === null) {\n return { matches: true };\n }\n if (a !== null && b !== null) {\n if (a.dev !== b.dev) {\n return { matches: false, reason: \"device boundary\" };\n }\n if (a.isFile() || b.isFile()) {\n if (!a.isFile() || !b.isFile()) {\n return { matches: false, reason: \"file type\" };\n }\n if (a.ino !== b.ino) {\n return {\n matches: false,\n reason: `file inode (${a.ino} vs. ${b.ino})`,\n };\n }\n if (a.size !== b.size) {\n return {\n matches: false,\n reason: `file size (${a.size} vs. ${b.size})`,\n };\n }\n if (a.mtimeMs !== b.mtimeMs) {\n return {\n matches: false,\n reason: `file mtime (${a.mtimeMs} vs. ${b.mtimeMs})`,\n };\n }\n return { matches: true };\n }\n if (a.isDirectory() || b.isDirectory()) {\n if (!b.isDirectory() || !b.isDirectory()) {\n return { matches: false, reason: \"dir file type\" };\n }\n if (a.ino !== b.ino) {\n return {\n matches: false,\n reason: `dir inode (${a.ino} vs. ${b.ino})`,\n };\n }\n return { matches: true };\n }\n // If we have something other than a file or directory, just compare inodes.\n if (a.ino !== b.ino) {\n return {\n matches: false,\n reason: `special inode (${a.ino} vs. ${b.ino})`,\n };\n }\n return { matches: true };\n }\n return { matches: false, reason: \"deleted mismatch\" };\n}\n\n// Sort consistent with unix directory listings.\nexport function consistentPathSort(a: Dirent, b: Dirent) {\n for (let i = 0; i < Math.min(a.name.length, b.name.length); i++) {\n if (a.name.charCodeAt(i) !== b.name.charCodeAt(i)) {\n return a.name.charCodeAt(i) - b.name.charCodeAt(i);\n }\n }\n return a.name.length - b.name.length;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,mBAA4B;AAC5B,gBAAuD;AACvD,iBAA4B;AAC5B,gBAAe;AACf,kBAAiB;AACjB,oBAAmB;AAKnB,MAAM,oBAAoB;AAC1B,SAAS,aAAa;AAWpB,QAAM,YAAY,QAAQ,IAAI,iBAAiB;AAC/C,SAAO,aAAa,UAAAA,QAAG,OAAO;AAChC;AACA,MAAM,aAAa,WAAW;AAE9B,IAAI,SAAS;AACb,SAAS,oBAAoB,SAAiB;AAC5C,QAAM,SAAS,YAAAC,QAAK,QAAQ,OAAO;AACnC,MAAI,CAAC,QAAQ;AAGX,YAAQ;AAAA,MACN,yBAAY;AAAA,QACV,wBAAwB,UAAU,4BAA4B,MAAM;AAAA,MACtE;AAAA,IACF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,eAAO,EAAE,SAAS,OAAO,QAAQ,gBAAgB;AAAA,MACnD;AACA,UAAI,EAAE,QAAQ,EAAE,KAAK;AACnB,eAAO;AAAA,UACL,SAAS;AAAA,UACT,QAAQ,cAAc,EAAE,GAAG,QAAQ,EAAE,GAAG;AAAA,QAC1C;AAAA,MACF;AACA,aAAO,EAAE,SAAS,KAAK;AAAA,IACzB;AAEA,QAAI,EAAE,QAAQ,EAAE,KAAK;AACnB,aAAO;AAAA,QACL,SAAS;AAAA,QACT,QAAQ,kBAAkB,EAAE,GAAG,QAAQ,EAAE,GAAG;AAAA,MAC9C;AAAA,IACF;AACA,WAAO,EAAE,SAAS,KAAK;AAAA,EACzB;AACA,SAAO,EAAE,SAAS,OAAO,QAAQ,mBAAmB;AACtD;AAGO,SAAS,mBAAmB,GAAW,GAAW;AACvD,WAAS,IAAI,GAAG,IAAI,KAAK,IAAI,EAAE,KAAK,QAAQ,EAAE,KAAK,MAAM,GAAG,KAAK;AAC/D,QAAI,EAAE,KAAK,WAAW,CAAC,MAAM,EAAE,KAAK,WAAW,CAAC,GAAG;AACjD,aAAO,EAAE,KAAK,WAAW,CAAC,IAAI,EAAE,KAAK,WAAW,CAAC;AAAA,IACnD;AAAA,EACF;AACA,SAAO,EAAE,KAAK,SAAS,EAAE,KAAK;AAChC;",
|
|
4
|
+
"sourcesContent": ["// Disable our restriction on `throw` because these aren't developer-facing\n// error messages.\n/* eslint-disable no-restricted-imports */\n/* eslint-disable no-restricted-syntax */\nimport { chalkStderr } from \"chalk\";\nimport stdFs, { Dirent, Mode, ReadStream, Stats } from \"fs\";\nimport * as fsPromises from \"fs/promises\";\nimport os from \"os\";\nimport path from \"path\";\nimport crypto from \"crypto\";\nimport { Readable } from \"stream\";\n\nexport type NormalizedPath = string;\n\nconst tmpDirOverrideVar = \"CONVEX_TMPDIR\";\nfunction tmpDirPath() {\n // Allow users to override the temporary directory path with an environment variable.\n // This override needs to (1) be project-specific, since the user may have projects\n // on different filesystems, but also (2) be device-specific and not checked in, since\n // it's dependent on where the user has checked out their project. So, we don't want\n // this state in the project-specific `convex.json`, which is shared across all\n // devices, or in the top-level `~/.convex` directory, which is shared across all\n // projects on the local machine.\n //\n // Therefore, just let advanced users configure this behavior with an environment\n // variable that they're responsible for managing themselves for now.\n const envTmpDir = process.env[tmpDirOverrideVar];\n return envTmpDir ?? os.tmpdir();\n}\nconst tmpDirRoot = tmpDirPath();\n\nlet warned = false;\nfunction warnCrossFilesystem(dstPath: string) {\n const dstDir = path.dirname(dstPath);\n if (!warned) {\n // It's hard for these to use `logMessage` without creating a circular dependency, so just log directly.\n // eslint-disable-next-line no-console\n console.warn(\n chalkStderr.yellow(\n `Temporary directory '${tmpDirRoot}' and project directory '${dstDir}' are on different filesystems.`,\n ),\n );\n // eslint-disable-next-line no-console\n console.warn(\n chalkStderr.gray(\n ` If you're running into errors with other tools watching the project directory, override the temporary directory location with the ${chalkStderr.bold(\n tmpDirOverrideVar,\n )} environment variable.`,\n ),\n );\n // eslint-disable-next-line no-console\n console.warn(\n chalkStderr.gray(\n ` Be sure to pick a temporary directory that's on the same filesystem as your project.`,\n ),\n );\n warned = true;\n }\n}\n\nexport interface Filesystem {\n listDir(dirPath: string): Dirent[];\n\n exists(path: string): boolean;\n stat(path: string): Stats;\n lstat(path: string): Stats;\n readUtf8File(path: string): string;\n // createReadStream returns a stream for which [Symbol.asyncIterator]\n // yields chunks of size highWaterMark (until the last one), or 64KB if\n // highWaterMark isn't specified.\n // https://nodejs.org/api/stream.html#readablesymbolasynciterator\n createReadStream(\n path: string,\n options: { highWaterMark?: number },\n ): ReadStream;\n access(path: string): void;\n\n writeUtf8File(path: string, contents: string, mode?: Mode): void;\n mkdir(\n dirPath: string,\n options?: { allowExisting?: boolean; recursive?: boolean },\n ): void;\n rmdir(path: string): void;\n unlink(path: string): void;\n swapTmpFile(fromPath: TempPath, toPath: string): void;\n\n registerPath(path: string, st: Stats | null): void;\n invalidate(): void;\n}\n\nexport type TempPath = string & { __tempPath: \"tempPath\" };\n\nexport interface TempDir {\n writeUtf8File(contents: string): TempPath;\n writeFileStream(\n path: TempPath,\n stream: Readable,\n onData?: (chunk: any) => void,\n ): Promise<void>;\n registerTempPath(st: Stats | null): TempPath;\n path: TempPath;\n}\n\nexport async function withTmpDir(\n callback: (tmpDir: TempDir) => Promise<void>,\n): Promise<void> {\n // Create temporary directories inside `tmpDirRoot` of the form `convex-<random>`.\n const tmpPath = stdFs.mkdtempSync(path.join(tmpDirRoot, \"convex\"));\n const tmpDir = {\n writeUtf8File(contents: string): TempPath {\n const filePath = path.join(tmpPath, crypto.randomUUID());\n nodeFs.writeUtf8File(filePath, contents);\n return filePath as TempPath;\n },\n registerTempPath(st: Stats | null): TempPath {\n const filePath = path.join(tmpPath, crypto.randomUUID());\n nodeFs.registerPath(filePath, st);\n return filePath as TempPath;\n },\n writeFileStream(\n path: TempPath,\n stream: Readable,\n onData?: (chunk: any) => void,\n ): Promise<void> {\n return nodeFs.writeFileStream(path, stream, onData);\n },\n path: tmpPath as TempPath,\n };\n try {\n await callback(tmpDir);\n } finally {\n stdFs.rmSync(tmpPath, { force: true, recursive: true });\n }\n}\n\n// Use `nodeFs` when you just want to read and write to the local filesystem\n// and don't care about collecting the paths touched. One-off commands\n// should use the singleton `nodeFs`.\nexport class NodeFs implements Filesystem {\n listDir(dirPath: string) {\n return stdFs.readdirSync(dirPath, { withFileTypes: true });\n }\n exists(path: string) {\n try {\n stdFs.statSync(path);\n return true;\n } catch (e: any) {\n if (e.code === \"ENOENT\") {\n return false;\n }\n throw e;\n }\n }\n stat(path: string) {\n return stdFs.statSync(path);\n }\n lstat(path: string) {\n return stdFs.lstatSync(path);\n }\n readUtf8File(path: string) {\n return stdFs.readFileSync(path, { encoding: \"utf-8\" });\n }\n createReadStream(\n path: string,\n options: { highWaterMark?: number },\n ): ReadStream {\n return stdFs.createReadStream(path, options);\n }\n // To avoid issues with filesystem events triggering for our own streamed file\n // writes, writeFileStream is intentionally not on the Filesystem interface\n // and not implemented by RecordingFs.\n async writeFileStream(\n path: string,\n stream: Readable,\n onData?: (chunk: any) => void,\n ): Promise<void> {\n // 'wx' means O_CREAT | O_EXCL | O_WRONLY\n // 0o644 means owner has readwrite access, everyone else has read access.\n const fileHandle = await fsPromises.open(path, \"wx\", 0o644);\n try {\n for await (const chunk of stream) {\n // For some reason, adding `stream.on(\"data\", onData)` causes issues with\n // the stream, but calling a callback here works.\n if (onData) {\n onData(chunk);\n }\n await fileHandle.write(chunk);\n }\n } finally {\n await fileHandle.close();\n }\n }\n access(path: string) {\n return stdFs.accessSync(path);\n }\n writeUtf8File(path: string, contents: string, mode?: Mode) {\n const fd = stdFs.openSync(path, \"w\", mode);\n try {\n stdFs.writeFileSync(fd, contents, { encoding: \"utf-8\" });\n try {\n stdFs.fsyncSync(fd);\n } catch (e: any) {\n // fsync(2) returns EINVAL on file descriptors that don't support\n // synchronization, e.g. FIFOs/pipes. Some integrations (such as\n // 1Password's Local Environment File) expose `.env.local` as a\n // FIFO so secrets can be streamed on demand; the write itself\n // succeeded, so treat the missing sync as best-effort.\n if (e?.code !== \"EINVAL\") {\n throw e;\n }\n }\n } finally {\n stdFs.closeSync(fd);\n }\n }\n mkdir(\n dirPath: string,\n options?: { allowExisting?: boolean; recursive?: boolean },\n ): void {\n try {\n stdFs.mkdirSync(dirPath, { recursive: options?.recursive });\n } catch (e: any) {\n if (options?.allowExisting && e.code === \"EEXIST\") {\n return;\n }\n throw e;\n }\n }\n rmdir(path: string) {\n stdFs.rmdirSync(path);\n }\n unlink(path: string) {\n return stdFs.unlinkSync(path);\n }\n swapTmpFile(fromPath: TempPath, toPath: string) {\n try {\n return stdFs.renameSync(fromPath, toPath);\n } catch (e: any) {\n // Fallback to copying the file if we're on different volumes.\n if (e.code === \"EXDEV\") {\n warnCrossFilesystem(toPath);\n stdFs.copyFileSync(fromPath, toPath);\n return;\n }\n throw e;\n }\n }\n registerPath(_path: string, _st: Stats | null) {\n // The node filesystem doesn't track reads, so we don't need to do anything here.\n }\n invalidate() {\n // We don't track invalidations for the node filesystem either.\n }\n}\nexport const nodeFs = new NodeFs();\n\n// Filesystem implementation that records all paths observed. This is useful\n// for implementing continuous watch commands that need to manage a filesystem\n// watcher and know when a command's inputs were invalidated.\nexport class RecordingFs implements Filesystem {\n // Absolute path -> Set of observed child names\n private observedDirectories: Map<string, Set<string>> = new Map();\n\n // Absolute path -> observed stat (or null if observed nonexistent)\n private observedFiles: Map<string, Stats | null> = new Map();\n\n // lstat observes the link itself, while stat observes its target.\n private observedLstats: Map<string, Stats | null> = new Map();\n\n // Have we noticed that files have changed while recording?\n private invalidated = false;\n\n private traceEvents: boolean;\n\n constructor(traceEvents: boolean) {\n this.traceEvents = traceEvents;\n }\n\n listDir(dirPath: string): Dirent[] {\n const absDirPath = path.resolve(dirPath);\n\n // Register observing the directory itself.\n const dirSt = nodeFs.stat(absDirPath);\n this.registerNormalized(absDirPath, dirSt);\n\n // List the directory and register observing all of its children.\n const entries = nodeFs.listDir(dirPath);\n for (const entry of entries) {\n const childPath = path.join(absDirPath, entry.name);\n const childSt = nodeFs.stat(childPath);\n this.registerPath(childPath, childSt);\n }\n\n // Register observing the directory's children.\n const observedNames = new Set(entries.map((e) => e.name));\n const existingNames = this.observedDirectories.get(absDirPath);\n if (existingNames) {\n if (!setsEqual(observedNames, existingNames)) {\n if (this.traceEvents) {\n // eslint-disable-next-line no-console\n console.log(\n \"Invalidating due to directory children mismatch\",\n observedNames,\n existingNames,\n );\n }\n this.invalidated = true;\n }\n }\n this.observedDirectories.set(absDirPath, observedNames);\n\n return entries;\n }\n\n lstat(filePath: string): Stats {\n const absPath = path.resolve(filePath);\n try {\n const st = nodeFs.lstat(filePath);\n this.registerNormalized(absPath, st, this.observedLstats);\n return st;\n } catch (err: any) {\n if (err.code === \"ENOENT\") {\n this.registerNormalized(absPath, null, this.observedLstats);\n }\n throw err;\n }\n }\n\n exists(path: string): boolean {\n try {\n const st = nodeFs.stat(path);\n this.registerPath(path, st);\n return true;\n } catch (err: any) {\n if (err.code === \"ENOENT\") {\n this.registerPath(path, null);\n return false;\n }\n throw err;\n }\n }\n stat(path: string): Stats {\n try {\n const st = nodeFs.stat(path);\n this.registerPath(path, st);\n return st;\n } catch (err: any) {\n if (err.code === \"ENOENT\") {\n this.registerPath(path, null);\n }\n throw err;\n }\n }\n readUtf8File(path: string): string {\n try {\n const st = nodeFs.stat(path);\n this.registerPath(path, st);\n return nodeFs.readUtf8File(path);\n } catch (err: any) {\n if (err.code === \"ENOENT\") {\n this.registerPath(path, null);\n }\n throw err;\n }\n }\n createReadStream(\n path: string,\n options: { highWaterMark?: number },\n ): ReadStream {\n try {\n const st = nodeFs.stat(path);\n this.registerPath(path, st);\n return nodeFs.createReadStream(path, options);\n } catch (err: any) {\n if (err.code === \"ENOENT\") {\n this.registerPath(path, null);\n }\n throw err;\n }\n }\n access(path: string) {\n try {\n const st = nodeFs.stat(path);\n this.registerPath(path, st);\n return nodeFs.access(path);\n } catch (err: any) {\n if (err.code === \"ENOENT\") {\n this.registerPath(path, null);\n }\n throw err;\n }\n }\n\n writeUtf8File(filePath: string, contents: string, mode?: Mode) {\n const absPath = path.resolve(filePath);\n\n nodeFs.writeUtf8File(filePath, contents, mode);\n\n this.updateOnWrite(absPath);\n }\n\n mkdir(\n dirPath: string,\n options?: { allowExisting?: boolean; recursive?: boolean },\n ): void {\n const absPath = path.resolve(dirPath);\n try {\n stdFs.mkdirSync(absPath, { recursive: options?.recursive });\n } catch (e: any) {\n if (options?.allowExisting && e.code === \"EEXIST\") {\n const st = nodeFs.stat(absPath);\n this.registerNormalized(absPath, st);\n return;\n }\n throw e;\n }\n this.updateOnWrite(absPath);\n }\n\n rmdir(dirPath: string) {\n const absPath = path.resolve(dirPath);\n stdFs.rmdirSync(absPath);\n this.updateOnDelete(absPath);\n }\n unlink(filePath: string) {\n const absPath = path.resolve(filePath);\n stdFs.unlinkSync(absPath);\n this.updateOnDelete(absPath);\n }\n swapTmpFile(fromPath: TempPath, toPath: string) {\n const absToPath = path.resolve(toPath);\n nodeFs.swapTmpFile(fromPath, absToPath);\n this.updateOnWrite(absToPath);\n }\n\n private updateOnWrite(absPath: string) {\n // Stat the file or dir after writing and make it our expected observation. If we read the file after\n // writing it and it doesn't match this stat (implying a subsequent write), we'll invalidate\n // the current reader.\n const newSt = nodeFs.stat(absPath);\n // Skip invalidation checking since we don't want to conflict if we previously read this file.\n this.observedFiles.set(absPath, newSt);\n if (this.observedLstats.has(absPath))\n this.observedLstats.set(absPath, nodeFs.lstat(absPath));\n\n // If we observed the parent, add our newly created file.\n const parentPath = path.resolve(path.dirname(absPath));\n const observedParent = this.observedDirectories.get(parentPath);\n if (observedParent !== undefined) {\n observedParent.add(path.basename(absPath));\n }\n }\n private updateOnDelete(absPath: string) {\n // Expect this file to be gone.\n this.observedFiles.set(absPath, null);\n if (this.observedLstats.has(absPath))\n this.observedLstats.set(absPath, null);\n\n // Unlink it from our parent if observed.\n const parentPath = path.resolve(path.dirname(absPath));\n const observedParent = this.observedDirectories.get(parentPath);\n if (observedParent !== undefined) {\n observedParent.delete(path.basename(absPath));\n }\n }\n\n registerPath(p: string, st: Stats | null) {\n const absPath = path.resolve(p);\n this.registerNormalized(absPath, st);\n }\n\n invalidate() {\n this.invalidated = true;\n }\n\n registerNormalized(\n absPath: string,\n observed: Stats | null,\n observations = this.observedFiles,\n ): void {\n const existing = observations.get(absPath);\n if (existing !== undefined) {\n const stMatch = stMatches(observed, existing);\n if (!stMatch.matches) {\n if (this.traceEvents) {\n // eslint-disable-next-line no-console\n console.log(\n \"Invalidating due to st mismatch\",\n absPath,\n observed,\n existing,\n stMatch.reason,\n );\n }\n this.invalidated = true;\n }\n }\n observations.set(absPath, observed);\n }\n\n finalize(): Observations | \"invalidated\" {\n if (this.invalidated) {\n return \"invalidated\";\n }\n return new Observations(\n this.observedDirectories,\n this.observedFiles,\n this.observedLstats,\n );\n }\n}\n\nexport type WatchEvent = {\n name: \"add\" | \"addDir\" | \"change\" | \"unlink\" | \"unlinkDir\";\n absPath: string;\n};\n\nexport class Observations {\n directories: Map<string, Set<string>>;\n files: Map<string, Stats | null>;\n\n constructor(\n directories: Map<string, Set<string>>,\n files: Map<string, Stats | null>,\n private lstats: Map<string, Stats | null> = new Map(),\n ) {\n this.directories = directories;\n this.files = files;\n }\n\n paths(): string[] {\n const out = [];\n for (const path of this.directories.keys()) {\n out.push(path);\n }\n for (const path of this.files.keys()) {\n out.push(path);\n }\n for (const path of this.lstats.keys()) out.push(path);\n return [...new Set(out)];\n }\n\n overlaps({\n absPath,\n }: WatchEvent): { overlaps: false } | { overlaps: true; reason: string } {\n let currentSt: null | Stats;\n try {\n currentSt = nodeFs.stat(absPath);\n } catch (e: any) {\n if (e.code === \"ENOENT\") {\n currentSt = null;\n } else {\n throw e;\n }\n }\n\n // First, check to see if we observed `absPath` as a file.\n const observedSt = this.files.get(absPath);\n if (observedSt !== undefined) {\n const stMatch = stMatches(observedSt, currentSt);\n if (!stMatch.matches) {\n const reason = `modified (${stMatch.reason})`;\n return { overlaps: true, reason };\n }\n }\n\n const observedLstat = this.lstats.get(absPath);\n if (observedLstat !== undefined) {\n let currentLstat: Stats | null;\n try {\n currentLstat = nodeFs.lstat(absPath);\n } catch (err: any) {\n if (err.code !== \"ENOENT\") throw err;\n currentLstat = null;\n }\n const match = stMatches(observedLstat, currentLstat);\n if (!match.matches)\n return { overlaps: true, reason: `modified (${match.reason})` };\n }\n\n // Second, check if we listed the directory this file is in.\n const parentPath = path.resolve(path.dirname(absPath));\n const observedParent = this.directories.get(parentPath);\n if (observedParent !== undefined) {\n const filename = path.basename(absPath);\n\n // If the file is gone now, but we observed it in its directory, then\n // it was deleted.\n if (currentSt === null && observedParent.has(filename)) {\n return { overlaps: true, reason: \"deleted\" };\n }\n\n // If the file exists now, but we didn't see it when listing its directory,\n // then it was added.\n if (currentSt !== null && !observedParent.has(filename)) {\n return { overlaps: true, reason: \"added\" };\n }\n }\n\n return { overlaps: false };\n }\n}\n\nfunction setsEqual<T>(a: Set<T>, b: Set<T>): boolean {\n if (a.size !== b.size) {\n return false;\n }\n for (const elem of a.keys()) {\n if (!b.has(elem)) {\n return false;\n }\n }\n return true;\n}\n\nexport function stMatches(\n a: Stats | null,\n b: Stats | null,\n): { matches: true } | { matches: false; reason: string } {\n if (a === null && b === null) {\n return { matches: true };\n }\n if (a !== null && b !== null) {\n if (a.dev !== b.dev) {\n return { matches: false, reason: \"device boundary\" };\n }\n if (a.isFile() || b.isFile()) {\n if (!a.isFile() || !b.isFile()) {\n return { matches: false, reason: \"file type\" };\n }\n if (a.ino !== b.ino) {\n return {\n matches: false,\n reason: `file inode (${a.ino} vs. ${b.ino})`,\n };\n }\n if (a.size !== b.size) {\n return {\n matches: false,\n reason: `file size (${a.size} vs. ${b.size})`,\n };\n }\n if (a.mtimeMs !== b.mtimeMs) {\n return {\n matches: false,\n reason: `file mtime (${a.mtimeMs} vs. ${b.mtimeMs})`,\n };\n }\n return { matches: true };\n }\n if (a.isDirectory() || b.isDirectory()) {\n if (!b.isDirectory() || !b.isDirectory()) {\n return { matches: false, reason: \"dir file type\" };\n }\n if (a.ino !== b.ino) {\n return {\n matches: false,\n reason: `dir inode (${a.ino} vs. ${b.ino})`,\n };\n }\n return { matches: true };\n }\n // If we have something other than a file or directory, just compare inodes.\n if (a.ino !== b.ino) {\n return {\n matches: false,\n reason: `special inode (${a.ino} vs. ${b.ino})`,\n };\n }\n return { matches: true };\n }\n return { matches: false, reason: \"deleted mismatch\" };\n}\n\n// Sort consistent with unix directory listings.\nexport function consistentPathSort(a: Dirent, b: Dirent) {\n for (let i = 0; i < Math.min(a.name.length, b.name.length); i++) {\n if (a.name.charCodeAt(i) !== b.name.charCodeAt(i)) {\n return a.name.charCodeAt(i) - b.name.charCodeAt(i);\n }\n }\n return a.name.length - b.name.length;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var account_exports = {};
|
|
30
|
+
__export(account_exports, {
|
|
31
|
+
account: () => account,
|
|
32
|
+
handleNoAccessToConfiguredProject: () => handleNoAccessToConfiguredProject
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(account_exports);
|
|
35
|
+
var import_extra_typings = require("@commander-js/extra-typings");
|
|
36
|
+
var import_path = __toESM(require("path"), 1);
|
|
37
|
+
var import_login = require("./login.js");
|
|
38
|
+
var import_logout = require("./logout.js");
|
|
39
|
+
var import_context = require("../bundler/context.js");
|
|
40
|
+
var import_log = require("../bundler/log.js");
|
|
41
|
+
var import_envvars = require("./lib/envvars.js");
|
|
42
|
+
var import_login2 = require("./lib/login.js");
|
|
43
|
+
var import_profiles = require("./lib/profiles.js");
|
|
44
|
+
var import_profileManagement = require("./lib/profileManagement.js");
|
|
45
|
+
var import_deployKeyWarning = require("./lib/deployKeyWarning.js");
|
|
46
|
+
var import_prompts = require("./lib/utils/prompts.js");
|
|
47
|
+
async function profileContext() {
|
|
48
|
+
const ctx = await (0, import_context.oneoffContext)({ skipAuth: true });
|
|
49
|
+
(0, import_envvars.loadProjectEnvironmentVariables)();
|
|
50
|
+
return ctx;
|
|
51
|
+
}
|
|
52
|
+
const profileList = new import_extra_typings.Command("list").description(
|
|
53
|
+
"List saved accounts, credential status, and directory selections"
|
|
54
|
+
).allowExcessArguments(false).action(async () => {
|
|
55
|
+
const ctx = await profileContext();
|
|
56
|
+
const settings = await (0, import_profiles.readProfileSettings)(ctx);
|
|
57
|
+
const selected = await (0, import_profiles.getProfileSelection)(ctx);
|
|
58
|
+
const names = /* @__PURE__ */ new Set([
|
|
59
|
+
...(0, import_profiles.savedProfileNames)(ctx),
|
|
60
|
+
...Object.values(settings.directories ?? {}),
|
|
61
|
+
...settings.defaultProfile === void 0 ? [] : [settings.defaultProfile],
|
|
62
|
+
...selected === null ? [] : [selected.name]
|
|
63
|
+
]);
|
|
64
|
+
(0, import_deployKeyWarning.warnIfDeployKeyOverridesLogin)(
|
|
65
|
+
ctx,
|
|
66
|
+
typeof settings.accessToken === "string" || (0, import_profiles.savedProfileNames)(ctx).length > 0
|
|
67
|
+
);
|
|
68
|
+
if (names.size === 0) {
|
|
69
|
+
(0, import_log.logMessage)(
|
|
70
|
+
typeof settings.accessToken === "string" ? await (0, import_login2.isAuthorizedHeader)(ctx, `Bearer ${settings.accessToken}`) ? "Logged in without a named account. Name this login with `npx convex login --account personal --select`." : "Your saved login is no longer valid. Run `npx convex login --account <name>`." : "No saved accounts. Run `npx convex login --account <name>`."
|
|
71
|
+
);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (selected !== null)
|
|
75
|
+
(0, import_log.logMessage)(`Selected account: ${selected.name} (${selected.source})`);
|
|
76
|
+
if (settings.defaultProfile !== void 0)
|
|
77
|
+
(0, import_log.logMessage)(`Default account: ${settings.defaultProfile}`);
|
|
78
|
+
for (const name of [...names].sort()) {
|
|
79
|
+
const credentials = await (0, import_profiles.readProfileCredentials)(
|
|
80
|
+
ctx,
|
|
81
|
+
{ name, source: "saved accounts" },
|
|
82
|
+
true
|
|
83
|
+
);
|
|
84
|
+
const valid = credentials !== null && await (0, import_login2.isAuthorizedHeader)(ctx, `Bearer ${credentials.accessToken}`);
|
|
85
|
+
const label = `${name}${credentials?.email ? ` (${credentials.email})` : ""}`;
|
|
86
|
+
const status = credentials === null ? " \u26A0\uFE0F Not logged in" : valid ? "" : " \u26A0\uFE0F Invalid credentials";
|
|
87
|
+
(0, import_log.logOutput)(`${label}${status}`);
|
|
88
|
+
for (const [directory, profile] of Object.entries(
|
|
89
|
+
settings.directories ?? {}
|
|
90
|
+
)) {
|
|
91
|
+
if (profile === name) (0, import_log.logOutput)(` ${directory}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
const accountSelect = new import_extra_typings.Command("select").description("Use a saved account in this directory and its subdirectories").argument("<account>", "Account name, such as work or personal").option(
|
|
96
|
+
"--force",
|
|
97
|
+
"Select this account even if deployment access cannot be verified"
|
|
98
|
+
).allowExcessArguments(false).action(async (name, options) => {
|
|
99
|
+
const ctx = await profileContext();
|
|
100
|
+
if (!await (0, import_profileManagement.bindProfileToDirectory)(ctx, name, options.force)) {
|
|
101
|
+
await ctx.crash({
|
|
102
|
+
exitCode: 1,
|
|
103
|
+
errorType: "fatal",
|
|
104
|
+
printedMessage: null
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
const profileDefault = new import_extra_typings.Command("default").description(
|
|
109
|
+
"Show or set the default account for directories without a directory selection"
|
|
110
|
+
).argument("[account]", "Account name").allowExcessArguments(false).action(async (name) => {
|
|
111
|
+
const ctx = await profileContext();
|
|
112
|
+
if (name === void 0) {
|
|
113
|
+
const settings = await (0, import_profiles.readProfileSettings)(ctx);
|
|
114
|
+
(0, import_log.logOutput)(
|
|
115
|
+
settings.defaultProfile === void 0 ? "No default account is set." : `Default account: ${settings.defaultProfile}`
|
|
116
|
+
);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
await (0, import_profiles.updateProfileSettings)(ctx, async (settings) => {
|
|
120
|
+
const credentials = await (0, import_profiles.readProfileCredentials)(ctx, {
|
|
121
|
+
name,
|
|
122
|
+
source: "account default"
|
|
123
|
+
});
|
|
124
|
+
settings.defaultProfile = name;
|
|
125
|
+
settings.accessToken = credentials.accessToken;
|
|
126
|
+
});
|
|
127
|
+
(0, import_log.logFinishedStep)(`Default account: ${name}`);
|
|
128
|
+
});
|
|
129
|
+
const accountDeselect = new import_extra_typings.Command("deselect").description(
|
|
130
|
+
"Clear this directory's account selection, inheriting its parent's selection or the default"
|
|
131
|
+
).allowExcessArguments(false).action(async () => {
|
|
132
|
+
const ctx = await profileContext();
|
|
133
|
+
const directory = import_path.default.resolve(process.cwd());
|
|
134
|
+
const removed = await (0, import_profiles.updateProfileSettings)(ctx, (settings) => {
|
|
135
|
+
if (settings.directories && Object.hasOwn(settings.directories, directory)) {
|
|
136
|
+
delete settings.directories[directory];
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
return false;
|
|
140
|
+
});
|
|
141
|
+
if (removed)
|
|
142
|
+
(0, import_log.logFinishedStep)(`Removed the directory selection for ${directory}.`);
|
|
143
|
+
else (0, import_log.logMessage)(`No directory selection is saved for ${directory}.`);
|
|
144
|
+
const selected = await (0, import_profiles.getProfileSelection)(ctx);
|
|
145
|
+
if (selected !== null)
|
|
146
|
+
(0, import_log.logMessage)(`Selected account: ${selected.name} (${selected.source})`);
|
|
147
|
+
});
|
|
148
|
+
const profileSettings = new import_extra_typings.Command("settings").summary("Show or change account settings").description(
|
|
149
|
+
"Show or change account settings.\n\nRenewing an account login revokes its replaced personal access token unless another saved login uses it. To keep replaced tokens active, run:\n\n `npx convex@latest account settings revoke-replaced-tokens false`"
|
|
150
|
+
).argument("[name]", "revoke-replaced-tokens").argument("[value]", "true or false").allowExcessArguments(false).action(async (name, value, _options, cmd) => {
|
|
151
|
+
const ctx = await profileContext();
|
|
152
|
+
const settings = await (0, import_profiles.readProfileSettings)(ctx);
|
|
153
|
+
if (name === void 0 && value === void 0) {
|
|
154
|
+
(0, import_log.logOutput)(
|
|
155
|
+
`revoke-replaced-tokens: ${settings.revokeReplacedTokens ?? true}`
|
|
156
|
+
);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (name !== "revoke-replaced-tokens" || value !== "true" && value !== "false") {
|
|
160
|
+
cmd.error(
|
|
161
|
+
"Usage: npx convex account settings revoke-replaced-tokens <true|false>"
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
await (0, import_profiles.updateProfileSettings)(ctx, (settings2) => {
|
|
165
|
+
settings2.revokeReplacedTokens = value === "true";
|
|
166
|
+
});
|
|
167
|
+
(0, import_log.logFinishedStep)(`Set revoke-replaced-tokens to ${value}.`);
|
|
168
|
+
});
|
|
169
|
+
const account = new import_extra_typings.Command("account").summary("Manage saved accounts and their directory selections").description(
|
|
170
|
+
"Manage saved accounts and their directory selections.\n\nSave logins for multiple Convex accounts under names such as work and personal. `npx convex@latest account login` and `npx convex@latest account logout` are aliases for the top-level login and logout commands, with the same options. Select the appropriate account for each personal, work, or client project.\n\nIn your personal project directory, save an account:\n\n `npx convex@latest login --account personal --select`\n\nIn your work project directory, log in with your work account and check its teams:\n\n `npx convex@latest login --account work --select`\n `npx convex@latest login status`\n\nChoose the appropriate account in the browser; sign out of the dashboard first if it is using another account. Upgrade each project's `convex` dependency to a version that supports saved accounts, then run `npx convex dev` to develop with its selected account.\n\n`login --account` saves credentials without changing directory selections. Add `--select` to select the account for this directory and its subdirectories after checking deployment access. The first saved account becomes the default if no other account is saved. To select a saved account in another directory, run `npx convex@latest account select work`. Run `npx convex@latest account deselect` to remove this directory's selection and inherit its parent or default. Run `npx convex@latest account default` to show the default, or `npx convex@latest account default work` to change it. The closest directory selection wins. Selections use absolute paths, so select the account again after moving a project.\n\nThe first account name is assigned to your existing login if you are already logged in, and becomes the default for directories without a selection. Use `--force` to authenticate another account instead, keeping the existing login as the default. Names start with a lowercase letter or number and contain only lowercase letters, numbers, hyphens, and underscores.\n\n`CONVEX_ACCOUNT` in the shell or project env file overrides directory selections and the default account. Deployment and project keys take priority over saved accounts.\n\nUse `npx convex@latest logout --account work` to remove one account's credentials, or `npx convex@latest logout --all` to remove all saved credentials. Logout preserves directory selections; a logged-out account requires login before use.\n\nAfter saving accounts, use `npx convex@latest` for login, logout, and account commands in every project directory on this machine. Plain `npx convex` can run the older version installed in that project. Specifying `@latest` runs the latest published CLI without updating the project's dependency.\n\nOlder CLIs ignore directory selections and `CONVEX_ACCOUNT`, using the shared login instead (normally the default account). Upgrade the project's `convex` dependency to use saved accounts with project commands such as `npx convex dev` and `npx convex deploy`.\n\nLogging in with an older CLI can change the shared login independently of your saved accounts, or discard account settings if the shared login has been removed. Logging out with an older CLI deletes directory selections and the default selection but leaves named account credentials behind. Recreate any lost selections with `npx convex@latest account select <name>` and `npx convex@latest account default <name>`.\n\nRenewing an account login can revoke its previous token and interrupt running CLI processes of any version that still use it. Restart those commands after renewing the login, or keep replaced tokens active with `npx convex@latest account settings revoke-replaced-tokens false`."
|
|
171
|
+
).addCommand(profileList).addCommand(accountSelect).addCommand(profileDefault).addCommand(accountDeselect).addCommand(profileSettings).addCommand((0, import_login.createLoginCommand)()).addCommand((0, import_logout.createLogoutCommand)()).addHelpCommand(false);
|
|
172
|
+
async function handleNoAccessToConfiguredProject(ctx, target, envFile) {
|
|
173
|
+
const auth = ctx.bigBrainAuth();
|
|
174
|
+
const current = auth?.kind === "accessToken" ? auth.profile?.name : void 0;
|
|
175
|
+
const project = target.kind === "deploymentName" ? `deployment "${target.deploymentName}"` : target.kind === "teamAndProjectSlugs" ? `project "${target.teamSlug}/${target.projectSlug}"` : "the configured project";
|
|
176
|
+
(0, import_log.logWarning)(
|
|
177
|
+
`${current ? `Account "${current}"` : "Your account"} cannot access ${project}. It may belong to another account.`
|
|
178
|
+
);
|
|
179
|
+
const alternatives = [];
|
|
180
|
+
if (target.kind !== "projectDeployKey") {
|
|
181
|
+
for (const name2 of (0, import_profiles.savedProfileNames)(ctx)) {
|
|
182
|
+
if (name2 === current) continue;
|
|
183
|
+
const credentials = await (0, import_profiles.readProfileCredentials)(ctx, {
|
|
184
|
+
name: name2,
|
|
185
|
+
source: "saved accounts"
|
|
186
|
+
});
|
|
187
|
+
if (await (0, import_profileManagement.projectAccess)(credentials.accessToken, target) === "yes")
|
|
188
|
+
alternatives.push(name2);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (!process.stdin.isTTY) {
|
|
192
|
+
const selection2 = await (0, import_profiles.getProfileSelection)(ctx, { envFile });
|
|
193
|
+
const overrideHint = selection2?.source.startsWith("CONVEX_ACCOUNT") ? ` Update or unset CONVEX_ACCOUNT (${selection2.source}) before retrying.` : "";
|
|
194
|
+
return await ctx.crash({
|
|
195
|
+
exitCode: 1,
|
|
196
|
+
errorType: "fatal",
|
|
197
|
+
printedMessage: `${alternatives.length > 0 ? `A saved account can access it: ${alternatives.map((name2) => `\`npx convex account select ${name2}\``).join(" or ")}.` : "Log in to its account with `npx convex login --account <name> --select`."}${overrideHint} To select a different project, run \`npx convex dev --configure\` (this changes CONVEX_DEPLOYMENT).`
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
const choice = await (0, import_prompts.promptOptions)(ctx, {
|
|
201
|
+
message: "Which account should this project use?",
|
|
202
|
+
choices: [
|
|
203
|
+
...alternatives.map((name2) => ({
|
|
204
|
+
name: `Use account "${name2}"`,
|
|
205
|
+
value: { kind: "use", name: name2 }
|
|
206
|
+
})),
|
|
207
|
+
{ name: "Log in to another account", value: { kind: "login" } },
|
|
208
|
+
{
|
|
209
|
+
name: "Configure a different project (changes CONVEX_DEPLOYMENT)",
|
|
210
|
+
value: { kind: "chooseProject" }
|
|
211
|
+
}
|
|
212
|
+
]
|
|
213
|
+
});
|
|
214
|
+
if (choice.kind === "chooseProject") return "chooseProject";
|
|
215
|
+
const name = choice.kind === "use" ? choice.name : await (0, import_prompts.promptString)(ctx, {
|
|
216
|
+
message: "Account name (for example, work):"
|
|
217
|
+
});
|
|
218
|
+
await (0, import_profiles.validateProfileName)(ctx, name);
|
|
219
|
+
if (choice.kind === "login") {
|
|
220
|
+
const selection2 = { name, source: "account recovery" };
|
|
221
|
+
await (0, import_login2.performLogin)(ctx, { profile: selection2 });
|
|
222
|
+
await (0, import_profiles.initializeDefaultProfile)(ctx, selection2, false);
|
|
223
|
+
}
|
|
224
|
+
if (!await (0, import_profileManagement.bindProfileToDirectory)(ctx, name, false, target))
|
|
225
|
+
return "chooseProject";
|
|
226
|
+
const selection = await (0, import_profiles.getProfileSelection)(ctx, { envFile });
|
|
227
|
+
if (selection?.name !== name) {
|
|
228
|
+
return await ctx.crash({
|
|
229
|
+
exitCode: 1,
|
|
230
|
+
errorType: "invalid filesystem or env vars",
|
|
231
|
+
printedMessage: `Remove the account override from ${selection?.source} before retrying.`
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
ctx._updateBigBrainAuth(await (0, import_profiles.readProfileAuth)(ctx, selection));
|
|
235
|
+
return "retry";
|
|
236
|
+
}
|
|
237
|
+
//# sourceMappingURL=account.js.map
|