@cosmicdrift/kumiko-framework 0.412.0 → 0.413.1
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-engine.md +1 -0
- package/agents/boot-rules.md +343 -0
- package/agents/examples/api-docs.md +79 -71
- package/agents/examples/golden-path.md +11 -11
- package/agents/examples/{contact.md → helpdesk.md} +41 -34
- package/agents/examples.md +1 -1
- package/agents/features-index.md +2 -2
- package/agents/features.md +16 -16
- package/dist/engine/boot-validator/boot-report.d.ts +3 -0
- package/dist/engine/boot-validator/boot-report.js +2 -2
- package/dist/engine/boot-validator/boot-rules.d.ts +570 -0
- package/dist/engine/boot-validator/boot-rules.js +20 -0
- package/dist/engine/boot-validator/definition-config-events-jobs-rules.d.ts +77 -0
- package/dist/engine/boot-validator/definition-config-events-jobs-rules.js +77 -0
- package/dist/engine/boot-validator/definition-events-rules.d.ts +42 -0
- package/dist/engine/boot-validator/definition-events-rules.js +42 -0
- package/dist/engine/boot-validator/definition-feature-rules.d.ts +42 -0
- package/dist/engine/boot-validator/definition-feature-rules.js +42 -0
- package/dist/engine/boot-validator/definition-field-factories-rules.d.ts +17 -0
- package/dist/engine/boot-validator/definition-field-factories-rules.js +17 -0
- package/dist/engine/boot-validator/definition-handlers-rules.d.ts +72 -0
- package/dist/engine/boot-validator/definition-handlers-rules.js +72 -0
- package/dist/engine/boot-validator/definition-ownership-from-rules.d.ts +27 -0
- package/dist/engine/boot-validator/definition-ownership-from-rules.js +27 -0
- package/dist/engine/boot-validator/definition-probes-rules.d.ts +47 -0
- package/dist/engine/boot-validator/definition-probes-rules.js +47 -0
- package/dist/engine/boot-validator/definition-role-assignment-rules.d.ts +27 -0
- package/dist/engine/boot-validator/definition-role-assignment-rules.js +27 -0
- package/dist/engine/boot-validator/definition-ui-extensions-rules.d.ts +197 -0
- package/dist/engine/boot-validator/definition-ui-extensions-rules.js +197 -0
- package/dist/engine/boot-validator/definition-webhook-events-rules.d.ts +32 -0
- package/dist/engine/boot-validator/definition-webhook-events-rules.js +32 -0
- package/dist/engine/define-feature.js +26 -9
- package/dist/engine/define-handler.js +8 -4
- package/dist/engine/definition-violations.d.ts +14 -0
- package/dist/engine/definition-violations.js +71 -0
- package/dist/engine/entity-handlers.js +39 -13
- package/dist/engine/event-def.js +32 -12
- package/dist/engine/factories.js +16 -5
- package/dist/engine/feature-config-events-jobs.js +63 -27
- package/dist/engine/feature-entity-handlers.js +15 -6
- package/dist/engine/feature-probes.js +29 -9
- package/dist/engine/feature-ui-extensions.js +178 -92
- package/dist/engine/object-form.js +8 -2
- package/dist/engine/ownership.js +17 -5
- package/dist/engine/registry-validate.d.ts +1 -0
- package/dist/engine/registry-validate.js +7 -0
- package/dist/engine/registry.js +2 -1
- package/dist/engine/role-assignment.js +17 -5
- package/dist/engine/soft-delete-cleanup.js +4 -3
- package/dist/engine/webhook-events.js +20 -6
- package/dist/files/feature.js +1 -0
- package/dist/files/file-routes.js +1 -1
- package/dist/jobs/job-runner-gates.js +5 -1
- package/dist/schema-cli/shared.d.ts +11 -0
- package/dist/schema-cli/shared.js +37 -3
- package/dist/schema-cli/validate-command.js +10 -3
- package/package.json +3 -3
- package/src/changes.json +12 -0
package/dist/engine/ownership.js
CHANGED
|
@@ -19,6 +19,8 @@
|
|
|
19
19
|
import { isPlainObject } from "@cosmicdrift/kumiko-types/type-guards";
|
|
20
20
|
import { toSnakeCase } from "../db/table-builder.js";
|
|
21
21
|
import { columnSqlNameOf, schemaTableName } from "../db/table-introspection.js";
|
|
22
|
+
import { bootRuleError } from "./boot-validator/boot-rule.js";
|
|
23
|
+
import { DEFINITION_OWNERSHIP_FROM_RULES } from "./boot-validator/definition-ownership-from-rules.js";
|
|
22
24
|
import { assertQualifiedWhereFragment, tableColumnSqlNames } from "./where-rule-lint.js";
|
|
23
25
|
// Parse an OwnershipRef into kind + resolved path + default column.
|
|
24
26
|
// Throws on malformed input so the error surfaces at `from()`-call-site (in
|
|
@@ -26,7 +28,9 @@ import { assertQualifiedWhereFragment, tableColumnSqlNames } from "./where-rule-
|
|
|
26
28
|
export function from(ref, column) {
|
|
27
29
|
const firstColon = ref.indexOf(":");
|
|
28
30
|
if (firstColon < 0) {
|
|
29
|
-
throw
|
|
31
|
+
throw bootRuleError(DEFINITION_OWNERSHIP_FROM_RULES.refWithoutColon, {
|
|
32
|
+
message: `from("${ref}"): expected "user:<field>" or "claim:<featureName>:<key>" — no colon found.`,
|
|
33
|
+
});
|
|
30
34
|
}
|
|
31
35
|
const prefix = ref.slice(0, firstColon);
|
|
32
36
|
const rest = ref.slice(firstColon + 1);
|
|
@@ -35,17 +39,23 @@ export function from(ref, column) {
|
|
|
35
39
|
// column on the row must be given explicitly (a user.id is rarely
|
|
36
40
|
// named `id` on a child table — usually `ownerId`, `assigneeId`, ...).
|
|
37
41
|
if (!column) {
|
|
38
|
-
throw
|
|
42
|
+
throw bootRuleError(DEFINITION_OWNERSHIP_FROM_RULES.userColumnMissing, {
|
|
43
|
+
message: `from("${ref}"): user-refs require an explicit column name — e.g. from("user:id", "assigneeId").`,
|
|
44
|
+
});
|
|
39
45
|
}
|
|
40
46
|
if (rest !== "id" && rest !== "tenantId") {
|
|
41
|
-
throw
|
|
47
|
+
throw bootRuleError(DEFINITION_OWNERSHIP_FROM_RULES.userRefUnsupported, {
|
|
48
|
+
message: `from("${ref}"): user-ref supports only "user:id" or "user:tenantId" (got "user:${rest}").`,
|
|
49
|
+
});
|
|
42
50
|
}
|
|
43
51
|
return { kind: "from", refKind: "user", refPath: rest, column };
|
|
44
52
|
}
|
|
45
53
|
if (prefix === "claim") {
|
|
46
54
|
// "claim:<feature>:<key>" — rest is the 2-segment claim QN.
|
|
47
55
|
if (!rest.includes(":")) {
|
|
48
|
-
throw
|
|
56
|
+
throw bootRuleError(DEFINITION_OWNERSHIP_FROM_RULES.claimRefInvalid, {
|
|
57
|
+
message: `from("${ref}"): claim-ref must be "claim:<featureName>:<shortName>" (got "claim:${rest}").`,
|
|
58
|
+
});
|
|
49
59
|
}
|
|
50
60
|
// Default column = claim shortName (second segment).
|
|
51
61
|
const defaultColumn = rest.slice(rest.indexOf(":") + 1);
|
|
@@ -56,7 +66,9 @@ export function from(ref, column) {
|
|
|
56
66
|
column: column ?? defaultColumn,
|
|
57
67
|
};
|
|
58
68
|
}
|
|
59
|
-
throw
|
|
69
|
+
throw bootRuleError(DEFINITION_OWNERSHIP_FROM_RULES.prefixUnsupported, {
|
|
70
|
+
message: `from("${ref}"): unsupported ref prefix "${prefix}". Supported: "user", "claim".`,
|
|
71
|
+
});
|
|
60
72
|
}
|
|
61
73
|
// Evaluate an ownership rule against a concrete row (plain data, no Drizzle).
|
|
62
74
|
// Used by field-level filters on query responses and by field-level
|
|
@@ -27,6 +27,7 @@ export declare function validateLifecycleHookTargets(state: RegistryState): void
|
|
|
27
27
|
export declare function validateEntityHookTargets(state: RegistryState, features: readonly FeatureDefinition[]): void;
|
|
28
28
|
export declare function resolveJobTriggers(state: RegistryState): void;
|
|
29
29
|
export declare function validateLiveEntities(state: RegistryState): void;
|
|
30
|
+
export declare function validateIncludeSystemTenantJobs(state: RegistryState): void;
|
|
30
31
|
export declare function validateBootGates(state: RegistryState): void;
|
|
31
32
|
export declare function validateJobBackoff(state: RegistryState): void;
|
|
32
33
|
export declare function validateMaxDefers(state: RegistryState): void;
|
|
@@ -744,6 +744,13 @@ export function validateLiveEntities(state) {
|
|
|
744
744
|
}
|
|
745
745
|
}
|
|
746
746
|
}
|
|
747
|
+
export function validateIncludeSystemTenantJobs(state) {
|
|
748
|
+
for (const [jobName, jobDef] of state.jobMap) {
|
|
749
|
+
if (jobDef.includeSystemTenant && !jobDef.perTenant) {
|
|
750
|
+
throw new Error(`Job "${jobName}" sets includeSystemTenant without perTenant`);
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
}
|
|
747
754
|
export function validateBootGates(state) {
|
|
748
755
|
// Boot gates run inline in JobRunner.start(), which has neither the
|
|
749
756
|
// per-tenant fan-out (that re-enqueues) nor the sequential lock's
|
package/dist/engine/registry.js
CHANGED
|
@@ -4,7 +4,7 @@ import { buildRegistryFacade } from "./registry-facade.js";
|
|
|
4
4
|
import { populateClaimsAndAuth, populateConfigKeys, populateEvents, populateExtensionsAndSeeds, populateFeatureCore, populateHandlers, populateHooks, populateJobsAndNotifications, populateMetricsAndSecrets, populateProjectionsAndTables, populateScreensNavWorkspaces, populateSystemEvents, populateTranslations, } from "./registry-ingest.js";
|
|
5
5
|
import { populateReadModelEntities } from "./registry-read-models.js";
|
|
6
6
|
import { createInitialState } from "./registry-state.js";
|
|
7
|
-
import { applyExtensionUsages, autoWireSoftDeleteJobs, buildEntityEventUpcasterChains, buildEventUpcasterChains, buildImplicitProjections, buildIncomingRelations, buildSearchableSortableCaches, computeHasRateLimitedHandler, finalizeWorkspaceNavMembership, populateHandlerEntityMappings, publishEventPiiCatalog, resolveJobTriggers, resolveNotificationTriggersAndRegisterHooks, validateBootGates, validateEntityHookTargets, validateEventMigrationVersions, validateExtensionSelectors, validateExtensionUsageTargets, validateFieldAccessHandlersAreEntityMapped, validateJobBackoff, validateLifecycleHookTargets, validateLiveEntities, validateMaxDefers, validateMaxPerTenant, validateNotificationRecordMappings, validateNotificationRenamedFrom, validateProjectionApplyKeys, validateRelationTargetsExist, validateRequiredFeatures, } from "./registry-validate.js";
|
|
7
|
+
import { applyExtensionUsages, autoWireSoftDeleteJobs, buildEntityEventUpcasterChains, buildEventUpcasterChains, buildImplicitProjections, buildIncomingRelations, buildSearchableSortableCaches, computeHasRateLimitedHandler, finalizeWorkspaceNavMembership, populateHandlerEntityMappings, publishEventPiiCatalog, resolveJobTriggers, resolveNotificationTriggersAndRegisterHooks, validateBootGates, validateEntityHookTargets, validateEventMigrationVersions, validateExtensionSelectors, validateExtensionUsageTargets, validateFieldAccessHandlersAreEntityMapped, validateIncludeSystemTenantJobs, validateJobBackoff, validateLifecycleHookTargets, validateLiveEntities, validateMaxDefers, validateMaxPerTenant, validateNotificationRecordMappings, validateNotificationRenamedFrom, validateProjectionApplyKeys, validateRelationTargetsExist, validateRequiredFeatures, } from "./registry-validate.js";
|
|
8
8
|
// This is where the magic happens. By "magic" I mean: precomputed maps.
|
|
9
9
|
// I build everything once at boot (hooks, relations, searchable fields, ...)
|
|
10
10
|
// so nothing has to iterate over objects at runtime. O(1) instead of O(n*m).
|
|
@@ -49,6 +49,7 @@ export function createRegistry(rawFeatures) {
|
|
|
49
49
|
validateEntityHookTargets(state, features);
|
|
50
50
|
resolveJobTriggers(state);
|
|
51
51
|
validateBootGates(state);
|
|
52
|
+
validateIncludeSystemTenantJobs(state);
|
|
52
53
|
validateLiveEntities(state);
|
|
53
54
|
validateJobBackoff(state);
|
|
54
55
|
validateMaxDefers(state);
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { ROLES } from "../auth/roles.js";
|
|
2
|
+
import { bootRuleError } from "./boot-validator/boot-rule.js";
|
|
3
|
+
import { DEFINITION_ROLE_ASSIGNMENT_RULES } from "./boot-validator/definition-role-assignment-rules.js";
|
|
2
4
|
import { EXT_ASSIGNABLE_ROLE } from "./extension-names.js";
|
|
3
5
|
import { isForbiddenMembershipRole } from "./membership-roles.js";
|
|
4
6
|
const PLATFORM_ROLE_NAMES = new Set(Object.values(ROLES));
|
|
@@ -39,25 +41,35 @@ export function assignableAppRolesFromUsages(usages) {
|
|
|
39
41
|
for (const usage of usages) {
|
|
40
42
|
const role = usage.entityName;
|
|
41
43
|
if (role === "") {
|
|
42
|
-
throw
|
|
44
|
+
throw bootRuleError(DEFINITION_ROLE_ASSIGNMENT_RULES.nameEmpty, {
|
|
45
|
+
message: "assignableRole: role name must not be empty",
|
|
46
|
+
});
|
|
43
47
|
}
|
|
44
48
|
// Platform roles (TenantOwner, DataProtectionOfficer) gate handlers that
|
|
45
49
|
// TenantAdmin/Admin cannot reach — declaring one would let an Admin
|
|
46
50
|
// self-grant it, so they stay out of reach of app declarations.
|
|
47
51
|
if (ROLE_RANKS.has(role) || PLATFORM_ROLE_NAMES.has(role)) {
|
|
48
|
-
throw
|
|
52
|
+
throw bootRuleError(DEFINITION_ROLE_ASSIGNMENT_RULES.builtIn, {
|
|
53
|
+
message: `assignableRole: "${role}" is a built-in role and cannot be redeclared`,
|
|
54
|
+
});
|
|
49
55
|
}
|
|
50
56
|
if (isForbiddenMembershipRole(role)) {
|
|
51
|
-
throw
|
|
57
|
+
throw bootRuleError(DEFINITION_ROLE_ASSIGNMENT_RULES.reservedMembership, {
|
|
58
|
+
message: `assignableRole: "${role}" is a reserved role and cannot be a membership role`,
|
|
59
|
+
});
|
|
52
60
|
}
|
|
53
61
|
const declaredAssignableFrom = usage.options?.["assignableFrom"];
|
|
54
62
|
if (declaredAssignableFrom !== undefined && !isAssignableFromRole(declaredAssignableFrom)) {
|
|
55
|
-
throw
|
|
63
|
+
throw bootRuleError(DEFINITION_ROLE_ASSIGNMENT_RULES.assignableFromInvalid, {
|
|
64
|
+
message: `assignableRole: "${role}" has invalid assignableFrom, expected one of ${[...ASSIGNABLE_FROM_ROLES].join(", ")}`,
|
|
65
|
+
});
|
|
56
66
|
}
|
|
57
67
|
const assignableFrom = declaredAssignableFrom ?? DEFAULT_APP_ROLE_ASSIGNABLE_FROM;
|
|
58
68
|
const existing = result.get(role);
|
|
59
69
|
if (existing !== undefined && existing !== assignableFrom) {
|
|
60
|
-
throw
|
|
70
|
+
throw bootRuleError(DEFINITION_ROLE_ASSIGNMENT_RULES.assignableFromConflict, {
|
|
71
|
+
message: `assignableRole: "${role}" is declared with conflicting assignableFrom (${existing} vs ${assignableFrom})`,
|
|
72
|
+
});
|
|
61
73
|
}
|
|
62
74
|
result.set(role, assignableFrom);
|
|
63
75
|
}
|
|
@@ -62,7 +62,7 @@ export const softDeleteCleanupJob = async (_payload, ctx) => {
|
|
|
62
62
|
if (!db || !registry) {
|
|
63
63
|
throw new Error("soft-delete cleanup: ctx.db + ctx.registry required (JobContext incomplete)");
|
|
64
64
|
}
|
|
65
|
-
// perTenant fan-out → one run per active tenant, systemUser scoped to it.
|
|
65
|
+
// perTenant fan-out → one run per active tenant plus the system tenant, systemUser scoped to it.
|
|
66
66
|
// The job's db is a tenant-filtered TenantDb, but every delete is still
|
|
67
67
|
// explicitly tenant-filtered below as defense-in-depth — otherwise a
|
|
68
68
|
// tenant with a short grace would purge another tenant's still-within-grace
|
|
@@ -73,7 +73,7 @@ export const softDeleteCleanupJob = async (_payload, ctx) => {
|
|
|
73
73
|
return;
|
|
74
74
|
}
|
|
75
75
|
const graceDays = await resolveGraceDays(ctx, tenantId, db);
|
|
76
|
-
const cutoff =
|
|
76
|
+
const cutoff = ctx.tz.now().subtract({ hours: graceDays * 24 });
|
|
77
77
|
for (const proj of registry.getAllProjections().values()) {
|
|
78
78
|
if (proj.isImplicit !== true || typeof proj.source !== "string" || !proj.table)
|
|
79
79
|
continue;
|
|
@@ -143,7 +143,7 @@ export const softDeleteCleanupSystemJob = async (_payload, ctx) => {
|
|
|
143
143
|
if (!db || !registry) {
|
|
144
144
|
throw new Error("soft-delete system cleanup: ctx.db + ctx.registry required (JobContext incomplete)");
|
|
145
145
|
}
|
|
146
|
-
const cutoff =
|
|
146
|
+
const cutoff = ctx.tz.now().subtract({ hours: DEFAULT_GRACE_DAYS * 24 });
|
|
147
147
|
for (const proj of registry.getAllProjections().values()) {
|
|
148
148
|
if (proj.isImplicit !== true || typeof proj.source !== "string" || !proj.table)
|
|
149
149
|
continue;
|
|
@@ -168,6 +168,7 @@ export function buildSoftDeleteCleanupJob() {
|
|
|
168
168
|
handler: softDeleteCleanupJob,
|
|
169
169
|
trigger: { maintenance: true },
|
|
170
170
|
perTenant: true,
|
|
171
|
+
includeSystemTenant: true,
|
|
171
172
|
concurrency: "skip",
|
|
172
173
|
runIn: "worker",
|
|
173
174
|
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { ZodObject } from "zod";
|
|
2
|
+
import { bootRuleError } from "./boot-validator/boot-rule.js";
|
|
3
|
+
import { DEFINITION_WEBHOOK_EVENT_RULES } from "./boot-validator/definition-webhook-events-rules.js";
|
|
2
4
|
import { isObjectArgument, throwObjectArgumentRequired } from "./object-form.js";
|
|
3
5
|
import { isKebabSegment, toKebab } from "./qualified-name.js";
|
|
4
6
|
/** Delivery sends the returned payload, never the input: zod strips keys the contract does not
|
|
@@ -38,25 +40,37 @@ export function buildWebhookEventMethods(state, featureName) {
|
|
|
38
40
|
const { name, description, payload, version } = definition;
|
|
39
41
|
const where = `[Feature ${featureName}] defineWebhookEvent`;
|
|
40
42
|
if (typeof name !== "string" || !isKebabSegment(name)) {
|
|
41
|
-
throw
|
|
43
|
+
throw bootRuleError(DEFINITION_WEBHOOK_EVENT_RULES.nameNotKebab, {
|
|
44
|
+
message: `${where}: name must be kebab-case, got ${JSON.stringify(name)}`,
|
|
45
|
+
});
|
|
42
46
|
}
|
|
43
47
|
if (typeof description !== "string" || description.trim() === "") {
|
|
44
|
-
throw
|
|
48
|
+
throw bootRuleError(DEFINITION_WEBHOOK_EVENT_RULES.descriptionEmpty, {
|
|
49
|
+
message: `${where}("${name}"): description must be a non-empty sentence`,
|
|
50
|
+
});
|
|
45
51
|
}
|
|
46
52
|
if (!(payload instanceof ZodObject)) {
|
|
47
|
-
throw
|
|
53
|
+
throw bootRuleError(DEFINITION_WEBHOOK_EVENT_RULES.payloadNotZodObject, {
|
|
54
|
+
message: `${where}("${name}"): payload must be a zod object schema`,
|
|
55
|
+
});
|
|
48
56
|
}
|
|
49
57
|
if (!Number.isInteger(version) || version < 1) {
|
|
50
|
-
throw
|
|
58
|
+
throw bootRuleError(DEFINITION_WEBHOOK_EVENT_RULES.versionInvalid, {
|
|
59
|
+
message: `${where}("${name}"): version must be a positive integer`,
|
|
60
|
+
});
|
|
51
61
|
}
|
|
52
62
|
if (definition.wireName !== undefined &&
|
|
53
63
|
(typeof definition.wireName !== "string" || definition.wireName.trim() === "")) {
|
|
54
|
-
throw
|
|
64
|
+
throw bootRuleError(DEFINITION_WEBHOOK_EVENT_RULES.wireNameEmpty, {
|
|
65
|
+
message: `${where}("${name}"): wireName must be a non-empty string`,
|
|
66
|
+
});
|
|
55
67
|
}
|
|
56
68
|
const wireName = definition.wireName?.trim() ?? name;
|
|
57
69
|
const qn = `${toKebab(featureName)}:${name}`;
|
|
58
70
|
if (state.webhookEvents[qn] !== undefined) {
|
|
59
|
-
throw
|
|
71
|
+
throw bootRuleError(DEFINITION_WEBHOOK_EVENT_RULES.duplicate, {
|
|
72
|
+
message: `${where}("${name}"): already registered in this feature`,
|
|
73
|
+
});
|
|
60
74
|
}
|
|
61
75
|
state.webhookEvents[qn] = {
|
|
62
76
|
qn,
|
package/dist/files/feature.js
CHANGED
|
@@ -42,6 +42,7 @@ export function createFilesFeature(options = {}) {
|
|
|
42
42
|
name: "sweep-orphaned-uploads",
|
|
43
43
|
trigger: { maintenance: true },
|
|
44
44
|
perTenant: true,
|
|
45
|
+
includeSystemTenant: true,
|
|
45
46
|
concurrency: "skip",
|
|
46
47
|
handler: async (_payload, ctx) => {
|
|
47
48
|
await sweepOrphanedUploads({
|
|
@@ -499,7 +499,7 @@ export function createFileRoutes(options) {
|
|
|
499
499
|
const meta = await loadReadableFileMeta(c.req.param("id"), getUser(c));
|
|
500
500
|
return meta ? c.json(meta) : c.json({ error: "not_found" }, 404);
|
|
501
501
|
});
|
|
502
|
-
// Read-only crossing: SYSTEM_TENANT_ID files (e.g.
|
|
502
|
+
// Read-only crossing: SYSTEM_TENANT_ID files (e.g. helpdesk attachments) are
|
|
503
503
|
// visible to a SystemAdmin whose session sits in another tenant. Delete,
|
|
504
504
|
// variant and upload keep using loadFileForTenant and stay tenant-equal.
|
|
505
505
|
async function loadReadableFileRef(id, user) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SYSTEM_TENANT_ID } from "../engine/types/index.js";
|
|
1
2
|
import { prepareJobRun } from "./job-runner-context.js";
|
|
2
3
|
import { attemptNumberOf, buildRetryBullOpts, DEFER_COUNT_KEY, deferDelayMs, isFinalAttempt, priorAttemptsOf, priorDeferCountOf, } from "./job-runner-helpers.js";
|
|
3
4
|
import { ACTIVE_TENANT_IDS_QUERY_NAME, perTenantChildJobId } from "./job-runner-schedulers.js";
|
|
@@ -35,7 +36,10 @@ async function enqueuePerTenantChildren(scope, bullJob, actualName) {
|
|
|
35
36
|
if (!actualDef) {
|
|
36
37
|
throw new Error(`Unknown job: ${actualName}`);
|
|
37
38
|
}
|
|
38
|
-
const
|
|
39
|
+
const activeTenantIds = await getActiveTenantIds();
|
|
40
|
+
const tenantIds = actualDef.includeSystemTenant === true && !activeTenantIds.includes(SYSTEM_TENANT_ID)
|
|
41
|
+
? [...activeTenantIds, SYSTEM_TENANT_ID]
|
|
42
|
+
: activeTenantIds;
|
|
39
43
|
const targetQueue = scope.queues[laneForJob(actualDef)];
|
|
40
44
|
// wrapperJobId is only absent for a Job BullMQ somehow never assigned
|
|
41
45
|
// an id to (not observed in practice) — falling back to a constant
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type renderTablesDdl } from "../db/index.ts";
|
|
2
2
|
import { type RowLevelSecurityMode } from "../db/render-rls-ddl.ts";
|
|
3
|
+
import type { BootViolation } from "../engine/boot-validator/boot-rule.ts";
|
|
3
4
|
import type { FeatureDefinition } from "../engine/types/feature.ts";
|
|
4
5
|
export type SchemaCliOut = {
|
|
5
6
|
readonly log: (line: string) => void;
|
|
@@ -42,6 +43,16 @@ export declare function parseSchemaRowLevelSecurity(value: unknown, schemaFile:
|
|
|
42
43
|
export declare function describeThrown(e: unknown): string;
|
|
43
44
|
export declare function nextSequenceNumber(migrationsDir: string): number;
|
|
44
45
|
export declare function loadPreviousSnapshot(snapshotPath: string): import("../db/migrate-generator.ts").Snapshot | null;
|
|
46
|
+
export type CollectedSchemaLoad = {
|
|
47
|
+
readonly kind: "loaded";
|
|
48
|
+
readonly schemaMod: SchemaMod;
|
|
49
|
+
} | {
|
|
50
|
+
readonly kind: "violations";
|
|
51
|
+
readonly violations: readonly BootViolation[];
|
|
52
|
+
} | {
|
|
53
|
+
readonly kind: "failed";
|
|
54
|
+
};
|
|
55
|
+
export declare function loadSchemaModCollectingDefinitionViolations(ctx: SchemaCliContext): Promise<CollectedSchemaLoad>;
|
|
45
56
|
export declare function loadSchemaModOrReport(ctx: SchemaCliContext): Promise<SchemaMod | undefined>;
|
|
46
57
|
export declare function loadRowLevelSecurityModeOrReport(ctx: SchemaCliContext): Promise<RowLevelSecurityMode | undefined>;
|
|
47
58
|
export declare function readDatabaseUrlOrReport(out: SchemaCliOut): string | undefined;
|
|
@@ -12,6 +12,8 @@ import { loadSnapshotJson } from "../db/index.js";
|
|
|
12
12
|
import { assertUniqueTableNames } from "../db/migrate-generator.js";
|
|
13
13
|
import { DEFAULT_ROW_LEVEL_SECURITY_MODE, ROW_LEVEL_SECURITY_MODES, } from "../db/render-rls-ddl.js";
|
|
14
14
|
import { isEntityTableMeta } from "../db/table-introspection.js";
|
|
15
|
+
import { isRuntimeCrash, violationsOf } from "../engine/boot-validator/boot-report.js";
|
|
16
|
+
import { collectDefinitionViolations } from "../engine/definition-violations.js";
|
|
15
17
|
export const SNAPSHOT_FILENAME = ".snapshot.json";
|
|
16
18
|
// An absent export means the default mode; a typo must not silently switch tenant isolation off.
|
|
17
19
|
export function parseSchemaRowLevelSecurity(value, schemaFile) {
|
|
@@ -74,12 +76,44 @@ export function nextSequenceNumber(migrationsDir) {
|
|
|
74
76
|
export function loadPreviousSnapshot(snapshotPath) {
|
|
75
77
|
return existsSync(snapshotPath) ? loadSnapshotJson(snapshotPath) : null;
|
|
76
78
|
}
|
|
79
|
+
function reportMissingSchemaFile({ out, schemaFile }) {
|
|
80
|
+
out.err(` ${schemaFile} is missing.`);
|
|
81
|
+
out.err(" App convention: kumiko/schema.ts with");
|
|
82
|
+
out.err(" export const ENTITY_METAS: EntityTableMeta[] = [...]");
|
|
83
|
+
}
|
|
84
|
+
// Loads kumiko/schema.ts in collect mode: definition-layer violations of all features come back
|
|
85
|
+
// together instead of the first one aborting the import.
|
|
86
|
+
export async function loadSchemaModCollectingDefinitionViolations(ctx) {
|
|
87
|
+
const { out, schemaFile } = ctx;
|
|
88
|
+
if (!existsSync(schemaFile)) {
|
|
89
|
+
reportMissingSchemaFile(ctx);
|
|
90
|
+
return { kind: "failed" };
|
|
91
|
+
}
|
|
92
|
+
const { violations, outcome } = await collectDefinitionViolations(() => loadSchemaModFromApp(schemaFile));
|
|
93
|
+
if (outcome.loaded) {
|
|
94
|
+
return violations.length === 0
|
|
95
|
+
? { kind: "loaded", schemaMod: outcome.value }
|
|
96
|
+
: { kind: "violations", violations };
|
|
97
|
+
}
|
|
98
|
+
const { thrown } = outcome;
|
|
99
|
+
if (isRuntimeCrash(thrown)) {
|
|
100
|
+
if (violations.length > 0)
|
|
101
|
+
return { kind: "violations", violations };
|
|
102
|
+
out.err(` ${describeThrown(thrown)}`);
|
|
103
|
+
return { kind: "failed" };
|
|
104
|
+
}
|
|
105
|
+
if (thrown instanceof Error) {
|
|
106
|
+
return {
|
|
107
|
+
kind: "violations",
|
|
108
|
+
violations: [...violations, ...violationsOf(thrown, "loadSchemaMod", undefined)],
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
return { kind: "violations", violations };
|
|
112
|
+
}
|
|
77
113
|
export async function loadSchemaModOrReport(ctx) {
|
|
78
114
|
const { out, schemaFile } = ctx;
|
|
79
115
|
if (!existsSync(schemaFile)) {
|
|
80
|
-
|
|
81
|
-
out.err(" App convention: kumiko/schema.ts with");
|
|
82
|
-
out.err(" export const ENTITY_METAS: EntityTableMeta[] = [...]");
|
|
116
|
+
reportMissingSchemaFile(ctx);
|
|
83
117
|
return undefined;
|
|
84
118
|
}
|
|
85
119
|
try {
|
|
@@ -6,7 +6,7 @@ import { readMigrationSqlTexts } from "../db/migrate-runner.js";
|
|
|
6
6
|
import { diffReplayAgainstSnapshot, replayMigrationsDir } from "../db/replay-migration-sql.js";
|
|
7
7
|
import { BootValidationError, bootRuleDocLink, } from "../engine/boot-validator/boot-rule.js";
|
|
8
8
|
import { validateBoot } from "../engine/boot-validator.js";
|
|
9
|
-
import { describeThrown, loadPreviousSnapshot,
|
|
9
|
+
import { describeThrown, loadPreviousSnapshot, loadSchemaModCollectingDefinitionViolations, nextSequenceNumber, SNAPSHOT_FILENAME, } from "./shared.js";
|
|
10
10
|
import { featureDefinitionsOf, parseValidateBootOptions, withFileStoragePresence, } from "./validate-boot-input.js";
|
|
11
11
|
// 1. Schema drift — compute the diff, never write.
|
|
12
12
|
function checkSchemaDrift(ctx, schemaMod, prevSnapshot) {
|
|
@@ -189,8 +189,14 @@ export async function runValidateCommand(ctx) {
|
|
|
189
189
|
// stdout carries exactly one JSON document in --json mode.
|
|
190
190
|
const out = jsonMode ? { log: ctx.out.err, err: ctx.out.err } : ctx.out;
|
|
191
191
|
const humanCtx = { ...ctx, out };
|
|
192
|
-
const
|
|
193
|
-
if (
|
|
192
|
+
const loaded = await loadSchemaModCollectingDefinitionViolations(humanCtx);
|
|
193
|
+
if (loaded.kind === "violations") {
|
|
194
|
+
reportBootViolations(out, loaded.violations);
|
|
195
|
+
if (jsonMode)
|
|
196
|
+
printBootJson(ctx, { ok: false, violations: loaded.violations });
|
|
197
|
+
return 1;
|
|
198
|
+
}
|
|
199
|
+
if (loaded.kind === "failed") {
|
|
194
200
|
if (jsonMode) {
|
|
195
201
|
const message = "kumiko/schema.ts could not be loaded";
|
|
196
202
|
printBootJson(ctx, {
|
|
@@ -200,6 +206,7 @@ export async function runValidateCommand(ctx) {
|
|
|
200
206
|
}
|
|
201
207
|
return 1;
|
|
202
208
|
}
|
|
209
|
+
const { schemaMod } = loaded;
|
|
203
210
|
const prevSnapshot = loadPreviousSnapshot(join(ctx.migrationsDir, SNAPSHOT_FILENAME));
|
|
204
211
|
const schemaOk = checkSchemaDrift(humanCtx, schemaMod, prevSnapshot);
|
|
205
212
|
const boot = checkBootValidity(out, schemaMod);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cosmicdrift/kumiko-framework",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.413.1",
|
|
4
4
|
"description": "Framework core — engine, pipeline, API, DB, and every other bit that makes Kumiko go.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Marc Frost <marc@cosmicdriftgamestudio.com>",
|
|
@@ -203,7 +203,7 @@
|
|
|
203
203
|
"./package.json": "./package.json"
|
|
204
204
|
},
|
|
205
205
|
"dependencies": {
|
|
206
|
-
"@cosmicdrift/kumiko-types": "0.
|
|
206
|
+
"@cosmicdrift/kumiko-types": "0.413.1",
|
|
207
207
|
"bullmq": "^5.81.5",
|
|
208
208
|
"hono": "^4.13.14",
|
|
209
209
|
"i18next": "^26.5.12",
|
|
@@ -225,7 +225,7 @@
|
|
|
225
225
|
}
|
|
226
226
|
},
|
|
227
227
|
"devDependencies": {
|
|
228
|
-
"@cosmicdrift/kumiko-testing": "0.
|
|
228
|
+
"@cosmicdrift/kumiko-testing": "0.413.1",
|
|
229
229
|
"bun-types": "^1.4.4",
|
|
230
230
|
"fflate": "^0.8.3",
|
|
231
231
|
"meilisearch": "^0.62.0",
|
package/src/changes.json
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.413.0",
|
|
4
|
+
"type": "improvement",
|
|
5
|
+
"title": "Definition errors in schema.ts are collected by validate",
|
|
6
|
+
"detail": "`kumiko-schema validate` (and `kumiko check`) loads `kumiko/schema.ts` in a collect mode. Every failing registrar call and every failing feature setup is recorded instead of aborting the import, so one run prints one `✗ boot [<id>]` line per violation across all features, with `Fix:` and `Rule:` lines, and `--json` lists them in `boot.violations` with `check` (e.g. `r.nav`) and `feature`. Example ids: `nav/id-not-kebab`, `feature/describe-twice`, `handler/access-missing`, `event/pii-stance-empty`, `probe/name-not-kebab`. When such violations exist, validate skips the boot and migration checks, because the feature set is incomplete. Outside validate nothing changes: createApp, the server, the dev server and tests still throw at the first error, at the same place and with the same message; the thrown error is now a `BootRuleViolation` (a subclass of `Error`). A throw at module level outside `defineFeature` still stops the import and appears next to the violations collected before it."
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"version": "0.413.0",
|
|
10
|
+
"type": "improvement",
|
|
11
|
+
"title": "Bundled-feature factory options fail with boot rule ids",
|
|
12
|
+
"detail": "Invalid factory options (`createBillingFoundationFeature` baseUrl and consumerProtection, `createHostDispatch` redirects and locales, `createMetricsFeature` duplicate ids, `createTemplateResolverFeature` tenantEditable, `createSubscriptionMollieFeature` price maps, empty `parents` allowlists on folders, tags and notes-history, and the tenant, readiness and personal-access-tokens boot checks) now throw a `BootRuleViolation` (a subclass of `Error`) carrying `rule.id`. Example ids: `billing-foundation/base-url-required`, `host-routing/invalid-redirect`, `subscription-mollie/price-map-drift`, `template-resolver/tenant-editable-duplicate`, `shared/where-rule-in-ownership-write`. Messages, conditions and the fail-fast behaviour at the same place are unchanged."
|
|
13
|
+
},
|
|
2
14
|
{
|
|
3
15
|
"version": "0.412.0",
|
|
4
16
|
"type": "fix",
|