@cosmicdrift/kumiko-framework 0.406.0 → 0.409.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/agents/api/framework-db.md +1 -0
- package/agents/api/framework-engine.md +15 -2
- package/agents/api/framework-ui-types.md +15 -0
- package/agents/api/renderer-web.md +156 -2
- package/agents/api/types.md +113 -71
- package/agents/api.md +4 -4
- package/agents/boot-rules.md +743 -0
- package/agents/examples/contact.md +167 -0
- package/agents/examples/delivery-notifications.md +34 -1
- package/agents/examples/record-detail-layout.md +13 -2
- package/agents/examples/search.md +65 -3
- package/agents/examples/secrets-demo.md +96 -2
- package/agents/examples/tenant-inactivity.md +138 -0
- package/agents/examples.md +2 -0
- package/agents/features-index.md +4 -0
- package/agents/features.md +24 -1
- package/agents/widgets.md +12 -1
- package/dist/api/export/export-rows.js +1 -0
- package/dist/compliance/index.d.ts +1 -1
- package/dist/db/event-store-executor-read-where.js +15 -5
- package/dist/db/index.d.ts +1 -1
- package/dist/db/index.js +1 -1
- package/dist/db/migrate-generator.js +3 -1
- package/dist/db/queries/event-consumer.js +11 -7
- package/dist/db/queries/event-store.d.ts +2 -1
- package/dist/db/queries/event-store.js +25 -6
- package/dist/db/queries/rls-boot-catalog.js +3 -1
- package/dist/db/queries/session-advisory-lock.d.ts +7 -0
- package/dist/db/queries/session-advisory-lock.js +23 -0
- package/dist/db/query.js +7 -10
- package/dist/db/row-level-security-connection.js +4 -2
- package/dist/engine/active-membership.js +1 -0
- package/dist/engine/boot-validator/access-declarations.js +57 -33
- package/dist/engine/boot-validator/action-wiring.js +8 -6
- package/dist/engine/boot-validator/agent-effect-rules.d.ts +12 -0
- package/dist/engine/boot-validator/agent-effect-rules.js +12 -0
- package/dist/engine/boot-validator/agent-effect.d.ts +2 -0
- package/dist/engine/boot-validator/agent-effect.js +20 -0
- package/dist/engine/boot-validator/boot-context.js +5 -1
- package/dist/engine/boot-validator/boot-environment-rules.d.ts +12 -0
- package/dist/engine/boot-validator/boot-environment-rules.js +12 -0
- package/dist/engine/boot-validator/boot-phases-app.js +5 -1
- package/dist/engine/boot-validator/boot-phases.js +3 -1
- package/dist/engine/boot-validator/boot-rules.d.ts +2619 -0
- package/dist/engine/boot-validator/boot-rules.js +58 -0
- package/dist/engine/boot-validator/bundled-lists-table.js +23 -9
- package/dist/engine/boot-validator/config-deps.js +71 -23
- package/dist/engine/boot-validator/config-edit-action-rules.d.ts +17 -0
- package/dist/engine/boot-validator/config-edit-action-rules.js +17 -0
- package/dist/engine/boot-validator/config-key-rules.d.ts +117 -0
- package/dist/engine/boot-validator/config-key-rules.js +117 -0
- package/dist/engine/boot-validator/custom-screen-write-qns.js +6 -2
- package/dist/engine/boot-validator/derived-sql-fields-rules.d.ts +77 -0
- package/dist/engine/boot-validator/derived-sql-fields-rules.js +77 -0
- package/dist/engine/boot-validator/derived-sql-fields.js +53 -17
- package/dist/engine/boot-validator/detail-screens.js +10 -4
- package/dist/engine/boot-validator/entity-declaration-rules.d.ts +92 -0
- package/dist/engine/boot-validator/entity-declaration-rules.js +92 -0
- package/dist/engine/boot-validator/entity-handler-access-rules.d.ts +102 -0
- package/dist/engine/boot-validator/entity-handler-access-rules.js +102 -0
- package/dist/engine/boot-validator/entity-handler.d.ts +0 -7
- package/dist/engine/boot-validator/entity-handler.js +259 -355
- package/dist/engine/boot-validator/entity-image-variants.d.ts +2 -0
- package/dist/engine/boot-validator/entity-image-variants.js +91 -0
- package/dist/engine/boot-validator/entity-list-aggregate-options.js +8 -2
- package/dist/engine/boot-validator/entity-reference-embedded-rules.d.ts +117 -0
- package/dist/engine/boot-validator/entity-reference-embedded-rules.js +117 -0
- package/dist/engine/boot-validator/entity-select-image-rules.d.ts +122 -0
- package/dist/engine/boot-validator/entity-select-image-rules.js +122 -0
- package/dist/engine/boot-validator/entity-select.d.ts +8 -0
- package/dist/engine/boot-validator/entity-select.js +197 -0
- package/dist/engine/boot-validator/entity-structure-rules.d.ts +107 -0
- package/dist/engine/boot-validator/entity-structure-rules.js +107 -0
- package/dist/engine/boot-validator/field-conditions-rules.d.ts +92 -0
- package/dist/engine/boot-validator/field-conditions-rules.js +92 -0
- package/dist/engine/boot-validator/field-conditions.js +67 -22
- package/dist/engine/boot-validator/form-derivations-rules.d.ts +77 -0
- package/dist/engine/boot-validator/form-derivations-rules.js +77 -0
- package/dist/engine/boot-validator/form-derivations.js +52 -18
- package/dist/engine/boot-validator/global-tenancy.js +13 -7
- package/dist/engine/boot-validator/handler-declaration-rules.d.ts +72 -0
- package/dist/engine/boot-validator/handler-declaration-rules.js +72 -0
- package/dist/engine/boot-validator/handler-field-references-rules.d.ts +22 -0
- package/dist/engine/boot-validator/handler-field-references-rules.js +22 -0
- package/dist/engine/boot-validator/handler-field-references.js +14 -6
- package/dist/engine/boot-validator/list-bulk-actions-rules.d.ts +42 -0
- package/dist/engine/boot-validator/list-bulk-actions-rules.js +42 -0
- package/dist/engine/boot-validator/list-bulk-actions.js +29 -11
- package/dist/engine/boot-validator/list-column-layout.js +22 -10
- package/dist/engine/boot-validator/list-query-rules.d.ts +107 -0
- package/dist/engine/boot-validator/list-query-rules.js +107 -0
- package/dist/engine/boot-validator/list-table-aggregate-options.js +43 -15
- package/dist/engine/boot-validator/list-table-aggregate-query.js +7 -3
- package/dist/engine/boot-validator/list-table-aggregate-rules.d.ts +82 -0
- package/dist/engine/boot-validator/list-table-aggregate-rules.js +82 -0
- package/dist/engine/boot-validator/list-table-export-options.js +19 -7
- package/dist/engine/boot-validator/list-table-options.js +33 -13
- package/dist/engine/boot-validator/list-table-reject-unknown-keys.js +6 -2
- package/dist/engine/boot-validator/list-table-rules.d.ts +132 -0
- package/dist/engine/boot-validator/list-table-rules.js +132 -0
- package/dist/engine/boot-validator/nav-rules.d.ts +42 -0
- package/dist/engine/boot-validator/nav-rules.js +42 -0
- package/dist/engine/boot-validator/nav.js +29 -15
- package/dist/engine/boot-validator/ownership-rules.d.ts +27 -0
- package/dist/engine/boot-validator/ownership-rules.js +27 -0
- package/dist/engine/boot-validator/ownership.js +28 -12
- package/dist/engine/boot-validator/parent-ref.js +32 -20
- package/dist/engine/boot-validator/projection-list-screens.js +76 -35
- package/dist/engine/boot-validator/query-output-columns.js +9 -3
- package/dist/engine/boot-validator/query-refs.js +20 -10
- package/dist/engine/boot-validator/query-rules.d.ts +37 -0
- package/dist/engine/boot-validator/query-rules.js +37 -0
- package/dist/engine/boot-validator/read-gate.js +14 -10
- package/dist/engine/boot-validator/record-owned.js +5 -1
- package/dist/engine/boot-validator/related-list-table-rules.js +17 -7
- package/dist/engine/boot-validator/screens-actions-rules.d.ts +185 -0
- package/dist/engine/boot-validator/screens-actions-rules.js +185 -0
- package/dist/engine/boot-validator/screens-actions.js +169 -93
- package/dist/engine/boot-validator/screens-dashboard-chart-rules.d.ts +87 -0
- package/dist/engine/boot-validator/screens-dashboard-chart-rules.js +87 -0
- package/dist/engine/boot-validator/screens-dashboard-rules.d.ts +227 -0
- package/dist/engine/boot-validator/screens-dashboard-rules.js +227 -0
- package/dist/engine/boot-validator/screens-dashboard.js +222 -85
- package/dist/engine/boot-validator/screens-forms-layout-rules.d.ts +122 -0
- package/dist/engine/boot-validator/screens-forms-layout-rules.js +122 -0
- package/dist/engine/boot-validator/screens-forms-rules.d.ts +152 -0
- package/dist/engine/boot-validator/screens-forms-rules.js +152 -0
- package/dist/engine/boot-validator/screens-forms.js +240 -112
- package/dist/engine/boot-validator/screens-kind-config-edit.js +72 -16
- package/dist/engine/boot-validator/screens-kind-entity-edit.js +15 -7
- package/dist/engine/boot-validator/screens-kind-entity-list.js +57 -32
- package/dist/engine/boot-validator/screens-kind-projection-detail-rules.d.ts +92 -0
- package/dist/engine/boot-validator/screens-kind-projection-detail-rules.js +92 -0
- package/dist/engine/boot-validator/screens-kind-projection-detail.js +85 -47
- package/dist/engine/boot-validator/screens-kind-rules.d.ts +137 -0
- package/dist/engine/boot-validator/screens-kind-rules.js +137 -0
- package/dist/engine/boot-validator/screens-kind-secret-mint.js +18 -8
- package/dist/engine/boot-validator/screens-kind-shared.js +40 -22
- package/dist/engine/boot-validator/screens-lists-rules.d.ts +82 -0
- package/dist/engine/boot-validator/screens-lists-rules.js +82 -0
- package/dist/engine/boot-validator/screens-lists.js +90 -45
- package/dist/engine/boot-validator/screens-rules.d.ts +57 -0
- package/dist/engine/boot-validator/screens-rules.js +57 -0
- package/dist/engine/boot-validator/screens.js +17 -12
- package/dist/engine/boot-validator/transaction-phases.js +12 -4
- package/dist/engine/boot-validator/transfer-graph.js +17 -11
- package/dist/engine/boot-validator/url-prefill-fields.js +9 -5
- package/dist/engine/boot-validator/workspaces.js +11 -5
- package/dist/engine/boot-validator/zod-shape.js +6 -2
- package/dist/engine/entity-handlers.d.ts +1 -0
- package/dist/engine/entity-handlers.js +3 -0
- package/dist/engine/entity-list-runtime-options.js +23 -29
- package/dist/engine/extensions/tenant-data.d.ts +3 -0
- package/dist/engine/factories.d.ts +1 -1
- package/dist/engine/factories.js +4 -3
- package/dist/engine/index.d.ts +4 -2
- package/dist/engine/index.js +2 -0
- package/dist/engine/project-app-schema-for-roles.js +29 -14
- package/dist/engine/registry-facade.js +7 -8
- package/dist/engine/registry-validate.js +5 -1
- package/dist/engine/soft-delete-cleanup.d.ts +1 -0
- package/dist/engine/soft-delete-cleanup.js +5 -0
- package/dist/engine/steps/describe-workflow-step-error.js +1 -0
- package/dist/es-ops/operations-schema.d.ts +1 -1
- package/dist/event-store/ensure-dead-letter-table.d.ts +2 -0
- package/dist/event-store/ensure-dead-letter-table.js +10 -0
- package/dist/event-store/rebuild-dead-letter.js +2 -8
- package/dist/event-store/upcaster-dead-letter.js +2 -8
- package/dist/files/copy-pending-file-refs-to-tenant.d.ts +28 -0
- package/dist/files/copy-pending-file-refs-to-tenant.js +87 -0
- package/dist/files/file-routes.d.ts +1 -1
- package/dist/files/file-routes.js +21 -6
- package/dist/files/index.d.ts +2 -0
- package/dist/files/index.js +1 -0
- package/dist/i18n/required-surface-keys.js +1 -0
- package/dist/jobs/job-runner-helpers.js +1 -0
- package/dist/jobs/job-runner.js +7 -12
- package/dist/logging/utils.js +30 -60
- package/dist/observability/metrics-handle.js +10 -21
- package/dist/pipeline/cascade-handler.js +7 -6
- package/dist/pipeline/dispatch-query.js +18 -5
- package/dist/pipeline/dispatch-shared.d.ts +1 -0
- package/dist/pipeline/dispatch-shared.js +3 -1
- package/dist/pipeline/dispatch-write.js +10 -12
- package/dist/pipeline/dispatcher.js +12 -14
- package/dist/pipeline/event-dispatcher-admin.js +9 -8
- package/dist/pipeline/event-dispatcher-delivery.d.ts +19 -1
- package/dist/pipeline/event-dispatcher-delivery.js +121 -29
- package/dist/pipeline/event-dispatcher.d.ts +5 -1
- package/dist/pipeline/event-dispatcher.js +28 -21
- package/dist/pipeline/handler-context-phase-denials.js +2 -0
- package/dist/pipeline/multi-stream-apply-context.js +12 -20
- package/dist/pipeline/system-hooks.d.ts +4 -1
- package/dist/pipeline/system-hooks.js +79 -6
- package/dist/pipeline/system-identity-switch.js +10 -7
- package/dist/search/build-search-snippet.d.ts +9 -0
- package/dist/search/build-search-snippet.js +40 -0
- package/dist/search/index.d.ts +1 -0
- package/dist/search/index.js +1 -0
- package/dist/search/meilisearch-adapter.d.ts +32 -0
- package/dist/search/meilisearch-adapter.js +153 -56
- package/dist/search/meilisearch-chunking.d.ts +21 -0
- package/dist/search/meilisearch-chunking.js +96 -0
- package/dist/search/reindex-entity.d.ts +1 -0
- package/dist/search/reindex-entity.js +97 -52
- package/dist/ui-types/index.d.ts +1 -1
- package/dist/upgrade-cli.js +3 -14
- package/package.json +3 -3
- package/src/changes.json +73 -0
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { filterByPhase, filterOwned } from "./registry-state.js";
|
|
2
|
+
function isFeatureSystemScoped(state, featureName) {
|
|
3
|
+
if (!featureName)
|
|
4
|
+
return false;
|
|
5
|
+
return state.featureMap.get(featureName)?.systemScope ?? false;
|
|
6
|
+
}
|
|
2
7
|
// Builds the public Registry surface (64 getters) bound to a specific
|
|
3
8
|
// RegistryState instance — pure move-diff from createRegistry's former
|
|
4
9
|
// return-object literal, only the closure-captured variable changed
|
|
@@ -102,16 +107,10 @@ export function buildRegistryFacade(state) {
|
|
|
102
107
|
return state.handlerEntityMap.get(qualifiedHandler);
|
|
103
108
|
},
|
|
104
109
|
isHandlerSystemScoped(qualifiedHandler) {
|
|
105
|
-
|
|
106
|
-
if (!featureName)
|
|
107
|
-
return false;
|
|
108
|
-
return state.featureMap.get(featureName)?.systemScope ?? false;
|
|
110
|
+
return isFeatureSystemScoped(state, state.handlerFeatureMap.get(qualifiedHandler));
|
|
109
111
|
},
|
|
110
112
|
isJobSystemScoped(qualifiedJobName) {
|
|
111
|
-
|
|
112
|
-
if (!featureName)
|
|
113
|
-
return false;
|
|
114
|
-
return state.featureMap.get(featureName)?.systemScope ?? false;
|
|
113
|
+
return isFeatureSystemScoped(state, state.jobFeatureMap.get(qualifiedJobName));
|
|
115
114
|
},
|
|
116
115
|
getHandlerFeature(qualifiedHandler) {
|
|
117
116
|
return state.handlerFeatureMap.get(qualifiedHandler);
|
|
@@ -198,6 +198,10 @@ function buildSortableReferenceField(entityName, fieldName, field) {
|
|
|
198
198
|
labelField: field.labelField,
|
|
199
199
|
};
|
|
200
200
|
}
|
|
201
|
+
// longText becomes searchable only through `find: "fuzzy"` (indexed in chunks by the SearchAdapter).
|
|
202
|
+
function isSearchableStringField(field) {
|
|
203
|
+
return (field.type === "text" || field.type === "longText") && field.searchable === true;
|
|
204
|
+
}
|
|
201
205
|
// Precompute: searchable/sortable fields, searchable + sortable reference fields.
|
|
202
206
|
export function buildSearchableSortableCaches(state) {
|
|
203
207
|
for (const [name, entity] of state.entityMap) {
|
|
@@ -206,7 +210,7 @@ export function buildSearchableSortableCaches(state) {
|
|
|
206
210
|
const searchableReferences = [];
|
|
207
211
|
const sortableReferences = [];
|
|
208
212
|
for (const [fieldName, field] of Object.entries(entity.fields)) {
|
|
209
|
-
if (field
|
|
213
|
+
if (isSearchableStringField(field))
|
|
210
214
|
searchable.push(fieldName);
|
|
211
215
|
if (field.type === "text" && field.sortable === true)
|
|
212
216
|
sortable.push(fieldName);
|
|
@@ -5,6 +5,7 @@ export declare const SOFT_DELETE_CLEANUP_SYSTEM_JOB = "soft-delete:job:cleanup-s
|
|
|
5
5
|
export declare const SOFT_DELETE_GRACE_DAYS_KEY = "soft-delete:config:grace-days";
|
|
6
6
|
export declare const DEFAULT_GRACE_DAYS = 30;
|
|
7
7
|
export declare const softDeleteGraceDaysConfig: ConfigKeyDefinition;
|
|
8
|
+
export declare function readSoftDeleteGraceDays(config: ((qualifiedKey: string) => Promise<unknown>) | undefined): Promise<number>;
|
|
8
9
|
export declare function isSystemScopedSoftDeleteTable(table: unknown, entity: Pick<EntityDefinition, "tenancy">): boolean;
|
|
9
10
|
export declare const softDeleteCleanupJob: JobHandlerFn;
|
|
10
11
|
export declare const softDeleteCleanupSystemJob: JobHandlerFn;
|
|
@@ -36,6 +36,11 @@ export const softDeleteGraceDaysConfig = {
|
|
|
36
36
|
// existing silent-below-bound / audited-crossing behavior.
|
|
37
37
|
bounds: { min: 1 },
|
|
38
38
|
};
|
|
39
|
+
// ctx.config skips the key's read roles, so a plain user's trash query can show the period.
|
|
40
|
+
export async function readSoftDeleteGraceDays(config) {
|
|
41
|
+
const value = await config?.(SOFT_DELETE_GRACE_DAYS_KEY);
|
|
42
|
+
return typeof value === "number" && value >= 1 ? value : DEFAULT_GRACE_DAYS;
|
|
43
|
+
}
|
|
39
44
|
function hasTenantIdColumn(table) {
|
|
40
45
|
return hasFieldProperty(table, "tenantId");
|
|
41
46
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// raw error message can echo recipients or payload fragments. Events carry only
|
|
3
3
|
// this generic text; the raw error goes to the log.
|
|
4
4
|
import { unwrapWorkflowStepError } from "./workflow-step-error.js";
|
|
5
|
+
// guard:dup-ok one template-literal message; only the shape matches unrelated string builders
|
|
5
6
|
export function describeWorkflowStepError(error) {
|
|
6
7
|
const original = unwrapWorkflowStepError(error);
|
|
7
8
|
return `workflow step failed (${original instanceof Error ? original.name : "unknown error"})`;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type DbConnection } from "../db/index.ts";
|
|
2
|
-
export type EsOperationType = "seed-migration" | "stream-migration";
|
|
2
|
+
export type EsOperationType = "seed-migration" | "stream-migration" | "search-reindex";
|
|
3
3
|
export type EsOperationAppliedBy = "boot" | "cli" | "ci-pipeline";
|
|
4
4
|
export declare const esOperationsTable: import("@cosmicdrift/kumiko-types/executor-brand").WritableSchemaTable;
|
|
5
5
|
export declare function createEsOperationsTable(db: DbConnection): Promise<void>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { tableExists } from "../db/schema-inspection.js";
|
|
2
|
+
import { ensureTableRowLevelSecurity, unsafePushTables } from "../db/table-push.js";
|
|
3
|
+
export async function ensureDeadLetterTable(db, qualifiedName, pushKey, table) {
|
|
4
|
+
// skip: table already exists — bootstrap called from multiple paths
|
|
5
|
+
if (await tableExists(db, qualifiedName)) {
|
|
6
|
+
await ensureTableRowLevelSecurity(db, table);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
await unsafePushTables(db, { [pushKey]: table });
|
|
10
|
+
}
|
|
@@ -13,8 +13,7 @@
|
|
|
13
13
|
// `kumiko_rebuild_dead_letters`, and the replay continues. Replay-after-fix
|
|
14
14
|
// is a separate ops step — same stance as the upcaster dead-letter.
|
|
15
15
|
import { bigint, index, jsonb, table as pgTable, text, timestamp, uuid } from "../db/dialect.js";
|
|
16
|
-
import {
|
|
17
|
-
import { ensureTableRowLevelSecurity, unsafePushTables } from "../db/table-push.js";
|
|
16
|
+
import { ensureDeadLetterTable } from "./ensure-dead-letter-table.js";
|
|
18
17
|
export const rebuildDeadLetterTable = pgTable("kumiko_rebuild_dead_letters", {
|
|
19
18
|
// Surrogate PK — the same event can land here across multiple rebuild
|
|
20
19
|
// attempts before the fix ships, without unique-violation noise.
|
|
@@ -38,12 +37,7 @@ export const rebuildDeadLetterTable = pgTable("kumiko_rebuild_dead_letters", {
|
|
|
38
37
|
// tx whenever quarantine mode is active, so the opt-in works on databases
|
|
39
38
|
// provisioned before this table existed.
|
|
40
39
|
export async function createRebuildDeadLetterTable(db) {
|
|
41
|
-
|
|
42
|
-
if (await tableExists(db, "public.kumiko_rebuild_dead_letters")) {
|
|
43
|
-
await ensureTableRowLevelSecurity(db, rebuildDeadLetterTable);
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
await unsafePushTables(db, { kumikoRebuildDeadLetters: rebuildDeadLetterTable });
|
|
40
|
+
await ensureDeadLetterTable(db, "public.kumiko_rebuild_dead_letters", "kumikoRebuildDeadLetters", rebuildDeadLetterTable);
|
|
47
41
|
}
|
|
48
42
|
// Bulk-write, called ONCE at the end of a quarantining rebuild (inside its
|
|
49
43
|
// tx). Unqualified insert — during the rebuild the search_path points at the
|
|
@@ -12,8 +12,7 @@
|
|
|
12
12
|
// ops tooling. Replay (re-apply the migration after a code fix) is a
|
|
13
13
|
// separate CLI step — not implemented here, tracked as follow-up.
|
|
14
14
|
import { bigint, index, integer, jsonb, table as pgTable, text, timestamp, uuid, } from "../db/dialect.js";
|
|
15
|
-
import {
|
|
16
|
-
import { ensureTableRowLevelSecurity, unsafePushTables } from "../db/table-push.js";
|
|
15
|
+
import { ensureDeadLetterTable } from "./ensure-dead-letter-table.js";
|
|
17
16
|
export const upcasterDeadLetterTable = pgTable("kumiko_upcaster_dead_letters", {
|
|
18
17
|
// Surrogate PK. We don't reuse eventId so a single event can land
|
|
19
18
|
// here multiple times (retry attempts across deploys before the fix
|
|
@@ -39,12 +38,7 @@ export const upcasterDeadLetterTable = pgTable("kumiko_upcaster_dead_letters", {
|
|
|
39
38
|
// Idempotent table-create. Called from setupTestStack for suites that
|
|
40
39
|
// exercise the quarantine path; production boot uses drizzle-kit push.
|
|
41
40
|
export async function createUpcasterDeadLetterTable(db) {
|
|
42
|
-
|
|
43
|
-
if (await tableExists(db, "public.kumiko_upcaster_dead_letters")) {
|
|
44
|
-
await ensureTableRowLevelSecurity(db, upcasterDeadLetterTable);
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
await unsafePushTables(db, { kumikoUpcasterDeadLetters: upcasterDeadLetterTable });
|
|
41
|
+
await ensureDeadLetterTable(db, "public.kumiko_upcaster_dead_letters", "kumikoUpcasterDeadLetters", upcasterDeadLetterTable);
|
|
48
42
|
}
|
|
49
43
|
// Writes a dead-letter row. Called by upcastStoredEvent when errorPolicy
|
|
50
44
|
// is "quarantine" and a transform threw. Returns the inserted row id —
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { WriteResult } from "@cosmicdrift/kumiko-types/handlers";
|
|
2
|
+
import type { TenantDb } from "../db/tenant-db.ts";
|
|
3
|
+
import type { Registry, SessionUser } from "../engine/types/index.ts";
|
|
4
|
+
import type { FileContext } from "./file-handle.ts";
|
|
5
|
+
export type PendingUploadSource = {
|
|
6
|
+
readonly db: TenantDb;
|
|
7
|
+
readonly user: SessionUser;
|
|
8
|
+
readonly files: FileContext | undefined;
|
|
9
|
+
/** Where the upload is pending: the actionForm screen QN and its files field. */
|
|
10
|
+
readonly entityType: string;
|
|
11
|
+
readonly fieldName: string;
|
|
12
|
+
};
|
|
13
|
+
export type FileRefCopyTarget = {
|
|
14
|
+
readonly db: TenantDb;
|
|
15
|
+
readonly user: SessionUser;
|
|
16
|
+
readonly registry: Registry;
|
|
17
|
+
readonly files: FileContext | undefined;
|
|
18
|
+
readonly attachTo: {
|
|
19
|
+
readonly entityType: string;
|
|
20
|
+
readonly fieldName: string;
|
|
21
|
+
readonly entityId: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export declare function copyPendingFileRefsToTenant(args: {
|
|
25
|
+
readonly source: PendingUploadSource;
|
|
26
|
+
readonly target: FileRefCopyTarget;
|
|
27
|
+
readonly fileIds: readonly string[];
|
|
28
|
+
}): Promise<WriteResult<readonly string[]>>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { FrameworkReasons, InternalError, reraiseAsKumikoError, UnprocessableError, writeFailure, } from "../errors/index.js";
|
|
2
|
+
import { bindPendingFileRef, loadPendingFileRef } from "./bind-pending-file-refs.js";
|
|
3
|
+
import { getFileRefExecutor } from "./create-file-ref.js";
|
|
4
|
+
import { createFileRefFromBytes } from "./create-file-ref-from-bytes.js";
|
|
5
|
+
function fileNotPending(fileRefId) {
|
|
6
|
+
return writeFailure(new UnprocessableError(FrameworkReasons.fileRejected, {
|
|
7
|
+
details: { error: `file ${fileRefId} is not a pending upload of the caller` },
|
|
8
|
+
}));
|
|
9
|
+
}
|
|
10
|
+
// Cross-tenant copy reads and re-stores the bytes, so the target field's accept/maxSize apply and
|
|
11
|
+
// the source uploads are deleted afterwards; within one tenant the uploads are bound in place.
|
|
12
|
+
export async function copyPendingFileRefsToTenant(args) {
|
|
13
|
+
const { source, target } = args;
|
|
14
|
+
const fileIds = [...new Set(args.fileIds)];
|
|
15
|
+
if (source.user.tenantId === target.user.tenantId) {
|
|
16
|
+
return bindInPlace(source, target, fileIds);
|
|
17
|
+
}
|
|
18
|
+
if (source.files === undefined || target.files === undefined) {
|
|
19
|
+
return writeFailure(new InternalError({
|
|
20
|
+
message: "copyPendingFileRefsToTenant: file storage is unavailable for source or target",
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
const executor = getFileRefExecutor();
|
|
24
|
+
const uploads = [];
|
|
25
|
+
for (const fileRefId of fileIds) {
|
|
26
|
+
const pending = await loadPendingFileRef({
|
|
27
|
+
fileRefId,
|
|
28
|
+
entityName: source.entityType,
|
|
29
|
+
fieldName: source.fieldName,
|
|
30
|
+
user: source.user,
|
|
31
|
+
db: source.db,
|
|
32
|
+
});
|
|
33
|
+
if (pending === undefined)
|
|
34
|
+
return fileNotPending(fileRefId);
|
|
35
|
+
// Read through the executor so an encrypted file name arrives as plain text.
|
|
36
|
+
const detail = await executor.detail({ id: fileRefId }, source.user, source.db);
|
|
37
|
+
if (detail === null)
|
|
38
|
+
return fileNotPending(fileRefId);
|
|
39
|
+
uploads.push({
|
|
40
|
+
id: fileRefId,
|
|
41
|
+
storageKey: pending.storageKey,
|
|
42
|
+
mimeType: pending.mimeType,
|
|
43
|
+
fileName: detail.fileName,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const copiedIds = [];
|
|
47
|
+
for (const upload of uploads) {
|
|
48
|
+
const data = await source.files.ref(upload.storageKey).read();
|
|
49
|
+
const created = await createFileRefFromBytes({
|
|
50
|
+
db: target.db,
|
|
51
|
+
services: { files: target.files },
|
|
52
|
+
registry: target.registry,
|
|
53
|
+
user: target.user,
|
|
54
|
+
}, {
|
|
55
|
+
fileName: upload.fileName,
|
|
56
|
+
mimeType: upload.mimeType,
|
|
57
|
+
data,
|
|
58
|
+
attachTo: target.attachTo,
|
|
59
|
+
});
|
|
60
|
+
if (!created.isSuccess)
|
|
61
|
+
return created;
|
|
62
|
+
copiedIds.push(created.data.id);
|
|
63
|
+
}
|
|
64
|
+
for (const upload of uploads) {
|
|
65
|
+
const removed = await executor.delete({ id: upload.id }, source.user, source.db);
|
|
66
|
+
if (!removed.isSuccess)
|
|
67
|
+
throw reraiseAsKumikoError(removed.error);
|
|
68
|
+
}
|
|
69
|
+
return { isSuccess: true, data: copiedIds };
|
|
70
|
+
}
|
|
71
|
+
async function bindInPlace(source, target, fileIds) {
|
|
72
|
+
for (const fileRefId of fileIds) {
|
|
73
|
+
const outcome = await bindPendingFileRef({
|
|
74
|
+
fileRefId,
|
|
75
|
+
entityName: source.entityType,
|
|
76
|
+
fieldName: source.fieldName,
|
|
77
|
+
entityId: target.attachTo.entityId,
|
|
78
|
+
bindTo: { entityName: target.attachTo.entityType, fieldName: target.attachTo.fieldName },
|
|
79
|
+
registry: target.registry,
|
|
80
|
+
user: source.user,
|
|
81
|
+
db: source.db,
|
|
82
|
+
});
|
|
83
|
+
if (outcome !== "bound")
|
|
84
|
+
return fileNotPending(fileRefId);
|
|
85
|
+
}
|
|
86
|
+
return { isSuccess: true, data: fileIds };
|
|
87
|
+
}
|
|
@@ -2,7 +2,7 @@ import type { RateLimitResolver } from "@cosmicdrift/kumiko-types/rate-limit-typ
|
|
|
2
2
|
import type { WriteErrorInfo } from "@cosmicdrift/kumiko-types/write-error-info-types";
|
|
3
3
|
import { Hono } from "hono";
|
|
4
4
|
import type { DbConnection } from "../db/connection.ts";
|
|
5
|
-
import type
|
|
5
|
+
import { type Registry, type SessionUser, type TenantId } from "../engine/types/index.ts";
|
|
6
6
|
import type { FileProviderResolver } from "./provider-resolver.ts";
|
|
7
7
|
import type { RecordReadCheck } from "./record-read-check.ts";
|
|
8
8
|
import { type RecordWriteCheck } from "./record-write-check.ts";
|
|
@@ -4,6 +4,7 @@ import { Hono } from "hono";
|
|
|
4
4
|
import { bodyLimit } from "hono/body-limit";
|
|
5
5
|
import { getUser } from "../api/auth-middleware.js";
|
|
6
6
|
import { requestContext } from "../api/request-context.js";
|
|
7
|
+
import { ROLES } from "../auth/roles.js";
|
|
7
8
|
import { collectPiiSubjectFields, configuredPiiSubjectKms, decryptPiiFieldValues, isPiiCiphertext, PII_ERASED_SENTINEL, } from "../crypto/index.js";
|
|
8
9
|
import { selectMany } from "../db/query.js";
|
|
9
10
|
import { runInRowLevelSecurityScope, tenantRowLevelSecurityScope, } from "../db/row-level-security-scope.js";
|
|
@@ -12,6 +13,7 @@ import { createDerivativesContext, resolveRenderer } from "../derivatives/deriva
|
|
|
12
13
|
import { resolveFieldVariant } from "../derivatives/index.js";
|
|
13
14
|
import { isFileField } from "../engine/field-helpers.js";
|
|
14
15
|
import { isAnonymousSessionUser } from "../engine/system-user.js";
|
|
16
|
+
import { SYSTEM_TENANT_ID, } from "../engine/types/index.js";
|
|
15
17
|
import { createFailOpenReporter, respondRateLimited } from "../rate-limit/middleware.js";
|
|
16
18
|
import { listActionFormFileFields, mayUseActionForm } from "./action-form-upload.js";
|
|
17
19
|
import { buildContentDispositionHeader } from "./content-disposition.js";
|
|
@@ -91,6 +93,9 @@ export function configuredMaxUploadBytes(registry) {
|
|
|
91
93
|
const configured = readFilesRouteOptions(registry).maxUploadSize;
|
|
92
94
|
return configured === undefined ? undefined : parseMaxSize(configured);
|
|
93
95
|
}
|
|
96
|
+
function canReadSystemTenantFile(user, fileTenantId) {
|
|
97
|
+
return fileTenantId === SYSTEM_TENANT_ID && user.roles.includes(ROLES.SystemAdmin);
|
|
98
|
+
}
|
|
94
99
|
export function createFileRoutes(options) {
|
|
95
100
|
const { db, metaBatchRateLimitResolver } = options;
|
|
96
101
|
const reportMetaBatchLimiterFailOpen = createFailOpenReporter("files-meta-batch");
|
|
@@ -292,7 +297,7 @@ export function createFileRoutes(options) {
|
|
|
292
297
|
// GET /files/:id — download.
|
|
293
298
|
//
|
|
294
299
|
// Authorization stack:
|
|
295
|
-
// 1. tenantId must match (hard isolation
|
|
300
|
+
// 1. tenantId must match (hard isolation); the one crossing is a SystemAdmin reading a SYSTEM_TENANT_ID file.
|
|
296
301
|
// 2. The configured FileAccessGuard decides read access. Default:
|
|
297
302
|
// unattached → allow; attached → uploader, privileged role or a
|
|
298
303
|
// reader of the record.
|
|
@@ -300,7 +305,7 @@ export function createFileRoutes(options) {
|
|
|
300
305
|
api.get("/files/:id", async (c) => {
|
|
301
306
|
const user = getUser(c);
|
|
302
307
|
const id = c.req.param("id");
|
|
303
|
-
const fileRef = await
|
|
308
|
+
const fileRef = await loadReadableFileRef(id, user);
|
|
304
309
|
if (!fileRef)
|
|
305
310
|
return c.json({ error: "not_found" }, 404);
|
|
306
311
|
const decision = await guard({ fileRef, user, operation: "read" });
|
|
@@ -309,7 +314,7 @@ export function createFileRoutes(options) {
|
|
|
309
314
|
// an unauthorised caller — matches the tenant-miss response.
|
|
310
315
|
return c.json({ error: "not_found" }, 404);
|
|
311
316
|
}
|
|
312
|
-
const storageProvider = await options.resolveProvider(
|
|
317
|
+
const storageProvider = await options.resolveProvider(fileRef.tenantId);
|
|
313
318
|
const data = await storageProvider.read(fileRef.storageKey);
|
|
314
319
|
// The stored mimeType is client-declared (file.type off the upload) and
|
|
315
320
|
// never verified against the bytes — serving it as-is would let a
|
|
@@ -428,7 +433,7 @@ export function createFileRoutes(options) {
|
|
|
428
433
|
api.get("/files/:id/download-url", async (c) => {
|
|
429
434
|
const user = getUser(c);
|
|
430
435
|
const id = c.req.param("id");
|
|
431
|
-
const fileRef = await
|
|
436
|
+
const fileRef = await loadReadableFileRef(id, user);
|
|
432
437
|
if (!fileRef)
|
|
433
438
|
return c.json({ error: "not_found" }, 404);
|
|
434
439
|
const decision = await guard({ fileRef, user, operation: "read" });
|
|
@@ -436,7 +441,7 @@ export function createFileRoutes(options) {
|
|
|
436
441
|
return c.json({ error: "not_found" }, 404);
|
|
437
442
|
// Resolve after access-check: tenant-scoped provider, and capability
|
|
438
443
|
// disclosure (501) stays behind the auth+guard gate.
|
|
439
|
-
const storageProvider = await options.resolveProvider(
|
|
444
|
+
const storageProvider = await options.resolveProvider(fileRef.tenantId);
|
|
440
445
|
if (!storageProvider.getSignedUrl) {
|
|
441
446
|
return c.json({
|
|
442
447
|
error: "signed_urls_not_supported: this provider does not support signed URLs — use GET /files/:id to stream",
|
|
@@ -474,8 +479,9 @@ export function createFileRoutes(options) {
|
|
|
474
479
|
// detail()'s "pass"-ownership read widens to tenantId IN (self, SYSTEM),
|
|
475
480
|
// narrower in loadFileForTenant's selectMany. Restore that here so meta
|
|
476
481
|
// doesn't leak reference-tenant rows.
|
|
477
|
-
if (fileRef.tenantId !== user.tenantId)
|
|
482
|
+
if (fileRef.tenantId !== user.tenantId && !canReadSystemTenantFile(user, fileRef.tenantId)) {
|
|
478
483
|
return null;
|
|
484
|
+
}
|
|
479
485
|
const decision = await guard({ fileRef, user, operation: "read" });
|
|
480
486
|
if (decision === "deny")
|
|
481
487
|
return null;
|
|
@@ -493,6 +499,15 @@ export function createFileRoutes(options) {
|
|
|
493
499
|
const meta = await loadReadableFileMeta(c.req.param("id"), getUser(c));
|
|
494
500
|
return meta ? c.json(meta) : c.json({ error: "not_found" }, 404);
|
|
495
501
|
});
|
|
502
|
+
// Read-only crossing: SYSTEM_TENANT_ID files (e.g. contact attachments) are
|
|
503
|
+
// visible to a SystemAdmin whose session sits in another tenant. Delete,
|
|
504
|
+
// variant and upload keep using loadFileForTenant and stay tenant-equal.
|
|
505
|
+
async function loadReadableFileRef(id, user) {
|
|
506
|
+
const own = await loadFileForTenant(id, user.tenantId);
|
|
507
|
+
if (own || !canReadSystemTenantFile(user, SYSTEM_TENANT_ID))
|
|
508
|
+
return own;
|
|
509
|
+
return loadFileForTenant(id, SYSTEM_TENANT_ID);
|
|
510
|
+
}
|
|
496
511
|
async function loadFileForTenant(id, tenantId) {
|
|
497
512
|
// fileRefsTable.id is a UUID column — a malformed id must fail here, not
|
|
498
513
|
// at Postgres (22P02 poisons the pooled connection). 404, not
|
package/dist/files/index.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ export type { PendingFileRef } from "./bind-pending-file-refs.ts";
|
|
|
3
3
|
export { bindPendingFileRef, loadPendingFileRef } from "./bind-pending-file-refs.ts";
|
|
4
4
|
export type { CanReadFileRefContext } from "./can-caller-read-file-ref.ts";
|
|
5
5
|
export { canCallerReadFileRef } from "./can-caller-read-file-ref.ts";
|
|
6
|
+
export type { FileRefCopyTarget, PendingUploadSource } from "./copy-pending-file-refs-to-tenant.ts";
|
|
7
|
+
export { copyPendingFileRefsToTenant } from "./copy-pending-file-refs-to-tenant.ts";
|
|
6
8
|
export type { CreatedFileRef, CreateFileRefInput, UploadedFileBytes, } from "./create-file-ref-from-bytes.ts";
|
|
7
9
|
export { createFileRefFromBytes, createFileRefFromUploadedBytes, uploadFileBytesBeforeTransaction, } from "./create-file-ref-from-bytes.ts";
|
|
8
10
|
export { createDefaultGuard } from "./default-file-guard.ts";
|
package/dist/files/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { listActionFormFileFields, resolveActionFormFileField } from "./action-form-upload.js";
|
|
2
2
|
export { bindPendingFileRef, loadPendingFileRef } from "./bind-pending-file-refs.js";
|
|
3
3
|
export { canCallerReadFileRef } from "./can-caller-read-file-ref.js";
|
|
4
|
+
export { copyPendingFileRefsToTenant } from "./copy-pending-file-refs-to-tenant.js";
|
|
4
5
|
export { createFileRefFromBytes, createFileRefFromUploadedBytes, uploadFileBytesBeforeTransaction, } from "./create-file-ref-from-bytes.js";
|
|
5
6
|
export { createDefaultGuard } from "./default-file-guard.js";
|
|
6
7
|
export { deleteFileRefsBoundToRecord } from "./delete-record-file-refs.js";
|
|
@@ -299,6 +299,7 @@ function collectActionFormKeys(ctx, form) {
|
|
|
299
299
|
pushKey(ctx.out, link.label);
|
|
300
300
|
for (const fact of form.successFacts ?? [])
|
|
301
301
|
pushKey(ctx.out, fact.label);
|
|
302
|
+
pushKey(ctx.out, form.successItems?.link?.label);
|
|
302
303
|
for (const fieldName of Object.keys(form.fields)) {
|
|
303
304
|
pushFieldLabelOrOverrideKey(ctx, ACTION_FORM_ENTITY, fieldName, form.fieldLabels);
|
|
304
305
|
}
|
|
@@ -117,6 +117,7 @@ export async function resolveJobTz(config, context, logger) {
|
|
|
117
117
|
export function missingDbProxy(jobName) {
|
|
118
118
|
// @cast-boundary db-operator — every access throws, so no TenantDb member is ever returned
|
|
119
119
|
return new Proxy({}, {
|
|
120
|
+
// guard:dup-ok a throw-only proxy trap; the message is its whole content
|
|
120
121
|
get() {
|
|
121
122
|
throw new InternalError({
|
|
122
123
|
message: `[jobs] job runner constructed without a db connection — ctx.db is unavailable for "${jobName}"`,
|
package/dist/jobs/job-runner.js
CHANGED
|
@@ -53,6 +53,10 @@ export function createJobRunner(options) {
|
|
|
53
53
|
// an expected "Connection is closed." Downgrading to debug once stopping
|
|
54
54
|
// is true keeps those out of error-rate alerts without losing them.
|
|
55
55
|
let stopping = false;
|
|
56
|
+
const logRedisConnectionError = (label, err) => {
|
|
57
|
+
const log = stopping ? errorLogger.debug : errorLogger.error;
|
|
58
|
+
log(`${label} redis connection error`, { error: err.message });
|
|
59
|
+
};
|
|
56
60
|
// Default for perTenant fan-out when the caller didn't supply
|
|
57
61
|
// options.getActiveTenantIds: if the tenant feature is mounted (its
|
|
58
62
|
// active-tenant-ids query is in the registry), resolve tenants through
|
|
@@ -140,10 +144,7 @@ export function createJobRunner(options) {
|
|
|
140
144
|
// Without a listener, a post-close 'error' (e.g. a teardown-race
|
|
141
145
|
// "Connection is closed") is unhandled and crashes the process — in
|
|
142
146
|
// bun:test it gets attributed to whichever test happens to run next.
|
|
143
|
-
lockRedis.on("error", (err) =>
|
|
144
|
-
const log = stopping ? errorLogger.debug : errorLogger.error;
|
|
145
|
-
log("lock redis connection error", { error: err.message });
|
|
146
|
-
});
|
|
147
|
+
lockRedis.on("error", (err) => logRedisConnectionError("lock", err));
|
|
147
148
|
const lockScope = consumerLane ?? "enqueue";
|
|
148
149
|
// Scoped by queueNamePrefix like the queues themselves, so runners
|
|
149
150
|
// isolated by prefix on a shared Redis don't contend for the same lock.
|
|
@@ -176,10 +177,7 @@ export function createJobRunner(options) {
|
|
|
176
177
|
// Same unhandled-'error'-crash hazard as lockRedis above, just via
|
|
177
178
|
// BullMQ's internal ioredis client.
|
|
178
179
|
for (const queue of Object.values(queues)) {
|
|
179
|
-
queue.on("error", (err) =>
|
|
180
|
-
const log = stopping ? errorLogger.debug : errorLogger.error;
|
|
181
|
-
log("queue redis connection error", { error: err.message });
|
|
182
|
-
});
|
|
180
|
+
queue.on("error", (err) => logRedisConnectionError("queue", err));
|
|
183
181
|
}
|
|
184
182
|
let worker = null;
|
|
185
183
|
let queueDepthTimer = null;
|
|
@@ -384,10 +382,7 @@ export function createJobRunner(options) {
|
|
|
384
382
|
// previous run must not execute against an unmet boot precondition.
|
|
385
383
|
autorun: false,
|
|
386
384
|
});
|
|
387
|
-
worker.on("error", (err) =>
|
|
388
|
-
const log = stopping ? errorLogger.debug : errorLogger.error;
|
|
389
|
-
log("worker redis connection error", { error: err.message });
|
|
390
|
-
});
|
|
385
|
+
worker.on("error", (err) => logRedisConnectionError("worker", err));
|
|
391
386
|
// A caller that calls stop() right after start() otherwise races the
|
|
392
387
|
// still-settling blocking connection: it rejects in-flight commands
|
|
393
388
|
// via ioredis's flushQueue() during close(), which isn't a listenable
|
package/dist/logging/utils.js
CHANGED
|
@@ -20,35 +20,31 @@ export function createFallbackLogger(namespace, logger) {
|
|
|
20
20
|
debug: (msg, data) => child.debug(msg, data),
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
+
const levelLogger = (level, sinkFor) => {
|
|
24
|
+
return (msg, data) => {
|
|
25
|
+
const sink = sinkFor();
|
|
26
|
+
if (sink) {
|
|
27
|
+
sink(msg, data);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
writeConsole(console[level], `[${namespace}] ${msg}`, data);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
};
|
|
23
34
|
if (logger) {
|
|
35
|
+
const prefixedSink = (level) => {
|
|
36
|
+
return () => {
|
|
37
|
+
const write = logger[level];
|
|
38
|
+
return write && ((msg, data) => write.call(logger, `[${namespace}] ${msg}`, data));
|
|
39
|
+
};
|
|
40
|
+
};
|
|
24
41
|
return {
|
|
25
|
-
info(
|
|
26
|
-
if (logger.info) {
|
|
27
|
-
logger.info(`[${namespace}] ${msg}`, data);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
writeConsole(console.info, `[${namespace}] ${msg}`, data);
|
|
31
|
-
}
|
|
32
|
-
},
|
|
42
|
+
info: levelLogger("info", prefixedSink("info")),
|
|
33
43
|
error(msg, data) {
|
|
34
44
|
logger.error(`[${namespace}] ${msg}`, data);
|
|
35
45
|
},
|
|
36
|
-
warn(
|
|
37
|
-
|
|
38
|
-
logger.warn(`[${namespace}] ${msg}`, data);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
writeConsole(console.warn, `[${namespace}] ${msg}`, data);
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
debug(msg, data) {
|
|
45
|
-
if (logger.debug) {
|
|
46
|
-
logger.debug(`[${namespace}] ${msg}`, data);
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
writeConsole(console.debug, `[${namespace}] ${msg}`, data);
|
|
50
|
-
}
|
|
51
|
-
},
|
|
46
|
+
warn: levelLogger("warn", prefixedSink("warn")),
|
|
47
|
+
debug: levelLogger("debug", prefixedSink("debug")),
|
|
52
48
|
};
|
|
53
49
|
}
|
|
54
50
|
let cachedParent = null;
|
|
@@ -62,43 +58,17 @@ export function createFallbackLogger(namespace, logger) {
|
|
|
62
58
|
}
|
|
63
59
|
return cachedChild;
|
|
64
60
|
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const child = resolveProcessChild();
|
|
68
|
-
if (child) {
|
|
69
|
-
child.info(msg, data);
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
writeConsole(console.info, `[${namespace}] ${msg}`, data);
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
error(msg, data) {
|
|
61
|
+
const processChildSink = (level) => {
|
|
62
|
+
return () => {
|
|
76
63
|
const child = resolveProcessChild();
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const child = resolveProcessChild();
|
|
86
|
-
if (child) {
|
|
87
|
-
child.warn(msg, data);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
writeConsole(console.warn, `[${namespace}] ${msg}`, data);
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
debug(msg, data) {
|
|
94
|
-
const child = resolveProcessChild();
|
|
95
|
-
if (child) {
|
|
96
|
-
child.debug(msg, data);
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
writeConsole(console.debug, `[${namespace}] ${msg}`, data);
|
|
100
|
-
}
|
|
101
|
-
},
|
|
64
|
+
return child ? (msg, data) => child[level](msg, data) : undefined;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
return {
|
|
68
|
+
info: levelLogger("info", processChildSink("info")),
|
|
69
|
+
error: levelLogger("error", processChildSink("error")),
|
|
70
|
+
warn: levelLogger("warn", processChildSink("warn")),
|
|
71
|
+
debug: levelLogger("debug", processChildSink("debug")),
|
|
102
72
|
};
|
|
103
73
|
}
|
|
104
74
|
// A full Logger for contexts whose typed surface promises one (ctx.obs.log) but that have no
|
|
@@ -50,28 +50,17 @@ function tryBuildMetricName(featureName, shortName) {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
export function createSafeMetricsHandle(meter, featureName) {
|
|
53
|
+
const ifRegistered = (shortName, record) => {
|
|
54
|
+
const name = tryBuildMetricName(featureName, shortName);
|
|
55
|
+
// skip: invalid featureName or unregistered name are the documented no-op contract of this handle
|
|
56
|
+
if (name === undefined || !meter.definitions().has(name))
|
|
57
|
+
return;
|
|
58
|
+
record(name);
|
|
59
|
+
};
|
|
53
60
|
return {
|
|
54
|
-
inc(shortName, labels, value)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (name === undefined || !meter.definitions().has(name))
|
|
58
|
-
return;
|
|
59
|
-
meter.counter(name).inc(value, labels);
|
|
60
|
-
},
|
|
61
|
-
observe(shortName, value, labels) {
|
|
62
|
-
const name = tryBuildMetricName(featureName, shortName);
|
|
63
|
-
// skip: invalid featureName or unregistered name are the documented no-op contract of this handle
|
|
64
|
-
if (name === undefined || !meter.definitions().has(name))
|
|
65
|
-
return;
|
|
66
|
-
meter.histogram(name).observe(value, labels);
|
|
67
|
-
},
|
|
68
|
-
set(shortName, value, labels) {
|
|
69
|
-
const name = tryBuildMetricName(featureName, shortName);
|
|
70
|
-
// skip: invalid featureName or unregistered name are the documented no-op contract of this handle
|
|
71
|
-
if (name === undefined || !meter.definitions().has(name))
|
|
72
|
-
return;
|
|
73
|
-
meter.gauge(name).set(value, labels);
|
|
74
|
-
},
|
|
61
|
+
inc: (shortName, labels, value) => ifRegistered(shortName, (name) => meter.counter(name).inc(value, labels)),
|
|
62
|
+
observe: (shortName, value, labels) => ifRegistered(shortName, (name) => meter.histogram(name).observe(value, labels)),
|
|
63
|
+
set: (shortName, value, labels) => ifRegistered(shortName, (name) => meter.gauge(name).set(value, labels)),
|
|
75
64
|
};
|
|
76
65
|
}
|
|
77
66
|
// Fallback for contexts where the feature is unknown (e.g. system-hooks,
|
|
@@ -116,15 +116,16 @@ const THROUGH_ON_DELETE = {
|
|
|
116
116
|
cascade: deleteThroughRows,
|
|
117
117
|
setNull: leaveChildrenUnchanged,
|
|
118
118
|
};
|
|
119
|
-
async function
|
|
120
|
-
const row = await fetchOne(run.db,
|
|
119
|
+
async function rejectIfReferenced(run, table, key, blockingEntity) {
|
|
120
|
+
const row = await fetchOne(run.db, table, { [key]: run.parentId });
|
|
121
121
|
if (row)
|
|
122
|
-
throw deleteRestrictedError(run,
|
|
122
|
+
throw deleteRestrictedError(run, blockingEntity);
|
|
123
|
+
}
|
|
124
|
+
async function rejectReferencedParent(run, link) {
|
|
125
|
+
await rejectIfReferenced(run, link.table, link.foreignKey, link.target);
|
|
123
126
|
}
|
|
124
127
|
async function rejectReferencedThroughRows(run, link) {
|
|
125
|
-
|
|
126
|
-
if (row)
|
|
127
|
-
throw deleteRestrictedError(run, link.throughTable);
|
|
128
|
+
await rejectIfReferenced(run, link.table, link.sourceKey, link.throughTable);
|
|
128
129
|
}
|
|
129
130
|
function deleteRestrictedError(run, blockingEntity) {
|
|
130
131
|
return new ConflictError({
|