@protobase/server 0.129.1 → 0.130.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assistant/query-runner/grants-sql.js +32 -0
- package/dist/assistant/query-runner/query-input.js +33 -0
- package/dist/assistant/query-runner/query-module.js +44 -0
- package/dist/assistant/query-runner/query-runner.d.ts +8 -11
- package/dist/assistant/query-runner/query-runner.js +15 -57
- package/dist/assistant/query-runner/read-query.js +54 -0
- package/dist/assistant/query-runner/runner-sql.js +4 -20
- package/dist/assistant/query-runner/steps/001-role.js +19 -0
- package/dist/auth-store.d.ts +2 -2
- package/dist/auth-store.js +3 -3
- package/dist/better-auth/auth-schema.d.ts +13 -4
- package/dist/better-auth/auth-schema.js +40 -32
- package/dist/better-auth/auth-settings.d.ts +59 -11
- package/dist/better-auth/auth-settings.js +57 -13
- package/dist/better-auth/auth-tables.d.ts +6 -3
- package/dist/better-auth/auth-tables.js +12 -7
- package/dist/better-auth/authenticator.js +10 -2
- package/dist/better-auth/create-auth.d.ts +62 -7
- package/dist/better-auth/create-auth.js +55 -14
- package/dist/better-auth/device-sign-in-check.js +13 -0
- package/dist/better-auth/names/declaration.d.ts +18 -5
- package/dist/better-auth/names/declaration.js +3 -1
- package/dist/better-auth/names/modules/auth.js +9 -0
- package/dist/better-auth/names/modules/index.d.ts +34 -4
- package/dist/better-auth/names/modules/organizations.js +10 -3
- package/dist/better-auth/names/modules/personal-access-tokens.js +6 -3
- package/dist/better-auth/names/modules-on.js +25 -2
- package/dist/better-auth/names/resolve-names.d.ts +9 -1
- package/dist/better-auth/names/resolve-names.js +15 -9
- package/dist/better-auth/organizations/accept-invitation.js +5 -4
- package/dist/better-auth/organizations/add-every-user.js +3 -2
- package/dist/better-auth/organizations/host-scope.d.ts +10 -0
- package/dist/better-auth/organizations/host-scope.js +15 -0
- package/dist/better-auth/organizations/host.d.ts +12 -6
- package/dist/better-auth/organizations/host.js +99 -61
- package/dist/better-auth/organizations/kept-organizations.d.ts +21 -0
- package/dist/better-auth/organizations/kept-organizations.js +62 -0
- package/dist/better-auth/organizations/member-endpoints.js +4 -3
- package/dist/better-auth/organizations/options.d.ts +15 -0
- package/dist/better-auth/organizations/options.js +19 -1
- package/dist/better-auth/organizations/people-endpoint.js +3 -2
- package/dist/better-auth/organizations/pinned-membership.js +81 -0
- package/dist/better-auth/organizations/pinned-sessions.js +46 -0
- package/dist/better-auth/organizations/session-organization.js +3 -2
- package/dist/better-auth/organizations/store.js +14 -9
- package/dist/better-auth/personal-access-tokens/pinned-tokens.js +23 -0
- package/dist/better-auth/personal-access-tokens/token-plugin.js +75 -54
- package/dist/better-auth/personal-access-tokens/token-sessions.js +6 -3
- package/dist/better-auth/personal-access-tokens/token-store.js +15 -11
- package/dist/better-auth/store/adoption.js +25 -10
- package/dist/better-auth/store/drift.js +5 -4
- package/dist/better-auth/store/legacy-record.d.ts +10 -0
- package/dist/better-auth/store/legacy-record.js +56 -0
- package/dist/better-auth/store/migration-sql.js +31 -26
- package/dist/better-auth/store/offline/baseline-store.d.ts +11 -7
- package/dist/better-auth/store/offline/baseline-store.js +15 -12
- package/dist/better-auth/store/offline/module-switches.d.ts +27 -0
- package/dist/better-auth/store/offline/module-switches.js +94 -0
- package/dist/better-auth/store/offline/name-changes.d.ts +4 -1
- package/dist/better-auth/store/offline/name-changes.js +5 -2
- package/dist/better-auth/store/offline/offline-steps.d.ts +21 -7
- package/dist/better-auth/store/offline/offline-steps.js +29 -20
- package/dist/better-auth/store/offline/retired-watch.d.ts +5 -0
- package/dist/better-auth/store/offline/retired-watch.js +36 -0
- package/dist/better-auth/store/offline/settings-names.d.ts +3 -2
- package/dist/better-auth/store/offline/settings-names.js +10 -3
- package/dist/better-auth/store/offline/store-model.d.ts +9 -1
- package/dist/better-auth/store/offline/store-model.js +22 -5
- package/dist/better-auth/store/resources-outside.js +1 -1
- package/dist/better-auth/store/step-record.d.ts +13 -0
- package/dist/better-auth/store/step-record.js +59 -0
- package/dist/better-auth/store/steps/index.js +6 -1
- package/dist/better-auth/store/steps/legacy-versions.d.ts +7 -0
- package/dist/better-auth/store/steps/legacy-versions.js +4 -0
- package/dist/better-auth/store/steps/organizations/003-default-organization.js +113 -0
- package/dist/better-auth/store/steps/render.d.ts +3 -0
- package/dist/better-auth/store/steps/render.js +48 -25
- package/dist/better-auth/store/steps/step-lint.d.ts +14 -0
- package/dist/better-auth/store/steps/step-lint.js +31 -10
- package/dist/better-auth/store/steps/step.d.ts +18 -0
- package/dist/better-auth/store/steps/step.js +7 -1
- package/dist/better-auth/store/store-db.d.ts +6 -0
- package/dist/better-auth/store/store-db.js +11 -5
- package/dist/better-auth/store/store-names.d.ts +4 -0
- package/dist/better-auth/token-standing.js +12 -7
- package/dist/better-auth/users.d.ts +7 -2
- package/dist/better-auth/users.js +25 -3
- package/dist/built-in-resources.js +1 -1
- package/dist/calls/calls-module.js +42 -0
- package/dist/calls/calls-sql.js +4 -30
- package/dist/changes/capture-names.d.ts +3 -1
- package/dist/changes/capture-names.js +5 -2
- package/dist/changes/capture-schema-sql.d.ts +10 -0
- package/dist/changes/capture-schema-sql.js +21 -0
- package/dist/changes/capture-schema.d.ts +0 -18
- package/dist/changes/capture-schema.js +1 -74
- package/dist/changes/capture-sql.js +30 -24
- package/dist/changes/changes-input.js +36 -0
- package/dist/changes/changes-module.js +44 -0
- package/dist/changes/read-capture.js +67 -0
- package/dist/changes/steps/001-outbox.js +23 -0
- package/dist/channels/sends-module.js +37 -0
- package/dist/channels/sends-schema-sql.js +5 -5
- package/dist/comments/comments-module.js +30 -0
- package/dist/comments/comments-sql.js +1 -22
- package/dist/computed/buckets-sql.d.ts +5 -1
- package/dist/computed/buckets-sql.js +39 -46
- package/dist/computed/{buckets-schema.d.ts → buckets-targets.d.ts} +2 -3
- package/dist/computed/buckets-targets.js +50 -0
- package/dist/computed/computed-input.js +65 -0
- package/dist/computed/computed-module.js +102 -0
- package/dist/computed/formula-sql.js +14 -1
- package/dist/computed/read-computed.js +100 -0
- package/dist/computed/rollup-sql.js +13 -10
- package/dist/config-exports.d.ts +2 -2
- package/dist/create-admin.js +21 -5
- package/dist/derived/derived-module.js +89 -0
- package/dist/derived/derived-sql.js +1 -47
- package/dist/functions/define-function.d.ts +10 -4
- package/dist/functions/routes.js +5 -3
- package/dist/functions/supabase-routes.js +7 -5
- package/dist/history/history-module.js +34 -0
- package/dist/index.d.ts +19 -28
- package/dist/index.js +11 -21
- package/dist/internal.d.ts +26 -10
- package/dist/internal.js +22 -8
- package/dist/jobs/functions-sql.js +7 -11
- package/dist/jobs/job-data.js +36 -0
- package/dist/jobs/job-types.d.ts +6 -3
- package/dist/jobs/jobs-module.d.ts +5 -0
- package/dist/jobs/jobs-module.js +84 -0
- package/dist/jobs/run-job.d.ts +1 -1
- package/dist/jobs/run-job.js +7 -5
- package/dist/jobs/runtime.d.ts +9 -4
- package/dist/jobs/runtime.js +11 -6
- package/dist/jobs/schema.d.ts +0 -11
- package/dist/jobs/schema.js +1 -59
- package/dist/jobs/steps/001-pg-boss-45.js +483 -0
- package/dist/live/notices-module.js +30 -0
- package/dist/live/notices-sql.js +2 -1
- package/dist/mail/feedback/feedback-schema.js +3 -30
- package/dist/mail/feedback/mail-feedback-module.js +37 -0
- package/dist/mail/unsubscribe/unsubscribe-schema.js +3 -21
- package/dist/mail/unsubscribe/unsubscribes-module.js +31 -0
- package/dist/migration-record/check-record.d.ts +9 -7
- package/dist/migration-record/check-record.js +12 -11
- package/dist/migration-record/module-needs.js +30 -0
- package/dist/migration-record/read-record.js +27 -15
- package/dist/migration-record/record-model.d.ts +7 -2
- package/dist/migration-record/record-model.js +14 -6
- package/dist/migration-record/startup-decision.js +18 -7
- package/dist/migration-sql/additive-statements.d.ts +4 -0
- package/dist/migration-sql/additive-statements.js +105 -0
- package/dist/notifications/devices-module.js +61 -0
- package/dist/notifications/history-module.js +50 -0
- package/dist/notifications/notifications-targets.js +23 -0
- package/dist/notifications/read-table.js +16 -0
- package/dist/notifications/schema-sql.js +1 -22
- package/dist/notifications/schema.js +1 -101
- package/dist/notifications/table-names.js +40 -0
- package/dist/organization-scope/app-scope.js +38 -0
- package/dist/organization-scope/auth-request-organization.js +71 -0
- package/dist/organization-scope/organization-tables.js +20 -0
- package/dist/organization-scope/sign-in-organization.js +21 -0
- package/dist/package.js +1 -1
- package/dist/personal-mail/shared-sender-store.js +4 -2
- package/dist/realtime/relay/realtime-relay-module.js +37 -0
- package/dist/relation-found.js +6 -0
- package/dist/relay/read-relay.js +85 -0
- package/dist/relay/realtime-members-sql.js +51 -28
- package/dist/relay/relay-module.js +53 -0
- package/dist/relay/relay-targets.js +28 -0
- package/dist/relay/session-end.js +1 -3
- package/dist/relay/sessions-sql.js +4 -27
- package/dist/rest/table-routes.js +9 -2
- package/dist/schema-modules/feature-schemas-sql.d.ts +40 -0
- package/dist/schema-modules/feature-schemas-sql.js +51 -0
- package/dist/schema-modules/module-difference.d.ts +31 -0
- package/dist/schema-modules/module-difference.js +98 -0
- package/dist/schema-modules/modules-sql.js +13 -0
- package/dist/schema-modules/modules.d.ts +37 -0
- package/dist/schema-modules/modules.js +56 -0
- package/dist/schema-modules/needed-modules.d.ts +41 -0
- package/dist/schema-modules/needed-modules.js +61 -0
- package/dist/schema-modules/resource-difference.js +83 -0
- package/dist/schema-modules/schema-module.d.ts +112 -0
- package/dist/schema-modules/schema-module.js +8 -0
- package/dist/status/status-module.js +63 -0
- package/dist/status/status-targets.js +21 -0
- package/dist/types.d.ts +6 -1
- package/dist/user-tables/reloading-admin.d.ts +1 -0
- package/dist/user-tables/reloading-admin.js +1 -0
- package/dist/user-tables/schema-sql.js +1 -14
- package/dist/user-tables/schema.js +4 -27
- package/dist/user-tables/user-tables-module.js +38 -0
- package/dist/webhooks/table/delivery-log-module.js +36 -0
- package/dist/webhooks/table/owner-roles.js +3 -2
- package/dist/webhooks/table/schema-sql.js +27 -26
- package/dist/webhooks/table/webhooks-schema-module.js +63 -0
- package/dist/webhooks/table/webhooks-targets.js +26 -0
- package/dist/webhooks/webhooks.js +1 -1
- package/dist/workflows/custom-steps/custom-steps-module.js +51 -0
- package/dist/workflows/custom-steps/custom-steps-sql.js +10 -7
- package/dist/workflows/custom-steps/runners-sql.js +10 -7
- package/dist/workflows/read-catalogue.js +23 -0
- package/dist/workflows/schema-sql.js +12 -9
- package/dist/workflows/status-sql.js +12 -6
- package/dist/workflows/storage/storage-module.js +39 -0
- package/dist/workflows/storage/storage-sql.js +8 -5
- package/dist/workflows/workflows-schema-module.js +49 -0
- package/dist/workflows/workflows-tables-sql.js +32 -0
- package/dist/workflows/workflows-targets.js +16 -0
- package/package.json +6 -6
- package/dist/assistant/query-runner/runner-plan.js +0 -30
- package/dist/better-auth/store/migrations-table.js +0 -27
- package/dist/better-auth/store/modules-off.js +0 -17
- package/dist/calls/calls-sql.d.ts +0 -11
- package/dist/changes/capture-plan.js +0 -79
- package/dist/channels/sends-schema.d.ts +0 -7
- package/dist/channels/sends-schema.js +0 -18
- package/dist/comments/comments-sql.d.ts +0 -14
- package/dist/computed/buckets-plan.d.ts +0 -2
- package/dist/computed/buckets-plan.js +0 -88
- package/dist/computed/buckets-schema.js +0 -39
- package/dist/computed/computed-plan.js +0 -81
- package/dist/computed/computed-schema.d.ts +0 -16
- package/dist/computed/computed-schema.js +0 -63
- package/dist/derived/derived-sql.d.ts +0 -12
- package/dist/mail/feedback/feedback-schema.d.ts +0 -7
- package/dist/mail/unsubscribe/unsubscribe-schema.d.ts +0 -10
- package/dist/notifications/schema.d.ts +0 -14
- package/dist/realtime/relay/relay-schema.d.ts +0 -7
- package/dist/realtime/relay/relay-schema.js +0 -20
- package/dist/relay/realtime-members-schema.js +0 -67
- package/dist/relay/relay-schema.d.ts +0 -14
- package/dist/relay/relay-schema.js +0 -28
- package/dist/status/schema.d.ts +0 -12
- package/dist/status/schema.js +0 -33
- package/dist/user-tables/schema.d.ts +0 -11
- package/dist/webhooks/table/schema.d.ts +0 -16
- package/dist/webhooks/table/schema.js +0 -56
- package/dist/workflows/schema.d.ts +0 -13
- package/dist/workflows/schema.js +0 -88
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HttpProblem, MissingCredentials, badRequest, forbidden, notFound, unauthorized } from "./problem.js";
|
|
2
|
-
import {
|
|
2
|
+
import { jobsSchema } from "./jobs/schema.js";
|
|
3
3
|
import { capturedBy, isCaptured } from "./changes/capture-sql.js";
|
|
4
4
|
import { ConnectionsBusy } from "./connections-busy.js";
|
|
5
5
|
import { longQueryTimeoutMs } from "./statement-timeout.js";
|
|
@@ -29,6 +29,7 @@ import { relayed, sqlSends } from "./realtime/relay/realtime-options.js";
|
|
|
29
29
|
import { backgroundSettled, waitUntil } from "./functions/wait-until.js";
|
|
30
30
|
import { objectKey } from "./storage/object-key.js";
|
|
31
31
|
import { appNameOver, defaultAppName, shownAppName } from "./app-name.js";
|
|
32
|
+
import { authStoreTables } from "./better-auth/auth-tables.js";
|
|
32
33
|
import { supabasePath } from "./supabase-paths.js";
|
|
33
34
|
import { goTruePath } from "./gotrue/keys.js";
|
|
34
35
|
import { defaultSignInPolicy, signInPolicyMethods } from "./better-auth/sign-in-policy.js";
|
|
@@ -43,8 +44,6 @@ import { readOperatorSettings } from "./better-auth/operator-provider.js";
|
|
|
43
44
|
import { readPlatformSignIns } from "./better-auth/platform-sign-in-env.js";
|
|
44
45
|
import { normalizeRoles } from "./better-auth/create-auth.js";
|
|
45
46
|
import { mcpApprovals } from "./mcp/mcp-approval-store.js";
|
|
46
|
-
import { changesMigration, checkChanges, migrationCommand } from "./changes/capture-schema.js";
|
|
47
|
-
import { checkComments, commentsMigration } from "./comments/comments-sql.js";
|
|
48
47
|
import { mcpToolContext } from "./mcp/mcp-context.js";
|
|
49
48
|
import { mcpGate, sessionOf } from "./mcp/mcp-gate.js";
|
|
50
49
|
import { mcpHandler } from "./mcp/mcp-handler.js";
|
|
@@ -62,11 +61,10 @@ import { workflowReadTools } from "./workflows/mcp/workflow-read-tools.js";
|
|
|
62
61
|
import { workflowWriteTools } from "./workflows/mcp/workflow-write-tools.js";
|
|
63
62
|
import { mcpTools } from "./mcp/mcp-tools.js";
|
|
64
63
|
import { workflowInstructions } from "./workflows/mcp/workflow-instructions.js";
|
|
65
|
-
import { addAppRoleToOwners, addMember, createOrganization, listOrganizations, organizationsPageSize, removeMember, setMemberRoles } from "./better-auth/organizations/host.js";
|
|
64
|
+
import { addAppRoleToOwners, addMember, createOrganization, isMemberByEmail, listOrganizations, organizationByKey, organizationsPageSize, removeMember, setMemberRoles } from "./better-auth/organizations/host.js";
|
|
66
65
|
import { createUser, deleteUser, hasUsers, listUsers, roleChoices, setUserBanned, setUserRole, usersPageSize } from "./better-auth/users.js";
|
|
67
66
|
import { enqueueJob } from "./jobs/declared-job.js";
|
|
68
|
-
import {
|
|
69
|
-
import { hasBuckets } from "./computed/buckets-schema.js";
|
|
67
|
+
import { hasBuckets } from "./computed/buckets-targets.js";
|
|
70
68
|
import { coalesce } from "./changes/coalesce.js";
|
|
71
69
|
import { eventMatcher } from "./changes/match-events.js";
|
|
72
70
|
import { parseColumns, readOutbox } from "./changes/outbox.js";
|
|
@@ -137,33 +135,23 @@ import { betterAuthTokens } from "./better-auth/authenticator.js";
|
|
|
137
135
|
import { overSignIn } from "./better-auth/over-sign-in.js";
|
|
138
136
|
import { issueToken, maxTokenTtlSeconds } from "./better-auth/tokens.js";
|
|
139
137
|
import { authSchemaMigration } from "./better-auth/auth-schema.js";
|
|
138
|
+
import { jobsSchemaSql } from "./jobs/jobs-module.js";
|
|
140
139
|
import { checkMigrationRecord } from "./migration-record/check-record.js";
|
|
140
|
+
import { neededModules } from "./schema-modules/needed-modules.js";
|
|
141
141
|
import { authSchemaDrift } from "./better-auth/store/drift.js";
|
|
142
|
-
import { authStoreTables } from "./better-auth/auth-tables.js";
|
|
143
142
|
import { checkResourcesOutsideAuthStore } from "./better-auth/store/resources-outside.js";
|
|
144
|
-
import {
|
|
145
|
-
import { checkWebhooksSchema, webhooksMigration } from "./webhooks/table/schema.js";
|
|
146
|
-
import { checkWorkflowsSchema, workflowsMigration } from "./workflows/schema.js";
|
|
143
|
+
import { migrationCommand } from "./changes/capture-schema.js";
|
|
147
144
|
import { releaseConnectionsWithUsers } from "./workflows/connections/release-without-engine.js";
|
|
148
|
-
import { checkUserTablesSchema, userTablesMigration } from "./user-tables/schema.js";
|
|
149
145
|
import { ownedDefinitionsMigration } from "./user-tables/owned-definitions.js";
|
|
150
146
|
import { userTableResources } from "./user-tables/user-table-resources.js";
|
|
151
147
|
import { readDefinitionsVersion } from "./user-tables/definitions-version.js";
|
|
152
148
|
import { reloadingAdmin } from "./user-tables/reloading-admin.js";
|
|
153
|
-
import { checkRealtimeRelay, realtimeRelayMigration } from "./realtime/relay/relay-schema.js";
|
|
154
|
-
import { channelSendsMigration, checkChannelSends } from "./channels/sends-schema.js";
|
|
155
|
-
import { callsMigration, checkCalls } from "./calls/calls-sql.js";
|
|
156
149
|
import { checkAi } from "./ai/check-ai.js";
|
|
157
|
-
import { checkNotificationsSchema, notificationsMigration } from "./notifications/schema.js";
|
|
158
|
-
import { checkStatusSchema, statusMigration } from "./status/schema.js";
|
|
159
|
-
import { checkUnsubscribesSchema, unsubscribesMigration } from "./mail/unsubscribe/unsubscribe-schema.js";
|
|
160
150
|
import { BulkMailError } from "./mail/unsubscribe/bulk-mail-error.js";
|
|
161
|
-
import { checkMailFeedbackSchema, mailFeedbackMigration } from "./mail/feedback/feedback-schema.js";
|
|
162
151
|
import { relayClientEvents, typingResources } from "./relay/client-events.js";
|
|
163
|
-
import { checkRelaySchema, relayMigration } from "./relay/relay-schema.js";
|
|
164
152
|
import { addEveryUser } from "./better-auth/organizations/add-every-user.js";
|
|
165
153
|
import { maxWidgetPropsBytes, widget } from "./assistant/widget.js";
|
|
166
|
-
import {
|
|
154
|
+
import { checkQueryRoleSafety } from "./assistant/query-runner/query-runner.js";
|
|
167
155
|
import { startErrorReporting } from "./error-reporting/error-reporter.js";
|
|
168
156
|
import { functionApp } from "./functions/function-app.js";
|
|
169
157
|
import { readJson } from "./functions/read-json.js";
|
|
@@ -178,4 +166,6 @@ import { defineEmail } from "./mail/define-email.js";
|
|
|
178
166
|
import { definePdf } from "./pdf/define-pdf.js";
|
|
179
167
|
import { startJobs } from "./jobs/runtime.js";
|
|
180
168
|
import { jobsDrainApp } from "./jobs/drain-route.js";
|
|
181
|
-
|
|
169
|
+
import { captureSchemaSql } from "./changes/capture-schema-sql.js";
|
|
170
|
+
import { callsSchemaSql, channelSendsSchemaSql, commentsSchemaSql, computedSchemaSql, derivedSchemaSql, mailFeedbackSchemaSql, notificationsSchemaSql, querySchemaSql, realtimeRelaySchemaSql, relaySchemaSql, statusSchemaSql, unsubscribesSchemaSql, userTablesSchemaSql, webhooksSchemaSql, workflowsSchemaSql } from "./schema-modules/feature-schemas-sql.js";
|
|
171
|
+
export { BulkMailError, ConnectionsBusy, DeviceStoreError, FatalJobError, HistoryStoreError, HttpProblem, MailSenderRefusedError, MailServerTimeoutError, MissingCredentials, ModelError, NotificationSendError, PersonalMailError, PushMessageError, SenderAddressError, SenderAddressNotFoundError, TemplateDataError, addAppRoleToOwners, addCommentTool, addEveryUser, addMember, apiKeyCaller, apiKeySettings, apiKeyVariables, apnsKeyIdVariable, apnsKeyVariable, apnsSender, apnsTeamIdVariable, appNameOver, appRelayChannels, aspectRatio, assistantProtocolRoutes, assistantRoles, assistantSettings, assistantVariables, authSchemaDrift, authSchemaMigration, authStoreTables, backgroundSettled, badRequest, batchWriteTool, beforeSignInPluginsVariable, betterAuthTokens, bridgeClosings, callsSchemaSql, capSocketMessages, captureSchemaSql, capturedBy, channelSendsSchemaSql, checkAi, checkMigrationRecord, checkQueryRoleSafety, checkRelayOptions, checkResourcesOutsideAuthStore, checkSourceNames, checkViewQueries, coalesce, commentTools, commentsSchemaSql, computedSchemaSql, configExports, consoleAuditQueue, conversationKey, countRecordsTool, createAdmin, createConversations, createEncryptionTools, createFileCleanup, createOrganization, createRecordTool, createUser, defaultAppName, defaultHistoryPage, defaultRelayChannels, defaultSignInPolicy, defineEmail, defineFunction, defineJob, definePdf, defineTemplate, defineTool, deleteRecordTool, deleteUser, derivedSchemaSql, describeResourceTool, deviceIdParam, deviceStore, devicesPath, enqueueJob, errorReportingSettings, errorReportingVariable, eventMatcher, fcmSender, fcmServiceAccountVariable, fileConversationStore, fileSize, fileType, forbidden, formatUri, functionApp, generateVapidKeys, getRecordTool, gmailSettingsScope, goTruePath, handleDroppedConnections, hasBuckets, hasUsers, historyIdParam, historyIdPattern, historyLimits, historyPath, historyStore, honorSocketMessageCaps, hookPath, imageSize, isBackgroundWork, isCaptured, isJobDefinition, isMailTemplate, isMemberByEmail, isOAuthWellKnownPath, isSchedule, issueToken, jobDefinitions, jobsDrainApp, jobsSchema, jobsSchemaSql, jwtAuthenticator, jwtVerifier, limitedFileStore, listCommentsTool, listOrganizations, listRecordsTool, listResourcesTool, listUsers, localFileStore, longQueryTimeoutMs, mailFeedbackHeaders, mailFeedbackResource, mailFeedbackSchemaSql, mailFeedbackSecret, mapSettings, mapStyleUrl, mapStyleVariable, maxDevicesPerUser, maxHistoryPage, maxMessageBytes, maxRecipients, maxRelayDevices, maxTokenTtlSeconds, maxTtlSeconds, maxUnreadCount, maxWidgetPropsBytes, mcpApprovals, mcpGate, mcpHandler, mcpIcons, mcpInstructions, mcpRoutes, mcpServer, mcpToolContext, mcpTools, migrationCommand, neededModules, newWebhookSecret, normalizeRoles, notFound, notificationSenders, notificationsSchemaSql, oauthWellKnownPaths, objectKey, onDoNotDisturb, organizationByKey, organizationsPageSize, overSignIn, ownedDefinitionsMigration, parseColumns, parseRoles, passwordLength, pluginOptions, pluginsBeforeSignIn, pluginsFor, pluginsVariable, pngIcons, poolWaitMs, postgresDeviceStore, postgresHistoryStore, processor, pushMessage, querySchemaSql, readApnsSettings, readDbConnections, readDefinitionsVersion, readFcmSettings, readJson, readOnlyQueryTool, readOperatorSettings, readOutbox, readPlatformSignIns, readRecordTools, readRelaySettings, readRelaySwitch, readVapidSettings, readWriteQueryTool, readableResources, realtimeLimits, realtimeRelaySchemaSql, realtimeSwitchVariable, realtimeVariables, recordBlocksOf, recordOf, redactHookKeys, refusalOf, refused, relayClientEvents, relayCredentialVariable, relayHandle, relayPresencePath, relayResults, relaySchemaSql, relaySendAnswer, relaySendPath, relaySendRequest, relaySender, relaySettings, relayUrlVariable, relayed, releaseConnectionsWithUsers, reloadingAdmin, removeDevicesWithUsers, removeHistoryWithUsers, removeMember, renderVariant, requestApproval, requireEnv, resourceChange, roleChoices, runInBackground, runReadOnlyQuery, runReadWriteQuery, runTurn, runtimeUrl, runtimeVariable, s3FileStore, seesAssistant, seesRuntime, sendNotification, sessionOf, setMemberRoles, setUserBanned, setUserRole, shownAppName, signInPolicyMethods, socketMessageCapOf, sourceOptions, sourcesFor, sourcesVariable, sqlSends, startErrorReporting, startJobs, startWorkflow, statusNames, statusSchemaSql, storageCleanupSchedule, storageProvider, storeFile, storeUsage, streamChatCompletion, subscription, supabasePath, tcpBridge, thumbHash, typingResources, unauthorized, unsubscribesSchemaSql, updateRecordTool, urgencies, userTableResources, userTablesSchemaSql, usersPageSize, vapidPrivateKeyVariable, vapidPublicKeyVariable, vapidSubjectVariable, variantPath, verifySignature, verifyStandardWebhook, waitUntil, wantsLongQueries, webManifestPath, webPushSender, webauthnPath, webhookIssuePath, webhookParams, webhooksSchemaSql, widget, withCacheBreakpoints, withTrustedApps, workflowInstructions, workflowReadTools, workflowTypes, workflowWriteTools, workflowsSchemaSql, writeRecordTools };
|
package/dist/internal.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { ModuleId } from "./better-auth/names/modules/index.js";
|
|
2
|
+
import { resolveNames } from "./better-auth/names/resolve-names.js";
|
|
3
|
+
import { organizationsEnabled } from "./better-auth/organizations/options.js";
|
|
4
|
+
import { keptNames } from "./better-auth/organizations/kept-organizations.js";
|
|
1
5
|
import { AuthPlugins, buildAuth, createAuth, loadAuthPlugins } from "./better-auth/create-auth.js";
|
|
2
6
|
import { checkNotificationsOptions } from "./notifications/options.js";
|
|
3
7
|
import { checkCallsOptions } from "./calls/calls-options.js";
|
|
@@ -9,26 +13,38 @@ import { betterAuthAuthenticator } from "./better-auth/authenticator.js";
|
|
|
9
13
|
import { buildAuthenticator } from "./better-auth/authenticate-settings.js";
|
|
10
14
|
import { isOverSignIn } from "./better-auth/over-sign-in.js";
|
|
11
15
|
import { readOrigins } from "./better-auth/origins.js";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
16
|
+
import { appDialect } from "./app-dialect.js";
|
|
17
|
+
import { readPasskeyDomain } from "./better-auth/passkey-domain.js";
|
|
14
18
|
import { localFiles } from "./files/local-files.js";
|
|
15
19
|
import { s3Files } from "./files/s3-files.js";
|
|
16
20
|
import { fileProviderOf } from "./files/provider-settings.js";
|
|
17
|
-
import { declaredJob } from "./jobs/declared-job.js";
|
|
18
21
|
import { webhooksModule } from "./webhooks/table/webhooks-module.js";
|
|
19
22
|
import { workflowsModule } from "./workflows/workflows-module.js";
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import { captureNames } from "./changes/capture-names.js";
|
|
23
|
+
import { captureNames, uncapturedMessage } from "./changes/capture-names.js";
|
|
24
|
+
import { declaredJob } from "./jobs/declared-job.js";
|
|
23
25
|
import { bucketsRefreshes, refreshBuckets } from "./computed/buckets-job.js";
|
|
24
26
|
import { workflowPlugins } from "./workflows/default-plugins.js";
|
|
25
27
|
import { StoreNames, storeNames } from "./better-auth/store/store-names.js";
|
|
26
28
|
import { settingsStoreNames } from "./better-auth/store/offline/settings-names.js";
|
|
27
|
-
import {
|
|
29
|
+
import { OrganizationsInput, organizationsInput } from "./better-auth/store/steps/step.js";
|
|
30
|
+
import { KeptModule, LastSteps, StoreModel, keptModule, latestSteps, storeModel, storeNamesList } from "./better-auth/store/offline/store-model.js";
|
|
28
31
|
import { nameChanges } from "./better-auth/store/offline/name-changes.js";
|
|
29
|
-
import { offlineStepsMigration } from "./better-auth/store/offline/offline-steps.js";
|
|
32
|
+
import { SnapshotStore, offlineStepsMigration } from "./better-auth/store/offline/offline-steps.js";
|
|
33
|
+
import { retiredSchema } from "./better-auth/store/offline/retired-watch.js";
|
|
34
|
+
import { OffChoice, forceSetting, keepSql, keptTables, offChoices, revivalCheckSql, revivalRefusal, unwatchSql } from "./better-auth/store/offline/module-switches.js";
|
|
35
|
+
import { bucketsCommentPrefix } from "./computed/buckets-sql.js";
|
|
36
|
+
import { AppliedStep } from "./better-auth/store/step-record.js";
|
|
30
37
|
import { LiveStore, baselineStore } from "./better-auth/store/offline/baseline-store.js";
|
|
31
|
-
import {
|
|
38
|
+
import { stepRecordMigration, stepsOfVersions } from "./better-auth/store/legacy-record.js";
|
|
39
|
+
import { legacyVersions } from "./better-auth/store/steps/legacy-versions.js";
|
|
40
|
+
import { LintedStep, SquawkFinding, contractingRules, lintSteps, lockingRules, squawkReport } from "./better-auth/store/steps/step-lint.js";
|
|
41
|
+
import { contractingSql } from "./migration-sql/additive-statements.js";
|
|
42
|
+
import { ModuleInput, ModuleModel, SchemaModule, noInput } from "./schema-modules/schema-module.js";
|
|
43
|
+
import { ModuleTargets, ModulesModel, SchemaModuleId, latestModules, schemaModules, targetIds } from "./schema-modules/modules.js";
|
|
32
44
|
import { RecordModel, modelHash, runtimeModel } from "./migration-record/record-model.js";
|
|
33
45
|
import { AfterIndex, recordTable, recordTableSql } from "./migration-record/record-table.js";
|
|
34
|
-
|
|
46
|
+
import { recordsRuntimeModel } from "./migration-record/check-record.js";
|
|
47
|
+
import { plainStoreDb } from "./better-auth/store/store-db.js";
|
|
48
|
+
import { moduleDifference, retiredDifference } from "./schema-modules/module-difference.js";
|
|
49
|
+
import { keptStoreModules } from "./better-auth/auth-schema.js";
|
|
50
|
+
export { type AfterIndex, type AppAuthInput, type AppliedStep, type AuthPlugins, type KeptModule, type LastSteps, type LintedStep, type LiveStore, type ModuleId, type ModuleInput, type ModuleModel, type ModuleTargets, type ModulesModel, type OffChoice, type OrganizationsInput, type RecordModel, type SchemaModule, type SchemaModuleId, type SnapshotStore, type SquawkFinding, type StoreModel, type StoreNames, appAuthOptions, appDialect, appPool, baselineStore, betterAuthAuthenticator, bucketsCommentPrefix, bucketsRefreshes, buildAppAuth, buildAuth, buildAuthenticator, captureNames, checkCallsOptions, checkNotificationsOptions, checkStatusOptions, contractingRules, contractingSql, createAuth, declaredJob, fileProviderOf, forceSetting, isOverSignIn, isSubscription, keepSql, keptModule, keptNames, keptStoreModules, keptTables, latestModules, latestSteps, legacyVersions, lintSteps, loadAuthPlugins, localFiles, lockingRules, longQueryPool, modelHash, moduleDifference, nameChanges, noInput, offChoices, offlineStepsMigration, organizationsEnabled, organizationsInput, plainStoreDb, readOrigins, readPasskeyDomain, recordTable, recordTableSql, recordsRuntimeModel, refreshBuckets, resolveNames, retiredDifference, retiredSchema, revivalCheckSql, revivalRefusal, runtimeModel, s3Files, schemaModules, settingsStoreNames, squawkReport, stepRecordMigration, stepsOfVersions, storeModel, storeNames, storeNamesList, targetIds, uncapturedMessage, unwatchSql, webhooksModule, workflowPlugins, workflowsModule };
|
package/dist/internal.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { readOrigins } from "./better-auth/origins.js";
|
|
2
|
-
import {
|
|
2
|
+
import { resolveNames } from "./better-auth/names/resolve-names.js";
|
|
3
3
|
import { storeNames } from "./better-auth/store/store-names.js";
|
|
4
|
+
import { plainStoreDb } from "./better-auth/store/store-db.js";
|
|
5
|
+
import { keptNames } from "./better-auth/organizations/kept-organizations.js";
|
|
6
|
+
import { organizationsEnabled } from "./better-auth/organizations/options.js";
|
|
7
|
+
import { readPasskeyDomain } from "./better-auth/passkey-domain.js";
|
|
4
8
|
import { buildAuth, createAuth, loadAuthPlugins } from "./better-auth/create-auth.js";
|
|
5
|
-
import { uncapturedMessage } from "./changes/capture-schema.js";
|
|
6
9
|
import { declaredJob } from "./jobs/declared-job.js";
|
|
10
|
+
import { bucketsCommentPrefix } from "./computed/buckets-sql.js";
|
|
7
11
|
import { bucketsRefreshes, refreshBuckets } from "./computed/buckets-job.js";
|
|
8
12
|
import { isSubscription } from "./webhooks/subscription.js";
|
|
9
13
|
import { workflowPlugins } from "./workflows/default-plugins.js";
|
|
@@ -15,9 +19,17 @@ import { checkStatusOptions } from "./status/options.js";
|
|
|
15
19
|
import { appPool, longQueryPool } from "./app-pool.js";
|
|
16
20
|
import { betterAuthAuthenticator } from "./better-auth/authenticator.js";
|
|
17
21
|
import { isOverSignIn } from "./better-auth/over-sign-in.js";
|
|
18
|
-
import { latestSteps, storeModel, storeNamesList } from "./better-auth/store/offline/store-model.js";
|
|
19
|
-
import {
|
|
22
|
+
import { keptModule, latestSteps, storeModel, storeNamesList } from "./better-auth/store/offline/store-model.js";
|
|
23
|
+
import { baselineStore } from "./better-auth/store/offline/baseline-store.js";
|
|
24
|
+
import { legacyVersions } from "./better-auth/store/steps/legacy-versions.js";
|
|
25
|
+
import { stepRecordMigration, stepsOfVersions } from "./better-auth/store/legacy-record.js";
|
|
26
|
+
import { organizationsInput } from "./better-auth/store/steps/step.js";
|
|
27
|
+
import { keptStoreModules } from "./better-auth/auth-schema.js";
|
|
20
28
|
import { recordTable, recordTableSql } from "./migration-record/record-table.js";
|
|
29
|
+
import { noInput } from "./schema-modules/schema-module.js";
|
|
30
|
+
import { moduleDifference, retiredDifference } from "./schema-modules/module-difference.js";
|
|
31
|
+
import { latestModules, schemaModules, targetIds } from "./schema-modules/modules.js";
|
|
32
|
+
import { modelHash, runtimeModel } from "./migration-record/record-model.js";
|
|
21
33
|
import { nameChanges } from "./better-auth/store/offline/name-changes.js";
|
|
22
34
|
import { recordsRuntimeModel } from "./migration-record/check-record.js";
|
|
23
35
|
import { webhooksModule } from "./webhooks/table/webhooks-module.js";
|
|
@@ -25,10 +37,12 @@ import { workflowsModule } from "./workflows/workflows-module.js";
|
|
|
25
37
|
import { appDialect } from "./app-dialect.js";
|
|
26
38
|
import { appAuthOptions, buildAppAuth } from "./better-auth/auth-settings.js";
|
|
27
39
|
import { buildAuthenticator } from "./better-auth/authenticate-settings.js";
|
|
28
|
-
import { captureNames } from "./changes/capture-names.js";
|
|
40
|
+
import { captureNames, uncapturedMessage } from "./changes/capture-names.js";
|
|
29
41
|
import { checkCallsOptions } from "./calls/calls-options.js";
|
|
30
42
|
import { settingsStoreNames } from "./better-auth/store/offline/settings-names.js";
|
|
31
43
|
import { offlineStepsMigration } from "./better-auth/store/offline/offline-steps.js";
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
34
|
-
|
|
44
|
+
import { retiredSchema } from "./better-auth/store/offline/retired-watch.js";
|
|
45
|
+
import { forceSetting, keepSql, keptTables, offChoices, revivalCheckSql, revivalRefusal, unwatchSql } from "./better-auth/store/offline/module-switches.js";
|
|
46
|
+
import { contractingRules, lintSteps, lockingRules, squawkReport } from "./better-auth/store/steps/step-lint.js";
|
|
47
|
+
import { contractingSql } from "./migration-sql/additive-statements.js";
|
|
48
|
+
export { appAuthOptions, appDialect, appPool, baselineStore, betterAuthAuthenticator, bucketsCommentPrefix, bucketsRefreshes, buildAppAuth, buildAuth, buildAuthenticator, captureNames, checkCallsOptions, checkNotificationsOptions, checkStatusOptions, contractingRules, contractingSql, createAuth, declaredJob, fileProviderOf, forceSetting, isOverSignIn, isSubscription, keepSql, keptModule, keptNames, keptStoreModules, keptTables, latestModules, latestSteps, legacyVersions, lintSteps, loadAuthPlugins, localFiles, lockingRules, longQueryPool, modelHash, moduleDifference, nameChanges, noInput, offChoices, offlineStepsMigration, organizationsEnabled, organizationsInput, plainStoreDb, readOrigins, readPasskeyDomain, recordTable, recordTableSql, recordsRuntimeModel, refreshBuckets, resolveNames, retiredDifference, retiredSchema, revivalCheckSql, revivalRefusal, runtimeModel, s3Files, schemaModules, settingsStoreNames, squawkReport, stepRecordMigration, stepsOfVersions, storeModel, storeNames, storeNamesList, targetIds, uncapturedMessage, unwatchSql, webhooksModule, workflowPlugins, workflowsModule };
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
+
import { organizationKey } from "./job-data.js";
|
|
1
2
|
/** The comment each Protobase function in the jobs schema carries, which the startup check reads. */
|
|
2
|
-
const functionsComment = `Protobase jobs
|
|
3
|
-
/** Protobase's own functions beside pg-boss's tables, by name; each carries `functionsComment`. */
|
|
4
|
-
const functionNames = [
|
|
5
|
-
"enqueue",
|
|
6
|
-
"next_due",
|
|
7
|
-
"failed_retry",
|
|
8
|
-
"failed_delete"
|
|
9
|
-
];
|
|
3
|
+
const functionsComment = `Protobase jobs 4`;
|
|
10
4
|
/**
|
|
11
5
|
* `jobs.enqueue(name, payload, run_at, key, group_key, priority)`: a job from SQL, such as a trigger, in the caller's
|
|
12
6
|
* transaction. It inserts what pg-boss's `send()` does, with the queue's retry settings; it creates a queue that no
|
|
@@ -87,12 +81,14 @@ $$;
|
|
|
87
81
|
comment on function ${schema}.next_due() is '${functionsComment}';`;
|
|
88
82
|
/**
|
|
89
83
|
* `jobs.failed`: the failed jobs, for the admin app's page, with their last error. Updating `retry` to true retries a
|
|
90
|
-
* job, as pg-boss's `retry()` does: one more attempt, from now; deleting a row deletes the job.
|
|
84
|
+
* job, as pg-boss's `retry()` does: one more attempt, from now; deleting a row deletes the job. Its `payload` is the
|
|
85
|
+
* job's payload alone, without the organization the runtime stores beside it (`jobData`).
|
|
91
86
|
*/
|
|
92
87
|
const failed = (schema) => `create index if not exists job_failed_i on ${schema}.job (completed_on) where state = 'failed';
|
|
93
88
|
drop view if exists ${schema}.failed;
|
|
94
89
|
create view ${schema}.failed as
|
|
95
|
-
select id, name,
|
|
90
|
+
select id, name,
|
|
91
|
+
case when jsonb_typeof(data) = 'object' and data ? '${organizationKey}' then data -> 'payload' else data end as payload, retry_count + 1 as attempts,
|
|
96
92
|
coalesce(output ->> 'message', output -> 'value' ->> 'message', output ->> 'value') as error,
|
|
97
93
|
output, completed_on as failed_at, created_on as created_at, singleton_key as key, false as retry
|
|
98
94
|
from ${schema}.job where state = 'failed';
|
|
@@ -126,4 +122,4 @@ const functionsSql = (schema) => [
|
|
|
126
122
|
failed(schema)
|
|
127
123
|
].join("\n\n");
|
|
128
124
|
//#endregion
|
|
129
|
-
export {
|
|
125
|
+
export { functionsComment, functionsSql };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//#region src/jobs/job-data.ts
|
|
2
|
+
/**
|
|
3
|
+
* The key of the stored data that holds the organization a job was enqueued in, beside its payload under `payload`:
|
|
4
|
+
* `{ "~organization": "org_1", "payload": { ... } }`. The failed jobs view (`functionsSql`) shows `payload` alone.
|
|
5
|
+
*/
|
|
6
|
+
const organizationKey = "~organization";
|
|
7
|
+
const isStored = (data) => typeof data === "object" && data !== null && !Array.isArray(data) && Object.hasOwn(data, "~organization");
|
|
8
|
+
/** The organization `db` works in: a `ScopedDb`'s own one, or none for every organization, `unscoped()` or a plain database. */
|
|
9
|
+
const organizationOf = (db) => {
|
|
10
|
+
const organization = db.organization;
|
|
11
|
+
return typeof organization === "string" || typeof organization === "number" ? organization : void 0;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* What pg-boss stores for a job: the payload alone when it works in no organization, or the organization beside it. A
|
|
15
|
+
* payload of its own that holds `organizationKey` goes beside one too, so it stays payload and never names the organization.
|
|
16
|
+
*/
|
|
17
|
+
const jobData = (payload, organization) => {
|
|
18
|
+
if (organization === void 0 && !isStored(payload)) return payload ?? null;
|
|
19
|
+
return {
|
|
20
|
+
[organizationKey]: organization ?? null,
|
|
21
|
+
payload: payload ?? null
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
/** The payload and the organization of a job's stored data; data without `organizationKey`, such as `jobs.enqueue`'s from SQL, works in none. */
|
|
25
|
+
const readJobData = (data) => {
|
|
26
|
+
if (!isStored(data)) return {
|
|
27
|
+
payload: data,
|
|
28
|
+
organization: void 0
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
payload: data.payload,
|
|
32
|
+
organization: data["~organization"] ?? void 0
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
//#endregion
|
|
36
|
+
export { jobData, organizationKey, organizationOf, readJobData };
|
package/dist/jobs/job-types.d.ts
CHANGED
|
@@ -2,12 +2,15 @@ import { Mailer } from "../mail/mail-message.js";
|
|
|
2
2
|
import { DecryptField } from "../encryption/decrypt-field-types.js";
|
|
3
3
|
import { StandardSchema } from "../functions/read-json.js";
|
|
4
4
|
import { SendNotification } from "../notifications/send-input.js";
|
|
5
|
-
import { Db } from "@protobase/query";
|
|
5
|
+
import { Db, ScopedDb } from "@protobase/query";
|
|
6
6
|
//#region src/jobs/job-types.d.ts
|
|
7
7
|
/** What `run` gets beside the payload. */
|
|
8
8
|
export type JobContext = {
|
|
9
|
-
/**
|
|
10
|
-
|
|
9
|
+
/**
|
|
10
|
+
* The database pool. The enqueuer's transaction has committed by the time a job runs. A job works in no organization:
|
|
11
|
+
* `db` reads no row of the tables whose rows belong to one, and writes none (`ScopedDb`); `db.unscoped('<reason>')` reads them all.
|
|
12
|
+
*/
|
|
13
|
+
db: ScopedDb;
|
|
11
14
|
/** The job, and when this try took it: each try takes it at a new time. */
|
|
12
15
|
job: {
|
|
13
16
|
id: string;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { jobsSchema } from "./schema.js";
|
|
2
|
+
import { noInput } from "../schema-modules/schema-module.js";
|
|
3
|
+
import { moduleDifference } from "../schema-modules/module-difference.js";
|
|
4
|
+
import { functionsSql } from "./functions-sql.js";
|
|
5
|
+
import { pgBoss45 } from "./steps/001-pg-boss-45.js";
|
|
6
|
+
import { CompiledQuery } from "kysely";
|
|
7
|
+
//#region src/jobs/jobs-module.ts
|
|
8
|
+
/** The pg-boss schema version of each step that installs or migrates pg-boss, by step: pg-boss stays pinned to the last. */
|
|
9
|
+
const pgBossSteps = { 1: 45 };
|
|
10
|
+
const rows = async (db, text, parameters = []) => (await db.executeQuery(CompiledQuery.raw(text, parameters))).rows;
|
|
11
|
+
const commentVersion = (comment) => {
|
|
12
|
+
const found = comment && /^Protobase jobs (\d+)$/.exec(comment);
|
|
13
|
+
return found ? Number(found[1]) : void 0;
|
|
14
|
+
};
|
|
15
|
+
/** Protobase's functions in the jobs schema by the signature `functionsSql` makes them with, so an overload of one is not it. */
|
|
16
|
+
const functionSignatures = [
|
|
17
|
+
"enqueue(text, jsonb, timestamptz, text, text, integer)",
|
|
18
|
+
"next_due()",
|
|
19
|
+
"failed_retry()",
|
|
20
|
+
"failed_delete()"
|
|
21
|
+
];
|
|
22
|
+
/**
|
|
23
|
+
* The functions' part of the jobs schema's model from the version each function's comment names, `undefined` for one
|
|
24
|
+
* missing or without a version: the oldest known version, so replacing it from there says what it breaks, or absent
|
|
25
|
+
* when one is missing and none known is older, so the functions are written again as new. Refuses a version newer than
|
|
26
|
+
* this version of Protobase writes.
|
|
27
|
+
*/
|
|
28
|
+
const functionsModel = (versions) => {
|
|
29
|
+
const known = versions.filter((version) => version !== void 0);
|
|
30
|
+
const newest = Math.max(...known);
|
|
31
|
+
if (newest > 4) throw new Error(`Protobase's functions of the jobs schema are at version ${newest}, newer than the 4 this version of Protobase writes: upgrade Protobase`);
|
|
32
|
+
if (known.length === 0) return {};
|
|
33
|
+
const oldest = Math.min(...known);
|
|
34
|
+
if (known.length < versions.length && oldest === 4) return {};
|
|
35
|
+
return { functions: oldest };
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* The jobs schema as the database has it: pg-boss's version as the step that installs it, and Protobase's functions as
|
|
39
|
+
* `functionsModel` reads them. Refuses a pg-boss version no step records.
|
|
40
|
+
*/
|
|
41
|
+
const readJobs = async (db) => {
|
|
42
|
+
const [{ installed }] = await rows(db, `select to_regclass('${jobsSchema}.version') is not null as installed`);
|
|
43
|
+
if (!installed) return;
|
|
44
|
+
const [found] = await rows(db, `select version from ${jobsSchema}.version`);
|
|
45
|
+
const pgBoss = Number(found?.version);
|
|
46
|
+
const step = Object.entries(pgBossSteps).find(([, version]) => version === pgBoss)?.[0];
|
|
47
|
+
const pinned = Object.values(pgBossSteps).at(-1);
|
|
48
|
+
if (pgBoss > pinned) throw new Error(`The jobs schema is at pg-boss schema version ${pgBoss}, newer than the ${pinned} this version of Protobase records: upgrade Protobase`);
|
|
49
|
+
if (step === void 0) throw new Error(`The jobs schema is at pg-boss schema version ${pgBoss}, which no step of this version of Protobase records: bring it to version ${pgBossSteps[1]} with \`protobase migration\` and \`protobase migrate\` of Protobase 0.14.2 first, then run this command again`);
|
|
50
|
+
const functions = await rows(db, `select obj_description(to_regprocedure(signature), 'pg_proc') as comment from unnest($1::text[]) with ordinality as s(signature, n) order by n`, [functionSignatures.map((signature) => `${jobsSchema}.${signature}`)]);
|
|
51
|
+
return {
|
|
52
|
+
lastStep: Number(step),
|
|
53
|
+
replaceables: functionsModel(functions.map((one) => commentVersion(one.comment)))
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* The jobs schema: pg-boss's tables, installed by its own plan copied into a step for each pg-boss version Protobase
|
|
58
|
+
* pins, and Protobase's functions over them. pg-boss stays pinned to an exact version; a bump copies its migration
|
|
59
|
+
* plan into the next step by hand, reviewed like any step.
|
|
60
|
+
*/
|
|
61
|
+
const jobsModule = {
|
|
62
|
+
label: "the jobs schema",
|
|
63
|
+
title: "The jobs schema this version of Protobase needs",
|
|
64
|
+
steps: [{
|
|
65
|
+
step: 1,
|
|
66
|
+
name: "pg_boss_45",
|
|
67
|
+
title: "pg-boss's tables at its schema version 45",
|
|
68
|
+
additive: true,
|
|
69
|
+
sql: () => pgBoss45
|
|
70
|
+
}],
|
|
71
|
+
replaceables: [{
|
|
72
|
+
name: "functions",
|
|
73
|
+
title: "Protobase's functions of the jobs schema",
|
|
74
|
+
version: 4,
|
|
75
|
+
compatibleFrom: 4,
|
|
76
|
+
sql: () => functionsSql(jobsSchema)
|
|
77
|
+
}],
|
|
78
|
+
resourceReplaceables: [],
|
|
79
|
+
read: readJobs
|
|
80
|
+
};
|
|
81
|
+
/** The whole jobs schema, as a migration writes it on a database without it. */
|
|
82
|
+
const jobsSchemaSql = () => moduleDifference(jobsModule, noInput, void 0).sql;
|
|
83
|
+
//#endregion
|
|
84
|
+
export { functionsModel, jobsModule, jobsSchemaSql, pgBossSteps };
|
package/dist/jobs/run-job.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "../notifications/send-input.js";
|
|
2
2
|
import "./job-types.js";
|
|
3
|
-
import {
|
|
3
|
+
import { Organization, ScopedDb } from "@protobase/query";
|
|
4
4
|
import "pg-boss";
|
|
5
5
|
//#region src/jobs/run-job.d.ts
|
|
6
6
|
/** Thrown from a job's `run`, it fails the job now: the attempts it has left are not used. */
|
package/dist/jobs/run-job.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isStatementTimeout, statementTimeoutDetail } from "../statement-timeout.js";
|
|
2
|
+
import { readJobData } from "./job-data.js";
|
|
2
3
|
//#region src/jobs/run-job.ts
|
|
3
4
|
/** Thrown from a job's `run`, it fails the job now: the attempts it has left are not used. */
|
|
4
5
|
var FatalJobError = class extends Error {
|
|
@@ -53,14 +54,15 @@ const noDecrypter = (name) => async () => {
|
|
|
53
54
|
throw new Error(`Job "${name}" cannot decrypt fields: startJobs was not given the app's decryptField`);
|
|
54
55
|
};
|
|
55
56
|
/**
|
|
56
|
-
* One try of one job
|
|
57
|
-
* failed for good on a `FatalJobError` or an invalid payload.
|
|
57
|
+
* One try of one job, its `db` from `dbFor` in the organization it was enqueued in: completed when `run` returns, failed
|
|
58
|
+
* (to be retried while attempts are left) when it throws, and failed for good on a `FatalJobError` or an invalid payload.
|
|
58
59
|
*/
|
|
59
|
-
const runJob = async (definition, job,
|
|
60
|
+
const runJob = async (definition, job, dbFor, { mail, sendNotification, decryptField } = {}) => {
|
|
60
61
|
try {
|
|
61
|
-
const
|
|
62
|
+
const stored = readJobData(job.data);
|
|
63
|
+
const payload = await checkPayload(definition, stored.payload ?? void 0);
|
|
62
64
|
const context = {
|
|
63
|
-
db,
|
|
65
|
+
db: dbFor(stored.organization),
|
|
64
66
|
job: {
|
|
65
67
|
id: job.id,
|
|
66
68
|
name: job.name,
|
package/dist/jobs/runtime.d.ts
CHANGED
|
@@ -3,10 +3,15 @@ import { UnsubscribeLinks } from "../mail/unsubscribe/unsubscribe-links.js";
|
|
|
3
3
|
import { FieldDecrypter } from "../encryption/decrypt-field-types.js";
|
|
4
4
|
import { JobDefinition } from "./job-types.js";
|
|
5
5
|
import { JobsEnqueuer } from "./current.js";
|
|
6
|
-
import { Db } from "@protobase/query";
|
|
6
|
+
import { Db, ScopedTables } from "@protobase/query";
|
|
7
7
|
//#region src/jobs/runtime.d.ts
|
|
8
8
|
export type StartJobsOptions = {
|
|
9
9
|
db: Db;
|
|
10
|
+
/**
|
|
11
|
+
* The tables whose rows belong to one organization, `createAdmin(...).organizationScope`: a job's `db` sees the rows
|
|
12
|
+
* of the organization it was enqueued in, and none in a job enqueued in none. Default none, for an app without organizations.
|
|
13
|
+
*/
|
|
14
|
+
scope?: ScopedTables;
|
|
10
15
|
jobs: JobDefinition[];
|
|
11
16
|
/** Runs the jobs in this process; `false` only enqueues them, for a process whose jobs another one runs. Default true. */
|
|
12
17
|
work?: boolean;
|
|
@@ -57,8 +62,8 @@ export type JobsRuntime = JobsEnqueuer & {
|
|
|
57
62
|
};
|
|
58
63
|
/**
|
|
59
64
|
* Starts the app's jobs in this process: their queues, a worker per job unless `work` is false, and the maintenance
|
|
60
|
-
* that retries jobs whose worker died. It reads the jobs schema, never changes it:
|
|
61
|
-
* `
|
|
65
|
+
* that retries jobs whose worker died. It reads the jobs schema, never changes it: the startup checks the
|
|
66
|
+
* record of migrations for it first (`checkMigrationRecord`). Enqueueing through `defineJob(...).enqueue` reaches the runtime started here.
|
|
62
67
|
*/
|
|
63
|
-
export declare const startJobs: ({ db, jobs, work, pollSeconds, shutdownSeconds, onError, now, mailer, unsubscribe, decryptField }: StartJobsOptions) => Promise<JobsRuntime>;
|
|
68
|
+
export declare const startJobs: ({ db, scope, jobs, work, pollSeconds, shutdownSeconds, onError, now, mailer, unsubscribe, decryptField }: StartJobsOptions) => Promise<JobsRuntime>;
|
|
64
69
|
//#endregion
|
package/dist/jobs/runtime.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { clearCurrentJobs, setCurrentJobs } from "./current.js";
|
|
2
2
|
import { jobsSchema } from "./schema.js";
|
|
3
3
|
import "./schedule.js";
|
|
4
|
+
import { jobData, organizationOf } from "./job-data.js";
|
|
4
5
|
import { runJob, validatePayload } from "./run-job.js";
|
|
5
6
|
import { platformMailer } from "../mail/platform-mailer.js";
|
|
6
7
|
import "../notifications/push-job-name.js";
|
|
7
8
|
import { sendNotification } from "../notifications/send-notification.js";
|
|
9
|
+
import { noOrganizationTables } from "../organization-scope/organization-tables.js";
|
|
8
10
|
import { runInBackground } from "../background-work.js";
|
|
9
11
|
import { afterCommit } from "../commit-hooks.js";
|
|
10
12
|
import { appBulkMailer } from "../mail/unsubscribe/bulk-mailer.js";
|
|
@@ -12,6 +14,7 @@ import { busyDatabase } from "./busy-database.js";
|
|
|
12
14
|
import { jobsDatabase } from "./database.js";
|
|
13
15
|
import { queueOptions, queueSettingsDiffer, sendOptions, workOptions } from "./options.js";
|
|
14
16
|
import { createSchedules } from "./schedules.js";
|
|
17
|
+
import { scopedDb } from "@protobase/query";
|
|
15
18
|
import { sql } from "kysely";
|
|
16
19
|
import { randomUUID } from "node:crypto";
|
|
17
20
|
import { PgBoss } from "pg-boss";
|
|
@@ -30,10 +33,10 @@ const createBoss = (db, work) => new PgBoss({
|
|
|
30
33
|
});
|
|
31
34
|
/**
|
|
32
35
|
* Starts the app's jobs in this process: their queues, a worker per job unless `work` is false, and the maintenance
|
|
33
|
-
* that retries jobs whose worker died. It reads the jobs schema, never changes it:
|
|
34
|
-
* `
|
|
36
|
+
* that retries jobs whose worker died. It reads the jobs schema, never changes it: the startup checks the
|
|
37
|
+
* record of migrations for it first (`checkMigrationRecord`). Enqueueing through `defineJob(...).enqueue` reaches the runtime started here.
|
|
35
38
|
*/
|
|
36
|
-
const startJobs = async ({ db, jobs, work = true, pollSeconds = 2, shutdownSeconds = 30, onError, now = () => /* @__PURE__ */ new Date(), mailer, unsubscribe, decryptField }) => {
|
|
39
|
+
const startJobs = async ({ db, scope = noOrganizationTables, jobs, work = true, pollSeconds = 2, shutdownSeconds = 30, onError, now = () => /* @__PURE__ */ new Date(), mailer, unsubscribe, decryptField }) => {
|
|
37
40
|
const base = mailer === void 0 ? platformMailer() : mailer || void 0;
|
|
38
41
|
const mail = base && appBulkMailer(base, db, unsubscribe);
|
|
39
42
|
let decrypter = decryptField;
|
|
@@ -42,6 +45,7 @@ const startJobs = async ({ db, jobs, work = true, pollSeconds = 2, shutdownSecon
|
|
|
42
45
|
boss.on("error", onError);
|
|
43
46
|
await boss.start();
|
|
44
47
|
const schedules = createSchedules(boss, db, now);
|
|
48
|
+
const jobDb = (organization) => scopedDb(db, scope, organization);
|
|
45
49
|
const definitions = /* @__PURE__ */ new Map();
|
|
46
50
|
const workers = /* @__PURE__ */ new Map();
|
|
47
51
|
const ensureQueue = async (definition) => {
|
|
@@ -63,7 +67,7 @@ const startJobs = async ({ db, jobs, work = true, pollSeconds = 2, shutdownSecon
|
|
|
63
67
|
const current = definitions.get(definition.name) ?? definition;
|
|
64
68
|
return runInBackground(async () => {
|
|
65
69
|
if (current.options.schedule !== void 0 && job.singletonKey === "protobase.schedule") await schedules.following(current, job.startAfter);
|
|
66
|
-
return [await runJob(current, job,
|
|
70
|
+
return [await runJob(current, job, jobDb, {
|
|
67
71
|
mail,
|
|
68
72
|
...decrypter && { decryptField: decrypter },
|
|
69
73
|
...definitions.has("notifications.send") && { sendNotification }
|
|
@@ -93,7 +97,7 @@ const startJobs = async ({ db, jobs, work = true, pollSeconds = 2, shutdownSecon
|
|
|
93
97
|
if (!definitions.has(name)) throw new Error(`Job "${name}" is not among the app's jobs; export it from the module protobase.config.ts passes as \`jobs\``);
|
|
94
98
|
const checked = await validatePayload(definition, payload);
|
|
95
99
|
if ("invalid" in checked) throw new Error(checked.invalid);
|
|
96
|
-
const data = checked.value
|
|
100
|
+
const data = jobData(checked.value, organizationOf(target));
|
|
97
101
|
const orderedId = definition.options.ordered ? (await sql`select uuidv7() as id`.execute(target)).rows[0].id : void 0;
|
|
98
102
|
const send = {
|
|
99
103
|
...sendOptions(definition.options, options),
|
|
@@ -114,12 +118,13 @@ const startJobs = async ({ db, jobs, work = true, pollSeconds = 2, shutdownSecon
|
|
|
114
118
|
const enqueueMany = async (definition, target, jobs) => {
|
|
115
119
|
const { name } = definition;
|
|
116
120
|
if (!definitions.has(name)) throw new Error(`Job "${name}" is not among the app's jobs; export it from the module protobase.config.ts passes as \`jobs\``);
|
|
121
|
+
const organization = organizationOf(target);
|
|
117
122
|
const sends = await Promise.all(jobs.map(async ({ payload, options = {} }) => {
|
|
118
123
|
if (options.mode === "replace") throw new Error(`Job "${name}": enqueueMany keeps a waiting job of a key; replace one with enqueue`);
|
|
119
124
|
const checked = await validatePayload(definition, payload);
|
|
120
125
|
if ("invalid" in checked) throw new Error(checked.invalid);
|
|
121
126
|
return {
|
|
122
|
-
data: checked.value
|
|
127
|
+
data: jobData(checked.value, organization),
|
|
123
128
|
send: sendOptions(definition.options, options),
|
|
124
129
|
key: options.key
|
|
125
130
|
};
|
package/dist/jobs/schema.d.ts
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
import { Db } from "@protobase/query";
|
|
2
1
|
//#region src/jobs/schema.d.ts
|
|
3
2
|
/** The schema the job queue lives in: pg-boss's tables and Protobase's functions. */
|
|
4
3
|
export declare const jobsSchema = "jobs";
|
|
5
|
-
/**
|
|
6
|
-
* The SQL that brings the jobs schema to what this version of Protobase runs: pg-boss's own construction plan when it
|
|
7
|
-
* is missing, or its migration plan from the version installed, then Protobase's functions. `undefined` when current.
|
|
8
|
-
*/
|
|
9
|
-
export declare const jobsSchemaMigration: (db: Db) => Promise<string | undefined>;
|
|
10
|
-
/**
|
|
11
|
-
* Refuses to go on while the jobs schema is missing or not the version this Protobase runs. The server never creates
|
|
12
|
-
* or migrates it: the project's migrations do, before the new version serves.
|
|
13
|
-
*/
|
|
14
|
-
export declare const checkJobsSchema: (db: Db) => Promise<void>;
|
|
15
4
|
//#endregion
|