@protobase/server 0.129.0 → 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 +35 -0
- package/dist/better-auth/store/offline/baseline-store.js +65 -0
- 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 -6
- package/dist/better-auth/store/offline/offline-steps.js +30 -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 +13 -4
- 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 +27 -10
- package/dist/internal.js +22 -7
- 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
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { changesSchema } from "../../changes/events-options.js";
|
|
2
|
+
import { webhooksSchema } from "./options.js";
|
|
3
|
+
//#region src/webhooks/table/webhooks-targets.ts
|
|
4
|
+
/**
|
|
5
|
+
* The schema modules `webhooks` needs, each with its names: the webhooks schema in the schema `options` names, whose
|
|
6
|
+
* subscriptions take their owner from the change capture's actor setting in the schema `events` names, and with
|
|
7
|
+
* `deliveryLog` the delivery log in that schema too.
|
|
8
|
+
*/
|
|
9
|
+
const webhooksTargets = (options, events) => {
|
|
10
|
+
const schema = webhooksSchema(options);
|
|
11
|
+
return {
|
|
12
|
+
webhooks: {
|
|
13
|
+
names: {
|
|
14
|
+
schema,
|
|
15
|
+
changes: changesSchema(events)
|
|
16
|
+
},
|
|
17
|
+
resources: {}
|
|
18
|
+
},
|
|
19
|
+
...options.deliveryLog && { webhook_delivery_log: {
|
|
20
|
+
names: { schema },
|
|
21
|
+
resources: {}
|
|
22
|
+
} }
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
26
|
+
export { webhooksTargets };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { capturedBy, dispatchJobName } from "../changes/capture-sql.js";
|
|
2
2
|
import { defineJob } from "../jobs/define-job.js";
|
|
3
3
|
import { FatalJobError } from "../jobs/run-job.js";
|
|
4
|
-
import { writeNotices } from "../live/notices-sql.js";
|
|
5
4
|
import { coalesce } from "../changes/coalesce.js";
|
|
6
5
|
import { EventCodeError } from "../changes/event-code-error.js";
|
|
7
6
|
import { eventMatcher } from "../changes/match-events.js";
|
|
@@ -10,6 +9,7 @@ import { currentChange, resourceChange } from "../changes/resource-change.js";
|
|
|
10
9
|
import { callerRecords } from "../functions/records.js";
|
|
11
10
|
import { writeHistory } from "../history/write-history.js";
|
|
12
11
|
import { liveNotices } from "../live/live-notices.js";
|
|
12
|
+
import { writeNotices } from "../live/notices-sql.js";
|
|
13
13
|
import { maxTries, nextRetryDelay } from "./retry-schedule.js";
|
|
14
14
|
import { eventChange, subscriberEvents } from "./subscriber-view.js";
|
|
15
15
|
import { attemptDelivery } from "./attempt.js";
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { tablesFound, triggersFound } from "../read-catalogue.js";
|
|
2
|
+
import { customStepsFunctionsSql, customStepsTables, customStepsTablesSql } from "./custom-steps-sql.js";
|
|
3
|
+
import { runnersFunctionsSql, runnersTables, runnersTablesSql } from "./runners-sql.js";
|
|
4
|
+
//#region src/workflows/custom-steps/custom-steps-module.ts
|
|
5
|
+
const triggers = [
|
|
6
|
+
"custom_step_version",
|
|
7
|
+
"runner_written",
|
|
8
|
+
"custom_step_job_answered",
|
|
9
|
+
"custom_step_run_ended"
|
|
10
|
+
];
|
|
11
|
+
/**
|
|
12
|
+
* The custom steps' tables as the database has them: step 1 once every one is there, their triggers at version 1 while
|
|
13
|
+
* each is on its table. Refuses some of the tables without the others, which no step records.
|
|
14
|
+
*/
|
|
15
|
+
const readCustomSteps = async (db, { names }) => {
|
|
16
|
+
const schema = names.schema;
|
|
17
|
+
const tables = [...customStepsTables, ...runnersTables];
|
|
18
|
+
if (!await tablesFound(db, schema, tables.slice(0, 1))) return;
|
|
19
|
+
if (!await tablesFound(db, schema, tables)) throw new Error(`The custom steps' tables in schema "${schema}" are not all there, which no step of this version of Protobase records: add them with \`protobase migration\` and \`protobase migrate\` of Protobase 0.14.2 first, then run this command again`);
|
|
20
|
+
return {
|
|
21
|
+
lastStep: 1,
|
|
22
|
+
replaceables: await triggersFound(db, schema, triggers) ? { functions: 1 } : {},
|
|
23
|
+
names
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* The custom steps, their versions, runners and jobs, with `customSteps`, in the workflows schema (`names.schema`): a
|
|
28
|
+
* module of its own, after the workflows schema, whose runs and task tokens its triggers are on.
|
|
29
|
+
*/
|
|
30
|
+
const workflowCustomStepsModule = {
|
|
31
|
+
label: "the workflows' custom steps",
|
|
32
|
+
title: "The custom steps, their versions, runners and jobs",
|
|
33
|
+
steps: [{
|
|
34
|
+
step: 1,
|
|
35
|
+
name: "custom_steps",
|
|
36
|
+
title: "The tables of the custom steps, their versions, runners and jobs, and their indexes",
|
|
37
|
+
additive: true,
|
|
38
|
+
sql: (names) => `${customStepsTablesSql(names.schema)};\n\n${runnersTablesSql(names.schema)};`
|
|
39
|
+
}],
|
|
40
|
+
replaceables: [{
|
|
41
|
+
name: "functions",
|
|
42
|
+
title: "The triggers that number a custom step's versions and keep its runners and jobs",
|
|
43
|
+
version: 1,
|
|
44
|
+
compatibleFrom: 1,
|
|
45
|
+
sql: (names) => `${customStepsFunctionsSql(names.schema)};\n\n${runnersFunctionsSql(names.schema)};`
|
|
46
|
+
}],
|
|
47
|
+
resourceReplaceables: [],
|
|
48
|
+
read: readCustomSteps
|
|
49
|
+
};
|
|
50
|
+
//#endregion
|
|
51
|
+
export { workflowCustomStepsModule };
|
|
@@ -18,7 +18,7 @@ const manifest = [
|
|
|
18
18
|
"error_prefix",
|
|
19
19
|
"errors"
|
|
20
20
|
];
|
|
21
|
-
/** The tables `customStepsSql` makes, which
|
|
21
|
+
/** The tables `customStepsSql` makes, which `protobase migration baseline` finds with custom steps on. */
|
|
22
22
|
const customStepsTables = ["custom_steps", "custom_step_versions"];
|
|
23
23
|
/**
|
|
24
24
|
* The custom steps of each tenant, by a name unique in it, and each version of their manifests as it was saved. A step
|
|
@@ -27,9 +27,8 @@ const customStepsTables = ["custom_steps", "custom_step_versions"];
|
|
|
27
27
|
* a step made again under a deleted one's name goes on from its last version. Each write gives the row a new
|
|
28
28
|
* `updated_at`, its ETag. Every statement is idempotent.
|
|
29
29
|
*/
|
|
30
|
-
const
|
|
30
|
+
const customStepsTablesSql = (schema) => {
|
|
31
31
|
const s = quoteIdent(schema);
|
|
32
|
-
const changed = (row) => `(${manifest.map((column) => `${row}.${column}`).join(", ")})`;
|
|
33
32
|
return `create table if not exists ${s}."custom_steps" (
|
|
34
33
|
"id" uuid primary key default gen_random_uuid(),
|
|
35
34
|
"name" text not null,
|
|
@@ -58,9 +57,13 @@ create table if not exists ${s}."custom_step_versions" (
|
|
|
58
57
|
);
|
|
59
58
|
create unique index if not exists "custom_step_versions_name" on ${s}."custom_step_versions" (coalesce("tenant_id", ''), "name", "version");
|
|
60
59
|
create index if not exists "custom_step_versions_step" on ${s}."custom_step_versions" ("custom_step_id", "version");
|
|
61
|
-
create index if not exists "custom_step_versions_version" on ${s}."custom_step_versions" ("version")
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
create index if not exists "custom_step_versions_version" on ${s}."custom_step_versions" ("version")`;
|
|
61
|
+
};
|
|
62
|
+
/** The trigger that numbers a custom step's next version as a write changes its manifest (`customStepsTablesSql`). */
|
|
63
|
+
const customStepsFunctionsSql = (schema) => {
|
|
64
|
+
const s = quoteIdent(schema);
|
|
65
|
+
const changed = (row) => `(${manifest.map((column) => `${row}.${column}`).join(", ")})`;
|
|
66
|
+
return `create or replace function ${s}."custom_step_version"() returns trigger
|
|
64
67
|
language plpgsql as $$
|
|
65
68
|
begin
|
|
66
69
|
if tg_op = 'INSERT' then
|
|
@@ -80,4 +83,4 @@ drop trigger if exists "custom_step_version" on ${s}."custom_steps";
|
|
|
80
83
|
create trigger "custom_step_version" before insert or update on ${s}."custom_steps" for each row execute function ${s}."custom_step_version"()`;
|
|
81
84
|
};
|
|
82
85
|
//#endregion
|
|
83
|
-
export {
|
|
86
|
+
export { customStepsFunctionsSql, customStepsTables, customStepsTablesSql };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { quoteIdent } from "../../changes/capture-sql.js";
|
|
2
2
|
//#region src/workflows/custom-steps/runners-sql.ts
|
|
3
|
-
/** The tables `runnersSql` makes, which
|
|
3
|
+
/** The tables `runnersSql` makes, which `protobase migration baseline` finds with custom steps on. */
|
|
4
4
|
const runnersTables = [
|
|
5
5
|
"runners",
|
|
6
6
|
"custom_step_jobs",
|
|
@@ -31,9 +31,8 @@ const runnersTables = [
|
|
|
31
31
|
*
|
|
32
32
|
* Every statement is idempotent.
|
|
33
33
|
*/
|
|
34
|
-
const
|
|
34
|
+
const runnersTablesSql = (schema) => {
|
|
35
35
|
const s = quoteIdent(schema);
|
|
36
|
-
const ended = `"finished_at" = now(), "arguments" = null, "lease_until" = null`;
|
|
37
36
|
return `create table if not exists ${s}."runners" (
|
|
38
37
|
"id" uuid primary key default gen_random_uuid(),
|
|
39
38
|
"name" text not null,
|
|
@@ -122,9 +121,13 @@ create table if not exists ${s}."custom_step_wanted" (
|
|
|
122
121
|
primary key ("workflow_id", "version_id")
|
|
123
122
|
);
|
|
124
123
|
create index if not exists "custom_step_wanted_version" on ${s}."custom_step_wanted" ("version_id");
|
|
125
|
-
create index if not exists "custom_step_wanted_tenant" on ${s}."custom_step_wanted" ("tenant_id")
|
|
126
|
-
|
|
127
|
-
|
|
124
|
+
create index if not exists "custom_step_wanted_tenant" on ${s}."custom_step_wanted" ("tenant_id")`;
|
|
125
|
+
};
|
|
126
|
+
/** The triggers of the runners' tables (`runnersTablesSql`). */
|
|
127
|
+
const runnersFunctionsSql = (schema) => {
|
|
128
|
+
const s = quoteIdent(schema);
|
|
129
|
+
const ended = `"finished_at" = now(), "arguments" = null, "lease_until" = null`;
|
|
130
|
+
return `create or replace function ${s}."runner_written"() returns trigger
|
|
128
131
|
language plpgsql as $$
|
|
129
132
|
begin
|
|
130
133
|
if tg_op = 'DELETE' or (new.revoked and not old.revoked) then
|
|
@@ -173,4 +176,4 @@ create trigger "custom_step_run_ended" after update of "status" on ${s}."runs" f
|
|
|
173
176
|
when (new.status in ('succeeded', 'failed') and old.status is distinct from new.status) execute function ${s}."custom_step_run_ended"()`;
|
|
174
177
|
};
|
|
175
178
|
//#endregion
|
|
176
|
-
export {
|
|
179
|
+
export { runnersFunctionsSql, runnersTables, runnersTablesSql };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { quoteIdent } from "../changes/capture-sql.js";
|
|
2
|
+
import { relationFound } from "../relation-found.js";
|
|
3
|
+
import { sql } from "kysely";
|
|
4
|
+
//#region src/workflows/read-catalogue.ts
|
|
5
|
+
/** Whether the schema has each of the tables. */
|
|
6
|
+
const tablesFound = async (db, schema, tables) => {
|
|
7
|
+
for (const table of tables) if (!await relationFound(db, `${quoteIdent(schema)}.${quoteIdent(table)}`)) return false;
|
|
8
|
+
return true;
|
|
9
|
+
};
|
|
10
|
+
/** Whether every one of the database triggers is on a table of the schema: a trigger can be dropped while its function stays. */
|
|
11
|
+
const triggersFound = async (db, schema, triggers) => {
|
|
12
|
+
const { rows } = await sql`select count(distinct t.tgname)::int as found from pg_trigger t join pg_class c on c.oid = t.tgrelid join pg_namespace n on n.oid = c.relnamespace
|
|
13
|
+
where n.nspname = ${schema} and not t.tgisinternal and t.tgname = any(${triggers}::text[])`.execute(db);
|
|
14
|
+
return rows[0].found === triggers.length;
|
|
15
|
+
};
|
|
16
|
+
/** The comment on the schema's function of the name, `null` when it has none or there is no such function. */
|
|
17
|
+
const functionComment = async (db, schema, name) => {
|
|
18
|
+
const { rows } = await sql`select obj_description(p.oid, 'pg_proc') as comment from pg_proc p join pg_namespace n on n.oid = p.pronamespace
|
|
19
|
+
where n.nspname = ${schema} and p.proname = ${name}`.execute(db);
|
|
20
|
+
return rows[0]?.comment ?? null;
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { functionComment, tablesFound, triggersFound };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { quoteIdent } from "../changes/capture-sql.js";
|
|
2
|
-
/** The comment the schema's function carries, which
|
|
2
|
+
/** The comment the schema's function carries, which `protobase migration baseline` reads. */
|
|
3
3
|
const workflowsComment = `Protobase workflows 28`;
|
|
4
4
|
const commentVersion = (comment) => {
|
|
5
5
|
const match = comment?.match(/^Protobase workflows (\d+)$/);
|
|
@@ -220,8 +220,16 @@ create index if not exists "runs_status" on ${s}."runs" ("status");
|
|
|
220
220
|
create index if not exists "runs_created_at" on ${s}."runs" ("created_at")`;
|
|
221
221
|
};
|
|
222
222
|
const statusColumns = `array['run_status', 'status_run_id', 'status_run_at', 'unresolved_failures', 'resolved_at', 'resolved_by', 'updated_at']`;
|
|
223
|
-
/** The triggers `functionsSql` makes, which
|
|
223
|
+
/** The triggers `functionsSql` makes, which `protobase migration baseline` finds on their tables. */
|
|
224
224
|
const workflowsTriggers = ["workflow_version", "run_version"];
|
|
225
|
+
/** Columns and defaults added to the tables of `tablesSql` since. */
|
|
226
|
+
const functionsTablesSql = (schema) => {
|
|
227
|
+
const s = quoteIdent(schema);
|
|
228
|
+
return `alter table ${s}."runs" add column if not exists "rerun_from" text;
|
|
229
|
+
|
|
230
|
+
alter table ${s}."workflows" alter column "state_machine" set default '{"QueryLanguage":"JSONata","StartAt":"","States":{}}'::jsonb;
|
|
231
|
+
alter table ${s}."workflows" alter column "trigger" set default '{"manual":{}}'::jsonb`;
|
|
232
|
+
};
|
|
225
233
|
/**
|
|
226
234
|
* A workflow numbers its next version as a save changes its definition, in the row the write returns, so its ETag is
|
|
227
235
|
* the saved row's, and keeps of its layout only the positions of what it still has; the save hook keeps that version's definition and who saved it, and publishes only as `enabled_version`
|
|
@@ -233,12 +241,7 @@ const workflowsTriggers = ["workflow_version", "run_version"];
|
|
|
233
241
|
*/
|
|
234
242
|
const functionsSql = (schema) => {
|
|
235
243
|
const s = quoteIdent(schema);
|
|
236
|
-
return
|
|
237
|
-
|
|
238
|
-
alter table ${s}."workflows" alter column "state_machine" set default '{"QueryLanguage":"JSONata","StartAt":"","States":{}}'::jsonb;
|
|
239
|
-
alter table ${s}."workflows" alter column "trigger" set default '{"manual":{}}'::jsonb;
|
|
240
|
-
|
|
241
|
-
-- The layout a definition keeps: each view's own positions, Pins' and Simple's, of the views it knows alone. In each, a
|
|
244
|
+
return `-- The layout a definition keeps: each view's own positions, Pins' and Simple's, of the views it knows alone. In each, a
|
|
242
245
|
-- position only under the trigger's key or a state's name as keys write it ('%', '.' and a leading '#' or '$' escaped),
|
|
243
246
|
-- and in Pins also before a dot, as a Break or a Make of that state is kept, so a state removed takes its positions
|
|
244
247
|
-- along; a layout or a view that is no object is none.
|
|
@@ -340,4 +343,4 @@ drop trigger if exists "run_version" on ${s}."runs";
|
|
|
340
343
|
create trigger "run_version" before insert on ${s}."runs" for each row execute function ${s}."run_version"()`;
|
|
341
344
|
};
|
|
342
345
|
//#endregion
|
|
343
|
-
export { checkpointsSql, commentVersion, definitionPartsSql, droppedSql, effectsSql, functionsSql, indexesSql, layoutSql, layoutViews, tablesSql, triggerLayoutKey, triggerStateBytes, triggersSql, workflowsComment, workflowsTriggers };
|
|
346
|
+
export { checkpointsSql, commentVersion, definitionPartsSql, droppedSql, effectsSql, functionsSql, functionsTablesSql, indexesSql, layoutSql, layoutViews, tablesSql, triggerLayoutKey, triggerStateBytes, triggersSql, workflowsComment, workflowsTriggers };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { quoteIdent } from "../changes/capture-sql.js";
|
|
2
2
|
import { statusRuns, workflowStatuses } from "@protobase/schema/internal";
|
|
3
3
|
//#region src/workflows/status-sql.ts
|
|
4
|
-
/** The triggers `
|
|
4
|
+
/** The triggers `statusFunctionsSql` makes, which `protobase migration baseline` finds on their tables. */
|
|
5
5
|
const statusTriggers = [
|
|
6
6
|
"workflow_version_status",
|
|
7
7
|
"run_status",
|
|
@@ -14,7 +14,7 @@ const statusList = workflowStatuses.map((status) => `'${status}'`).join(", ");
|
|
|
14
14
|
* resolved and ran on the workflow's current version. Marking resolved is a row of `resolutions`, kept with who did it,
|
|
15
15
|
* which copies itself onto the workflow. Written whole each time: every statement is idempotent.
|
|
16
16
|
*/
|
|
17
|
-
const
|
|
17
|
+
const statusTablesSql = (schema) => {
|
|
18
18
|
const s = quoteIdent(schema);
|
|
19
19
|
return `alter table ${s}."workflows" add column if not exists "run_status" text not null default 'no_runs';
|
|
20
20
|
alter table ${s}."workflows" add column if not exists "status_run_id" uuid;
|
|
@@ -39,9 +39,15 @@ create index if not exists "resolutions_tenant" on ${s}."resolutions" ("tenant_i
|
|
|
39
39
|
create index if not exists "resolutions_resolved_at" on ${s}."resolutions" ("resolved_at");
|
|
40
40
|
create index if not exists "runs_ended" on ${s}."runs" ("workflow_id", "finished_at" desc, "id" desc) where "status" in ('succeeded', 'failed');
|
|
41
41
|
-- The runs a workflow's status counts, so its status skips no blocks' runs, of which a run starts many, to find them.
|
|
42
|
-
create index if not exists "runs_ended_top" on ${s}."runs" ("workflow_id", "finished_at" desc, "id" desc) where "status" in ('succeeded', 'failed') and "block_of" is null
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
create index if not exists "runs_ended_top" on ${s}."runs" ("workflow_id", "finished_at" desc, "id" desc) where "status" in ('succeeded', 'failed') and "block_of" is null`;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* The functions and triggers that keep a workflow's status (`statusTablesSql`), and each workflow's status computed
|
|
46
|
+
* again from its runs.
|
|
47
|
+
*/
|
|
48
|
+
const statusFunctionsSql = (schema) => {
|
|
49
|
+
const s = quoteIdent(schema);
|
|
50
|
+
return `-- The status of a workflow at its version and last mark as resolved, from its last ${statusRuns} ended runs, blocks' runs left out
|
|
45
51
|
-- (a block's failure is its run's): the run its
|
|
46
52
|
-- reason names is the latest for failing and healthy, the latest failure that counts for unresolved, none for the gray ones.
|
|
47
53
|
create or replace function ${s}."workflow_status"(workflow uuid, current_version integer, resolved timestamptz)
|
|
@@ -122,4 +128,4 @@ update ${s}."workflows" w set ("run_status", "status_run_id", "status_run_at", "
|
|
|
122
128
|
(select st.run_status, st.status_run_id, st.status_run_at, st.unresolved_failures from ${s}."workflow_status"(w.id, w.version, w.resolved_at) st)`;
|
|
123
129
|
};
|
|
124
130
|
//#endregion
|
|
125
|
-
export {
|
|
131
|
+
export { statusFunctionsSql, statusTablesSql, statusTriggers };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { tablesFound, triggersFound } from "../read-catalogue.js";
|
|
2
|
+
import { storageFunctionsSql, storageTablesSql } from "./storage-sql.js";
|
|
3
|
+
//#region src/workflows/storage/storage-module.ts
|
|
4
|
+
/** The storage configurations as the database has them: step 1 once the table is there, its trigger at version 1 while it is on it. */
|
|
5
|
+
const readStorage = async (db, { names }) => {
|
|
6
|
+
const schema = names.schema;
|
|
7
|
+
if (!await tablesFound(db, schema, ["storage_configurations"])) return;
|
|
8
|
+
return {
|
|
9
|
+
lastStep: 1,
|
|
10
|
+
replaceables: await triggersFound(db, schema, ["storage_configuration_updated"]) ? { functions: 1 } : {},
|
|
11
|
+
names
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The storage configurations workflows store files in, with `storage`, in the workflows schema (`names.schema`): a
|
|
16
|
+
* module of its own, after the workflows schema, so turning `storage` on later writes it alone.
|
|
17
|
+
*/
|
|
18
|
+
const workflowStorageModule = {
|
|
19
|
+
label: "the workflows' storage configurations",
|
|
20
|
+
title: "The storage configurations workflows store files in",
|
|
21
|
+
steps: [{
|
|
22
|
+
step: 1,
|
|
23
|
+
name: "storage_configurations",
|
|
24
|
+
title: "The storage configurations table and its indexes",
|
|
25
|
+
additive: true,
|
|
26
|
+
sql: (names) => `${storageTablesSql(names.schema)};`
|
|
27
|
+
}],
|
|
28
|
+
replaceables: [{
|
|
29
|
+
name: "functions",
|
|
30
|
+
title: "The trigger that gives a written storage configuration its new updated_at",
|
|
31
|
+
version: 1,
|
|
32
|
+
compatibleFrom: 1,
|
|
33
|
+
sql: (names) => `${storageFunctionsSql(names.schema)};`
|
|
34
|
+
}],
|
|
35
|
+
resourceReplaceables: [],
|
|
36
|
+
read: readStorage
|
|
37
|
+
};
|
|
38
|
+
//#endregion
|
|
39
|
+
export { workflowStorageModule };
|
|
@@ -4,7 +4,7 @@ import { quoteIdent } from "../../changes/capture-sql.js";
|
|
|
4
4
|
* The storage configurations workflows store files in, by name, unique per tenant: a folder under the storage root
|
|
5
5
|
* or a bucket, with the bucket's keys encrypted. Each write gives the row a new `updated_at`, its ETag.
|
|
6
6
|
*/
|
|
7
|
-
const
|
|
7
|
+
const storageTablesSql = (schema) => {
|
|
8
8
|
const s = quoteIdent(schema);
|
|
9
9
|
return `create table if not exists ${s}."storage_configurations" (
|
|
10
10
|
"id" uuid primary key default gen_random_uuid(),
|
|
@@ -24,9 +24,12 @@ create unique index if not exists "storage_configurations_name" on ${s}."storage
|
|
|
24
24
|
create index if not exists "storage_configurations_tenant" on ${s}."storage_configurations" ("tenant_id");
|
|
25
25
|
create index if not exists "storage_configurations_name_order" on ${s}."storage_configurations" ("name");
|
|
26
26
|
create index if not exists "storage_configurations_name_search" on ${s}."storage_configurations" using gin ("name" gin_trgm_ops);
|
|
27
|
-
create index if not exists "storage_configurations_updated_at" on ${s}."storage_configurations" ("updated_at")
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
create index if not exists "storage_configurations_updated_at" on ${s}."storage_configurations" ("updated_at")`;
|
|
28
|
+
};
|
|
29
|
+
/** The trigger that gives a written storage configuration its new `updated_at`. */
|
|
30
|
+
const storageFunctionsSql = (schema) => {
|
|
31
|
+
const s = quoteIdent(schema);
|
|
32
|
+
return `create or replace function ${s}."storage_configuration_updated"() returns trigger
|
|
30
33
|
language plpgsql as $$
|
|
31
34
|
begin
|
|
32
35
|
new.updated_at := greatest(clock_timestamp(), old.updated_at + interval '1 microsecond');
|
|
@@ -37,4 +40,4 @@ drop trigger if exists "storage_configuration_updated" on ${s}."storage_configur
|
|
|
37
40
|
create trigger "storage_configuration_updated" before update on ${s}."storage_configurations" for each row execute function ${s}."storage_configuration_updated"()`;
|
|
38
41
|
};
|
|
39
42
|
//#endregion
|
|
40
|
-
export {
|
|
43
|
+
export { storageFunctionsSql, storageTablesSql };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { commentVersion, functionsSql, workflowsTriggers } from "./schema-sql.js";
|
|
2
|
+
import { functionComment, tablesFound, triggersFound } from "./read-catalogue.js";
|
|
3
|
+
import { statusFunctionsSql, statusTriggers } from "./status-sql.js";
|
|
4
|
+
import { workflowsTablesSql } from "./workflows-tables-sql.js";
|
|
5
|
+
//#region src/workflows/workflows-schema-module.ts
|
|
6
|
+
/**
|
|
7
|
+
* The workflows schema as the database has it: step 1 once its tables are there and the run trigger's function names
|
|
8
|
+
* version 28, the version step 1 freezes, and its functions at that version while every trigger is on its table, or
|
|
9
|
+
* written again when one is not. Refuses another version, which no step records.
|
|
10
|
+
*/
|
|
11
|
+
const readWorkflows = async (db, { names }) => {
|
|
12
|
+
const schema = names.schema;
|
|
13
|
+
if (!await tablesFound(db, schema, ["runs"])) return;
|
|
14
|
+
const version = commentVersion(await functionComment(db, schema, "run_version"));
|
|
15
|
+
if (version !== void 0 && version > 28) throw new Error(`The ${schema} schema is at version ${version}, newer than the 28 this version of Protobase writes: upgrade Protobase`);
|
|
16
|
+
if (version !== 28 || !await tablesFound(db, schema, ["triggers"])) throw new Error(`The ${schema} schema is at ${version === void 0 ? "a version" : `version ${version}`} no step of this version of Protobase records: bring it to version 28 with \`protobase migration\` and \`protobase migrate\` of Protobase 0.14.2 first, then run this command again`);
|
|
17
|
+
return {
|
|
18
|
+
lastStep: 1,
|
|
19
|
+
replaceables: await triggersFound(db, schema, [...workflowsTriggers, ...statusTriggers]) ? { functions: 28 } : {},
|
|
20
|
+
names
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* The workflows, their versions, runs and triggers, in the schema `workflows` names (`names.schema`): the tables, and
|
|
25
|
+
* the functions and triggers that number a workflow's versions, pin a run's and keep a workflow's status. Its tables are
|
|
26
|
+
* never dropped.
|
|
27
|
+
*/
|
|
28
|
+
const workflowsSchemaModule = {
|
|
29
|
+
label: "the workflows schema",
|
|
30
|
+
title: "The workflows, their versions, runs and steps",
|
|
31
|
+
steps: [{
|
|
32
|
+
step: 1,
|
|
33
|
+
name: "workflows",
|
|
34
|
+
title: "The tables of the workflows, their versions, runs and triggers, and their indexes",
|
|
35
|
+
additive: true,
|
|
36
|
+
sql: (names) => workflowsTablesSql(names.schema)
|
|
37
|
+
}],
|
|
38
|
+
replaceables: [{
|
|
39
|
+
name: "functions",
|
|
40
|
+
title: "The functions and triggers that number a workflow's versions, pin a run's and keep a workflow's status",
|
|
41
|
+
version: 28,
|
|
42
|
+
compatibleFrom: 28,
|
|
43
|
+
sql: (names) => `${functionsSql(names.schema)};\n\n${statusFunctionsSql(names.schema)};`
|
|
44
|
+
}],
|
|
45
|
+
resourceReplaceables: [],
|
|
46
|
+
read: readWorkflows
|
|
47
|
+
};
|
|
48
|
+
//#endregion
|
|
49
|
+
export { workflowsSchemaModule };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { quoteIdent } from "../changes/capture-sql.js";
|
|
2
|
+
import { checkpointsSql, definitionPartsSql, droppedSql, effectsSql, functionsTablesSql, indexesSql, layoutSql, tablesSql, triggersSql } from "./schema-sql.js";
|
|
3
|
+
import { statusTablesSql } from "./status-sql.js";
|
|
4
|
+
import { stepCacheSql } from "./cache/step-cache-sql.js";
|
|
5
|
+
import { revocationsSql } from "./connections/revocations-sql.js";
|
|
6
|
+
import { blockRunsSql } from "./block-runs-sql.js";
|
|
7
|
+
import { hooksSql } from "./hooks/hooks-sql.js";
|
|
8
|
+
import { taskTokensSql } from "./task-tokens-sql.js";
|
|
9
|
+
import { testRunsSql } from "./test-runs-sql.js";
|
|
10
|
+
//#region src/workflows/workflows-tables-sql.ts
|
|
11
|
+
/** The workflows' tables and indexes at version 28 of the schema, before it had steps. */
|
|
12
|
+
const workflowsTablesSql = (schema) => `${[
|
|
13
|
+
`create schema if not exists ${quoteIdent(schema)}`,
|
|
14
|
+
tablesSql(schema),
|
|
15
|
+
definitionPartsSql(schema),
|
|
16
|
+
layoutSql(schema),
|
|
17
|
+
checkpointsSql(schema),
|
|
18
|
+
droppedSql(schema),
|
|
19
|
+
triggersSql(schema),
|
|
20
|
+
effectsSql(schema),
|
|
21
|
+
revocationsSql(schema),
|
|
22
|
+
hooksSql(schema),
|
|
23
|
+
stepCacheSql(schema),
|
|
24
|
+
indexesSql(schema),
|
|
25
|
+
blockRunsSql(schema),
|
|
26
|
+
taskTokensSql(schema),
|
|
27
|
+
testRunsSql(schema),
|
|
28
|
+
functionsTablesSql(schema),
|
|
29
|
+
statusTablesSql(schema)
|
|
30
|
+
].join(";\n\n")};`;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { workflowsTablesSql };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { workflowsCustomStepsOn, workflowsSchema, workflowsStorageOn } from "./options.js";
|
|
2
|
+
//#region src/workflows/workflows-targets.ts
|
|
3
|
+
/** The schema modules `workflows` needs, all in the schema it names: the workflows schema, and its storage and custom steps while they are on. */
|
|
4
|
+
const workflowsTargets = (options) => {
|
|
5
|
+
const input = {
|
|
6
|
+
names: { schema: workflowsSchema(options) },
|
|
7
|
+
resources: {}
|
|
8
|
+
};
|
|
9
|
+
return {
|
|
10
|
+
workflows: input,
|
|
11
|
+
...workflowsStorageOn(options) && { workflow_storage: input },
|
|
12
|
+
...workflowsCustomStepsOn(options) && { workflow_custom_steps: input }
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { workflowsTargets };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.130.0",
|
|
4
4
|
"description": "The Protobase REST API as a Hono app, with Better Auth sign-in.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
"@better-auth/sso": "^1.7.12",
|
|
45
45
|
"@livekit/protocol": "1.53.1",
|
|
46
46
|
"@modelcontextprotocol/server": "^2.3.1",
|
|
47
|
-
"@protobase/layout": "0.
|
|
48
|
-
"@protobase/query": "0.
|
|
49
|
-
"@protobase/schema": "0.
|
|
50
|
-
"@protobase/workflow-plugins": "0.
|
|
51
|
-
"@protobase/workflows": "0.
|
|
47
|
+
"@protobase/layout": "0.130.0",
|
|
48
|
+
"@protobase/query": "0.130.0",
|
|
49
|
+
"@protobase/schema": "0.130.0",
|
|
50
|
+
"@protobase/workflow-plugins": "0.130.0",
|
|
51
|
+
"@protobase/workflows": "0.130.0",
|
|
52
52
|
"@react-email/render": "^2.1.0",
|
|
53
53
|
"@react-pdf/primitives": "^4.4.0",
|
|
54
54
|
"@react-pdf/renderer": "^4.9.0",
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
//#region src/assistant/query-runner/runner-plan.ts
|
|
2
|
-
const same = (a, b) => a.schema === b.schema && a.name === b.name;
|
|
3
|
-
const unique = (items, equal) => items.filter((item, index) => items.findIndex((other) => equal(item, other)) === index);
|
|
4
|
-
/**
|
|
5
|
-
* What the query role must be given and what taken back so that it reads exactly the resources' tables, never an auth
|
|
6
|
-
* table nor any table of a guarded schema, with usage on the schemas those are in. `resources` and `authTables` are the
|
|
7
|
-
* tables that exist, `granted` what the role holds now.
|
|
8
|
-
*/
|
|
9
|
-
const plannedGrants = ({ resources, authTables, guardedSchemas, granted }) => {
|
|
10
|
-
const tables = unique(resources.filter((table) => !guardedSchemas.includes(table.schema) && !authTables.some((auth) => same(table, auth))), same);
|
|
11
|
-
const schemas = [...new Set(tables.map((table) => table.schema))];
|
|
12
|
-
return {
|
|
13
|
-
grants: [...schemas.filter((schema) => !granted.schemas.includes(schema)).map((schema) => ({
|
|
14
|
-
on: "schema",
|
|
15
|
-
schema
|
|
16
|
-
})), ...tables.filter((table) => !granted.tables.some((found) => same(found, table))).map((table) => ({
|
|
17
|
-
on: "table",
|
|
18
|
-
...table
|
|
19
|
-
}))],
|
|
20
|
-
revokes: [...granted.tables.filter((found) => !tables.some((table) => same(table, found))).map((table) => ({
|
|
21
|
-
on: "table",
|
|
22
|
-
...table
|
|
23
|
-
})), ...granted.schemas.filter((schema) => !schemas.includes(schema)).map((schema) => ({
|
|
24
|
-
on: "schema",
|
|
25
|
-
schema
|
|
26
|
-
}))]
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
//#endregion
|
|
30
|
-
export { plannedGrants };
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { ddl } from "./ddl.js";
|
|
2
|
-
import { sql } from "kysely";
|
|
3
|
-
//#region src/better-auth/store/migrations-table.ts
|
|
4
|
-
/** The table, in the store's schema, as the store's names resolve `auth_migrations`. */
|
|
5
|
-
const migrationsTable = ({ names }) => names.table("auth_migrations");
|
|
6
|
-
/** The statement that makes the table; with `ifMissing`, only when it is not there yet. */
|
|
7
|
-
const createMigrationsTable = (names, ifMissing = false) => {
|
|
8
|
-
const table = migrationsTable(names);
|
|
9
|
-
const { version, name, applied_at } = table.columns;
|
|
10
|
-
return ddl`create table ${sql.raw(ifMissing ? "if not exists " : "")}${table} (
|
|
11
|
-
${version} integer primary key,
|
|
12
|
-
${name} text not null,
|
|
13
|
-
${applied_at} timestamptz default current_timestamp not null
|
|
14
|
-
)`;
|
|
15
|
-
};
|
|
16
|
-
/** The statement that records `migrations` as applied. */
|
|
17
|
-
const recordMigrations = (names, migrations) => ddl`insert into ${migrationsTable(names)} (${migrationsTable(names).columns.version}, ${migrationsTable(names).columns.name}) values ${sql.join(migrations.map(({ version, name }) => ddl`(${sql.lit(version)}, ${sql.lit(name)})`))}`;
|
|
18
|
-
/** The versions the store has applied, in order; `undefined` when it has no migrations table. */
|
|
19
|
-
const appliedVersions = async (db, names) => {
|
|
20
|
-
const table = migrationsTable(names);
|
|
21
|
-
const [found] = (await sql`select to_regclass(${String(table)}) is not null as found`.execute(db)).rows;
|
|
22
|
-
if (!found?.found) return void 0;
|
|
23
|
-
const { version } = table.columns;
|
|
24
|
-
return (await sql`select ${version} as version from ${table} order by ${version}`.execute(db)).rows.map((row) => row.version);
|
|
25
|
-
};
|
|
26
|
-
//#endregion
|
|
27
|
-
export { appliedVersions, createMigrationsTable, migrationsTable, recordMigrations };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { allModules } from "../names/modules-on.js";
|
|
2
|
-
//#region src/better-auth/store/modules-off.ts
|
|
3
|
-
/** Refuses to write the store's migrations, an adoption included, while a module is off. */
|
|
4
|
-
const refuseModulesOff = (names) => {
|
|
5
|
-
const off = allModules.filter((module) => !names.names.modules.includes(module));
|
|
6
|
-
if (off.length > 0) throw new Error(`The auth store's migrations are written with every module on, and ${off.join(", ")} is off`);
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Whether the store has a step, from the versions it recorded: a version stands for every step naming it, whatever its
|
|
10
|
-
* module. Sound because every version was recorded with every module on, by the former chain, which made every
|
|
11
|
-
* module's tables, or since then behind `refuseModulesOff`; adoption records a version only once the store has every
|
|
12
|
-
* column its steps make. A released step keeps its version and a new one takes a version no other step has
|
|
13
|
-
* (`shipped-steps.test.ts`).
|
|
14
|
-
*/
|
|
15
|
-
const hadByVersion = (applied) => (_module, step) => applied.includes(step.version);
|
|
16
|
-
//#endregion
|
|
17
|
-
export { hadByVersion, refuseModulesOff };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { EventsOptions } from "../changes/events-options.js";
|
|
2
|
-
import { Db } from "@protobase/query";
|
|
3
|
-
//#region src/calls/calls-sql.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* The SQL that adds the `calls` schema and its tables, or the guest tables to a calls schema without them, and the changes schema's notices table rings reach open pages
|
|
6
|
-
* through, `undefined` when they are there. They are never dropped.
|
|
7
|
-
*/
|
|
8
|
-
export declare const callsMigration: (db: Db, events?: EventsOptions) => Promise<string | undefined>;
|
|
9
|
-
/** Refuses to go on while the app has `calls` and the database lacks their tables; the project's migrations add them. */
|
|
10
|
-
export declare const checkCalls: (db: Db, calls: unknown, events?: EventsOptions) => Promise<void>;
|
|
11
|
-
//#endregion
|