@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/status/schema.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { migrationCommand } from "../changes/capture-schema.js";
|
|
2
|
-
import { qualified } from "../notifications/schema-sql.js";
|
|
3
|
-
import { checkStatusAuth, statusNames } from "./options.js";
|
|
4
|
-
import { authUsersTable, regclass, userIdType } from "../notifications/schema.js";
|
|
5
|
-
import { statusesTableSql } from "./schema-sql.js";
|
|
6
|
-
//#region src/status/schema.ts
|
|
7
|
-
/**
|
|
8
|
-
* The SQL that adds the statuses table `status` keeps people's statuses in, its user column pointing at auth's users
|
|
9
|
-
* table; `undefined` when it exists. An app without organizations is refused (see `checkStatusAuth`).
|
|
10
|
-
*/
|
|
11
|
-
const statusMigration = async (db, options, auth) => {
|
|
12
|
-
checkStatusAuth(auth);
|
|
13
|
-
const names = statusNames(options);
|
|
14
|
-
if (await regclass(db, qualified(names)) !== null) return;
|
|
15
|
-
const users = authUsersTable(auth);
|
|
16
|
-
const type = await userIdType(db, users, {
|
|
17
|
-
feature: "status",
|
|
18
|
-
rows: "statuses"
|
|
19
|
-
});
|
|
20
|
-
return `${statusesTableSql(names, {
|
|
21
|
-
type,
|
|
22
|
-
references: `${qualified(users)} (id)`
|
|
23
|
-
}).join(";\n\n")};`;
|
|
24
|
-
};
|
|
25
|
-
/** Refuses to start while the statuses table is missing, or the app has no organizations. */
|
|
26
|
-
const checkStatusSchema = async (db, options, auth) => {
|
|
27
|
-
checkStatusAuth(auth);
|
|
28
|
-
const table = qualified(statusNames(options));
|
|
29
|
-
if (await regclass(db, table) !== null) return;
|
|
30
|
-
throw new Error(`The statuses table ${table} of status is missing. Write it as a migration with \`${migrationCommand}\`, apply it with the project's migrations, then start again.`);
|
|
31
|
-
};
|
|
32
|
-
//#endregion
|
|
33
|
-
export { checkStatusSchema, statusMigration };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Db } from "@protobase/query";
|
|
2
|
-
//#region src/user-tables/schema.d.ts
|
|
3
|
-
/**
|
|
4
|
-
* The SQL that adds what user tables need: pg_trgm, the definitions schema with its `tables` and `fields`, and the
|
|
5
|
-
* schema the tables themselves live in. `undefined` when current. Nothing is dropped but the unique constraint on a
|
|
6
|
-
* definition's name, which a name unique per organization replaces.
|
|
7
|
-
*/
|
|
8
|
-
export declare const userTablesMigration: (db: Db) => Promise<string | undefined>;
|
|
9
|
-
/** Refuses to go on while the schemas of user tables are missing; the project's migrations add them. */
|
|
10
|
-
export declare const checkUserTablesSchema: (db: Db) => Promise<void>;
|
|
11
|
-
//#endregion
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { EventsOptions } from "../../changes/events-options.js";
|
|
2
|
-
import { WebhooksOptions } from "./options.js";
|
|
3
|
-
import { Db } from "@protobase/query";
|
|
4
|
-
//#region src/webhooks/table/schema.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* The SQL that brings the `webhooks` schema to what `webhooks` needs: the subscriptions table, its commands, the
|
|
7
|
-
* deliveries view and, with `deliveryLog`, the log table. `undefined` when current. Needs the jobs schema, which the
|
|
8
|
-
* deliveries view reads. Tables are never dropped.
|
|
9
|
-
*/
|
|
10
|
-
export declare const webhooksMigration: (db: Db, options?: WebhooksOptions, events?: EventsOptions) => Promise<string | undefined>;
|
|
11
|
-
/**
|
|
12
|
-
* Refuses to go on while the `webhooks` schema lacks what `webhooks` needs; the project's migrations add it. A schema
|
|
13
|
-
* written by an earlier version this one still serves on starts, and `protobase migration` brings it current.
|
|
14
|
-
*/
|
|
15
|
-
export declare const checkWebhooksSchema: (db: Db, options?: WebhooksOptions) => Promise<void>;
|
|
16
|
-
//#endregion
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { quoteIdent } from "../../changes/capture-sql.js";
|
|
2
|
-
import { changesSchema } from "../../changes/events-options.js";
|
|
3
|
-
import { migrationCommand } from "../../changes/capture-schema.js";
|
|
4
|
-
import { webhooksSchema } from "./options.js";
|
|
5
|
-
import { commandsSql, commentVersion, deliveriesSql, deliveryLogIndexesSql, deliveryLogSql, subscriptionsIndexesSql, subscriptionsSql } from "./schema-sql.js";
|
|
6
|
-
import { sql } from "kysely";
|
|
7
|
-
//#region src/webhooks/table/schema.ts
|
|
8
|
-
const functionNames = ["subscription_commands", "deliveries_resend"];
|
|
9
|
-
const readWebhooksSchema = async (db, schema) => {
|
|
10
|
-
const exists = async (table) => (await sql`select to_regclass(${`${quoteIdent(schema)}.${quoteIdent(table)}`}) is not null as found`.execute(db)).rows[0].found;
|
|
11
|
-
const { rows } = await sql`select p.proname as name, obj_description(p.oid, 'pg_proc') as comment
|
|
12
|
-
from pg_proc p join pg_namespace n on n.oid = p.pronamespace where n.nspname = ${schema} and p.proname = any(${functionNames}::text[]) order by p.proname`.execute(db);
|
|
13
|
-
const versions = functionNames.map((name) => commentVersion(rows.find((row) => row.name === name)?.comment ?? null));
|
|
14
|
-
const version = await exists("deliveries") && versions.every((found) => found !== void 0) ? Math.min(...versions) : void 0;
|
|
15
|
-
return {
|
|
16
|
-
subscriptions: await exists("subscriptions"),
|
|
17
|
-
current: version === 2,
|
|
18
|
-
served: version !== void 0 && version >= 1,
|
|
19
|
-
deliveryLog: await exists("delivery_log")
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* The SQL that brings the `webhooks` schema to what `webhooks` needs: the subscriptions table, its commands, the
|
|
24
|
-
* deliveries view and, with `deliveryLog`, the log table. `undefined` when current. Needs the jobs schema, which the
|
|
25
|
-
* deliveries view reads. Tables are never dropped.
|
|
26
|
-
*/
|
|
27
|
-
const webhooksMigration = async (db, options = {}, events) => {
|
|
28
|
-
const schema = webhooksSchema(options);
|
|
29
|
-
const found = await readWebhooksSchema(db, schema);
|
|
30
|
-
const needsLog = Boolean(options.deliveryLog) && !found.deliveryLog;
|
|
31
|
-
const current = found.subscriptions && found.current;
|
|
32
|
-
if (current && !needsLog) return void 0;
|
|
33
|
-
return `${[
|
|
34
|
-
`create schema if not exists ${quoteIdent(schema)}`,
|
|
35
|
-
...found.subscriptions ? [] : [subscriptionsSql(schema, changesSchema(events))],
|
|
36
|
-
...current ? [] : [
|
|
37
|
-
subscriptionsIndexesSql(schema),
|
|
38
|
-
commandsSql(schema),
|
|
39
|
-
deliveriesSql(schema)
|
|
40
|
-
],
|
|
41
|
-
...needsLog ? [deliveryLogSql(schema)] : [],
|
|
42
|
-
...needsLog || !current && found.deliveryLog ? [deliveryLogIndexesSql(schema)] : []
|
|
43
|
-
].join(";\n\n")};`;
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Refuses to go on while the `webhooks` schema lacks what `webhooks` needs; the project's migrations add it. A schema
|
|
47
|
-
* written by an earlier version this one still serves on starts, and `protobase migration` brings it current.
|
|
48
|
-
*/
|
|
49
|
-
const checkWebhooksSchema = async (db, options = {}) => {
|
|
50
|
-
const schema = webhooksSchema(options);
|
|
51
|
-
const found = await readWebhooksSchema(db, schema);
|
|
52
|
-
if (found.subscriptions && found.served && (!options.deliveryLog || found.deliveryLog)) return;
|
|
53
|
-
throw new Error(`The ${schema} schema is missing or behind this version of Protobase. Write it as a migration with \`${migrationCommand}\`, apply it with the project's migrations, then start again.`);
|
|
54
|
-
};
|
|
55
|
-
//#endregion
|
|
56
|
-
export { checkWebhooksSchema, webhooksMigration };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { WorkflowsOptions } from "./options.js";
|
|
2
|
-
import { Db } from "@protobase/query";
|
|
3
|
-
//#region src/workflows/schema.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* The SQL that brings the `workflows` schema to what `workflows` needs: its tables, indexes and the triggers that number a
|
|
6
|
-
* workflow's versions and pin a run's; `undefined` when current. A schema made before loses its `steps` table, which
|
|
7
|
-
* runs no longer keep. The storage configurations table is added only with `storage`, the custom steps' tables, with
|
|
8
|
-
* their runners and jobs, only with `customSteps`.
|
|
9
|
-
*/
|
|
10
|
-
export declare const workflowsMigration: (db: Db, options?: Pick<WorkflowsOptions, "schema" | "storage" | "customSteps">) => Promise<string | undefined>;
|
|
11
|
-
/** Refuses to go on while the `workflows` schema lacks what `workflows` needs; the project's migrations add it. */
|
|
12
|
-
export declare const checkWorkflowsSchema: (db: Db, options?: Pick<WorkflowsOptions, "schema" | "storage" | "customSteps">) => Promise<void>;
|
|
13
|
-
//#endregion
|
package/dist/workflows/schema.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { quoteIdent } from "../changes/capture-sql.js";
|
|
2
|
-
import { migrationCommand } from "../changes/capture-schema.js";
|
|
3
|
-
import { workflowsCustomStepsOn, workflowsSchema, workflowsStorageOn } from "./options.js";
|
|
4
|
-
import { checkpointsSql, commentVersion, definitionPartsSql, droppedSql, effectsSql, functionsSql, indexesSql, layoutSql, tablesSql, triggersSql, workflowsTriggers } from "./schema-sql.js";
|
|
5
|
-
import { hooksSql } from "./hooks/hooks-sql.js";
|
|
6
|
-
import { revocationsSql } from "./connections/revocations-sql.js";
|
|
7
|
-
import { stepCacheSql } from "./cache/step-cache-sql.js";
|
|
8
|
-
import { storageSql } from "./storage/storage-sql.js";
|
|
9
|
-
import { statusSql, statusTriggers } from "./status-sql.js";
|
|
10
|
-
import { blockRunsSql } from "./block-runs-sql.js";
|
|
11
|
-
import { taskTokensSql } from "./task-tokens-sql.js";
|
|
12
|
-
import { testRunsSql } from "./test-runs-sql.js";
|
|
13
|
-
import { customStepsSql, customStepsTables } from "./custom-steps/custom-steps-sql.js";
|
|
14
|
-
import { runnersSql, runnersTables } from "./custom-steps/runners-sql.js";
|
|
15
|
-
import { sql } from "kysely";
|
|
16
|
-
//#region src/workflows/schema.ts
|
|
17
|
-
const triggerNames = [...workflowsTriggers, ...statusTriggers];
|
|
18
|
-
const readWorkflowsSchema = async (db, schema, { storage, customSteps }) => {
|
|
19
|
-
const runs = `${quoteIdent(schema)}."runs"`;
|
|
20
|
-
const triggerRows = `${quoteIdent(schema)}."triggers"`;
|
|
21
|
-
const configurations = `${quoteIdent(schema)}."storage_configurations"`;
|
|
22
|
-
const custom = sql.join([...customStepsTables, ...runnersTables].map((table) => sql`to_regclass(${`${quoteIdent(schema)}."${table}"`}) is not null`), sql` and `);
|
|
23
|
-
const { rows } = await sql`select to_regclass(${runs}) is not null as found,
|
|
24
|
-
to_regclass(${triggerRows}) is not null as trigger_rows,
|
|
25
|
-
to_regclass(${configurations}) is not null as configurations,
|
|
26
|
-
${custom} as custom_steps,
|
|
27
|
-
(select obj_description(p.oid, 'pg_proc') from pg_proc p join pg_namespace n on n.oid = p.pronamespace where n.nspname = ${schema} and p.proname = 'run_version') as comment,
|
|
28
|
-
(select count(*)::int from pg_trigger t join pg_class c on c.oid = t.tgrelid join pg_namespace n on n.oid = c.relnamespace
|
|
29
|
-
where n.nspname = ${schema} and not t.tgisinternal and t.tgname = any(${triggerNames})) as triggers`.execute(db);
|
|
30
|
-
const row = rows[0];
|
|
31
|
-
const current = row.found && row.trigger_rows && commentVersion(row.comment) === 28 && row.triggers === triggerNames.length && (!storage || row.configurations) && (!customSteps || row.custom_steps);
|
|
32
|
-
return {
|
|
33
|
-
tables: row.found,
|
|
34
|
-
current
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
const turnedOn = (options) => ({
|
|
38
|
-
storage: workflowsStorageOn(options),
|
|
39
|
-
customSteps: workflowsCustomStepsOn(options)
|
|
40
|
-
});
|
|
41
|
-
/**
|
|
42
|
-
* The SQL that brings the `workflows` schema to what `workflows` needs: its tables, indexes and the triggers that number a
|
|
43
|
-
* workflow's versions and pin a run's; `undefined` when current. A schema made before loses its `steps` table, which
|
|
44
|
-
* runs no longer keep. The storage configurations table is added only with `storage`, the custom steps' tables, with
|
|
45
|
-
* their runners and jobs, only with `customSteps`.
|
|
46
|
-
*/
|
|
47
|
-
const workflowsMigration = async (db, options = {}) => {
|
|
48
|
-
const schema = workflowsSchema(options);
|
|
49
|
-
const on = turnedOn(options);
|
|
50
|
-
const found = await readWorkflowsSchema(db, schema, on);
|
|
51
|
-
if (found.current) return;
|
|
52
|
-
return workflowsSql(schema, {
|
|
53
|
-
tables: found.tables,
|
|
54
|
-
...on
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
/** The statements of a migration of the `workflows` schema: its tables only when missing, storage and custom steps only when on. */
|
|
58
|
-
const workflowsSql = (schema, { tables, storage, customSteps = false }) => {
|
|
59
|
-
return `${[
|
|
60
|
-
`create schema if not exists ${quoteIdent(schema)}`,
|
|
61
|
-
...tables ? [] : [tablesSql(schema)],
|
|
62
|
-
definitionPartsSql(schema),
|
|
63
|
-
layoutSql(schema),
|
|
64
|
-
checkpointsSql(schema),
|
|
65
|
-
droppedSql(schema),
|
|
66
|
-
triggersSql(schema),
|
|
67
|
-
effectsSql(schema),
|
|
68
|
-
revocationsSql(schema),
|
|
69
|
-
hooksSql(schema),
|
|
70
|
-
stepCacheSql(schema),
|
|
71
|
-
indexesSql(schema),
|
|
72
|
-
blockRunsSql(schema),
|
|
73
|
-
taskTokensSql(schema),
|
|
74
|
-
testRunsSql(schema),
|
|
75
|
-
...storage ? [storageSql(schema)] : [],
|
|
76
|
-
...customSteps ? [customStepsSql(schema), runnersSql(schema)] : [],
|
|
77
|
-
functionsSql(schema),
|
|
78
|
-
statusSql(schema)
|
|
79
|
-
].join(";\n\n")};`;
|
|
80
|
-
};
|
|
81
|
-
/** Refuses to go on while the `workflows` schema lacks what `workflows` needs; the project's migrations add it. */
|
|
82
|
-
const checkWorkflowsSchema = async (db, options = {}) => {
|
|
83
|
-
const schema = workflowsSchema(options);
|
|
84
|
-
if ((await readWorkflowsSchema(db, schema, turnedOn(options))).current) return;
|
|
85
|
-
throw new Error(`The ${schema} schema is missing or behind this version of Protobase. Write it as a migration with \`${migrationCommand}\`, apply it with the project's migrations, then start again.`);
|
|
86
|
-
};
|
|
87
|
-
//#endregion
|
|
88
|
-
export { checkWorkflowsSchema, workflowsMigration, workflowsSql };
|