@neon/sdk 1.5.0 → 2.0.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/README.md +194 -28
- package/dist/client/client/client.gen.js +1 -3
- package/dist/client/client/client.gen.js.map +1 -1
- package/dist/client/client/utils.gen.js +1 -3
- package/dist/client/client/utils.gen.js.map +1 -1
- package/dist/client/index.d.ts +3 -3
- package/dist/client/index.js +2 -2
- package/dist/client/raw.gen.d.ts +146 -16
- package/dist/client/raw.gen.d.ts.map +1 -1
- package/dist/client/raw.gen.js +8 -3
- package/dist/client/raw.gen.js.map +1 -1
- package/dist/client/sdk.gen.d.ts +137 -78
- package/dist/client/sdk.gen.d.ts.map +1 -1
- package/dist/client/sdk.gen.js +258 -96
- package/dist/client/sdk.gen.js.map +1 -1
- package/dist/client/types.gen.d.ts +1397 -315
- package/dist/client/types.gen.d.ts.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/neon/client.d.ts +2 -0
- package/dist/neon/client.d.ts.map +1 -1
- package/dist/neon/client.js +2 -0
- package/dist/neon/client.js.map +1 -1
- package/dist/neon/context.js +2 -1
- package/dist/neon/context.js.map +1 -1
- package/dist/neon/coverage.d.ts.map +1 -1
- package/dist/neon/coverage.js +12 -2
- package/dist/neon/coverage.js.map +1 -1
- package/dist/neon/paginate.d.ts.map +1 -1
- package/dist/neon/paginate.js +5 -2
- package/dist/neon/paginate.js.map +1 -1
- package/dist/neon/resources/branches.d.ts +0 -7
- package/dist/neon/resources/branches.d.ts.map +1 -1
- package/dist/neon/resources/branches.js +6 -15
- package/dist/neon/resources/branches.js.map +1 -1
- package/dist/neon/resources/logs.d.ts +76 -0
- package/dist/neon/resources/logs.d.ts.map +1 -0
- package/dist/neon/resources/logs.js +90 -0
- package/dist/neon/resources/logs.js.map +1 -0
- package/dist/neon/resources/postgres.js +2 -1
- package/dist/neon/resources/postgres.js.map +1 -1
- package/dist/neon/resources/projects.d.ts +61 -4
- package/dist/neon/resources/projects.d.ts.map +1 -1
- package/dist/neon/resources/projects.js +71 -5
- package/dist/neon/resources/projects.js.map +1 -1
- package/dist/raw.d.ts +3 -3
- package/dist/raw.js +8 -3
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coverage.js","names":[],"sources":["../../src/neon/coverage.ts"],"sourcesContent":["/**\n * Drift guard for the ergonomic layer.\n *\n * The raw layer is regenerated from the OpenAPI spec, so it auto-tracks new endpoints.\n * The ergonomic resource namespaces are hand-authored, so they can silently fall behind.\n * `coverage.test.ts` compares the generated operation set against {@link EXPECTED_OPERATIONS}\n * and fails CI when they differ — forcing a conscious decision on every spec change:\n * either wrap the new operation in a resource (and add it to {@link WRAPPED}) or accept\n * that it stays raw-only (and add it to the snapshot below).\n *\n * Workflow when the test fails after a `pnpm generate`:\n * 1. Review the `added` / `removed` operations the test reports.\n * 2. Wrap the ones worth ergonomic treatment (and list them in {@link WRAPPED}).\n * 3. Update {@link EXPECTED_OPERATIONS} to match the new generated set.\n */\n\n/** Operations surfaced by the ergonomic `createNeonClient` namespaces. */\nexport const WRAPPED: ReadonlySet<string> = new Set([\n\t// projects\n\t\"listProjects\",\n\t\"getProject\",\n\t\"createProject\",\n\t\"updateProject\",\n\t\"deleteProject\",\n\t// projects: transfer\n\t\"transferProjectsFromOrgToOrg\",\n\t\"transferProjectsFromUserToOrg\",\n\t// projects: recover + permissions\n\t\"recoverProject\",\n\t\"listProjectPermissions\",\n\t\"grantPermissionToProject\",\n\t\"revokePermissionFromProject\",\n\t// branches\n\t\"listProjectBranches\",\n\t\"getProjectBranch\",\n\t\"createProjectBranch\",\n\t\"updateProjectBranch\",\n\t\"deleteProjectBranch\",\n\t\"setDefaultProjectBranch\",\n\t\"finalizeRestoreBranch\",\n\t\"recoverProjectBranch\",\n\t// neon auth (branch-scoped)\n\t\"getNeonAuth\",\n\t\"createNeonAuth\",\n\t\"disableNeonAuth\",\n\t\"updateNeonAuthConfig\",\n\t\"listBranchNeonAuthOauthProviders\",\n\t\"addBranchNeonAuthOauthProvider\",\n\t\"updateBranchNeonAuthOauthProvider\",\n\t\"deleteBranchNeonAuthOauthProvider\",\n\t\"listBranchNeonAuthTrustedDomains\",\n\t\"addBranchNeonAuthTrustedDomain\",\n\t\"deleteBranchNeonAuthTrustedDomain\",\n\t\"createBranchNeonAuthNewUser\",\n\t\"deleteBranchNeonAuthUser\",\n\t\"updateNeonAuthUserRole\",\n\t// storage\n\t\"getProjectBranchStorage\",\n\t\"listProjectBranchBuckets\",\n\t\"createProjectBranchBucket\",\n\t\"deleteProjectBranchBucket\",\n\t\"listProjectBranchBucketObjects\",\n\t\"getProjectBranchBucketObject\",\n\t\"deleteProjectBranchBucketObject\",\n\t\"deleteProjectBranchBucketObjectsByPrefix\",\n\t\"presignProjectBranchBucketObject\",\n\t// ai gateway\n\t\"getProjectBranchAiGateway\",\n\t// credentials\n\t\"listCredentials\",\n\t\"createCredential\",\n\t\"revokeCredential\",\n\t// functions\n\t\"listProjectBranchFunctions\",\n\t\"getProjectBranchFunction\",\n\t\"updateProjectBranchFunction\",\n\t\"deleteProjectBranchFunction\",\n\t\"createProjectBranchFunctionDeployment\",\n\t// operations\n\t\"getProjectOperation\",\n\t\"listProjectOperations\",\n\t// postgres: endpoints\n\t\"listProjectEndpoints\",\n\t\"listProjectBranchEndpoints\",\n\t\"getProjectEndpoint\",\n\t\"createProjectEndpoint\",\n\t\"updateProjectEndpoint\",\n\t\"deleteProjectEndpoint\",\n\t\"startProjectEndpoint\",\n\t\"suspendProjectEndpoint\",\n\t\"restartProjectEndpoint\",\n\t// postgres: databases\n\t\"listProjectBranchDatabases\",\n\t\"getProjectBranchDatabase\",\n\t\"createProjectBranchDatabase\",\n\t\"updateProjectBranchDatabase\",\n\t\"deleteProjectBranchDatabase\",\n\t// postgres: roles\n\t\"listProjectBranchRoles\",\n\t\"getProjectBranchRole\",\n\t\"createProjectBranchRole\",\n\t\"deleteProjectBranchRole\",\n\t\"getProjectBranchRolePassword\",\n\t\"resetProjectBranchRolePassword\",\n\t// postgres: connection string + data api\n\t\"getConnectionUri\",\n\t\"getProjectBranchDataApi\",\n\t\"createProjectBranchDataApi\",\n\t\"updateProjectBranchDataApi\",\n\t\"deleteProjectBranchDataApi\",\n\t// snapshots\n\t\"listSnapshots\",\n\t\"createSnapshot\",\n\t\"updateSnapshot\",\n\t\"deleteSnapshot\",\n\t\"restoreSnapshot\",\n\t\"getSnapshotSchedule\",\n\t\"setSnapshotSchedule\",\n\t// consumption\n\t\"getConsumptionHistoryPerProject\",\n\t\"getConsumptionHistoryPerProjectV2\",\n\t\"getConsumptionHistoryPerBranchV2\",\n\t// account\n\t\"getCurrentUserInfo\",\n\t\"getCurrentUserOrganizations\",\n\t\"getActiveRegions\",\n\t\"listApiKeys\",\n\t\"createApiKey\",\n\t\"revokeApiKey\",\n]);\n\n/**\n * Committed snapshot of every operation the generated client exposes. Update this\n * deliberately whenever the spec (and thus the generated client) changes.\n */\nexport const EXPECTED_OPERATIONS: ReadonlySet<string> = new Set([\n\t\"acceptProjectTransferRequest\",\n\t\"addBranchNeonAuthOauthProvider\",\n\t\"addBranchNeonAuthTrustedDomain\",\n\t\"addNeonAuthDomainToRedirectUriWhitelist\",\n\t\"addNeonAuthOauthProvider\",\n\t\"addProjectJwks\",\n\t\"assignOrganizationVpcEndpoint\",\n\t\"assignProjectVpcEndpoint\",\n\t\"countProjectBranches\",\n\t\"createApiKey\",\n\t\"createBranchNeonAuthNewUser\",\n\t\"createCredential\",\n\t\"createNeonAuth\",\n\t\"createNeonAuthIntegration\",\n\t\"createNeonAuthNewUser\",\n\t\"createNeonAuthProviderSdkKeys\",\n\t\"createOrgApiKey\",\n\t\"createOrganizationInvitations\",\n\t\"createProject\",\n\t\"createProjectBranch\",\n\t\"createProjectBranchBucket\",\n\t\"createProjectBranchAnonymized\",\n\t\"createProjectBranchDataApi\",\n\t\"createProjectBranchDatabase\",\n\t\"createProjectBranchFunctionDeployment\",\n\t\"createProjectBranchRole\",\n\t\"createProjectEndpoint\",\n\t\"createProjectTransferRequest\",\n\t\"createSnapshot\",\n\t\"deleteBranchNeonAuthOauthProvider\",\n\t\"deleteBranchNeonAuthTrustedDomain\",\n\t\"deleteBranchNeonAuthUser\",\n\t\"deleteNeonAuthDomainFromRedirectUriWhitelist\",\n\t\"deleteNeonAuthIntegration\",\n\t\"deleteNeonAuthOauthProvider\",\n\t\"deleteNeonAuthUser\",\n\t\"deleteOrganizationSpendingLimit\",\n\t\"deleteOrganizationVpcEndpoint\",\n\t\"deleteProject\",\n\t\"deleteProjectBranch\",\n\t\"deleteProjectBranchBucket\",\n\t\"deleteProjectBranchBucketObject\",\n\t\"deleteProjectBranchBucketObjectsByPrefix\",\n\t\"deleteProjectBranchDataApi\",\n\t\"deleteProjectBranchDatabase\",\n\t\"deleteProjectBranchFunction\",\n\t\"deleteProjectBranchRole\",\n\t\"deleteProjectEndpoint\",\n\t\"deleteProjectJwks\",\n\t\"deleteProjectVpcEndpoint\",\n\t\"deleteSnapshot\",\n\t\"disableNeonAuth\",\n\t\"finalizeRestoreBranch\",\n\t\"getActiveRegions\",\n\t\"getAnonymizedBranchStatus\",\n\t\"getAuthDetails\",\n\t\"getAvailablePreloadLibraries\",\n\t\"getConnectionUri\",\n\t\"getConsumptionHistoryPerBranchV2\",\n\t\"getConsumptionHistoryPerProject\",\n\t\"getConsumptionHistoryPerProjectV2\",\n\t\"getCurrentUserInfo\",\n\t\"getCurrentUserOrganizations\",\n\t\"getMaskingRules\",\n\t\"getNeonAuth\",\n\t\"getNeonAuthAllowLocalhost\",\n\t\"getNeonAuthEmailAndPasswordConfig\",\n\t\"getNeonAuthEmailProvider\",\n\t\"getNeonAuthEmailServer\",\n\t\"getNeonAuthPhoneNumberPlugin\",\n\t\"getNeonAuthPluginConfigs\",\n\t\"getNeonAuthWebhookConfig\",\n\t\"getOrganization\",\n\t\"getOrganizationInvitations\",\n\t\"getOrganizationMember\",\n\t\"getOrganizationMembers\",\n\t\"getOrganizationSpendingLimit\",\n\t\"getOrganizationVpcEndpointDetails\",\n\t\"getProject\",\n\t\"getProjectAdvisorSecurityIssues\",\n\t\"getProjectBranch\",\n\t\"getProjectBranchAiGateway\",\n\t\"getProjectBranchBucketObject\",\n\t\"getProjectBranchDataApi\",\n\t\"getProjectBranchDatabase\",\n\t\"getProjectBranchFunction\",\n\t\"getProjectBranchRole\",\n\t\"getProjectBranchRolePassword\",\n\t\"getProjectBranchSchema\",\n\t\"getProjectBranchSchemaComparison\",\n\t\"getProjectBranchStorage\",\n\t\"getProjectEndpoint\",\n\t\"getProjectJwks\",\n\t\"getProjectOperation\",\n\t\"getSnapshotSchedule\",\n\t\"grantPermissionToProject\",\n\t\"listApiKeys\",\n\t\"listBranchNeonAuthOauthProviders\",\n\t\"listBranchNeonAuthTrustedDomains\",\n\t\"listCredentials\",\n\t\"listNeonAuthIntegrations\",\n\t\"listNeonAuthOauthProviders\",\n\t\"listNeonAuthRedirectUriWhitelistDomains\",\n\t\"listOrgApiKeys\",\n\t\"listOrganizationVpcEndpoints\",\n\t\"listOrganizationVpcEndpointsAllRegions\",\n\t\"listProjectBranchDatabases\",\n\t\"listProjectBranchBucketObjects\",\n\t\"listProjectBranchBuckets\",\n\t\"listProjectBranchEndpoints\",\n\t\"listProjectBranchRoles\",\n\t\"listProjectBranchFunctions\",\n\t\"listProjectBranches\",\n\t\"listProjectEndpoints\",\n\t\"listProjectOperations\",\n\t\"listProjectPermissions\",\n\t\"listProjectVpcEndpoints\",\n\t\"listProjects\",\n\t\"listSharedProjects\",\n\t\"listSnapshots\",\n\t\"presignProjectBranchBucketObject\",\n\t\"recoverProject\",\n\t\"recoverProjectBranch\",\n\t\"removeOrganizationMember\",\n\t\"resetProjectBranchRolePassword\",\n\t\"restartProjectEndpoint\",\n\t\"restoreProjectBranch\",\n\t\"restoreSnapshot\",\n\t\"revokeApiKey\",\n\t\"revokeCredential\",\n\t\"revokeOrgApiKey\",\n\t\"revokePermissionFromProject\",\n\t\"sendNeonAuthTestEmail\",\n\t\"setDefaultProjectBranch\",\n\t\"setOrganizationSpendingLimit\",\n\t\"setSnapshotSchedule\",\n\t\"startAnonymization\",\n\t\"startProjectEndpoint\",\n\t\"suspendProjectEndpoint\",\n\t\"transferNeonAuthProviderProject\",\n\t\"transferProjectsFromOrgToOrg\",\n\t\"transferProjectsFromUserToOrg\",\n\t\"updateBranchNeonAuthOauthProvider\",\n\t\"updateMaskingRules\",\n\t\"updateNeonAuthAllowLocalhost\",\n\t\"updateNeonAuthConfig\",\n\t\"updateNeonAuthEmailAndPasswordConfig\",\n\t\"updateNeonAuthEmailProvider\",\n\t\"updateNeonAuthEmailServer\",\n\t\"updateNeonAuthMagicLinkPlugin\",\n\t\"updateNeonAuthOauthProvider\",\n\t\"updateNeonAuthOrganizationPlugin\",\n\t\"updateNeonAuthPhoneNumberPlugin\",\n\t\"updateNeonAuthUserRole\",\n\t\"updateNeonAuthWebhookConfig\",\n\t\"updateOrganizationMember\",\n\t\"updateProject\",\n\t\"updateProjectBranch\",\n\t\"updateProjectBranchDataApi\",\n\t\"updateProjectBranchDatabase\",\n\t\"updateProjectBranchFunction\",\n\t\"updateProjectEndpoint\",\n\t\"updateSnapshot\",\n]);\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,MAAa,0BAA+B,IAAI,IAAI;CAEnD;CACA;CACA;CACA;CACA;CAEA;CACA;CAEA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CAEA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CAEA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;AACD,CAAC;;;;;AAMD,MAAa,sCAA2C,IAAI,IAAI;CAC/D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD,CAAC"}
|
|
1
|
+
{"version":3,"file":"coverage.js","names":[],"sources":["../../src/neon/coverage.ts"],"sourcesContent":["/**\n * Drift guard for the ergonomic layer.\n *\n * The raw layer is regenerated from the OpenAPI spec, so it auto-tracks new endpoints.\n * The ergonomic resource namespaces are hand-authored, so they can silently fall behind.\n * `coverage.test.ts` compares the generated operation set against {@link EXPECTED_OPERATIONS}\n * and fails CI when they differ — forcing a conscious decision on every spec change:\n * either wrap the new operation in a resource (and add it to {@link WRAPPED}) or accept\n * that it stays raw-only (and add it to the snapshot below).\n *\n * Workflow when the test fails after a `pnpm generate`:\n * 1. Review the `added` / `removed` operations the test reports.\n * 2. Wrap the ones worth ergonomic treatment (and list them in {@link WRAPPED}).\n * 3. Update {@link EXPECTED_OPERATIONS} to match the new generated set.\n */\n\n/** Operations surfaced by the ergonomic `createNeonClient` namespaces. */\nexport const WRAPPED: ReadonlySet<string> = new Set([\n\t// projects\n\t\"listProjects\",\n\t\"getProject\",\n\t\"createProject\",\n\t\"updateProject\",\n\t\"deleteProject\",\n\t// projects: transfer\n\t\"transferProjectsFromOrgToOrg\",\n\t\"transferProjectsFromUserToOrg\",\n\t// projects: recover + permissions\n\t\"recoverProject\",\n\t\"listProjectPermissions\",\n\t\"grantPermissionToProject\",\n\t\"revokePermissionFromProject\",\n\t// projects: org member roles\n\t\"listProjectMembers\",\n\t\"setProjectMemberRole\",\n\t\"removeProjectMemberRole\",\n\t// branches\n\t\"listProjectBranches\",\n\t\"getProjectBranch\",\n\t\"createProjectBranch\",\n\t\"updateProjectBranch\",\n\t\"deleteProjectBranch\",\n\t\"setDefaultProjectBranch\",\n\t\"finalizeRestoreBranch\",\n\t// logs (branch-scoped)\n\t\"queryProjectBranchLogs\",\n\t\"listProjectBranchLogFields\",\n\t\"listProjectBranchLogFieldValues\",\n\t// neon auth (branch-scoped)\n\t\"getNeonAuth\",\n\t\"createNeonAuth\",\n\t\"disableNeonAuth\",\n\t\"updateNeonAuthConfig\",\n\t\"listBranchNeonAuthOauthProviders\",\n\t\"addBranchNeonAuthOauthProvider\",\n\t\"updateBranchNeonAuthOauthProvider\",\n\t\"deleteBranchNeonAuthOauthProvider\",\n\t\"listBranchNeonAuthTrustedDomains\",\n\t\"addBranchNeonAuthTrustedDomain\",\n\t\"deleteBranchNeonAuthTrustedDomain\",\n\t\"createBranchNeonAuthNewUser\",\n\t\"deleteBranchNeonAuthUser\",\n\t\"updateNeonAuthUserRole\",\n\t// storage\n\t\"getProjectBranchStorage\",\n\t\"listProjectBranchBuckets\",\n\t\"createProjectBranchBucket\",\n\t\"deleteProjectBranchBucket\",\n\t\"listProjectBranchBucketObjects\",\n\t\"getProjectBranchBucketObject\",\n\t\"deleteProjectBranchBucketObject\",\n\t\"deleteProjectBranchBucketObjectsByPrefix\",\n\t\"presignProjectBranchBucketObject\",\n\t// ai gateway\n\t\"getProjectBranchAiGateway\",\n\t// credentials\n\t\"listCredentials\",\n\t\"createCredential\",\n\t\"revokeCredential\",\n\t// functions\n\t\"listProjectBranchFunctions\",\n\t\"getProjectBranchFunction\",\n\t\"updateProjectBranchFunction\",\n\t\"deleteProjectBranchFunction\",\n\t\"createProjectBranchFunctionDeployment\",\n\t// operations\n\t\"getProjectOperation\",\n\t\"listProjectOperations\",\n\t// postgres: endpoints\n\t\"listProjectEndpoints\",\n\t\"listProjectBranchEndpoints\",\n\t\"getProjectEndpoint\",\n\t\"createProjectEndpoint\",\n\t\"updateProjectEndpoint\",\n\t\"deleteProjectEndpoint\",\n\t\"startProjectEndpoint\",\n\t\"suspendProjectEndpoint\",\n\t\"restartProjectEndpoint\",\n\t// postgres: databases\n\t\"listProjectBranchDatabases\",\n\t\"getProjectBranchDatabase\",\n\t\"createProjectBranchDatabase\",\n\t\"updateProjectBranchDatabase\",\n\t\"deleteProjectBranchDatabase\",\n\t// postgres: roles\n\t\"listProjectBranchRoles\",\n\t\"getProjectBranchRole\",\n\t\"createProjectBranchRole\",\n\t\"deleteProjectBranchRole\",\n\t\"getProjectBranchRolePassword\",\n\t\"resetProjectBranchRolePassword\",\n\t// postgres: connection string + data api\n\t\"getConnectionUri\",\n\t\"getProjectBranchDataApi\",\n\t\"createProjectBranchDataApi\",\n\t\"updateProjectBranchDataApi\",\n\t\"deleteProjectBranchDataApi\",\n\t// snapshots\n\t\"listSnapshots\",\n\t\"createSnapshot\",\n\t\"updateSnapshot\",\n\t\"deleteSnapshot\",\n\t\"restoreSnapshot\",\n\t\"getSnapshotSchedule\",\n\t\"setSnapshotSchedule\",\n\t// consumption\n\t\"getConsumptionHistoryPerProject\",\n\t\"getConsumptionHistoryPerProjectV2\",\n\t\"getConsumptionHistoryPerBranchV2\",\n\t// account\n\t\"getCurrentUserInfo\",\n\t\"getCurrentUserOrganizations\",\n\t\"getActiveRegions\",\n\t\"listApiKeys\",\n\t\"createApiKey\",\n\t\"revokeApiKey\",\n]);\n\n/**\n * Committed snapshot of every operation the generated client exposes. Update this\n * deliberately whenever the spec (and thus the generated client) changes.\n */\nexport const EXPECTED_OPERATIONS: ReadonlySet<string> = new Set([\n\t\"acceptProjectTransferRequest\",\n\t\"addBranchNeonAuthOauthProvider\",\n\t\"addBranchNeonAuthTrustedDomain\",\n\t\"addNeonAuthDomainToRedirectUriWhitelist\",\n\t\"addNeonAuthOauthProvider\",\n\t\"addProjectJwks\",\n\t\"assignOrganizationVpcEndpoint\",\n\t\"assignProjectVpcEndpoint\",\n\t\"countProjectBranches\",\n\t\"createApiKey\",\n\t\"createBranchNeonAuthNewUser\",\n\t\"createCredential\",\n\t\"createNeonAuth\",\n\t\"createNeonAuthIntegration\",\n\t\"createNeonAuthNewUser\",\n\t\"createNeonAuthProviderSdkKeys\",\n\t\"createOrgApiKey\",\n\t\"createOrganizationInvitations\",\n\t\"createProject\",\n\t\"createProjectBranch\",\n\t\"createProjectBranchBucket\",\n\t\"createProjectBranchAnonymized\",\n\t\"createProjectBranchDataApi\",\n\t\"createProjectBranchDatabase\",\n\t\"createProjectBranchFunctionDeployment\",\n\t\"createProjectBranchRole\",\n\t\"createProjectEndpoint\",\n\t\"createProjectTransferRequest\",\n\t\"createSnapshot\",\n\t\"deleteBranchNeonAuthOauthProvider\",\n\t\"deleteBranchNeonAuthTrustedDomain\",\n\t\"deleteBranchNeonAuthUser\",\n\t\"deleteNeonAuthDomainFromRedirectUriWhitelist\",\n\t\"deleteNeonAuthIntegration\",\n\t\"deleteNeonAuthOauthProvider\",\n\t\"deleteNeonAuthUser\",\n\t\"deleteOrganizationSpendingLimit\",\n\t\"deleteOrganizationVpcEndpoint\",\n\t\"deleteProject\",\n\t\"deleteProjectBranch\",\n\t\"deleteProjectBranchBucket\",\n\t\"deleteProjectBranchBucketObject\",\n\t\"deleteProjectBranchBucketObjectsByPrefix\",\n\t\"deleteProjectBranchDataApi\",\n\t\"deleteProjectBranchDatabase\",\n\t\"deleteProjectBranchFunction\",\n\t\"deleteProjectBranchRole\",\n\t\"deleteProjectEndpoint\",\n\t\"deleteProjectJwks\",\n\t\"deleteProjectVpcEndpoint\",\n\t\"deleteSnapshot\",\n\t\"disableNeonAuth\",\n\t\"finalizeRestoreBranch\",\n\t\"getActiveRegions\",\n\t\"getAnonymizedBranchStatus\",\n\t\"getAuthDetails\",\n\t\"getAvailablePreloadLibraries\",\n\t\"getConnectionUri\",\n\t\"getConsumptionHistoryPerBranchV2\",\n\t\"getConsumptionHistoryPerProject\",\n\t\"getConsumptionHistoryPerProjectV2\",\n\t\"getCurrentUserInfo\",\n\t\"getCurrentUserOrganizations\",\n\t\"getMaskingRules\",\n\t\"getNeonAuth\",\n\t\"getNeonAuthAllowLocalhost\",\n\t\"getNeonAuthEmailAndPasswordConfig\",\n\t\"getNeonAuthEmailProvider\",\n\t\"getNeonAuthEmailServer\",\n\t\"getNeonAuthPhoneNumberPlugin\",\n\t\"getNeonAuthPluginConfigs\",\n\t\"getNeonAuthWebhookConfig\",\n\t\"getOrganization\",\n\t\"getOrganizationInvitations\",\n\t\"getOrganizationMember\",\n\t\"getOrganizationMembers\",\n\t\"getOrganizationSpendingLimit\",\n\t\"getOrganizationVpcEndpointDetails\",\n\t\"getProject\",\n\t\"getProjectAdvisorSecurityIssues\",\n\t\"getProjectBranch\",\n\t\"getProjectBranchAiGateway\",\n\t\"getProjectBranchBucketObject\",\n\t\"getProjectBranchDataApi\",\n\t\"getProjectBranchDatabase\",\n\t\"getProjectBranchFunction\",\n\t\"getProjectBranchRole\",\n\t\"getProjectBranchRolePassword\",\n\t\"getProjectBranchSchema\",\n\t\"getProjectBranchSchemaComparison\",\n\t\"getProjectBranchStorage\",\n\t\"getProjectEndpoint\",\n\t\"getProjectJwks\",\n\t\"getProjectOperation\",\n\t\"getSnapshotSchedule\",\n\t\"grantPermissionToProject\",\n\t\"listApiKeys\",\n\t\"listBranchNeonAuthOauthProviders\",\n\t\"listBranchNeonAuthTrustedDomains\",\n\t\"listCredentials\",\n\t\"listNeonAuthIntegrations\",\n\t\"listNeonAuthOauthProviders\",\n\t\"listNeonAuthRedirectUriWhitelistDomains\",\n\t\"listOrgApiKeys\",\n\t\"listOrganizationVpcEndpoints\",\n\t\"listOrganizationVpcEndpointsAllRegions\",\n\t\"listProjectBranchDatabases\",\n\t\"listProjectBranchBucketObjects\",\n\t\"listProjectBranchBuckets\",\n\t\"listProjectBranchEndpoints\",\n\t\"listProjectBranchRoles\",\n\t\"listProjectBranchFunctions\",\n\t\"listProjectBranchLogFields\",\n\t\"listProjectBranchLogFieldValues\",\n\t\"listProjectBranches\",\n\t\"listProjectEndpoints\",\n\t\"listProjectMembers\",\n\t\"listProjectOperations\",\n\t\"listProjectPermissions\",\n\t\"listProjectVpcEndpoints\",\n\t\"listProjects\",\n\t\"listSharedProjects\",\n\t\"listSnapshots\",\n\t\"presignProjectBranchBucketObject\",\n\t\"queryProjectBranchLogs\",\n\t\"recoverProject\",\n\t\"removeOrganizationMember\",\n\t\"removeProjectMemberRole\",\n\t\"resetProjectBranchRolePassword\",\n\t\"restartProjectEndpoint\",\n\t\"restoreProjectBranch\",\n\t\"restoreSnapshot\",\n\t\"revokeApiKey\",\n\t\"revokeCredential\",\n\t\"revokeOrgApiKey\",\n\t\"revokePermissionFromProject\",\n\t\"sendNeonAuthTestEmail\",\n\t\"setDefaultProjectBranch\",\n\t\"setOrganizationSpendingLimit\",\n\t\"setProjectMemberRole\",\n\t\"setSnapshotSchedule\",\n\t\"startAnonymization\",\n\t\"startProjectEndpoint\",\n\t\"suspendProjectEndpoint\",\n\t\"transferNeonAuthProviderProject\",\n\t\"transferProjectsFromOrgToOrg\",\n\t\"transferProjectsFromUserToOrg\",\n\t\"updateBranchNeonAuthOauthProvider\",\n\t\"updateMaskingRules\",\n\t\"updateNeonAuthAllowLocalhost\",\n\t\"updateNeonAuthConfig\",\n\t\"updateNeonAuthEmailAndPasswordConfig\",\n\t\"updateNeonAuthEmailProvider\",\n\t\"updateNeonAuthEmailServer\",\n\t\"updateNeonAuthMagicLinkPlugin\",\n\t\"updateNeonAuthOauthProvider\",\n\t\"updateNeonAuthOrganizationPlugin\",\n\t\"updateNeonAuthPhoneNumberPlugin\",\n\t\"updateNeonAuthUserRole\",\n\t\"updateNeonAuthWebhookConfig\",\n\t\"updateOrganizationMember\",\n\t\"updateProject\",\n\t\"updateProjectBranch\",\n\t\"updateProjectBranchDataApi\",\n\t\"updateProjectBranchDatabase\",\n\t\"updateProjectBranchFunction\",\n\t\"updateProjectEndpoint\",\n\t\"updateSnapshot\",\n]);\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,MAAa,0BAA+B,IAAI,IAAI;CAEnD;CACA;CACA;CACA;CACA;CAEA;CACA;CAEA;CACA;CACA;CACA;CAEA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CAEA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CAEA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;AACD,CAAC;;;;;AAMD,MAAa,sCAA2C,IAAI,IAAI;CAC/D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paginate.d.ts","names":[],"sources":["../../src/neon/paginate.ts"],"mappings":";;;;UAIiB;SACT;EADS;EAMP,MAAA,CAAA,EAAA,MAAS;AAAA;AACX,UADE,SACF,CAAA,CAAA,CAAA,CAAA;EAEI,IAAA,CAAA,EAFJ,CAEI,GAAA,SAAA;EAAQ,KAAA,CAAA,EAAA,OAAA;EAUH,QAAA,CAAA,EAVL,QAUc,GAAA,SAAA;AAAA;AAA0B;AAEJ;AAAL;AAAX;AAAR;AAEG;AAAX;AAAR,UAJS,SAIT,CAAA,CAAA,CAAA,SAJ8B,aAI9B,CAJ4C,CAI5C,CAAA,CAAA;EAJ8B;EAAa,IAAA,CAAA,MAAA,CAAA,EAAA,MAAA,CAAA,EAE3B,OAF2B,CAEnB,UAFmB,CAER,IAFQ,CAEH,CAFG,CAAA,CAAA,CAAA;
|
|
1
|
+
{"version":3,"file":"paginate.d.ts","names":[],"sources":["../../src/neon/paginate.ts"],"mappings":";;;;UAIiB;SACT;EADS;EAMP,MAAA,CAAA,EAAA,MAAS;AAAA;AACX,UADE,SACF,CAAA,CAAA,CAAA,CAAA;EAEI,IAAA,CAAA,EAFJ,CAEI,GAAA,SAAA;EAAQ,KAAA,CAAA,EAAA,OAAA;EAUH,QAAA,CAAA,EAVL,QAUc,GAAA,SAAA;AAAA;AAA0B;AAEJ;AAAL;AAAX;AAAR;AAEG;AAAX;AAAR,UAJS,SAIT,CAAA,CAAA,CAAA,SAJ8B,aAI9B,CAJ4C,CAI5C,CAAA,CAAA;EAJ8B;EAAa,IAAA,CAAA,MAAA,CAAA,EAAA,MAAA,CAAA,EAE3B,OAF2B,CAEnB,UAFmB,CAER,IAFQ,CAEH,CAFG,CAAA,CAAA,CAAA;EAkHnC;EAAQ,GAAA,EAAA,EA9GhB,OA8GgB,CA9GR,UA8GQ,CA9GG,CA8GH,EAAA,CAAA,CAAA;AAGb;AACa;AAAV;AAAR;AACW;AAAW;AAAL;AACH;AACP;AAAV,iBAPa,QAOb,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,SAAA,EAAA,CAAA,MAAA,EAAA,MAAA,GAAA,SAAA,EAAA,MAAA,CAAA,EAJQ,WAIR,EAAA,GAHG,OAGH,CAHW,SAGX,CAHqB,CAGrB,CAAA,CAAA,EAAA,OAAA,EAAA,CAAA,IAAA,EAFc,CAEd,EAAA,GAFoB,IAEpB,CAFyB,CAEzB,CAAA,EAAA,WAAA,EAAA,GAAA,GADiB,QACjB,CAAA,EAAA,SAAA,CAAU,CAAV,CAAA"}
|
package/dist/neon/paginate.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { toNeonError } from "./errors.js";
|
|
1
|
+
import { NeonError, toNeonError } from "./errors.js";
|
|
2
2
|
import { cancelled, runBounded } from "./deadline.js";
|
|
3
3
|
import { err, ok } from "./result.js";
|
|
4
4
|
//#region src/neon/paginate.ts
|
|
@@ -20,7 +20,10 @@ var PaginatedList = class {
|
|
|
20
20
|
}
|
|
21
21
|
const cancellation = cancelled(deadline);
|
|
22
22
|
if (cancellation) return err(cancellation);
|
|
23
|
-
if (raw === void 0 || raw.error || raw.data === void 0)
|
|
23
|
+
if (raw === void 0 || raw.error || raw.data === void 0) {
|
|
24
|
+
if (raw?.error instanceof NeonError) return err(raw.error);
|
|
25
|
+
return err(toNeonError(raw?.error, raw?.response));
|
|
26
|
+
}
|
|
24
27
|
return ok(this.#mapPage(raw.data));
|
|
25
28
|
}
|
|
26
29
|
async page(cursor) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paginate.js","names":["#fetchPage","#mapPage","#newDeadline","#page"],"sources":["../../src/neon/paginate.ts"],"sourcesContent":["import { cancelled, type Deadline, runBounded } from \"./deadline.js\";\nimport { toNeonError } from \"./errors.js\";\nimport { err, type NeonResult, ok } from \"./result.js\";\n\nexport interface Page<T> {\n\titems: T[];\n\t/** Cursor for the next page, when more results exist. */\n\tcursor?: string;\n}\n\ninterface RawResult<D> {\n\tdata?: D | undefined;\n\terror?: unknown;\n\tresponse?: Response | undefined;\n}\n\n/**\n * A lazy, cursor-paginated list. `all()` / `page()` return the `{ data, error }` envelope;\n * the async iterator streams items lazily and throws on a page-fetch error.\n *\n * Note: pagination helpers always use the result envelope (the iterator is the throwing\n * form) regardless of the client's `throwOnError` setting.\n */\nexport interface Paginated<T> extends AsyncIterable<T> {\n\t/** Fetch a single page (optionally from a cursor). */\n\tpage(cursor?: string): Promise<NeonResult<Page<T>>>;\n\t/** Fetch and concatenate every page. */\n\tall(): Promise<NeonResult<T[]>>;\n}\n\nclass PaginatedList<T, D> implements Paginated<T> {\n\treadonly #fetchPage: (\n\t\tcursor: string | undefined,\n\t\tsignal?: AbortSignal,\n\t) => Promise<RawResult<D>>;\n\treadonly #mapPage: (data: D) => Page<T>;\n\treadonly #newDeadline: () => Deadline;\n\n\tconstructor(\n\t\tfetchPage: (\n\t\t\tcursor: string | undefined,\n\t\t\tsignal?: AbortSignal,\n\t\t) => Promise<RawResult<D>>,\n\t\tmapPage: (data: D) => Page<T>,\n\t\tnewDeadline: () => Deadline,\n\t) {\n\t\tthis.#fetchPage = fetchPage;\n\t\tthis.#mapPage = mapPage;\n\t\tthis.#newDeadline = newDeadline;\n\t}\n\n\tasync #page(\n\t\tcursor: string | undefined,\n\t\tdeadline: Deadline,\n\t): Promise<NeonResult<Page<T>>> {\n\t\tlet raw: RawResult<D> | undefined;\n\t\ttry {\n\t\t\t// Bounded the same way the execution core bounds a request: the signal alone\n\t\t\t// does not cover the phases before `fetch` is reached, so a slow auth provider\n\t\t\t// would otherwise outlast the deadline.\n\t\t\traw = await runBounded(deadline, () =>\n\t\t\t\tthis.#fetchPage(cursor, deadline.signal),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\treturn err(cancelled(deadline) ?? toNeonError(error, undefined));\n\t\t}\n\t\tconst cancellation = cancelled(deadline);\n\t\tif (cancellation) return err(cancellation);\n\t\tif (raw === undefined || raw.error || raw.data === undefined) {\n\t\t\treturn err(toNeonError(raw?.error, raw?.response));\n\t\t}\n\t\treturn ok(this.#mapPage(raw.data));\n\t}\n\n\tasync page(cursor?: string): Promise<NeonResult<Page<T>>> {\n\t\tconst deadline = this.#newDeadline();\n\t\ttry {\n\t\t\treturn await this.#page(cursor, deadline);\n\t\t} finally {\n\t\t\tdeadline.dispose();\n\t\t}\n\t}\n\n\t/**\n\t * One deadline covers the whole walk, not each page: `all()` is a single operation\n\t * from the caller's side, and a per-page budget would leave an unbounded number of\n\t * pages unbounded in total.\n\t */\n\tasync all(): Promise<NeonResult<T[]>> {\n\t\tconst deadline = this.#newDeadline();\n\t\ttry {\n\t\t\tconst items: T[] = [];\n\t\t\tlet cursor: string | undefined;\n\t\t\twhile (true) {\n\t\t\t\tconst result = await this.#page(cursor, deadline);\n\t\t\t\tif (result.error) return err(result.error);\n\t\t\t\titems.push(...result.data.items);\n\t\t\t\tif (!result.data.cursor || result.data.items.length === 0)\n\t\t\t\t\tbreak;\n\t\t\t\tcursor = result.data.cursor;\n\t\t\t}\n\t\t\treturn ok(items);\n\t\t} finally {\n\t\t\tdeadline.dispose();\n\t\t}\n\t}\n\n\tasync *[Symbol.asyncIterator](): AsyncIterator<T> {\n\t\tconst deadline = this.#newDeadline();\n\t\ttry {\n\t\t\tlet cursor: string | undefined;\n\t\t\twhile (true) {\n\t\t\t\tconst result = await this.#page(cursor, deadline);\n\t\t\t\tif (result.error) throw result.error;\n\t\t\t\tyield* result.data.items;\n\t\t\t\tif (!result.data.cursor || result.data.items.length === 0)\n\t\t\t\t\tbreak;\n\t\t\t\tcursor = result.data.cursor;\n\t\t\t}\n\t\t} finally {\n\t\t\tdeadline.dispose();\n\t\t}\n\t}\n}\n\n/**\n * Build a {@link Paginated} list from a page fetcher and a page mapper. The response-body\n * type `D` is inferred and erased from the public `Paginated<T>` return.\n *\n * `newDeadline` is called once per consumption — each `page()`, each `all()`, each\n * iteration — because a `Paginated` is lazy and may be consumed more than once, so a\n * deadline created when the list was built would already be spent.\n */\nexport function paginate<T, D>(\n\tfetchPage: (\n\t\tcursor: string | undefined,\n\t\tsignal?: AbortSignal,\n\t) => Promise<RawResult<D>>,\n\tmapPage: (data: D) => Page<T>,\n\tnewDeadline: () => Deadline,\n): Paginated<T> {\n\treturn new PaginatedList(fetchPage, mapPage, newDeadline);\n}\n"],"mappings":";;;;AA8BA,IAAM,gBAAN,MAAkD;CACjD;CAIA;CACA;CAEA,YACC,WAIA,SACA,aACC;EACD,KAAKA,aAAa;EAClB,KAAKC,WAAW;EAChB,KAAKC,eAAe;CACrB;CAEA,MAAMC,MACL,QACA,UAC+B;EAC/B,IAAI;EACJ,IAAI;GAIH,MAAM,MAAM,WAAW,gBACtB,KAAKH,WAAW,QAAQ,SAAS,MAAM,CACxC;EACD,SAAS,OAAO;GACf,OAAO,IAAI,UAAU,QAAQ,KAAK,YAAY,OAAO,KAAA,CAAS,CAAC;EAChE;EACA,MAAM,eAAe,UAAU,QAAQ;EACvC,IAAI,cAAc,OAAO,IAAI,YAAY;EACzC,IAAI,QAAQ,KAAA,KAAa,IAAI,SAAS,IAAI,SAAS,KAAA,
|
|
1
|
+
{"version":3,"file":"paginate.js","names":["#fetchPage","#mapPage","#newDeadline","#page"],"sources":["../../src/neon/paginate.ts"],"sourcesContent":["import { cancelled, type Deadline, runBounded } from \"./deadline.js\";\nimport { NeonError, toNeonError } from \"./errors.js\";\nimport { err, type NeonResult, ok } from \"./result.js\";\n\nexport interface Page<T> {\n\titems: T[];\n\t/** Cursor for the next page, when more results exist. */\n\tcursor?: string;\n}\n\ninterface RawResult<D> {\n\tdata?: D | undefined;\n\terror?: unknown;\n\tresponse?: Response | undefined;\n}\n\n/**\n * A lazy, cursor-paginated list. `all()` / `page()` return the `{ data, error }` envelope;\n * the async iterator streams items lazily and throws on a page-fetch error.\n *\n * Note: pagination helpers always use the result envelope (the iterator is the throwing\n * form) regardless of the client's `throwOnError` setting.\n */\nexport interface Paginated<T> extends AsyncIterable<T> {\n\t/** Fetch a single page (optionally from a cursor). */\n\tpage(cursor?: string): Promise<NeonResult<Page<T>>>;\n\t/** Fetch and concatenate every page. */\n\tall(): Promise<NeonResult<T[]>>;\n}\n\nclass PaginatedList<T, D> implements Paginated<T> {\n\treadonly #fetchPage: (\n\t\tcursor: string | undefined,\n\t\tsignal?: AbortSignal,\n\t) => Promise<RawResult<D>>;\n\treadonly #mapPage: (data: D) => Page<T>;\n\treadonly #newDeadline: () => Deadline;\n\n\tconstructor(\n\t\tfetchPage: (\n\t\t\tcursor: string | undefined,\n\t\t\tsignal?: AbortSignal,\n\t\t) => Promise<RawResult<D>>,\n\t\tmapPage: (data: D) => Page<T>,\n\t\tnewDeadline: () => Deadline,\n\t) {\n\t\tthis.#fetchPage = fetchPage;\n\t\tthis.#mapPage = mapPage;\n\t\tthis.#newDeadline = newDeadline;\n\t}\n\n\tasync #page(\n\t\tcursor: string | undefined,\n\t\tdeadline: Deadline,\n\t): Promise<NeonResult<Page<T>>> {\n\t\tlet raw: RawResult<D> | undefined;\n\t\ttry {\n\t\t\t// Bounded the same way the execution core bounds a request: the signal alone\n\t\t\t// does not cover the phases before `fetch` is reached, so a slow auth provider\n\t\t\t// would otherwise outlast the deadline.\n\t\t\traw = await runBounded(deadline, () =>\n\t\t\t\tthis.#fetchPage(cursor, deadline.signal),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\treturn err(cancelled(deadline) ?? toNeonError(error, undefined));\n\t\t}\n\t\tconst cancellation = cancelled(deadline);\n\t\tif (cancellation) return err(cancellation);\n\t\tif (raw === undefined || raw.error || raw.data === undefined) {\n\t\t\t// A fetcher that already classified the failure keeps its own error.\n\t\t\t// Re-deriving one from the response would mislabel a fault the SDK\n\t\t\t// found in a 200 body as an API error with a 2xx status.\n\t\t\tif (raw?.error instanceof NeonError) return err(raw.error);\n\t\t\treturn err(toNeonError(raw?.error, raw?.response));\n\t\t}\n\t\treturn ok(this.#mapPage(raw.data));\n\t}\n\n\tasync page(cursor?: string): Promise<NeonResult<Page<T>>> {\n\t\tconst deadline = this.#newDeadline();\n\t\ttry {\n\t\t\treturn await this.#page(cursor, deadline);\n\t\t} finally {\n\t\t\tdeadline.dispose();\n\t\t}\n\t}\n\n\t/**\n\t * One deadline covers the whole walk, not each page: `all()` is a single operation\n\t * from the caller's side, and a per-page budget would leave an unbounded number of\n\t * pages unbounded in total.\n\t */\n\tasync all(): Promise<NeonResult<T[]>> {\n\t\tconst deadline = this.#newDeadline();\n\t\ttry {\n\t\t\tconst items: T[] = [];\n\t\t\tlet cursor: string | undefined;\n\t\t\twhile (true) {\n\t\t\t\tconst result = await this.#page(cursor, deadline);\n\t\t\t\tif (result.error) return err(result.error);\n\t\t\t\titems.push(...result.data.items);\n\t\t\t\tif (!result.data.cursor || result.data.items.length === 0)\n\t\t\t\t\tbreak;\n\t\t\t\tcursor = result.data.cursor;\n\t\t\t}\n\t\t\treturn ok(items);\n\t\t} finally {\n\t\t\tdeadline.dispose();\n\t\t}\n\t}\n\n\tasync *[Symbol.asyncIterator](): AsyncIterator<T> {\n\t\tconst deadline = this.#newDeadline();\n\t\ttry {\n\t\t\tlet cursor: string | undefined;\n\t\t\twhile (true) {\n\t\t\t\tconst result = await this.#page(cursor, deadline);\n\t\t\t\tif (result.error) throw result.error;\n\t\t\t\tyield* result.data.items;\n\t\t\t\tif (!result.data.cursor || result.data.items.length === 0)\n\t\t\t\t\tbreak;\n\t\t\t\tcursor = result.data.cursor;\n\t\t\t}\n\t\t} finally {\n\t\t\tdeadline.dispose();\n\t\t}\n\t}\n}\n\n/**\n * Build a {@link Paginated} list from a page fetcher and a page mapper. The response-body\n * type `D` is inferred and erased from the public `Paginated<T>` return.\n *\n * `newDeadline` is called once per consumption — each `page()`, each `all()`, each\n * iteration — because a `Paginated` is lazy and may be consumed more than once, so a\n * deadline created when the list was built would already be spent.\n */\nexport function paginate<T, D>(\n\tfetchPage: (\n\t\tcursor: string | undefined,\n\t\tsignal?: AbortSignal,\n\t) => Promise<RawResult<D>>,\n\tmapPage: (data: D) => Page<T>,\n\tnewDeadline: () => Deadline,\n): Paginated<T> {\n\treturn new PaginatedList(fetchPage, mapPage, newDeadline);\n}\n"],"mappings":";;;;AA8BA,IAAM,gBAAN,MAAkD;CACjD;CAIA;CACA;CAEA,YACC,WAIA,SACA,aACC;EACD,KAAKA,aAAa;EAClB,KAAKC,WAAW;EAChB,KAAKC,eAAe;CACrB;CAEA,MAAMC,MACL,QACA,UAC+B;EAC/B,IAAI;EACJ,IAAI;GAIH,MAAM,MAAM,WAAW,gBACtB,KAAKH,WAAW,QAAQ,SAAS,MAAM,CACxC;EACD,SAAS,OAAO;GACf,OAAO,IAAI,UAAU,QAAQ,KAAK,YAAY,OAAO,KAAA,CAAS,CAAC;EAChE;EACA,MAAM,eAAe,UAAU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AAgB,SACf,WAIA,SACA,aACe;CACf,OAAO,IAAI,cAAc,WAAW,SAAS,WAAW;AACzD"}
|
|
@@ -78,13 +78,6 @@ declare class Branches<DThrow extends boolean> {
|
|
|
78
78
|
finalizeRestore<Throw extends boolean = DThrow>(projectId: string, branchId: string, input: {
|
|
79
79
|
name?: string;
|
|
80
80
|
} | undefined, opts: CallOptions<Throw>): Promise<Outcome<void, Throw>>;
|
|
81
|
-
/**
|
|
82
|
-
* Recover a soft-deleted branch within the 7-day recovery window.
|
|
83
|
-
*
|
|
84
|
-
* @apiCall POST /projects/{project_id}/branches/{branch_id}/recover
|
|
85
|
-
*/
|
|
86
|
-
recover(projectId: string, branchId: string): Promise<Outcome<Branch, DThrow>>;
|
|
87
|
-
recover<Throw extends boolean = DThrow>(projectId: string, branchId: string, opts: CallOptions<Throw>): Promise<Outcome<Branch, Throw>>;
|
|
88
81
|
}
|
|
89
82
|
//#endregion
|
|
90
83
|
export { BranchWithCompute, Branches, CreateWithComputeInput };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"branches.d.ts","names":[],"sources":["../../../src/neon/resources/branches.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"branches.d.ts","names":[],"sources":["../../../src/neon/resources/branches.ts"],"mappings":";;;;;;KAsBK,SAAA,GAAY,KAAK,YAAY;KAC7B,WAAA,GAAc,YAAY;AAHiD,KAI3E,WAAA,GAAc,mBAFL,CAAA,QAAA,CAAA;AAAA;AAAoB,UAKxB,eALwB,CAAA,cAAA,OAAA,CAAA,SAKuB,WALvB,CAKmC,KALnC,CAAA,CAAA;EAAZ;EAAL,MAAA,CAAA,EAAA,OAAA;AAAI;AAAA;AACL,UAUC,sBAAA,CAVD;EAAe,IAAA,CAAA,EAAA,MAAA;EAAZ;EAAW,QAAA,CAAA,EAAA,MAAA;EACzB;EAGK,OAAA,CAAA,EAAA;IAAe,KAAA,CAAA,EAAA,MAAA;IAA4C,KAAA,CAAA,EAAA,MAAA;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|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NeonError } from "../errors.js";
|
|
2
2
|
import { err, finalize, ok } from "../result.js";
|
|
3
|
-
import { createProjectBranch, deleteProjectBranch, finalizeRestoreBranch, getProjectBranch, listProjectBranches,
|
|
3
|
+
import { createProjectBranch, deleteProjectBranch, finalizeRestoreBranch, getProjectBranch, listProjectBranches, setDefaultProjectBranch, updateProjectBranch } from "../../client/sdk.gen.js";
|
|
4
4
|
import { withConnectionString } from "../connection.js";
|
|
5
5
|
import { paginate } from "../paginate.js";
|
|
6
6
|
//#region src/neon/resources/branches.ts
|
|
@@ -71,7 +71,7 @@ var Branches = class {
|
|
|
71
71
|
}
|
|
72
72
|
async createWithCompute(projectId, input, opts) {
|
|
73
73
|
const shouldThrow = opts?.throwOnError ?? this.#ctx.defaults.throwOnError;
|
|
74
|
-
|
|
74
|
+
const result = await this.#ctx.execute({
|
|
75
75
|
...opts,
|
|
76
76
|
waitForReadiness: opts?.waitForReadiness ?? true
|
|
77
77
|
}, (client, signal) => createProjectBranch({
|
|
@@ -91,11 +91,13 @@ var Branches = class {
|
|
|
91
91
|
},
|
|
92
92
|
throwOnError: false,
|
|
93
93
|
signal
|
|
94
|
-
}), (data) => data)
|
|
94
|
+
}), (data) => data);
|
|
95
|
+
const out = withConnectionString(result, (data) => data.connection_uris, (data, connectionString) => ({
|
|
95
96
|
branch: data.branch,
|
|
96
97
|
endpoint: data.endpoints[0],
|
|
97
98
|
connectionString
|
|
98
|
-
}), opts?.pooled ?? true)
|
|
99
|
+
}), opts?.pooled ?? true);
|
|
100
|
+
return finalize(out, shouldThrow);
|
|
99
101
|
}
|
|
100
102
|
async getDefault(projectId, opts) {
|
|
101
103
|
const shouldThrow = opts?.throwOnError ?? this.#ctx.defaults.throwOnError;
|
|
@@ -133,17 +135,6 @@ var Branches = class {
|
|
|
133
135
|
signal
|
|
134
136
|
}), () => void 0);
|
|
135
137
|
}
|
|
136
|
-
recover(projectId, branchId, opts) {
|
|
137
|
-
return this.#ctx.run(opts, (client, signal) => recoverProjectBranch({
|
|
138
|
-
client,
|
|
139
|
-
path: {
|
|
140
|
-
project_id: projectId,
|
|
141
|
-
branch_id: branchId
|
|
142
|
-
},
|
|
143
|
-
throwOnError: false,
|
|
144
|
-
signal
|
|
145
|
-
}), (data) => data.branch);
|
|
146
|
-
}
|
|
147
138
|
};
|
|
148
139
|
//#endregion
|
|
149
140
|
export { Branches };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"branches.js","names":["#ctx"],"sources":["../../../src/neon/resources/branches.ts"],"sourcesContent":["import {\n\tcreateProjectBranch,\n\tdeleteProjectBranch,\n\tfinalizeRestoreBranch,\n\tgetProjectBranch,\n\tlistProjectBranches,\n\trecoverProjectBranch,\n\tsetDefaultProjectBranch,\n\tupdateProjectBranch,\n} from \"../../client/sdk.gen.js\";\nimport type {\n\tBranch,\n\tBranchCreateRequest,\n\tBranchUpdateRequest,\n\tEndpoint,\n\tListProjectBranchesData,\n} from \"../../client/types.gen.js\";\nimport { withConnectionString } from \"../connection.js\";\nimport type { CallOptions, RequestContext } from \"../context.js\";\nimport { NeonError } from \"../errors.js\";\nimport { type Paginated, paginate } from \"../paginate.js\";\nimport { err, finalize, type NeonResult, type Outcome, ok } from \"../result.js\";\n\ntype ListQuery = Omit<NonNullable<ListProjectBranchesData[\"query\"]>, \"cursor\">;\ntype CreateInput = NonNullable<BranchCreateRequest[\"branch\"]>;\ntype UpdateInput = BranchUpdateRequest[\"branch\"];\n\n/** Per-call options for the connect/compute workflows. */\ninterface WorkflowOptions<Throw extends boolean> extends CallOptions<Throw> {\n\t/** Return a pooled connection string (default `true`). */\n\tpooled?: boolean;\n}\n\n/** Input for {@link Branches.createWithCompute}. */\nexport interface CreateWithComputeInput {\n\tname?: string;\n\t/** Parent branch id. Defaults to the project's default branch. */\n\tparentId?: string;\n\t/** Autoscaling settings for the branch's read-write endpoint. */\n\tcompute?: {\n\t\tminCu?: number;\n\t\tmaxCu?: number;\n\t\tsuspendTimeoutSeconds?: number;\n\t};\n}\n\n/** A branch with its read-write endpoint and a ready-to-use connection string. */\nexport interface BranchWithCompute {\n\tbranch: Branch;\n\tendpoint: Endpoint;\n\tconnectionString: string;\n}\n\n/** Branch resource — one API call per CRUD method, plus the `createWithCompute` workflow. */\nexport class Branches<DThrow extends boolean> {\n\treadonly #ctx: RequestContext;\n\n\tconstructor(ctx: RequestContext) {\n\t\tthis.#ctx = ctx;\n\t}\n\n\t/** @apiCall GET /projects/{project_id}/branches (cursor-paginated) */\n\tlist(\n\t\tprojectId: string,\n\t\tquery?: ListQuery,\n\t\topts?: CallOptions,\n\t): Paginated<Branch> {\n\t\treturn paginate(\n\t\t\t(cursor, signal) =>\n\t\t\t\tlistProjectBranches({\n\t\t\t\t\tclient: this.#ctx.client,\n\t\t\t\t\tpath: { project_id: projectId },\n\t\t\t\t\tquery: { ...query, cursor },\n\t\t\t\t\tthrowOnError: false,\n\t\t\t\t\tsignal,\n\t\t\t\t}),\n\t\t\t(data) => ({\n\t\t\t\titems: data?.branches ?? [],\n\t\t\t\tcursor: data?.pagination?.next,\n\t\t\t}),\n\t\t\t() => this.#ctx.deadlineFor(opts),\n\t\t);\n\t}\n\n\t/** @apiCall GET /projects/{project_id}/branches/{branch_id} */\n\tget(projectId: string, branchId: string): Promise<Outcome<Branch, DThrow>>;\n\tget<Throw extends boolean = DThrow>(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\topts: CallOptions<Throw>,\n\t): Promise<Outcome<Branch, Throw>>;\n\tget(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\topts?: CallOptions,\n\t): Promise<Branch | NeonResult<Branch>> {\n\t\treturn this.#ctx.run(\n\t\t\topts,\n\t\t\t(client, signal) =>\n\t\t\t\tgetProjectBranch({\n\t\t\t\t\tclient,\n\t\t\t\t\tpath: { project_id: projectId, branch_id: branchId },\n\t\t\t\t\tthrowOnError: false,\n\t\t\t\t\tsignal,\n\t\t\t\t}),\n\t\t\t(data) => data.branch,\n\t\t);\n\t}\n\n\t/** @apiCall POST /projects/{project_id}/branches */\n\tcreate(\n\t\tprojectId: string,\n\t\tinput?: CreateInput,\n\t): Promise<Outcome<Branch, DThrow>>;\n\tcreate<Throw extends boolean = DThrow>(\n\t\tprojectId: string,\n\t\tinput: CreateInput | undefined,\n\t\topts: CallOptions<Throw>,\n\t): Promise<Outcome<Branch, Throw>>;\n\tcreate(\n\t\tprojectId: string,\n\t\tinput?: CreateInput,\n\t\topts?: CallOptions,\n\t): Promise<Branch | NeonResult<Branch>> {\n\t\treturn this.#ctx.run(\n\t\t\topts,\n\t\t\t(client, signal) =>\n\t\t\t\tcreateProjectBranch({\n\t\t\t\t\tclient,\n\t\t\t\t\tpath: { project_id: projectId },\n\t\t\t\t\tbody: { branch: input },\n\t\t\t\t\tthrowOnError: false,\n\t\t\t\t\tsignal,\n\t\t\t\t}),\n\t\t\t(data) => data.branch,\n\t\t);\n\t}\n\n\t/** @apiCall PATCH /projects/{project_id}/branches/{branch_id} */\n\tupdate(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\tinput: UpdateInput,\n\t): Promise<Outcome<Branch, DThrow>>;\n\tupdate<Throw extends boolean = DThrow>(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\tinput: UpdateInput,\n\t\topts: CallOptions<Throw>,\n\t): Promise<Outcome<Branch, Throw>>;\n\tupdate(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\tinput: UpdateInput,\n\t\topts?: CallOptions,\n\t): Promise<Branch | NeonResult<Branch>> {\n\t\treturn this.#ctx.run(\n\t\t\topts,\n\t\t\t(client, signal) =>\n\t\t\t\tupdateProjectBranch({\n\t\t\t\t\tclient,\n\t\t\t\t\tpath: { project_id: projectId, branch_id: branchId },\n\t\t\t\t\tbody: { branch: input },\n\t\t\t\t\tthrowOnError: false,\n\t\t\t\t\tsignal,\n\t\t\t\t}),\n\t\t\t(data) => data.branch,\n\t\t);\n\t}\n\n\t/** @apiCall DELETE /projects/{project_id}/branches/{branch_id} */\n\tdelete(projectId: string, branchId: string): Promise<Outcome<void, DThrow>>;\n\tdelete<Throw extends boolean = DThrow>(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\topts: CallOptions<Throw>,\n\t): Promise<Outcome<void, Throw>>;\n\tdelete(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\topts?: CallOptions,\n\t): Promise<void | NeonResult<void>> {\n\t\treturn this.#ctx.runVoid(opts, (client, signal) =>\n\t\t\tdeleteProjectBranch({\n\t\t\t\tclient,\n\t\t\t\tpath: { project_id: projectId, branch_id: branchId },\n\t\t\t\tthrowOnError: false,\n\t\t\t\tsignal,\n\t\t\t}),\n\t\t);\n\t}\n\n\t/**\n\t * Create a branch **with a read-write endpoint** and return a ready-to-use connection\n\t * string. One API call (Neon creates the endpoint inline) plus readiness polling.\n\t *\n\t * @workflow createProjectBranch (with endpoint) + waitForReadiness\n\t */\n\tcreateWithCompute(\n\t\tprojectId: string,\n\t\tinput: CreateWithComputeInput,\n\t): Promise<Outcome<BranchWithCompute, DThrow>>;\n\tcreateWithCompute<Throw extends boolean = DThrow>(\n\t\tprojectId: string,\n\t\tinput: CreateWithComputeInput,\n\t\topts: WorkflowOptions<Throw>,\n\t): Promise<Outcome<BranchWithCompute, Throw>>;\n\tasync createWithCompute(\n\t\tprojectId: string,\n\t\tinput: CreateWithComputeInput,\n\t\topts?: WorkflowOptions<boolean>,\n\t): Promise<BranchWithCompute | NeonResult<BranchWithCompute>> {\n\t\tconst shouldThrow =\n\t\t\topts?.throwOnError ?? this.#ctx.defaults.throwOnError;\n\t\tconst result = await this.#ctx.execute(\n\t\t\t{ ...opts, waitForReadiness: opts?.waitForReadiness ?? true },\n\t\t\t(client, signal) =>\n\t\t\t\tcreateProjectBranch({\n\t\t\t\t\tclient,\n\t\t\t\t\tpath: { project_id: projectId },\n\t\t\t\t\tbody: {\n\t\t\t\t\t\tbranch: { name: input.name, parent_id: input.parentId },\n\t\t\t\t\t\tendpoints: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"read_write\",\n\t\t\t\t\t\t\t\tautoscaling_limit_min_cu: input.compute?.minCu,\n\t\t\t\t\t\t\t\tautoscaling_limit_max_cu: input.compute?.maxCu,\n\t\t\t\t\t\t\t\tsuspend_timeout_seconds:\n\t\t\t\t\t\t\t\t\tinput.compute?.suspendTimeoutSeconds,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t\tthrowOnError: false,\n\t\t\t\t\tsignal,\n\t\t\t\t}),\n\t\t\t(data) => data,\n\t\t);\n\t\tconst out = withConnectionString(\n\t\t\tresult,\n\t\t\t(data) => data.connection_uris,\n\t\t\t(data, connectionString) => ({\n\t\t\t\tbranch: data.branch,\n\t\t\t\tendpoint: data.endpoints[0],\n\t\t\t\tconnectionString,\n\t\t\t}),\n\t\t\topts?.pooled ?? true,\n\t\t);\n\t\treturn finalize(out, shouldThrow);\n\t}\n\n\t/**\n\t * Resolve the project's default branch (by the `default` flag — not by name).\n\t * Returns a `client`-kind {@link NeonError} when no default branch is found.\n\t */\n\tgetDefault(projectId: string): Promise<Outcome<Branch, DThrow>>;\n\tgetDefault<Throw extends boolean = DThrow>(\n\t\tprojectId: string,\n\t\topts: CallOptions<Throw>,\n\t): Promise<Outcome<Branch, Throw>>;\n\tasync getDefault(\n\t\tprojectId: string,\n\t\topts?: CallOptions,\n\t): Promise<Branch | NeonResult<Branch>> {\n\t\tconst shouldThrow =\n\t\t\topts?.throwOnError ?? this.#ctx.defaults.throwOnError;\n\t\tconst result = await this.#ctx.execute(\n\t\t\topts,\n\t\t\t(client, signal) =>\n\t\t\t\tlistProjectBranches({\n\t\t\t\t\tclient,\n\t\t\t\t\tpath: { project_id: projectId },\n\t\t\t\t\tthrowOnError: false,\n\t\t\t\t\tsignal,\n\t\t\t\t}),\n\t\t\t(data) => data.branches,\n\t\t);\n\t\tif (result.error)\n\t\t\treturn finalize(err<Branch>(result.error), shouldThrow);\n\t\tconst branch = result.data.find((candidate) => candidate.default);\n\t\tif (!branch) {\n\t\t\treturn finalize(\n\t\t\t\terr<Branch>(\n\t\t\t\t\tnew NeonError(\n\t\t\t\t\t\t\"No default branch found for the project.\",\n\t\t\t\t\t\t\"client\",\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t\tshouldThrow,\n\t\t\t);\n\t\t}\n\t\treturn finalize(ok(branch), shouldThrow);\n\t}\n\n\t/** @apiCall POST /projects/{project_id}/branches/{branch_id}/set_as_default */\n\tsetDefault(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t): Promise<Outcome<Branch, DThrow>>;\n\tsetDefault<Throw extends boolean = DThrow>(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\topts: CallOptions<Throw>,\n\t): Promise<Outcome<Branch, Throw>>;\n\tsetDefault(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\topts?: CallOptions,\n\t): Promise<Branch | NeonResult<Branch>> {\n\t\treturn this.#ctx.run(\n\t\t\topts,\n\t\t\t(client, signal) =>\n\t\t\t\tsetDefaultProjectBranch({\n\t\t\t\t\tclient,\n\t\t\t\t\tpath: { project_id: projectId, branch_id: branchId },\n\t\t\t\t\tthrowOnError: false,\n\t\t\t\t\tsignal,\n\t\t\t\t}),\n\t\t\t(data) => data.branch,\n\t\t);\n\t}\n\n\t/**\n\t * Complete (commit) a restore previously started with `snapshots.restore({ finalize: false })`:\n\t * moves computes onto the restored branch and renames the replaced one. This is **only**\n\t * the second step — it does not restore anything itself.\n\t *\n\t * @apiCall POST /projects/{project_id}/branches/{branch_id}/restore/finalize\n\t */\n\tfinalizeRestore(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\tinput?: { name?: string },\n\t): Promise<Outcome<void, DThrow>>;\n\tfinalizeRestore<Throw extends boolean = DThrow>(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\tinput: { name?: string } | undefined,\n\t\topts: CallOptions<Throw>,\n\t): Promise<Outcome<void, Throw>>;\n\tfinalizeRestore(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\tinput?: { name?: string },\n\t\topts?: CallOptions,\n\t): Promise<void | NeonResult<void>> {\n\t\treturn this.#ctx.run(\n\t\t\topts,\n\t\t\t(client, signal) =>\n\t\t\t\tfinalizeRestoreBranch({\n\t\t\t\t\tclient,\n\t\t\t\t\tpath: { project_id: projectId, branch_id: branchId },\n\t\t\t\t\tbody: { name: input?.name },\n\t\t\t\t\tthrowOnError: false,\n\t\t\t\t\tsignal,\n\t\t\t\t}),\n\t\t\t() => undefined,\n\t\t);\n\t}\n\n\t/**\n\t * Recover a soft-deleted branch within the 7-day recovery window.\n\t *\n\t * @apiCall POST /projects/{project_id}/branches/{branch_id}/recover\n\t */\n\trecover(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t): Promise<Outcome<Branch, DThrow>>;\n\trecover<Throw extends boolean = DThrow>(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\topts: CallOptions<Throw>,\n\t): Promise<Outcome<Branch, Throw>>;\n\trecover(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\topts?: CallOptions,\n\t): Promise<Branch | NeonResult<Branch>> {\n\t\treturn this.#ctx.run(\n\t\t\topts,\n\t\t\t(client, signal) =>\n\t\t\t\trecoverProjectBranch({\n\t\t\t\t\tclient,\n\t\t\t\t\tpath: { project_id: projectId, branch_id: branchId },\n\t\t\t\t\tthrowOnError: false,\n\t\t\t\t\tsignal,\n\t\t\t\t}),\n\t\t\t(data) => data.branch,\n\t\t);\n\t}\n}\n"],"mappings":";;;;;;;AAsDA,IAAa,WAAb,MAA8C;CAC7C;CAEA,YAAY,KAAqB;EAChC,KAAKA,OAAO;CACb;;CAGA,KACC,WACA,OACA,MACoB;EACpB,OAAO,UACL,QAAQ,WACR,oBAAoB;GACnB,QAAQ,KAAKA,KAAK;GAClB,MAAM,EAAE,YAAY,UAAU;GAC9B,OAAO;IAAE,GAAG;IAAO;GAAO;GA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KA,KAAK,IAChB,OACC,QAAQ,WACR,qBAAqB;GACpB;GACA,MAAM;IAAE,YAAY;IAAW,WAAW;GAAS;GACnD,cAAc;GACd;EACD,CAAC,IACD,SAAS,KAAK,MAChB;CACD;AACD"}
|
|
1
|
+
{"version":3,"file":"branches.js","names":["#ctx"],"sources":["../../../src/neon/resources/branches.ts"],"sourcesContent":["import {\n\tcreateProjectBranch,\n\tdeleteProjectBranch,\n\tfinalizeRestoreBranch,\n\tgetProjectBranch,\n\tlistProjectBranches,\n\tsetDefaultProjectBranch,\n\tupdateProjectBranch,\n} from \"../../client/sdk.gen.js\";\nimport type {\n\tBranch,\n\tBranchCreateRequest,\n\tBranchUpdateRequest,\n\tEndpoint,\n\tListProjectBranchesData,\n} from \"../../client/types.gen.js\";\nimport { withConnectionString } from \"../connection.js\";\nimport type { CallOptions, RequestContext } from \"../context.js\";\nimport { NeonError } from \"../errors.js\";\nimport { type Paginated, paginate } from \"../paginate.js\";\nimport { err, finalize, type NeonResult, type Outcome, ok } from \"../result.js\";\n\ntype ListQuery = Omit<NonNullable<ListProjectBranchesData[\"query\"]>, \"cursor\">;\ntype CreateInput = NonNullable<BranchCreateRequest[\"branch\"]>;\ntype UpdateInput = BranchUpdateRequest[\"branch\"];\n\n/** Per-call options for the connect/compute workflows. */\ninterface WorkflowOptions<Throw extends boolean> extends CallOptions<Throw> {\n\t/** Return a pooled connection string (default `true`). */\n\tpooled?: boolean;\n}\n\n/** Input for {@link Branches.createWithCompute}. */\nexport interface CreateWithComputeInput {\n\tname?: string;\n\t/** Parent branch id. Defaults to the project's default branch. */\n\tparentId?: string;\n\t/** Autoscaling settings for the branch's read-write endpoint. */\n\tcompute?: {\n\t\tminCu?: number;\n\t\tmaxCu?: number;\n\t\tsuspendTimeoutSeconds?: number;\n\t};\n}\n\n/** A branch with its read-write endpoint and a ready-to-use connection string. */\nexport interface BranchWithCompute {\n\tbranch: Branch;\n\tendpoint: Endpoint;\n\tconnectionString: string;\n}\n\n/** Branch resource — one API call per CRUD method, plus the `createWithCompute` workflow. */\nexport class Branches<DThrow extends boolean> {\n\treadonly #ctx: RequestContext;\n\n\tconstructor(ctx: RequestContext) {\n\t\tthis.#ctx = ctx;\n\t}\n\n\t/** @apiCall GET /projects/{project_id}/branches (cursor-paginated) */\n\tlist(\n\t\tprojectId: string,\n\t\tquery?: ListQuery,\n\t\topts?: CallOptions,\n\t): Paginated<Branch> {\n\t\treturn paginate(\n\t\t\t(cursor, signal) =>\n\t\t\t\tlistProjectBranches({\n\t\t\t\t\tclient: this.#ctx.client,\n\t\t\t\t\tpath: { project_id: projectId },\n\t\t\t\t\tquery: { ...query, cursor },\n\t\t\t\t\tthrowOnError: false,\n\t\t\t\t\tsignal,\n\t\t\t\t}),\n\t\t\t(data) => ({\n\t\t\t\titems: data?.branches ?? [],\n\t\t\t\tcursor: data?.pagination?.next,\n\t\t\t}),\n\t\t\t() => this.#ctx.deadlineFor(opts),\n\t\t);\n\t}\n\n\t/** @apiCall GET /projects/{project_id}/branches/{branch_id} */\n\tget(projectId: string, branchId: string): Promise<Outcome<Branch, DThrow>>;\n\tget<Throw extends boolean = DThrow>(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\topts: CallOptions<Throw>,\n\t): Promise<Outcome<Branch, Throw>>;\n\tget(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\topts?: CallOptions,\n\t): Promise<Branch | NeonResult<Branch>> {\n\t\treturn this.#ctx.run(\n\t\t\topts,\n\t\t\t(client, signal) =>\n\t\t\t\tgetProjectBranch({\n\t\t\t\t\tclient,\n\t\t\t\t\tpath: { project_id: projectId, branch_id: branchId },\n\t\t\t\t\tthrowOnError: false,\n\t\t\t\t\tsignal,\n\t\t\t\t}),\n\t\t\t(data) => data.branch,\n\t\t);\n\t}\n\n\t/** @apiCall POST /projects/{project_id}/branches */\n\tcreate(\n\t\tprojectId: string,\n\t\tinput?: CreateInput,\n\t): Promise<Outcome<Branch, DThrow>>;\n\tcreate<Throw extends boolean = DThrow>(\n\t\tprojectId: string,\n\t\tinput: CreateInput | undefined,\n\t\topts: CallOptions<Throw>,\n\t): Promise<Outcome<Branch, Throw>>;\n\tcreate(\n\t\tprojectId: string,\n\t\tinput?: CreateInput,\n\t\topts?: CallOptions,\n\t): Promise<Branch | NeonResult<Branch>> {\n\t\treturn this.#ctx.run(\n\t\t\topts,\n\t\t\t(client, signal) =>\n\t\t\t\tcreateProjectBranch({\n\t\t\t\t\tclient,\n\t\t\t\t\tpath: { project_id: projectId },\n\t\t\t\t\tbody: { branch: input },\n\t\t\t\t\tthrowOnError: false,\n\t\t\t\t\tsignal,\n\t\t\t\t}),\n\t\t\t(data) => data.branch,\n\t\t);\n\t}\n\n\t/** @apiCall PATCH /projects/{project_id}/branches/{branch_id} */\n\tupdate(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\tinput: UpdateInput,\n\t): Promise<Outcome<Branch, DThrow>>;\n\tupdate<Throw extends boolean = DThrow>(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\tinput: UpdateInput,\n\t\topts: CallOptions<Throw>,\n\t): Promise<Outcome<Branch, Throw>>;\n\tupdate(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\tinput: UpdateInput,\n\t\topts?: CallOptions,\n\t): Promise<Branch | NeonResult<Branch>> {\n\t\treturn this.#ctx.run(\n\t\t\topts,\n\t\t\t(client, signal) =>\n\t\t\t\tupdateProjectBranch({\n\t\t\t\t\tclient,\n\t\t\t\t\tpath: { project_id: projectId, branch_id: branchId },\n\t\t\t\t\tbody: { branch: input },\n\t\t\t\t\tthrowOnError: false,\n\t\t\t\t\tsignal,\n\t\t\t\t}),\n\t\t\t(data) => data.branch,\n\t\t);\n\t}\n\n\t/** @apiCall DELETE /projects/{project_id}/branches/{branch_id} */\n\tdelete(projectId: string, branchId: string): Promise<Outcome<void, DThrow>>;\n\tdelete<Throw extends boolean = DThrow>(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\topts: CallOptions<Throw>,\n\t): Promise<Outcome<void, Throw>>;\n\tdelete(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\topts?: CallOptions,\n\t): Promise<void | NeonResult<void>> {\n\t\treturn this.#ctx.runVoid(opts, (client, signal) =>\n\t\t\tdeleteProjectBranch({\n\t\t\t\tclient,\n\t\t\t\tpath: { project_id: projectId, branch_id: branchId },\n\t\t\t\tthrowOnError: false,\n\t\t\t\tsignal,\n\t\t\t}),\n\t\t);\n\t}\n\n\t/**\n\t * Create a branch **with a read-write endpoint** and return a ready-to-use connection\n\t * string. One API call (Neon creates the endpoint inline) plus readiness polling.\n\t *\n\t * @workflow createProjectBranch (with endpoint) + waitForReadiness\n\t */\n\tcreateWithCompute(\n\t\tprojectId: string,\n\t\tinput: CreateWithComputeInput,\n\t): Promise<Outcome<BranchWithCompute, DThrow>>;\n\tcreateWithCompute<Throw extends boolean = DThrow>(\n\t\tprojectId: string,\n\t\tinput: CreateWithComputeInput,\n\t\topts: WorkflowOptions<Throw>,\n\t): Promise<Outcome<BranchWithCompute, Throw>>;\n\tasync createWithCompute(\n\t\tprojectId: string,\n\t\tinput: CreateWithComputeInput,\n\t\topts?: WorkflowOptions<boolean>,\n\t): Promise<BranchWithCompute | NeonResult<BranchWithCompute>> {\n\t\tconst shouldThrow =\n\t\t\topts?.throwOnError ?? this.#ctx.defaults.throwOnError;\n\t\tconst result = await this.#ctx.execute(\n\t\t\t{ ...opts, waitForReadiness: opts?.waitForReadiness ?? true },\n\t\t\t(client, signal) =>\n\t\t\t\tcreateProjectBranch({\n\t\t\t\t\tclient,\n\t\t\t\t\tpath: { project_id: projectId },\n\t\t\t\t\tbody: {\n\t\t\t\t\t\tbranch: { name: input.name, parent_id: input.parentId },\n\t\t\t\t\t\tendpoints: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"read_write\",\n\t\t\t\t\t\t\t\tautoscaling_limit_min_cu: input.compute?.minCu,\n\t\t\t\t\t\t\t\tautoscaling_limit_max_cu: input.compute?.maxCu,\n\t\t\t\t\t\t\t\tsuspend_timeout_seconds:\n\t\t\t\t\t\t\t\t\tinput.compute?.suspendTimeoutSeconds,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t\tthrowOnError: false,\n\t\t\t\t\tsignal,\n\t\t\t\t}),\n\t\t\t(data) => data,\n\t\t);\n\t\tconst out = withConnectionString(\n\t\t\tresult,\n\t\t\t(data) => data.connection_uris,\n\t\t\t(data, connectionString) => ({\n\t\t\t\tbranch: data.branch,\n\t\t\t\tendpoint: data.endpoints[0],\n\t\t\t\tconnectionString,\n\t\t\t}),\n\t\t\topts?.pooled ?? true,\n\t\t);\n\t\treturn finalize(out, shouldThrow);\n\t}\n\n\t/**\n\t * Resolve the project's default branch (by the `default` flag — not by name).\n\t * Returns a `client`-kind {@link NeonError} when no default branch is found.\n\t */\n\tgetDefault(projectId: string): Promise<Outcome<Branch, DThrow>>;\n\tgetDefault<Throw extends boolean = DThrow>(\n\t\tprojectId: string,\n\t\topts: CallOptions<Throw>,\n\t): Promise<Outcome<Branch, Throw>>;\n\tasync getDefault(\n\t\tprojectId: string,\n\t\topts?: CallOptions,\n\t): Promise<Branch | NeonResult<Branch>> {\n\t\tconst shouldThrow =\n\t\t\topts?.throwOnError ?? this.#ctx.defaults.throwOnError;\n\t\tconst result = await this.#ctx.execute(\n\t\t\topts,\n\t\t\t(client, signal) =>\n\t\t\t\tlistProjectBranches({\n\t\t\t\t\tclient,\n\t\t\t\t\tpath: { project_id: projectId },\n\t\t\t\t\tthrowOnError: false,\n\t\t\t\t\tsignal,\n\t\t\t\t}),\n\t\t\t(data) => data.branches,\n\t\t);\n\t\tif (result.error)\n\t\t\treturn finalize(err<Branch>(result.error), shouldThrow);\n\t\tconst branch = result.data.find((candidate) => candidate.default);\n\t\tif (!branch) {\n\t\t\treturn finalize(\n\t\t\t\terr<Branch>(\n\t\t\t\t\tnew NeonError(\n\t\t\t\t\t\t\"No default branch found for the project.\",\n\t\t\t\t\t\t\"client\",\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t\tshouldThrow,\n\t\t\t);\n\t\t}\n\t\treturn finalize(ok(branch), shouldThrow);\n\t}\n\n\t/** @apiCall POST /projects/{project_id}/branches/{branch_id}/set_as_default */\n\tsetDefault(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t): Promise<Outcome<Branch, DThrow>>;\n\tsetDefault<Throw extends boolean = DThrow>(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\topts: CallOptions<Throw>,\n\t): Promise<Outcome<Branch, Throw>>;\n\tsetDefault(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\topts?: CallOptions,\n\t): Promise<Branch | NeonResult<Branch>> {\n\t\treturn this.#ctx.run(\n\t\t\topts,\n\t\t\t(client, signal) =>\n\t\t\t\tsetDefaultProjectBranch({\n\t\t\t\t\tclient,\n\t\t\t\t\tpath: { project_id: projectId, branch_id: branchId },\n\t\t\t\t\tthrowOnError: false,\n\t\t\t\t\tsignal,\n\t\t\t\t}),\n\t\t\t(data) => data.branch,\n\t\t);\n\t}\n\n\t/**\n\t * Complete (commit) a restore previously started with `snapshots.restore({ finalize: false })`:\n\t * moves computes onto the restored branch and renames the replaced one. This is **only**\n\t * the second step — it does not restore anything itself.\n\t *\n\t * @apiCall POST /projects/{project_id}/branches/{branch_id}/restore/finalize\n\t */\n\tfinalizeRestore(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\tinput?: { name?: string },\n\t): Promise<Outcome<void, DThrow>>;\n\tfinalizeRestore<Throw extends boolean = DThrow>(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\tinput: { name?: string } | undefined,\n\t\topts: CallOptions<Throw>,\n\t): Promise<Outcome<void, Throw>>;\n\tfinalizeRestore(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\tinput?: { name?: string },\n\t\topts?: CallOptions,\n\t): Promise<void | NeonResult<void>> {\n\t\treturn this.#ctx.run(\n\t\t\topts,\n\t\t\t(client, signal) =>\n\t\t\t\tfinalizeRestoreBranch({\n\t\t\t\t\tclient,\n\t\t\t\t\tpath: { project_id: projectId, branch_id: branchId },\n\t\t\t\t\tbody: { name: input?.name },\n\t\t\t\t\tthrowOnError: false,\n\t\t\t\t\tsignal,\n\t\t\t\t}),\n\t\t\t() => undefined,\n\t\t);\n\t}\n}\n"],"mappings":";;;;;;;AAqDA,IAAa,WAAb,MAA8C;CAC7C;CAEA,YAAY,KAAqB;EAChC,KAAKA,OAAO;CACb;;CAGA,KACC,WACA,OACA,MACoB;EACpB,OAAO,UACL,QAAQ,WACR,oBAAoB;GACnB,QAAQ,KAAKA,KAAK;GAClB,MAAM,EAAE,YAAY,UAAU;GAC9B,OAAO;IAAE,GAAG;IAAO;GAAO;GAC1B,cAAc;GACd;EACD,CAAC,IACD,UAAU;GACV,OAAO,MAAM,YAAY,CAAC;GAC1B,QAAQ,MAAM,YAAY;EAC3B,UACM,KAAKA,KAAK,YAAY,IAAI,CACjC;CACD;CASA,IACC,WACA,UACA,MACuC;EACvC,OAAO,KAAKA,KAAK,IAChB,OACC,QAAQ,WACR,iBAAiB;GAChB;GACA,MAAM;IAAE,YAAY;IAAW,WAAW;GAAS;GACnD,cAAc;GACd;EACD,CAAC,IACD,SAAS,KAAK,MAChB;CACD;CAYA,OACC,WACA,OACA,MACuC;EACvC,OAAO,KAAKA,KAAK,IAChB,OACC,QAAQ,WACR,oBAAoB;GACnB;GACA,MAAM,EAAE,YAAY,UAAU;GAC9B,MAAM,EAAE,QAAQ,MAAM;GACtB,cAAc;GACd;EACD,CAAC,IACD,SAAS,KAAK,MAChB;CACD;CAcA,OACC,WACA,UACA,OACA,MACuC;EACvC,OAAO,KAAKA,KAAK,IAChB,OACC,QAAQ,WACR,oBAAoB;GACnB;GACA,MAAM;IAAE,YAAY;IAAW,WAAW;GAAS;GACnD,MAAM,EAAE,QAAQ,MAAM;GACtB,cAAc;GACd;EACD,CAAC,IACD,SAAS,KAAK,MAChB;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,CACD,GACA,WACD;EAED,OAAO,SAAS,GAAG,MAAM,GAAG,WAAW;CACxC;CAYA,WACC,WACA,UACA,MACuC;EACvC,OAAO,KAAKA,KAAK,IAChB,OACC,QAAQ,WACR,wBAAwB;GACvB;GACA,MAAM;IAAE,YAAY;IAAW,WAAW;GAAS;GACnD,cAAc;GACd;EACD,CAAC,IACD,SAAS,KAAK,MAChB;CACD;CAoBA,gBACC,WACA,UACA,OACA,MACmC;EACnC,OAAO,KAAKA,KAAK,IAChB,OACC,QAAQ,WACR,sBAAsB;GACrB;GACA,MAAM;IAAE,YAAY;IAAW,WAAW;GAAS;GACnD,MAAM,EAAE,MAAM,OAAO,KAAK;GAC1B,cAAc;GACd;EACD,CAAC,SACI,KAAA,CACP;CACD;AACD"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { ListProjectBranchLogFieldValuesData, ProjectBranchLogFieldValuesResponse, ProjectBranchLogRecord, ProjectBranchLogsQueryRequest } from "../../client/types.gen.js";
|
|
2
|
+
import { Outcome } from "../result.js";
|
|
3
|
+
import { CallOptions, RequestContext } from "../context.js";
|
|
4
|
+
import { Paginated } from "../paginate.js";
|
|
5
|
+
|
|
6
|
+
//#region src/neon/resources/logs.d.ts
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Filters for {@link Logs.query}.
|
|
10
|
+
*
|
|
11
|
+
* `cursor` is absent because {@link Paginated} owns paging: the endpoint requires
|
|
12
|
+
* every filter and the time window to be repeated unchanged on each page, and
|
|
13
|
+
* threading the cursor here is what guarantees that.
|
|
14
|
+
*/
|
|
15
|
+
type LogQueryInput = Omit<ProjectBranchLogsQueryRequest, "cursor">;
|
|
16
|
+
/** Query parameters for {@link Logs.fieldValues}. */
|
|
17
|
+
type LogFieldValuesQuery = NonNullable<ListProjectBranchLogFieldValuesData["query"]>;
|
|
18
|
+
/**
|
|
19
|
+
* Branch-scoped logs emitted by the services running on a branch — Neon Functions,
|
|
20
|
+
* object storage, and Postgres computes. Grouped under `neon.logs.*` alongside the
|
|
21
|
+
* other branch-scoped product surfaces.
|
|
22
|
+
*
|
|
23
|
+
* Private Beta. Telemetry is region-gated, so a branch outside an enabled region answers
|
|
24
|
+
* `404` with `reason: "telemetry_not_enabled"` rather than an empty result — treat that
|
|
25
|
+
* as an ordinary outcome. A branch that has telemetry but nothing recorded answers `200`
|
|
26
|
+
* with an empty array, and one whose backend is down answers `503`, which the client
|
|
27
|
+
* retries on by default.
|
|
28
|
+
*
|
|
29
|
+
* The spec is wider than the backend: of the three `source` values only `function` and
|
|
30
|
+
* `storage` were observed emitting, and `minimum_severity` can be rejected as unsupported
|
|
31
|
+
* by a branch's log backend, where `severity_text` still works.
|
|
32
|
+
*/
|
|
33
|
+
declare class Logs<DThrow extends boolean> {
|
|
34
|
+
#private;
|
|
35
|
+
constructor(ctx: RequestContext);
|
|
36
|
+
/**
|
|
37
|
+
* Query branch logs (cursor-paginated). Every supplied filter is combined with
|
|
38
|
+
* `AND`.
|
|
39
|
+
*
|
|
40
|
+
* Give the window as either `since` or `start_time` — supplying both is rejected.
|
|
41
|
+
* `logql` replaces the seven content filters rather than adding to them, while
|
|
42
|
+
* `limit`, `sort_order`, and the time window still apply alongside it. With no
|
|
43
|
+
* window the query covers the last hour, and seven days is the widest range served.
|
|
44
|
+
*
|
|
45
|
+
* @apiCall POST /projects/{project_id}/branches/{branch_id}/logs/query (cursor-paginated)
|
|
46
|
+
*/
|
|
47
|
+
query(projectId: string, branchId: string, input?: LogQueryInput, opts?: CallOptions): Paginated<ProjectBranchLogRecord>;
|
|
48
|
+
/**
|
|
49
|
+
* List the log fields whose values {@link Logs.fieldValues} can enumerate on
|
|
50
|
+
* this branch. Computed per branch and grows as fields are observed, so read it
|
|
51
|
+
* rather than assuming a fixed set.
|
|
52
|
+
*
|
|
53
|
+
* @apiCall GET /projects/{project_id}/branches/{branch_id}/logs/fields
|
|
54
|
+
*/
|
|
55
|
+
fields(projectId: string, branchId: string): Promise<Outcome<string[], DThrow>>;
|
|
56
|
+
fields<Throw extends boolean = DThrow>(projectId: string, branchId: string, opts: CallOptions<Throw>): Promise<Outcome<string[], Throw>>;
|
|
57
|
+
/**
|
|
58
|
+
* List the distinct values observed for one log field, for use as a filter.
|
|
59
|
+
* `fieldName` must be one of the names {@link Logs.fields} reports; anything else is
|
|
60
|
+
* rejected with `unknown_field`. The enumerable set and the set {@link Logs.query} can
|
|
61
|
+
* filter on overlap rather than nest: `source` is a filter but is not enumerable, and
|
|
62
|
+
* `entity_type` is enumerable but is not a filter.
|
|
63
|
+
*
|
|
64
|
+
* The whole response is returned rather than the bare values because
|
|
65
|
+
* `is_truncated` decides whether the list can be trusted: when it is `true` the
|
|
66
|
+
* values are an arbitrary subset, and the window or `source` needs narrowing
|
|
67
|
+
* before filtering on them.
|
|
68
|
+
*
|
|
69
|
+
* @apiCall GET /projects/{project_id}/branches/{branch_id}/logs/fields/{field_name}/values
|
|
70
|
+
*/
|
|
71
|
+
fieldValues(projectId: string, branchId: string, fieldName: string, query?: LogFieldValuesQuery): Promise<Outcome<ProjectBranchLogFieldValuesResponse, DThrow>>;
|
|
72
|
+
fieldValues<Throw extends boolean = DThrow>(projectId: string, branchId: string, fieldName: string, query: LogFieldValuesQuery | undefined, opts: CallOptions<Throw>): Promise<Outcome<ProjectBranchLogFieldValuesResponse, Throw>>;
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
export { LogFieldValuesQuery, LogQueryInput, Logs };
|
|
76
|
+
//# sourceMappingURL=logs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logs.d.ts","names":[],"sources":["../../../src/neon/resources/logs.ts"],"mappings":";;;;;;;;;AAwBA;AAAyB;AAAQ;AAAL;AAAI;AAGpB,KAHA,aAAA,GAAgB,IAGG,CAHE,6BAGF,EAAA,QAAA,CAAA;AAAA;AAC9B,KADW,mBAAA,GAAsB,WACjC,CAAA,mCAAA,CAAA,OAAA,CAAA,CAAA;AADiC;AAAW;AAmB7C;AAAiB;AAGC;AAkBR;AACD;AACK;AAAV;AAgD0B;AAAlB;AAAR;AAC4B;AAGZ;AAAZ;AACsB,cA5EjB,IA4EiB,CAAA,eAAA,OAAA,CAAA,CAAA;EAAlB,CAAA,OAAA;EAAR,WAAA,CAAA,GAAA,EAzEc,cAyEd;EAqCM;AACU;AAAqC;AAA7C;AAAR;AACiC;AAI5B;AACW;AAAZ;AACY;AAAqC;EAA7C,KAAA,CAAA,SAAA,EAAA,MAAA,EAAA,QAAA,EAAA,MAAA,EAAA,KAAA,CAAA,EApGF,aAoGE,EAAA,IAAA,CAAA,EAnGH,WAmGG,CAAA,EAlGR,SAkGQ,CAlGE,sBAkGF,CAAA;EAAR;AAAO;;;;;;+CAlDP,QAAQ,kBAAkB;iCACE,mDAGxB,YAAY,SAChB,QAAQ,kBAAkB;;;;;;;;;;;;;;;8EAqCpB,sBACN,QAAQ,QAAQ,qCAAqC;sCACpB,uEAI5B,uCACD,YAAY,SAChB,QAAQ,QAAQ,qCAAqC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { NeonError } from "../errors.js";
|
|
2
|
+
import { listProjectBranchLogFieldValues, listProjectBranchLogFields, queryProjectBranchLogs } from "../../client/sdk.gen.js";
|
|
3
|
+
import { paginate } from "../paginate.js";
|
|
4
|
+
//#region src/neon/resources/logs.ts
|
|
5
|
+
/**
|
|
6
|
+
* Branch-scoped logs emitted by the services running on a branch — Neon Functions,
|
|
7
|
+
* object storage, and Postgres computes. Grouped under `neon.logs.*` alongside the
|
|
8
|
+
* other branch-scoped product surfaces.
|
|
9
|
+
*
|
|
10
|
+
* Private Beta. Telemetry is region-gated, so a branch outside an enabled region answers
|
|
11
|
+
* `404` with `reason: "telemetry_not_enabled"` rather than an empty result — treat that
|
|
12
|
+
* as an ordinary outcome. A branch that has telemetry but nothing recorded answers `200`
|
|
13
|
+
* with an empty array, and one whose backend is down answers `503`, which the client
|
|
14
|
+
* retries on by default.
|
|
15
|
+
*
|
|
16
|
+
* The spec is wider than the backend: of the three `source` values only `function` and
|
|
17
|
+
* `storage` were observed emitting, and `minimum_severity` can be rejected as unsupported
|
|
18
|
+
* by a branch's log backend, where `severity_text` still works.
|
|
19
|
+
*/
|
|
20
|
+
var Logs = class {
|
|
21
|
+
#ctx;
|
|
22
|
+
constructor(ctx) {
|
|
23
|
+
this.#ctx = ctx;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Query branch logs (cursor-paginated). Every supplied filter is combined with
|
|
27
|
+
* `AND`.
|
|
28
|
+
*
|
|
29
|
+
* Give the window as either `since` or `start_time` — supplying both is rejected.
|
|
30
|
+
* `logql` replaces the seven content filters rather than adding to them, while
|
|
31
|
+
* `limit`, `sort_order`, and the time window still apply alongside it. With no
|
|
32
|
+
* window the query covers the last hour, and seven days is the widest range served.
|
|
33
|
+
*
|
|
34
|
+
* @apiCall POST /projects/{project_id}/branches/{branch_id}/logs/query (cursor-paginated)
|
|
35
|
+
*/
|
|
36
|
+
query(projectId, branchId, input, opts) {
|
|
37
|
+
const filters = { ...input };
|
|
38
|
+
return paginate(async (cursor, signal) => {
|
|
39
|
+
const page = await queryProjectBranchLogs({
|
|
40
|
+
client: this.#ctx.client,
|
|
41
|
+
path: {
|
|
42
|
+
project_id: projectId,
|
|
43
|
+
branch_id: branchId
|
|
44
|
+
},
|
|
45
|
+
body: {
|
|
46
|
+
...filters,
|
|
47
|
+
cursor
|
|
48
|
+
},
|
|
49
|
+
throwOnError: false,
|
|
50
|
+
signal
|
|
51
|
+
});
|
|
52
|
+
if (page.data?.is_truncated && !page.data.next_cursor) return {
|
|
53
|
+
response: page.response,
|
|
54
|
+
error: new NeonError("Neon reported more log records than it returned but gave no cursor to reach them.", "client")
|
|
55
|
+
};
|
|
56
|
+
return page;
|
|
57
|
+
}, (data) => ({
|
|
58
|
+
items: data?.logs ?? [],
|
|
59
|
+
cursor: data?.is_truncated ? data.next_cursor : void 0
|
|
60
|
+
}), () => this.#ctx.deadlineFor(opts));
|
|
61
|
+
}
|
|
62
|
+
fields(projectId, branchId, opts) {
|
|
63
|
+
return this.#ctx.run(opts, (client, signal) => listProjectBranchLogFields({
|
|
64
|
+
client,
|
|
65
|
+
path: {
|
|
66
|
+
project_id: projectId,
|
|
67
|
+
branch_id: branchId
|
|
68
|
+
},
|
|
69
|
+
throwOnError: false,
|
|
70
|
+
signal
|
|
71
|
+
}), (data) => data.fields);
|
|
72
|
+
}
|
|
73
|
+
fieldValues(projectId, branchId, fieldName, query, opts) {
|
|
74
|
+
return this.#ctx.run(opts, (client, signal) => listProjectBranchLogFieldValues({
|
|
75
|
+
client,
|
|
76
|
+
path: {
|
|
77
|
+
project_id: projectId,
|
|
78
|
+
branch_id: branchId,
|
|
79
|
+
field_name: fieldName
|
|
80
|
+
},
|
|
81
|
+
query,
|
|
82
|
+
throwOnError: false,
|
|
83
|
+
signal
|
|
84
|
+
}), (data) => data);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
//#endregion
|
|
88
|
+
export { Logs };
|
|
89
|
+
|
|
90
|
+
//# sourceMappingURL=logs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logs.js","names":["#ctx"],"sources":["../../../src/neon/resources/logs.ts"],"sourcesContent":["import {\n\tlistProjectBranchLogFields,\n\tlistProjectBranchLogFieldValues,\n\tqueryProjectBranchLogs,\n} from \"../../client/sdk.gen.js\";\nimport type {\n\tListProjectBranchLogFieldValuesData,\n\tProjectBranchLogFieldValuesResponse,\n\tProjectBranchLogRecord,\n\tProjectBranchLogsQueryRequest,\n\tProjectBranchLogsQueryResponse,\n} from \"../../client/types.gen.js\";\nimport type { CallOptions, RequestContext } from \"../context.js\";\nimport { NeonError } from \"../errors.js\";\nimport { type Paginated, paginate } from \"../paginate.js\";\nimport type { NeonResult, Outcome } from \"../result.js\";\n\n/**\n * Filters for {@link Logs.query}.\n *\n * `cursor` is absent because {@link Paginated} owns paging: the endpoint requires\n * every filter and the time window to be repeated unchanged on each page, and\n * threading the cursor here is what guarantees that.\n */\nexport type LogQueryInput = Omit<ProjectBranchLogsQueryRequest, \"cursor\">;\n\n/** Query parameters for {@link Logs.fieldValues}. */\nexport type LogFieldValuesQuery = NonNullable<\n\tListProjectBranchLogFieldValuesData[\"query\"]\n>;\n\n/**\n * Branch-scoped logs emitted by the services running on a branch — Neon Functions,\n * object storage, and Postgres computes. Grouped under `neon.logs.*` alongside the\n * other branch-scoped product surfaces.\n *\n * Private Beta. Telemetry is region-gated, so a branch outside an enabled region answers\n * `404` with `reason: \"telemetry_not_enabled\"` rather than an empty result — treat that\n * as an ordinary outcome. A branch that has telemetry but nothing recorded answers `200`\n * with an empty array, and one whose backend is down answers `503`, which the client\n * retries on by default.\n *\n * The spec is wider than the backend: of the three `source` values only `function` and\n * `storage` were observed emitting, and `minimum_severity` can be rejected as unsupported\n * by a branch's log backend, where `severity_text` still works.\n */\nexport class Logs<DThrow extends boolean> {\n\treadonly #ctx: RequestContext;\n\n\tconstructor(ctx: RequestContext) {\n\t\tthis.#ctx = ctx;\n\t}\n\n\t/**\n\t * Query branch logs (cursor-paginated). Every supplied filter is combined with\n\t * `AND`.\n\t *\n\t * Give the window as either `since` or `start_time` — supplying both is rejected.\n\t * `logql` replaces the seven content filters rather than adding to them, while\n\t * `limit`, `sort_order`, and the time window still apply alongside it. With no\n\t * window the query covers the last hour, and seven days is the widest range served.\n\t *\n\t * @apiCall POST /projects/{project_id}/branches/{branch_id}/logs/query (cursor-paginated)\n\t */\n\tquery(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\tinput?: LogQueryInput,\n\t\topts?: CallOptions,\n\t): Paginated<ProjectBranchLogRecord> {\n\t\t// Snapshot the filters. The endpoint returns wrong results unless every page\n\t\t// repeats them unchanged, and a `Paginated` is lazy — reading `input` per page\n\t\t// would let a caller mutating it afterwards change the query mid-walk.\n\t\tconst filters = { ...input };\n\t\treturn paginate<ProjectBranchLogRecord, ProjectBranchLogsQueryResponse>(\n\t\t\tasync (cursor, signal) => {\n\t\t\t\tconst page = await queryProjectBranchLogs({\n\t\t\t\t\tclient: this.#ctx.client,\n\t\t\t\t\tpath: { project_id: projectId, branch_id: branchId },\n\t\t\t\t\tbody: { ...filters, cursor },\n\t\t\t\t\tthrowOnError: false,\n\t\t\t\t\tsignal,\n\t\t\t\t});\n\t\t\t\t// Truncated with nothing to resume from: the remaining records are\n\t\t\t\t// unreachable. Stopping here would hand back a partial page that looks\n\t\t\t\t// like the whole result.\n\t\t\t\tif (page.data?.is_truncated && !page.data.next_cursor) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tresponse: page.response,\n\t\t\t\t\t\terror: new NeonError(\n\t\t\t\t\t\t\t\"Neon reported more log records than it returned but gave no cursor to reach them.\",\n\t\t\t\t\t\t\t\"client\",\n\t\t\t\t\t\t),\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn page;\n\t\t\t},\n\t\t\t(data) => ({\n\t\t\t\titems: data?.logs ?? [],\n\t\t\t\t// `next_cursor` is present but empty on the last page, so truncation is\n\t\t\t\t// the flag that ends the walk.\n\t\t\t\tcursor: data?.is_truncated ? data.next_cursor : undefined,\n\t\t\t}),\n\t\t\t() => this.#ctx.deadlineFor(opts),\n\t\t);\n\t}\n\n\t/**\n\t * List the log fields whose values {@link Logs.fieldValues} can enumerate on\n\t * this branch. Computed per branch and grows as fields are observed, so read it\n\t * rather than assuming a fixed set.\n\t *\n\t * @apiCall GET /projects/{project_id}/branches/{branch_id}/logs/fields\n\t */\n\tfields(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t): Promise<Outcome<string[], DThrow>>;\n\tfields<Throw extends boolean = DThrow>(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\topts: CallOptions<Throw>,\n\t): Promise<Outcome<string[], Throw>>;\n\tfields(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\topts?: CallOptions,\n\t): Promise<string[] | NeonResult<string[]>> {\n\t\treturn this.#ctx.run(\n\t\t\topts,\n\t\t\t(client, signal) =>\n\t\t\t\tlistProjectBranchLogFields({\n\t\t\t\t\tclient,\n\t\t\t\t\tpath: { project_id: projectId, branch_id: branchId },\n\t\t\t\t\tthrowOnError: false,\n\t\t\t\t\tsignal,\n\t\t\t\t}),\n\t\t\t(data) => data.fields,\n\t\t);\n\t}\n\n\t/**\n\t * List the distinct values observed for one log field, for use as a filter.\n\t * `fieldName` must be one of the names {@link Logs.fields} reports; anything else is\n\t * rejected with `unknown_field`. The enumerable set and the set {@link Logs.query} can\n\t * filter on overlap rather than nest: `source` is a filter but is not enumerable, and\n\t * `entity_type` is enumerable but is not a filter.\n\t *\n\t * The whole response is returned rather than the bare values because\n\t * `is_truncated` decides whether the list can be trusted: when it is `true` the\n\t * values are an arbitrary subset, and the window or `source` needs narrowing\n\t * before filtering on them.\n\t *\n\t * @apiCall GET /projects/{project_id}/branches/{branch_id}/logs/fields/{field_name}/values\n\t */\n\tfieldValues(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\tfieldName: string,\n\t\tquery?: LogFieldValuesQuery,\n\t): Promise<Outcome<ProjectBranchLogFieldValuesResponse, DThrow>>;\n\tfieldValues<Throw extends boolean = DThrow>(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\tfieldName: string,\n\t\tquery: LogFieldValuesQuery | undefined,\n\t\topts: CallOptions<Throw>,\n\t): Promise<Outcome<ProjectBranchLogFieldValuesResponse, Throw>>;\n\tfieldValues(\n\t\tprojectId: string,\n\t\tbranchId: string,\n\t\tfieldName: string,\n\t\tquery?: LogFieldValuesQuery,\n\t\topts?: CallOptions,\n\t): Promise<\n\t\t| ProjectBranchLogFieldValuesResponse\n\t\t| NeonResult<ProjectBranchLogFieldValuesResponse>\n\t> {\n\t\treturn this.#ctx.run(\n\t\t\topts,\n\t\t\t(client, signal) =>\n\t\t\t\tlistProjectBranchLogFieldValues({\n\t\t\t\t\tclient,\n\t\t\t\t\tpath: {\n\t\t\t\t\t\tproject_id: projectId,\n\t\t\t\t\t\tbranch_id: branchId,\n\t\t\t\t\t\tfield_name: fieldName,\n\t\t\t\t\t},\n\t\t\t\t\tquery,\n\t\t\t\t\tthrowOnError: false,\n\t\t\t\t\tsignal,\n\t\t\t\t}),\n\t\t\t(data) => data,\n\t\t);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA8CA,IAAa,OAAb,MAA0C;CACzC;CAEA,YAAY,KAAqB;EAChC,KAAKA,OAAO;CACb;;;;;;;;;;;;CAaA,MACC,WACA,UACA,OACA,MACoC;EAIpC,MAAM,UAAU,EAAE,GAAG,MAAM;EAC3B,OAAO,SACN,OAAO,QAAQ,WAAW;GACzB,MAAM,OAAO,MAAM,uBAAuB;IACzC,QAAQ,KAAKA,KAAK;IAClB,MAAM;KAAE,YAAY;KAAW,WAAW;IAAS;IACnD,MAAM;KAAE,GAAG;KAAS;IAAO;IAC3B,cAAc;IACd;GACD,CAAC;GAID,IAAI,KAAK,MAAM,gBAAgB,CAAC,KAAK,KAAK,aACzC,OAAO;IACN,UAAU,KAAK;IACf,OAAO,IAAI,UACV,qFACA,QACD;GACD;GAED,OAAO;EACR,IACC,UAAU;GACV,OAAO,MAAM,QAAQ,CAAC;GAGtB,QAAQ,MAAM,eAAe,KAAK,cAAc,KAAA;EACjD,UACM,KAAKA,KAAK,YAAY,IAAI,CACjC;CACD;CAkBA,OACC,WACA,UACA,MAC2C;EAC3C,OAAO,KAAKA,KAAK,IAChB,OACC,QAAQ,WACR,2BAA2B;GAC1B;GACA,MAAM;IAAE,YAAY;IAAW,WAAW;GAAS;GACnD,cAAc;GACd;EACD,CAAC,IACD,SAAS,KAAK,MAChB;CACD;CA6BA,YACC,WACA,UACA,WACA,OACA,MAIC;EACD,OAAO,KAAKA,KAAK,IAChB,OACC,QAAQ,WACR,gCAAgC;GAC/B;GACA,MAAM;IACL,YAAY;IACZ,WAAW;IACX,YAAY;GACb;GACA;GACA,cAAc;GACd;EACD,CAAC,IACD,SAAS,IACX;CACD;AACD"}
|
|
@@ -31,7 +31,8 @@ var Postgres = class {
|
|
|
31
31
|
try {
|
|
32
32
|
const resolved = await runBounded(deadline, () => this.#resolve(params, deadline.signal));
|
|
33
33
|
const cancellation = cancelled(deadline);
|
|
34
|
-
|
|
34
|
+
const result = cancellation !== void 0 ? err(cancellation) : resolved ?? err(new NeonError("The connection-string resolver ended without a result.", "client"));
|
|
35
|
+
return finalize(result, shouldThrow);
|
|
35
36
|
} finally {
|
|
36
37
|
deadline.dispose();
|
|
37
38
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.js","names":["#ctx","#resolve"],"sources":["../../../src/neon/resources/postgres.ts"],"sourcesContent":["import {\n\tgetConnectionUri,\n\tlistProjectBranchDatabases,\n\tlistProjectBranches,\n\tlistProjectBranchRoles,\n} from \"../../client/sdk.gen.js\";\nimport type { CallOptions, RequestContext } from \"../context.js\";\nimport { cancelled, runBounded } from \"../deadline.js\";\nimport { NeonError, toNeonError } from \"../errors.js\";\nimport { err, finalize, type NeonResult, type Outcome, ok } from \"../result.js\";\nimport { DataApi } from \"./dataapi.js\";\nimport { Databases } from \"./databases.js\";\nimport { Endpoints } from \"./endpoints.js\";\nimport { Roles } from \"./roles.js\";\n\n/** Parameters for {@link Postgres.connectionString}. */\nexport interface ConnectionStringParams {\n\tprojectId: string;\n\t/** Defaults to the project's default branch. */\n\tbranchId?: string;\n\t/** Defaults to the branch's read-write endpoint. */\n\tendpointId?: string;\n\t/** Auto-selected when the branch has exactly one database. */\n\tdatabaseName?: string;\n\t/** Auto-selected when the branch has exactly one role. */\n\troleName?: string;\n\t/** Pooled connection string (default `true`). */\n\tpooled?: boolean;\n}\n\n/**\n * The Postgres data plane of a branch: compute endpoints, roles, databases, the Data API,\n * and a connection-string helper. (Grouped under `neon.postgres.*` so future top-level\n * namespaces like `functions` / `storage` stay unambiguous.)\n */\nexport class Postgres<DThrow extends boolean> {\n\treadonly endpoints: Endpoints<DThrow>;\n\treadonly roles: Roles<DThrow>;\n\treadonly databases: Databases<DThrow>;\n\treadonly dataApi: DataApi<DThrow>;\n\treadonly #ctx: RequestContext;\n\n\tconstructor(ctx: RequestContext) {\n\t\tthis.#ctx = ctx;\n\t\tthis.endpoints = new Endpoints<DThrow>(ctx);\n\t\tthis.roles = new Roles<DThrow>(ctx);\n\t\tthis.databases = new Databases<DThrow>(ctx);\n\t\tthis.dataApi = new DataApi<DThrow>(ctx);\n\t}\n\n\t/**\n\t * Resolve a Postgres connection string. Auto-selects the default branch and the sole\n\t * role/database when not specified (mirrors `@neon/config`'s `fetchEnv`); returns\n\t * a `client`-kind {@link NeonError} when the selection is ambiguous.\n\t */\n\tconnectionString(\n\t\tparams: ConnectionStringParams,\n\t): Promise<Outcome<string, DThrow>>;\n\tconnectionString<Throw extends boolean = DThrow>(\n\t\tparams: ConnectionStringParams,\n\t\topts: CallOptions<Throw>,\n\t): Promise<Outcome<string, Throw>>;\n\tasync connectionString(\n\t\tparams: ConnectionStringParams,\n\t\topts?: CallOptions,\n\t): Promise<string | NeonResult<string>> {\n\t\tconst shouldThrow =\n\t\t\topts?.throwOnError ?? this.#ctx.defaults.throwOnError;\n\t\t// This resolver makes up to four sequential requests without going through\n\t\t// RequestContext, so it owns the deadline covering all of them.\n\t\tconst deadline = this.#ctx.deadlineFor(opts);\n\t\ttry {\n\t\t\tconst resolved = await runBounded(deadline, () =>\n\t\t\t\tthis.#resolve(params, deadline.signal),\n\t\t\t);\n\t\t\tconst cancellation = cancelled(deadline);\n\t\t\t// `runBounded` resolves undefined only when the deadline won the race, which\n\t\t\t// `cancelled` then reports, so the fallback is unreachable by construction.\n\t\t\tconst result: NeonResult<string> =\n\t\t\t\tcancellation !== undefined\n\t\t\t\t\t? err(cancellation)\n\t\t\t\t\t: (resolved ??\n\t\t\t\t\t\terr(\n\t\t\t\t\t\t\tnew NeonError(\n\t\t\t\t\t\t\t\t\"The connection-string resolver ended without a result.\",\n\t\t\t\t\t\t\t\t\"client\",\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t));\n\t\t\treturn finalize(result, shouldThrow);\n\t\t} finally {\n\t\t\tdeadline.dispose();\n\t\t}\n\t}\n\n\tasync #resolve(\n\t\tparams: ConnectionStringParams,\n\t\tsignal?: AbortSignal,\n\t): Promise<NeonResult<string>> {\n\t\tconst client = this.#ctx.client;\n\t\tconst projectId = params.projectId;\n\t\tlet branchId = params.branchId;\n\t\tlet roleName = params.roleName;\n\t\tlet databaseName = params.databaseName;\n\n\t\tif ((!roleName || !databaseName) && !branchId) {\n\t\t\tconst branches = await listProjectBranches({\n\t\t\t\tclient,\n\t\t\t\tpath: { project_id: projectId },\n\t\t\t\tthrowOnError: false,\n\t\t\t\tsignal,\n\t\t\t});\n\t\t\tif (branches.error || !branches.data) {\n\t\t\t\treturn err(toNeonError(branches.error, branches.response));\n\t\t\t}\n\t\t\tbranchId = branches.data.branches.find(\n\t\t\t\t(branch) => branch.default,\n\t\t\t)?.id;\n\t\t\tif (!branchId) {\n\t\t\t\treturn err(\n\t\t\t\t\tnew NeonError(\n\t\t\t\t\t\t\"Could not determine the default branch; pass branchId.\",\n\t\t\t\t\t\t\"client\",\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (!roleName) {\n\t\t\tif (!branchId) return err(branchRequired(\"roleName\"));\n\t\t\tconst roles = await listProjectBranchRoles({\n\t\t\t\tclient,\n\t\t\t\tpath: { project_id: projectId, branch_id: branchId },\n\t\t\t\tthrowOnError: false,\n\t\t\t\tsignal,\n\t\t\t});\n\t\t\tif (roles.error || !roles.data)\n\t\t\t\treturn err(toNeonError(roles.error, roles.response));\n\t\t\tif (roles.data.roles.length !== 1) {\n\t\t\t\treturn err(\n\t\t\t\t\tambiguous(\"role\", roles.data.roles.length, \"roleName\"),\n\t\t\t\t);\n\t\t\t}\n\t\t\troleName = roles.data.roles[0].name;\n\t\t}\n\n\t\tif (!databaseName) {\n\t\t\tif (!branchId) return err(branchRequired(\"databaseName\"));\n\t\t\tconst databases = await listProjectBranchDatabases({\n\t\t\t\tclient,\n\t\t\t\tpath: { project_id: projectId, branch_id: branchId },\n\t\t\t\tthrowOnError: false,\n\t\t\t\tsignal,\n\t\t\t});\n\t\t\tif (databases.error || !databases.data) {\n\t\t\t\treturn err(toNeonError(databases.error, databases.response));\n\t\t\t}\n\t\t\tif (databases.data.databases.length !== 1) {\n\t\t\t\treturn err(\n\t\t\t\t\tambiguous(\n\t\t\t\t\t\t\"database\",\n\t\t\t\t\t\tdatabases.data.databases.length,\n\t\t\t\t\t\t\"databaseName\",\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t\tdatabaseName = databases.data.databases[0].name;\n\t\t}\n\n\t\tconst conn = await getConnectionUri({\n\t\t\tclient,\n\t\t\tpath: { project_id: projectId },\n\t\t\tquery: {\n\t\t\t\tbranch_id: branchId,\n\t\t\t\tendpoint_id: params.endpointId,\n\t\t\t\tdatabase_name: databaseName,\n\t\t\t\trole_name: roleName,\n\t\t\t\tpooled: params.pooled ?? true,\n\t\t\t},\n\t\t\tthrowOnError: false,\n\t\t\tsignal,\n\t\t});\n\t\tif (conn.error || !conn.data)\n\t\t\treturn err(toNeonError(conn.error, conn.response));\n\t\treturn ok(conn.data.uri);\n\t}\n}\n\nfunction branchRequired(param: string): NeonError {\n\treturn new NeonError(\n\t\t`Pass branchId or ${param} to resolve a connection string.`,\n\t\t\"client\",\n\t);\n}\n\nfunction ambiguous(kind: string, count: number, param: string): NeonError {\n\treturn new NeonError(\n\t\t`Expected exactly one ${kind} to auto-select for the connection string; found ${count}. Pass ${param}.`,\n\t\t\"client\",\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;AAmCA,IAAa,WAAb,MAA8C;CAC7C;CACA;CACA;CACA;CACA;CAEA,YAAY,KAAqB;EAChC,KAAKA,OAAO;EACZ,KAAK,YAAY,IAAI,UAAkB,GAAG;EAC1C,KAAK,QAAQ,IAAI,MAAc,GAAG;EAClC,KAAK,YAAY,IAAI,UAAkB,GAAG;EAC1C,KAAK,UAAU,IAAI,QAAgB,GAAG;CACvC;CAcA,MAAM,iBACL,QACA,MACuC;EACvC,MAAM,cACL,MAAM,gBAAgB,KAAKA,KAAK,SAAS;EAG1C,MAAM,WAAW,KAAKA,KAAK,YAAY,IAAI;EAC3C,IAAI;GACH,MAAM,WAAW,MAAM,WAAW,gBACjC,KAAKC,SAAS,QAAQ,SAAS,MAAM,CACtC;GACA,MAAM,eAAe,UAAU,QAAQ;
|
|
1
|
+
{"version":3,"file":"postgres.js","names":["#ctx","#resolve"],"sources":["../../../src/neon/resources/postgres.ts"],"sourcesContent":["import {\n\tgetConnectionUri,\n\tlistProjectBranchDatabases,\n\tlistProjectBranches,\n\tlistProjectBranchRoles,\n} from \"../../client/sdk.gen.js\";\nimport type { CallOptions, RequestContext } from \"../context.js\";\nimport { cancelled, runBounded } from \"../deadline.js\";\nimport { NeonError, toNeonError } from \"../errors.js\";\nimport { err, finalize, type NeonResult, type Outcome, ok } from \"../result.js\";\nimport { DataApi } from \"./dataapi.js\";\nimport { Databases } from \"./databases.js\";\nimport { Endpoints } from \"./endpoints.js\";\nimport { Roles } from \"./roles.js\";\n\n/** Parameters for {@link Postgres.connectionString}. */\nexport interface ConnectionStringParams {\n\tprojectId: string;\n\t/** Defaults to the project's default branch. */\n\tbranchId?: string;\n\t/** Defaults to the branch's read-write endpoint. */\n\tendpointId?: string;\n\t/** Auto-selected when the branch has exactly one database. */\n\tdatabaseName?: string;\n\t/** Auto-selected when the branch has exactly one role. */\n\troleName?: string;\n\t/** Pooled connection string (default `true`). */\n\tpooled?: boolean;\n}\n\n/**\n * The Postgres data plane of a branch: compute endpoints, roles, databases, the Data API,\n * and a connection-string helper. (Grouped under `neon.postgres.*` so future top-level\n * namespaces like `functions` / `storage` stay unambiguous.)\n */\nexport class Postgres<DThrow extends boolean> {\n\treadonly endpoints: Endpoints<DThrow>;\n\treadonly roles: Roles<DThrow>;\n\treadonly databases: Databases<DThrow>;\n\treadonly dataApi: DataApi<DThrow>;\n\treadonly #ctx: RequestContext;\n\n\tconstructor(ctx: RequestContext) {\n\t\tthis.#ctx = ctx;\n\t\tthis.endpoints = new Endpoints<DThrow>(ctx);\n\t\tthis.roles = new Roles<DThrow>(ctx);\n\t\tthis.databases = new Databases<DThrow>(ctx);\n\t\tthis.dataApi = new DataApi<DThrow>(ctx);\n\t}\n\n\t/**\n\t * Resolve a Postgres connection string. Auto-selects the default branch and the sole\n\t * role/database when not specified (mirrors `@neon/config`'s `fetchEnv`); returns\n\t * a `client`-kind {@link NeonError} when the selection is ambiguous.\n\t */\n\tconnectionString(\n\t\tparams: ConnectionStringParams,\n\t): Promise<Outcome<string, DThrow>>;\n\tconnectionString<Throw extends boolean = DThrow>(\n\t\tparams: ConnectionStringParams,\n\t\topts: CallOptions<Throw>,\n\t): Promise<Outcome<string, Throw>>;\n\tasync connectionString(\n\t\tparams: ConnectionStringParams,\n\t\topts?: CallOptions,\n\t): Promise<string | NeonResult<string>> {\n\t\tconst shouldThrow =\n\t\t\topts?.throwOnError ?? this.#ctx.defaults.throwOnError;\n\t\t// This resolver makes up to four sequential requests without going through\n\t\t// RequestContext, so it owns the deadline covering all of them.\n\t\tconst deadline = this.#ctx.deadlineFor(opts);\n\t\ttry {\n\t\t\tconst resolved = await runBounded(deadline, () =>\n\t\t\t\tthis.#resolve(params, deadline.signal),\n\t\t\t);\n\t\t\tconst cancellation = cancelled(deadline);\n\t\t\t// `runBounded` resolves undefined only when the deadline won the race, which\n\t\t\t// `cancelled` then reports, so the fallback is unreachable by construction.\n\t\t\tconst result: NeonResult<string> =\n\t\t\t\tcancellation !== undefined\n\t\t\t\t\t? err(cancellation)\n\t\t\t\t\t: (resolved ??\n\t\t\t\t\t\terr(\n\t\t\t\t\t\t\tnew NeonError(\n\t\t\t\t\t\t\t\t\"The connection-string resolver ended without a result.\",\n\t\t\t\t\t\t\t\t\"client\",\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t));\n\t\t\treturn finalize(result, shouldThrow);\n\t\t} finally {\n\t\t\tdeadline.dispose();\n\t\t}\n\t}\n\n\tasync #resolve(\n\t\tparams: ConnectionStringParams,\n\t\tsignal?: AbortSignal,\n\t): Promise<NeonResult<string>> {\n\t\tconst client = this.#ctx.client;\n\t\tconst projectId = params.projectId;\n\t\tlet branchId = params.branchId;\n\t\tlet roleName = params.roleName;\n\t\tlet databaseName = params.databaseName;\n\n\t\tif ((!roleName || !databaseName) && !branchId) {\n\t\t\tconst branches = await listProjectBranches({\n\t\t\t\tclient,\n\t\t\t\tpath: { project_id: projectId },\n\t\t\t\tthrowOnError: false,\n\t\t\t\tsignal,\n\t\t\t});\n\t\t\tif (branches.error || !branches.data) {\n\t\t\t\treturn err(toNeonError(branches.error, branches.response));\n\t\t\t}\n\t\t\tbranchId = branches.data.branches.find(\n\t\t\t\t(branch) => branch.default,\n\t\t\t)?.id;\n\t\t\tif (!branchId) {\n\t\t\t\treturn err(\n\t\t\t\t\tnew NeonError(\n\t\t\t\t\t\t\"Could not determine the default branch; pass branchId.\",\n\t\t\t\t\t\t\"client\",\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (!roleName) {\n\t\t\tif (!branchId) return err(branchRequired(\"roleName\"));\n\t\t\tconst roles = await listProjectBranchRoles({\n\t\t\t\tclient,\n\t\t\t\tpath: { project_id: projectId, branch_id: branchId },\n\t\t\t\tthrowOnError: false,\n\t\t\t\tsignal,\n\t\t\t});\n\t\t\tif (roles.error || !roles.data)\n\t\t\t\treturn err(toNeonError(roles.error, roles.response));\n\t\t\tif (roles.data.roles.length !== 1) {\n\t\t\t\treturn err(\n\t\t\t\t\tambiguous(\"role\", roles.data.roles.length, \"roleName\"),\n\t\t\t\t);\n\t\t\t}\n\t\t\troleName = roles.data.roles[0].name;\n\t\t}\n\n\t\tif (!databaseName) {\n\t\t\tif (!branchId) return err(branchRequired(\"databaseName\"));\n\t\t\tconst databases = await listProjectBranchDatabases({\n\t\t\t\tclient,\n\t\t\t\tpath: { project_id: projectId, branch_id: branchId },\n\t\t\t\tthrowOnError: false,\n\t\t\t\tsignal,\n\t\t\t});\n\t\t\tif (databases.error || !databases.data) {\n\t\t\t\treturn err(toNeonError(databases.error, databases.response));\n\t\t\t}\n\t\t\tif (databases.data.databases.length !== 1) {\n\t\t\t\treturn err(\n\t\t\t\t\tambiguous(\n\t\t\t\t\t\t\"database\",\n\t\t\t\t\t\tdatabases.data.databases.length,\n\t\t\t\t\t\t\"databaseName\",\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t\tdatabaseName = databases.data.databases[0].name;\n\t\t}\n\n\t\tconst conn = await getConnectionUri({\n\t\t\tclient,\n\t\t\tpath: { project_id: projectId },\n\t\t\tquery: {\n\t\t\t\tbranch_id: branchId,\n\t\t\t\tendpoint_id: params.endpointId,\n\t\t\t\tdatabase_name: databaseName,\n\t\t\t\trole_name: roleName,\n\t\t\t\tpooled: params.pooled ?? true,\n\t\t\t},\n\t\t\tthrowOnError: false,\n\t\t\tsignal,\n\t\t});\n\t\tif (conn.error || !conn.data)\n\t\t\treturn err(toNeonError(conn.error, conn.response));\n\t\treturn ok(conn.data.uri);\n\t}\n}\n\nfunction branchRequired(param: string): NeonError {\n\treturn new NeonError(\n\t\t`Pass branchId or ${param} to resolve a connection string.`,\n\t\t\"client\",\n\t);\n}\n\nfunction ambiguous(kind: string, count: number, param: string): NeonError {\n\treturn new NeonError(\n\t\t`Expected exactly one ${kind} to auto-select for the connection string; found ${count}. Pass ${param}.`,\n\t\t\"client\",\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;AAmCA,IAAa,WAAb,MAA8C;CAC7C;CACA;CACA;CACA;CACA;CAEA,YAAY,KAAqB;EAChC,KAAKA,OAAO;EACZ,KAAK,YAAY,IAAI,UAAkB,GAAG;EAC1C,KAAK,QAAQ,IAAI,MAAc,GAAG;EAClC,KAAK,YAAY,IAAI,UAAkB,GAAG;EAC1C,KAAK,UAAU,IAAI,QAAgB,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