@swirls/looms 0.9.0 → 0.11.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/CHANGELOG.md +32 -0
- package/dist/actor/cell.d.ts +3 -1
- package/dist/actor/cell.js +1 -0
- package/dist/actor/host.d.ts +3 -1
- package/dist/actor/host.js +1 -0
- package/dist/actor/routing.js +2 -1
- package/dist/agent/debugger/agent-chat.js +6 -5
- package/dist/agent/debugger/index.js +2 -1
- package/dist/agent/module.d.ts +207 -1
- package/dist/agent/module.js +31 -0
- package/dist/agent/scope.js +1 -0
- package/dist/agent/signals.d.ts +108 -15
- package/dist/agent/signals.js +70 -47
- package/dist/approval/debugger/approvals-view.js +1 -1
- package/dist/approval/index.d.ts +1 -0
- package/dist/approval/index.js +1 -0
- package/dist/approval/module.d.ts +42 -1
- package/dist/approval/module.js +53 -0
- package/dist/approval/scope.js +1 -0
- package/dist/approval/signals.d.ts +19 -13
- package/dist/approval/signals.js +25 -45
- package/dist/approval/steps.d.ts +11 -0
- package/dist/approval/steps.js +39 -0
- package/dist/cli/commands.d.ts +1 -1
- package/dist/cli/commands.js +49 -14
- package/dist/client/client.d.ts +231 -21
- package/dist/client/client.js +20 -2
- package/dist/cloudflare/delete-terminal-run-storage.d.ts +39 -0
- package/dist/cloudflare/delete-terminal-run-storage.js +98 -0
- package/dist/cloudflare/durable-object.d.ts +11 -1
- package/dist/cloudflare/durable-object.js +23 -0
- package/dist/cloudflare/index.d.ts +1 -0
- package/dist/cloudflare/index.js +1 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +1 -0
- package/dist/core/module-scope.d.ts +50 -5
- package/dist/core/module-scope.js +22 -2
- package/dist/core/module.d.ts +29 -2
- package/dist/core/projection.d.ts +1 -0
- package/dist/core/published.d.ts +59 -1
- package/dist/core/published.js +97 -1
- package/dist/core/run-context.d.ts +50 -0
- package/dist/core/run-context.js +21 -1
- package/dist/core/signals.d.ts +56 -0
- package/dist/core/signals.js +93 -0
- package/dist/core/validate-event.d.ts +12 -1
- package/dist/core/validate-event.js +34 -11
- package/dist/debugger/app/assets/index-CO5gIvV8.css +2 -0
- package/dist/debugger/app/assets/{index-CMRl_aWQ.js → index-VTotlHcm.js} +2 -2
- package/dist/debugger/app/assets/routes-CEdsN9DO.js +47 -0
- package/dist/debugger/app/index.html +2 -2
- package/dist/debugger/index.d.ts +1 -1
- package/dist/debugger/index.js +1 -1
- package/dist/debugger/lib/cn.d.ts +1 -1
- package/dist/debugger/lib/cn.js +12 -1
- package/dist/debugger/plugin.d.ts +11 -1
- package/dist/debugger/plugin.js +41 -0
- package/dist/debugger/shell/debugger-shell.js +1 -1
- package/dist/debugger/shell/form-fields.d.ts +17 -0
- package/dist/debugger/shell/form-fields.js +38 -0
- package/dist/debugger/shell/run-action.d.ts +6 -0
- package/dist/debugger/shell/run-action.js +15 -0
- package/dist/debugger/shell/run-controls.js +3 -55
- package/dist/debugger/shell/schema-form.d.ts +10 -1
- package/dist/debugger/shell/schema-form.js +108 -10
- package/dist/debugger/shell/signal-form.d.ts +18 -0
- package/dist/debugger/shell/signal-form.js +185 -0
- package/dist/debugger/shell/start-form.js +2 -32
- package/dist/debugger/shell/use-debounced-preview.d.ts +22 -0
- package/dist/debugger/shell/use-debounced-preview.js +68 -0
- package/dist/evaluator/index.d.ts +1 -1
- package/dist/evaluator/index.js +1 -1
- package/dist/evaluator/module.d.ts +8 -1
- package/dist/evaluator/module.js +33 -0
- package/dist/evaluator/scope.js +1 -0
- package/dist/projectors/event-log-ops.d.ts +0 -6
- package/dist/projectors/event-log-ops.js +2 -12
- package/dist/projectors/event-log.d.ts +10 -5
- package/dist/projectors/event-log.js +26 -22
- package/dist/projectors/replica/columns.d.ts +41 -0
- package/dist/projectors/replica/columns.js +77 -0
- package/dist/projectors/replica/drizzle.d.ts +328 -57
- package/dist/projectors/replica/drizzle.js +18 -14
- package/dist/projectors/replica/migrations.d.ts +25 -5
- package/dist/projectors/replica/migrations.js +62 -14
- package/dist/projectors/replica/postgres.d.ts +12 -11
- package/dist/projectors/replica/postgres.js +12 -26
- package/dist/projectors/replica/sqlite-bun.d.ts +3 -1
- package/dist/projectors/replica/sqlite-bun.js +6 -2
- package/dist/projectors/replica/sqlite-migrations.d.ts +5 -5
- package/dist/projectors/replica/sqlite-migrations.js +22 -9
- package/dist/projectors/replica/sqlite.d.ts +12 -11
- package/dist/projectors/replica/sqlite.js +23 -16
- package/dist/runtime/looms.d.ts +27 -36
- package/dist/runtime/looms.js +1 -0
- package/dist/runtime/runtime.js +7 -1
- package/dist/runtime/server/http.js +4 -2
- package/dist/runtime/server/routes/definitions.d.ts +1 -1
- package/dist/runtime/server/routes/definitions.js +58 -2
- package/dist/runtime/server/routes/runs.js +25 -1
- package/dist/runtime/types.d.ts +6 -1
- package/dist/schedule/module.d.ts +117 -1
- package/dist/schedule/module.js +30 -0
- package/dist/schedule/scope.js +1 -0
- package/dist/schedule/signals.d.ts +59 -7
- package/dist/schedule/signals.js +35 -17
- package/dist/testing/corpus-module.d.ts +1 -1
- package/dist/testing/index.js +2 -1
- package/dist/testing/module-examples.d.ts +6 -0
- package/dist/testing/module-examples.js +66 -0
- package/dist/workflow/module.d.ts +3 -1
- package/dist/workflow/module.js +13 -0
- package/dist/workflow/scope.js +1 -0
- package/package.json +1 -1
- package/dist/debugger/app/assets/index-B7GdT1UA.css +0 -2
- package/dist/debugger/app/assets/routes-CfXxKG45.js +0 -47
- /package/dist/evaluator/{signals.d.ts → steps.d.ts} +0 -0
- /package/dist/evaluator/{signals.js → steps.js} +0 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { RunAttributeFields, RunAttributes } from '@swirls/looms/core';
|
|
2
|
+
/** Declared attributes with no fields. */
|
|
3
|
+
export type NoAdditionalFields = Record<never, never>;
|
|
4
|
+
export interface ReplicaPurgeOptions<Fields extends RunAttributeFields = RunAttributeFields> {
|
|
5
|
+
/** Delete event copies for runs that finished before this epoch millisecond. */
|
|
6
|
+
readonly finishedBefore: number;
|
|
7
|
+
/** Keep the run summary row. Defaults to true. */
|
|
8
|
+
readonly keepIndex?: boolean;
|
|
9
|
+
/** Only purge runs whose declared attributes equal these values. */
|
|
10
|
+
readonly where?: {
|
|
11
|
+
readonly [Key in keyof Fields & string]?: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/** A declared attribute and the `looms_run_index` column that stores it. */
|
|
15
|
+
export interface ResolvedReplicaColumn {
|
|
16
|
+
/** Attribute name, and the property name on the Drizzle table. */
|
|
17
|
+
readonly key: string;
|
|
18
|
+
/** SQL column name. */
|
|
19
|
+
readonly name: string;
|
|
20
|
+
readonly index: boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare function resolveReplicaColumns(fields: RunAttributeFields | undefined): readonly ResolvedReplicaColumn[];
|
|
23
|
+
/** The `where` entries that are set, as columns, in declaration order. Undeclared keys are refused. */
|
|
24
|
+
export declare function purgeFilters(columns: readonly ResolvedReplicaColumn[], where: {
|
|
25
|
+
readonly [key: string]: string | undefined;
|
|
26
|
+
} | undefined): readonly {
|
|
27
|
+
readonly column: string;
|
|
28
|
+
readonly value: string;
|
|
29
|
+
}[];
|
|
30
|
+
/** Value for each declared column from a run's attributes, or null when the run lacks it. */
|
|
31
|
+
export declare function columnValues(columns: readonly ResolvedReplicaColumn[], attributes: RunAttributes | undefined): readonly (string | null)[];
|
|
32
|
+
export declare function sqlStringLiteral(value: string): string;
|
|
33
|
+
export interface ReplicaMigration {
|
|
34
|
+
readonly id: string;
|
|
35
|
+
readonly sql: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Migrations for declared attribute columns, after the Looms tables.
|
|
39
|
+
* Each column and each index is its own migration, so declaring one later only adds that file.
|
|
40
|
+
*/
|
|
41
|
+
export declare function columnMigrations(fields: RunAttributeFields | undefined, migration: (id: string, sql: string) => ReplicaMigration, columnSql: (column: ResolvedReplicaColumn) => string, indexSql: (column: ResolvedReplicaColumn) => string): readonly ReplicaMigration[];
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/** Postgres caps identifiers at 63 bytes, and the index name adds `looms_run_index_`. */
|
|
2
|
+
const COLUMN_NAME = /^[a-z_][a-z0-9_]{0,46}$/;
|
|
3
|
+
const LOOMS_COLUMNS = new Set([
|
|
4
|
+
'run_id',
|
|
5
|
+
'status',
|
|
6
|
+
'kind',
|
|
7
|
+
'definition_name',
|
|
8
|
+
'definition_version',
|
|
9
|
+
'root_thread_id',
|
|
10
|
+
'parent_run_id',
|
|
11
|
+
'launched_by_effect_id',
|
|
12
|
+
'correlation_id',
|
|
13
|
+
'attributes',
|
|
14
|
+
'started_at',
|
|
15
|
+
'updated_at',
|
|
16
|
+
'completed_at',
|
|
17
|
+
'replicated_seq',
|
|
18
|
+
'purged_at',
|
|
19
|
+
]);
|
|
20
|
+
function snakeCase(key) {
|
|
21
|
+
return key
|
|
22
|
+
.replaceAll(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
|
|
23
|
+
.replaceAll(/([a-z0-9])([A-Z])/g, '$1_$2')
|
|
24
|
+
.replaceAll(/[^A-Za-z0-9_]/g, '_')
|
|
25
|
+
.toLowerCase();
|
|
26
|
+
}
|
|
27
|
+
export function resolveReplicaColumns(fields) {
|
|
28
|
+
const names = new Map();
|
|
29
|
+
return Object.entries(fields ?? {}).map(([key, field]) => {
|
|
30
|
+
const name = field.fieldName ?? snakeCase(key);
|
|
31
|
+
if (!COLUMN_NAME.test(name)) {
|
|
32
|
+
throw new Error(`Attribute "${key}" maps to column "${name}". Column names are lowercase snake_case, start with a letter or underscore, and are at most 47 characters; set fieldName.`);
|
|
33
|
+
}
|
|
34
|
+
if (LOOMS_COLUMNS.has(name)) {
|
|
35
|
+
throw new Error(`Attribute "${key}" maps to column "${name}", which Looms owns. Set fieldName.`);
|
|
36
|
+
}
|
|
37
|
+
const clash = names.get(name);
|
|
38
|
+
if (clash !== undefined) {
|
|
39
|
+
throw new Error(`Attributes "${clash}" and "${key}" both map to column "${name}".`);
|
|
40
|
+
}
|
|
41
|
+
names.set(name, key);
|
|
42
|
+
return { key, name, index: field.index === true };
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/** The `where` entries that are set, as columns, in declaration order. Undeclared keys are refused. */
|
|
46
|
+
export function purgeFilters(columns, where) {
|
|
47
|
+
if (where === undefined) {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
const declared = new Set(columns.map((column) => column.key));
|
|
51
|
+
for (const key of Object.keys(where)) {
|
|
52
|
+
if (!declared.has(key)) {
|
|
53
|
+
throw new Error(`purge where.${key} is not a declared attribute.`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return columns.flatMap((column) => {
|
|
57
|
+
const value = where[column.key];
|
|
58
|
+
return value === undefined ? [] : [{ column: column.name, value }];
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/** Value for each declared column from a run's attributes, or null when the run lacks it. */
|
|
62
|
+
export function columnValues(columns, attributes) {
|
|
63
|
+
return columns.map((column) => attributes?.[column.key] ?? null);
|
|
64
|
+
}
|
|
65
|
+
export function sqlStringLiteral(value) {
|
|
66
|
+
return `'${value.replaceAll("'", "''")}'`;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Migrations for declared attribute columns, after the Looms tables.
|
|
70
|
+
* Each column and each index is its own migration, so declaring one later only adds that file.
|
|
71
|
+
*/
|
|
72
|
+
export function columnMigrations(fields, migration, columnSql, indexSql) {
|
|
73
|
+
return resolveReplicaColumns(fields).flatMap((column) => {
|
|
74
|
+
const added = migration(`column_${column.name}`, columnSql(column));
|
|
75
|
+
return column.index ? [added, migration(`index_${column.name}`, indexSql(column))] : [added];
|
|
76
|
+
});
|
|
77
|
+
}
|
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import
|
|
1
|
+
import { type PgColumnBuilderBase, type PgTextBuilderInitial } from 'drizzle-orm/pg-core';
|
|
2
|
+
import type { RunAttributeFields } from '@swirls/looms/core';
|
|
3
|
+
import { type NoAdditionalFields } from './columns';
|
|
3
4
|
/** Column builders for `looms_run_index`. Call again for each table; do not reuse the result. */
|
|
4
5
|
export declare function loomsRunIndexColumns(): {
|
|
5
|
-
runId: import("drizzle-orm").IsPrimaryKey<import("drizzle-orm").NotNull<
|
|
6
|
-
status: import("drizzle-orm").NotNull<
|
|
7
|
-
kind:
|
|
8
|
-
definitionName:
|
|
9
|
-
definitionVersion:
|
|
10
|
-
rootThreadId:
|
|
11
|
-
parentRunId:
|
|
12
|
-
launchedByEffectId:
|
|
13
|
-
correlationId:
|
|
6
|
+
runId: import("drizzle-orm").IsPrimaryKey<import("drizzle-orm").NotNull<PgTextBuilderInitial<"run_id", [string, ...string[]]>>>;
|
|
7
|
+
status: import("drizzle-orm").NotNull<PgTextBuilderInitial<"status", [string, ...string[]]>>;
|
|
8
|
+
kind: PgTextBuilderInitial<"kind", [string, ...string[]]>;
|
|
9
|
+
definitionName: PgTextBuilderInitial<"definition_name", [string, ...string[]]>;
|
|
10
|
+
definitionVersion: PgTextBuilderInitial<"definition_version", [string, ...string[]]>;
|
|
11
|
+
rootThreadId: PgTextBuilderInitial<"root_thread_id", [string, ...string[]]>;
|
|
12
|
+
parentRunId: PgTextBuilderInitial<"parent_run_id", [string, ...string[]]>;
|
|
13
|
+
launchedByEffectId: PgTextBuilderInitial<"launched_by_effect_id", [string, ...string[]]>;
|
|
14
|
+
correlationId: PgTextBuilderInitial<"correlation_id", [string, ...string[]]>;
|
|
14
15
|
attributes: import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm").$Type<import("drizzle-orm/pg-core").PgJsonbBuilderInitial<"attributes">, Record<string, string>>>>;
|
|
15
|
-
tenant: import("drizzle-orm/pg-core").PgTextBuilderInitial<"tenant", [string, ...string[]]>;
|
|
16
|
-
project: import("drizzle-orm/pg-core").PgTextBuilderInitial<"project", [string, ...string[]]>;
|
|
17
|
-
org: import("drizzle-orm/pg-core").PgTextBuilderInitial<"org", [string, ...string[]]>;
|
|
18
16
|
startedAt: import("drizzle-orm/pg-core").PgTimestampBuilderInitial<"started_at">;
|
|
19
17
|
updatedAt: import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTimestampBuilderInitial<"updated_at">>>;
|
|
20
18
|
completedAt: import("drizzle-orm/pg-core").PgTimestampBuilderInitial<"completed_at">;
|
|
@@ -23,43 +21,43 @@ export declare function loomsRunIndexColumns(): {
|
|
|
23
21
|
};
|
|
24
22
|
/** Column builders for `looms_run_events`. */
|
|
25
23
|
export declare function loomsRunEventsColumns(): {
|
|
26
|
-
runId: import("drizzle-orm").NotNull<
|
|
24
|
+
runId: import("drizzle-orm").NotNull<PgTextBuilderInitial<"run_id", [string, ...string[]]>>;
|
|
27
25
|
seq: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgBigInt53BuilderInitial<"seq">>;
|
|
28
|
-
eventId: import("drizzle-orm").NotNull<
|
|
26
|
+
eventId: import("drizzle-orm").NotNull<PgTextBuilderInitial<"event_id", [string, ...string[]]>>;
|
|
29
27
|
ts: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTimestampBuilderInitial<"ts">>;
|
|
30
|
-
type: import("drizzle-orm").NotNull<
|
|
28
|
+
type: import("drizzle-orm").NotNull<PgTextBuilderInitial<"type", [string, ...string[]]>>;
|
|
31
29
|
payload: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgJsonbBuilderInitial<"payload">>;
|
|
32
|
-
threadId:
|
|
33
|
-
parentThreadId:
|
|
34
|
-
causationId:
|
|
35
|
-
correlationId:
|
|
36
|
-
effectId:
|
|
30
|
+
threadId: PgTextBuilderInitial<"thread_id", [string, ...string[]]>;
|
|
31
|
+
parentThreadId: PgTextBuilderInitial<"parent_thread_id", [string, ...string[]]>;
|
|
32
|
+
causationId: PgTextBuilderInitial<"causation_id", [string, ...string[]]>;
|
|
33
|
+
correlationId: PgTextBuilderInitial<"correlation_id", [string, ...string[]]>;
|
|
34
|
+
effectId: PgTextBuilderInitial<"effect_id", [string, ...string[]]>;
|
|
37
35
|
origin: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgJsonbBuilderInitial<"origin">>;
|
|
38
|
-
idempotencyKey:
|
|
36
|
+
idempotencyKey: PgTextBuilderInitial<"idempotency_key", [string, ...string[]]>;
|
|
39
37
|
ephemeral: import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgBooleanBuilderInitial<"ephemeral">>>;
|
|
40
38
|
};
|
|
41
39
|
/** Column builders for `looms_run_actors`. */
|
|
42
40
|
export declare function loomsRunActorsColumns(): {
|
|
43
|
-
runId: import("drizzle-orm").NotNull<
|
|
44
|
-
actorId: import("drizzle-orm").NotNull<
|
|
45
|
-
kind:
|
|
46
|
-
status:
|
|
47
|
-
definitionName:
|
|
48
|
-
parentActorId:
|
|
49
|
-
launchedByRunId:
|
|
50
|
-
launchedByEffectId:
|
|
51
|
-
correlationId:
|
|
41
|
+
runId: import("drizzle-orm").NotNull<PgTextBuilderInitial<"run_id", [string, ...string[]]>>;
|
|
42
|
+
actorId: import("drizzle-orm").NotNull<PgTextBuilderInitial<"actor_id", [string, ...string[]]>>;
|
|
43
|
+
kind: PgTextBuilderInitial<"kind", [string, ...string[]]>;
|
|
44
|
+
status: PgTextBuilderInitial<"status", [string, ...string[]]>;
|
|
45
|
+
definitionName: PgTextBuilderInitial<"definition_name", [string, ...string[]]>;
|
|
46
|
+
parentActorId: PgTextBuilderInitial<"parent_actor_id", [string, ...string[]]>;
|
|
47
|
+
launchedByRunId: PgTextBuilderInitial<"launched_by_run_id", [string, ...string[]]>;
|
|
48
|
+
launchedByEffectId: PgTextBuilderInitial<"launched_by_effect_id", [string, ...string[]]>;
|
|
49
|
+
correlationId: PgTextBuilderInitial<"correlation_id", [string, ...string[]]>;
|
|
52
50
|
updatedAt: import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTimestampBuilderInitial<"updated_at">>>;
|
|
53
51
|
};
|
|
54
52
|
/** Column builders for `looms_run_reviews`. */
|
|
55
53
|
export declare function loomsRunReviewsColumns(): {
|
|
56
|
-
runId: import("drizzle-orm").NotNull<
|
|
57
|
-
reviewId: import("drizzle-orm").NotNull<
|
|
58
|
-
status: import("drizzle-orm").NotNull<
|
|
59
|
-
title: import("drizzle-orm").NotNull<
|
|
54
|
+
runId: import("drizzle-orm").NotNull<PgTextBuilderInitial<"run_id", [string, ...string[]]>>;
|
|
55
|
+
reviewId: import("drizzle-orm").NotNull<PgTextBuilderInitial<"review_id", [string, ...string[]]>>;
|
|
56
|
+
status: import("drizzle-orm").NotNull<PgTextBuilderInitial<"status", [string, ...string[]]>>;
|
|
57
|
+
title: import("drizzle-orm").NotNull<PgTextBuilderInitial<"title", [string, ...string[]]>>;
|
|
60
58
|
updatedAt: import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTimestampBuilderInitial<"updated_at">>>;
|
|
61
59
|
};
|
|
62
|
-
export declare const loomsSchemaMigrations: PgTableWithColumns<{
|
|
60
|
+
export declare const loomsSchemaMigrations: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
63
61
|
name: "looms_schema_migrations";
|
|
64
62
|
schema: undefined;
|
|
65
63
|
columns: {
|
|
@@ -101,24 +99,34 @@ export declare const loomsSchemaMigrations: PgTableWithColumns<{
|
|
|
101
99
|
dialect: 'pg';
|
|
102
100
|
}>;
|
|
103
101
|
type RunIndexExtras = Record<string, PgColumnBuilderBase>;
|
|
104
|
-
|
|
105
|
-
type
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
102
|
+
/** One text column per declared attribute, keyed by attribute name. */
|
|
103
|
+
type AttributeColumnBuilders<Fields extends RunAttributeFields> = {
|
|
104
|
+
[Key in keyof Fields & string]: PgTextBuilderInitial<'', [string, ...string[]]>;
|
|
105
|
+
};
|
|
106
|
+
type RunIndexColumns<Extra extends RunIndexExtras, Fields extends RunAttributeFields> = ReturnType<typeof loomsRunIndexColumns> & AttributeColumnBuilders<Fields> & Extra;
|
|
107
|
+
export interface LoomsReplicaTablesOptions<Extra extends RunIndexExtras = Record<never, never>, Fields extends RunAttributeFields = NoAdditionalFields> {
|
|
108
|
+
/** Declared run attributes. Pass the same declaration the replica uses. */
|
|
109
|
+
readonly additionalFields?: Fields;
|
|
112
110
|
/** Host-owned columns on `looms_run_index`. Looms never writes these. */
|
|
113
111
|
readonly runIndex?: Extra;
|
|
114
112
|
}
|
|
115
113
|
/**
|
|
116
|
-
* Drizzle tables for the replica.
|
|
117
|
-
*
|
|
114
|
+
* Drizzle tables for the replica. `additionalFields` adds a column per declared attribute,
|
|
115
|
+
* keyed by attribute name, with its index. `runIndex` adds columns the host owns
|
|
116
|
+
* (`input`, `error`, and so on); those are not in Looms migrations.
|
|
118
117
|
*/
|
|
119
|
-
export declare function loomsReplicaTables<Extra extends RunIndexExtras = Record<never, never
|
|
120
|
-
loomsRunIndex:
|
|
121
|
-
|
|
118
|
+
export declare function loomsReplicaTables<Extra extends RunIndexExtras = Record<never, never>, const Fields extends RunAttributeFields = NoAdditionalFields>(options?: LoomsReplicaTablesOptions<Extra, Fields>): {
|
|
119
|
+
loomsRunIndex: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
120
|
+
name: "looms_run_index";
|
|
121
|
+
schema: undefined;
|
|
122
|
+
columns: RunIndexColumns<Extra, Fields> extends infer T extends Record<string, import("drizzle-orm").ColumnBuilderBase<import("drizzle-orm").ColumnBuilderBaseConfig<import("drizzle-orm").ColumnDataType, string>, object>> ? { [Key in keyof T]: import("drizzle-orm").BuildColumn<TTableName, {
|
|
123
|
+
_: Omit<T[Key]["_"], "name"> & {
|
|
124
|
+
name: T[Key]["_"]["name"] extends "" ? import("drizzle-orm").Assume<Key, string> : T[Key]["_"]["name"];
|
|
125
|
+
};
|
|
126
|
+
}, TDialect>; } : never;
|
|
127
|
+
dialect: 'pg';
|
|
128
|
+
}>;
|
|
129
|
+
loomsRunEvents: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
122
130
|
name: "looms_run_events";
|
|
123
131
|
schema: undefined;
|
|
124
132
|
columns: {
|
|
@@ -363,7 +371,7 @@ export declare function loomsReplicaTables<Extra extends RunIndexExtras = Record
|
|
|
363
371
|
};
|
|
364
372
|
dialect: 'pg';
|
|
365
373
|
}>;
|
|
366
|
-
loomsRunActors: PgTableWithColumns<{
|
|
374
|
+
loomsRunActors: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
367
375
|
name: "looms_run_actors";
|
|
368
376
|
schema: undefined;
|
|
369
377
|
columns: {
|
|
@@ -540,7 +548,7 @@ export declare function loomsReplicaTables<Extra extends RunIndexExtras = Record
|
|
|
540
548
|
};
|
|
541
549
|
dialect: 'pg';
|
|
542
550
|
}>;
|
|
543
|
-
loomsRunReviews: PgTableWithColumns<{
|
|
551
|
+
loomsRunReviews: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
544
552
|
name: "looms_run_reviews";
|
|
545
553
|
schema: undefined;
|
|
546
554
|
columns: {
|
|
@@ -632,7 +640,7 @@ export declare function loomsReplicaTables<Extra extends RunIndexExtras = Record
|
|
|
632
640
|
};
|
|
633
641
|
dialect: 'pg';
|
|
634
642
|
}>;
|
|
635
|
-
loomsSchemaMigrations: PgTableWithColumns<{
|
|
643
|
+
loomsSchemaMigrations: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
636
644
|
name: "looms_schema_migrations";
|
|
637
645
|
schema: undefined;
|
|
638
646
|
columns: {
|
|
@@ -674,8 +682,271 @@ export declare function loomsReplicaTables<Extra extends RunIndexExtras = Record
|
|
|
674
682
|
dialect: 'pg';
|
|
675
683
|
}>;
|
|
676
684
|
};
|
|
677
|
-
export declare const loomsRunIndex:
|
|
678
|
-
|
|
685
|
+
export declare const loomsRunIndex: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
686
|
+
name: "looms_run_index";
|
|
687
|
+
schema: undefined;
|
|
688
|
+
columns: {
|
|
689
|
+
runId: import("drizzle-orm/pg-core").PgColumn<{
|
|
690
|
+
name: "run_id";
|
|
691
|
+
tableName: "looms_run_index";
|
|
692
|
+
dataType: "string";
|
|
693
|
+
columnType: "PgText";
|
|
694
|
+
data: string;
|
|
695
|
+
driverParam: string;
|
|
696
|
+
notNull: true;
|
|
697
|
+
hasDefault: false;
|
|
698
|
+
isPrimaryKey: true;
|
|
699
|
+
isAutoincrement: false;
|
|
700
|
+
hasRuntimeDefault: false;
|
|
701
|
+
enumValues: [string, ...string[]];
|
|
702
|
+
baseColumn: never;
|
|
703
|
+
identity: undefined;
|
|
704
|
+
generated: undefined;
|
|
705
|
+
}, {}, {}>;
|
|
706
|
+
status: import("drizzle-orm/pg-core").PgColumn<{
|
|
707
|
+
name: "status";
|
|
708
|
+
tableName: "looms_run_index";
|
|
709
|
+
dataType: "string";
|
|
710
|
+
columnType: "PgText";
|
|
711
|
+
data: string;
|
|
712
|
+
driverParam: string;
|
|
713
|
+
notNull: true;
|
|
714
|
+
hasDefault: false;
|
|
715
|
+
isPrimaryKey: false;
|
|
716
|
+
isAutoincrement: false;
|
|
717
|
+
hasRuntimeDefault: false;
|
|
718
|
+
enumValues: [string, ...string[]];
|
|
719
|
+
baseColumn: never;
|
|
720
|
+
identity: undefined;
|
|
721
|
+
generated: undefined;
|
|
722
|
+
}, {}, {}>;
|
|
723
|
+
kind: import("drizzle-orm/pg-core").PgColumn<{
|
|
724
|
+
name: "kind";
|
|
725
|
+
tableName: "looms_run_index";
|
|
726
|
+
dataType: "string";
|
|
727
|
+
columnType: "PgText";
|
|
728
|
+
data: string;
|
|
729
|
+
driverParam: string;
|
|
730
|
+
notNull: false;
|
|
731
|
+
hasDefault: false;
|
|
732
|
+
isPrimaryKey: false;
|
|
733
|
+
isAutoincrement: false;
|
|
734
|
+
hasRuntimeDefault: false;
|
|
735
|
+
enumValues: [string, ...string[]];
|
|
736
|
+
baseColumn: never;
|
|
737
|
+
identity: undefined;
|
|
738
|
+
generated: undefined;
|
|
739
|
+
}, {}, {}>;
|
|
740
|
+
definitionName: import("drizzle-orm/pg-core").PgColumn<{
|
|
741
|
+
name: "definition_name";
|
|
742
|
+
tableName: "looms_run_index";
|
|
743
|
+
dataType: "string";
|
|
744
|
+
columnType: "PgText";
|
|
745
|
+
data: string;
|
|
746
|
+
driverParam: string;
|
|
747
|
+
notNull: false;
|
|
748
|
+
hasDefault: false;
|
|
749
|
+
isPrimaryKey: false;
|
|
750
|
+
isAutoincrement: false;
|
|
751
|
+
hasRuntimeDefault: false;
|
|
752
|
+
enumValues: [string, ...string[]];
|
|
753
|
+
baseColumn: never;
|
|
754
|
+
identity: undefined;
|
|
755
|
+
generated: undefined;
|
|
756
|
+
}, {}, {}>;
|
|
757
|
+
definitionVersion: import("drizzle-orm/pg-core").PgColumn<{
|
|
758
|
+
name: "definition_version";
|
|
759
|
+
tableName: "looms_run_index";
|
|
760
|
+
dataType: "string";
|
|
761
|
+
columnType: "PgText";
|
|
762
|
+
data: string;
|
|
763
|
+
driverParam: string;
|
|
764
|
+
notNull: false;
|
|
765
|
+
hasDefault: false;
|
|
766
|
+
isPrimaryKey: false;
|
|
767
|
+
isAutoincrement: false;
|
|
768
|
+
hasRuntimeDefault: false;
|
|
769
|
+
enumValues: [string, ...string[]];
|
|
770
|
+
baseColumn: never;
|
|
771
|
+
identity: undefined;
|
|
772
|
+
generated: undefined;
|
|
773
|
+
}, {}, {}>;
|
|
774
|
+
rootThreadId: import("drizzle-orm/pg-core").PgColumn<{
|
|
775
|
+
name: "root_thread_id";
|
|
776
|
+
tableName: "looms_run_index";
|
|
777
|
+
dataType: "string";
|
|
778
|
+
columnType: "PgText";
|
|
779
|
+
data: string;
|
|
780
|
+
driverParam: string;
|
|
781
|
+
notNull: false;
|
|
782
|
+
hasDefault: false;
|
|
783
|
+
isPrimaryKey: false;
|
|
784
|
+
isAutoincrement: false;
|
|
785
|
+
hasRuntimeDefault: false;
|
|
786
|
+
enumValues: [string, ...string[]];
|
|
787
|
+
baseColumn: never;
|
|
788
|
+
identity: undefined;
|
|
789
|
+
generated: undefined;
|
|
790
|
+
}, {}, {}>;
|
|
791
|
+
parentRunId: import("drizzle-orm/pg-core").PgColumn<{
|
|
792
|
+
name: "parent_run_id";
|
|
793
|
+
tableName: "looms_run_index";
|
|
794
|
+
dataType: "string";
|
|
795
|
+
columnType: "PgText";
|
|
796
|
+
data: string;
|
|
797
|
+
driverParam: string;
|
|
798
|
+
notNull: false;
|
|
799
|
+
hasDefault: false;
|
|
800
|
+
isPrimaryKey: false;
|
|
801
|
+
isAutoincrement: false;
|
|
802
|
+
hasRuntimeDefault: false;
|
|
803
|
+
enumValues: [string, ...string[]];
|
|
804
|
+
baseColumn: never;
|
|
805
|
+
identity: undefined;
|
|
806
|
+
generated: undefined;
|
|
807
|
+
}, {}, {}>;
|
|
808
|
+
launchedByEffectId: import("drizzle-orm/pg-core").PgColumn<{
|
|
809
|
+
name: "launched_by_effect_id";
|
|
810
|
+
tableName: "looms_run_index";
|
|
811
|
+
dataType: "string";
|
|
812
|
+
columnType: "PgText";
|
|
813
|
+
data: string;
|
|
814
|
+
driverParam: string;
|
|
815
|
+
notNull: false;
|
|
816
|
+
hasDefault: false;
|
|
817
|
+
isPrimaryKey: false;
|
|
818
|
+
isAutoincrement: false;
|
|
819
|
+
hasRuntimeDefault: false;
|
|
820
|
+
enumValues: [string, ...string[]];
|
|
821
|
+
baseColumn: never;
|
|
822
|
+
identity: undefined;
|
|
823
|
+
generated: undefined;
|
|
824
|
+
}, {}, {}>;
|
|
825
|
+
correlationId: import("drizzle-orm/pg-core").PgColumn<{
|
|
826
|
+
name: "correlation_id";
|
|
827
|
+
tableName: "looms_run_index";
|
|
828
|
+
dataType: "string";
|
|
829
|
+
columnType: "PgText";
|
|
830
|
+
data: string;
|
|
831
|
+
driverParam: string;
|
|
832
|
+
notNull: false;
|
|
833
|
+
hasDefault: false;
|
|
834
|
+
isPrimaryKey: false;
|
|
835
|
+
isAutoincrement: false;
|
|
836
|
+
hasRuntimeDefault: false;
|
|
837
|
+
enumValues: [string, ...string[]];
|
|
838
|
+
baseColumn: never;
|
|
839
|
+
identity: undefined;
|
|
840
|
+
generated: undefined;
|
|
841
|
+
}, {}, {}>;
|
|
842
|
+
attributes: import("drizzle-orm/pg-core").PgColumn<{
|
|
843
|
+
name: "attributes";
|
|
844
|
+
tableName: "looms_run_index";
|
|
845
|
+
dataType: "json";
|
|
846
|
+
columnType: "PgJsonb";
|
|
847
|
+
data: Record<string, string>;
|
|
848
|
+
driverParam: unknown;
|
|
849
|
+
notNull: true;
|
|
850
|
+
hasDefault: true;
|
|
851
|
+
isPrimaryKey: false;
|
|
852
|
+
isAutoincrement: false;
|
|
853
|
+
hasRuntimeDefault: false;
|
|
854
|
+
enumValues: undefined;
|
|
855
|
+
baseColumn: never;
|
|
856
|
+
identity: undefined;
|
|
857
|
+
generated: undefined;
|
|
858
|
+
}, {}, {
|
|
859
|
+
$type: Record<string, string>;
|
|
860
|
+
}>;
|
|
861
|
+
startedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
862
|
+
name: "started_at";
|
|
863
|
+
tableName: "looms_run_index";
|
|
864
|
+
dataType: "date";
|
|
865
|
+
columnType: "PgTimestamp";
|
|
866
|
+
data: Date;
|
|
867
|
+
driverParam: string;
|
|
868
|
+
notNull: false;
|
|
869
|
+
hasDefault: false;
|
|
870
|
+
isPrimaryKey: false;
|
|
871
|
+
isAutoincrement: false;
|
|
872
|
+
hasRuntimeDefault: false;
|
|
873
|
+
enumValues: undefined;
|
|
874
|
+
baseColumn: never;
|
|
875
|
+
identity: undefined;
|
|
876
|
+
generated: undefined;
|
|
877
|
+
}, {}, {}>;
|
|
878
|
+
updatedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
879
|
+
name: "updated_at";
|
|
880
|
+
tableName: "looms_run_index";
|
|
881
|
+
dataType: "date";
|
|
882
|
+
columnType: "PgTimestamp";
|
|
883
|
+
data: Date;
|
|
884
|
+
driverParam: string;
|
|
885
|
+
notNull: true;
|
|
886
|
+
hasDefault: true;
|
|
887
|
+
isPrimaryKey: false;
|
|
888
|
+
isAutoincrement: false;
|
|
889
|
+
hasRuntimeDefault: false;
|
|
890
|
+
enumValues: undefined;
|
|
891
|
+
baseColumn: never;
|
|
892
|
+
identity: undefined;
|
|
893
|
+
generated: undefined;
|
|
894
|
+
}, {}, {}>;
|
|
895
|
+
completedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
896
|
+
name: "completed_at";
|
|
897
|
+
tableName: "looms_run_index";
|
|
898
|
+
dataType: "date";
|
|
899
|
+
columnType: "PgTimestamp";
|
|
900
|
+
data: Date;
|
|
901
|
+
driverParam: string;
|
|
902
|
+
notNull: false;
|
|
903
|
+
hasDefault: false;
|
|
904
|
+
isPrimaryKey: false;
|
|
905
|
+
isAutoincrement: false;
|
|
906
|
+
hasRuntimeDefault: false;
|
|
907
|
+
enumValues: undefined;
|
|
908
|
+
baseColumn: never;
|
|
909
|
+
identity: undefined;
|
|
910
|
+
generated: undefined;
|
|
911
|
+
}, {}, {}>;
|
|
912
|
+
replicatedSeq: import("drizzle-orm/pg-core").PgColumn<{
|
|
913
|
+
name: "replicated_seq";
|
|
914
|
+
tableName: "looms_run_index";
|
|
915
|
+
dataType: "number";
|
|
916
|
+
columnType: "PgBigInt53";
|
|
917
|
+
data: number;
|
|
918
|
+
driverParam: string | number;
|
|
919
|
+
notNull: true;
|
|
920
|
+
hasDefault: true;
|
|
921
|
+
isPrimaryKey: false;
|
|
922
|
+
isAutoincrement: false;
|
|
923
|
+
hasRuntimeDefault: false;
|
|
924
|
+
enumValues: undefined;
|
|
925
|
+
baseColumn: never;
|
|
926
|
+
identity: undefined;
|
|
927
|
+
generated: undefined;
|
|
928
|
+
}, {}, {}>;
|
|
929
|
+
purgedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
930
|
+
name: "purged_at";
|
|
931
|
+
tableName: "looms_run_index";
|
|
932
|
+
dataType: "date";
|
|
933
|
+
columnType: "PgTimestamp";
|
|
934
|
+
data: Date;
|
|
935
|
+
driverParam: string;
|
|
936
|
+
notNull: false;
|
|
937
|
+
hasDefault: false;
|
|
938
|
+
isPrimaryKey: false;
|
|
939
|
+
isAutoincrement: false;
|
|
940
|
+
hasRuntimeDefault: false;
|
|
941
|
+
enumValues: undefined;
|
|
942
|
+
baseColumn: never;
|
|
943
|
+
identity: undefined;
|
|
944
|
+
generated: undefined;
|
|
945
|
+
}, {}, {}>;
|
|
946
|
+
};
|
|
947
|
+
dialect: 'pg';
|
|
948
|
+
}>;
|
|
949
|
+
export declare const loomsRunEvents: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
679
950
|
name: "looms_run_events";
|
|
680
951
|
schema: undefined;
|
|
681
952
|
columns: {
|
|
@@ -920,7 +1191,7 @@ export declare const loomsRunEvents: PgTableWithColumns<{
|
|
|
920
1191
|
};
|
|
921
1192
|
dialect: 'pg';
|
|
922
1193
|
}>;
|
|
923
|
-
export declare const loomsRunActors: PgTableWithColumns<{
|
|
1194
|
+
export declare const loomsRunActors: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
924
1195
|
name: "looms_run_actors";
|
|
925
1196
|
schema: undefined;
|
|
926
1197
|
columns: {
|
|
@@ -1097,7 +1368,7 @@ export declare const loomsRunActors: PgTableWithColumns<{
|
|
|
1097
1368
|
};
|
|
1098
1369
|
dialect: 'pg';
|
|
1099
1370
|
}>;
|
|
1100
|
-
export declare const loomsRunReviews: PgTableWithColumns<{
|
|
1371
|
+
export declare const loomsRunReviews: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
1101
1372
|
name: "looms_run_reviews";
|
|
1102
1373
|
schema: undefined;
|
|
1103
1374
|
columns: {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { sql } from 'drizzle-orm';
|
|
2
2
|
import { bigint, boolean, index, jsonb, pgTable, primaryKey, text, timestamp, } from 'drizzle-orm/pg-core';
|
|
3
|
+
import { resolveReplicaColumns } from './columns.js';
|
|
3
4
|
/** Column builders for `looms_run_index`. Call again for each table; do not reuse the result. */
|
|
4
5
|
export function loomsRunIndexColumns() {
|
|
5
6
|
return {
|
|
@@ -16,9 +17,6 @@ export function loomsRunIndexColumns() {
|
|
|
16
17
|
.$type()
|
|
17
18
|
.notNull()
|
|
18
19
|
.default(sql `'{}'::jsonb`),
|
|
19
|
-
tenant: text('tenant'),
|
|
20
|
-
project: text('project'),
|
|
21
|
-
org: text('org'),
|
|
22
20
|
startedAt: timestamp('started_at', { withTimezone: true }),
|
|
23
21
|
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
|
|
24
22
|
completedAt: timestamp('completed_at', { withTimezone: true }),
|
|
@@ -75,23 +73,29 @@ export const loomsSchemaMigrations = pgTable('looms_schema_migrations', {
|
|
|
75
73
|
appliedAt: timestamp('applied_at', { withTimezone: true }).notNull().defaultNow(),
|
|
76
74
|
});
|
|
77
75
|
/**
|
|
78
|
-
* Drizzle tables for the replica.
|
|
79
|
-
*
|
|
76
|
+
* Drizzle tables for the replica. `additionalFields` adds a column per declared attribute,
|
|
77
|
+
* keyed by attribute name, with its index. `runIndex` adds columns the host owns
|
|
78
|
+
* (`input`, `error`, and so on); those are not in Looms migrations.
|
|
80
79
|
*/
|
|
81
80
|
export function loomsReplicaTables(options) {
|
|
81
|
+
const attributeColumns = resolveReplicaColumns(options?.additionalFields);
|
|
82
|
+
// SAFETY: resolveReplicaColumns returns one column for each key of Fields, and runIndex is Extra.
|
|
82
83
|
const columns = {
|
|
83
84
|
...loomsRunIndexColumns(),
|
|
85
|
+
...Object.fromEntries(attributeColumns.map((column) => [column.key, text(column.name)])),
|
|
84
86
|
...options?.runIndex,
|
|
85
87
|
};
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
88
|
+
const runIndex = pgTable('looms_run_index', columns, (table) => {
|
|
89
|
+
const byKey = table;
|
|
90
|
+
return [
|
|
91
|
+
index('looms_run_index_parent').on(table.parentRunId),
|
|
92
|
+
index('looms_run_index_status').on(table.status),
|
|
93
|
+
...attributeColumns.flatMap((column) => {
|
|
94
|
+
const built = byKey[column.key];
|
|
95
|
+
return column.index && built ? [index(`looms_run_index_${column.name}`).on(built)] : [];
|
|
96
|
+
}),
|
|
97
|
+
];
|
|
98
|
+
});
|
|
95
99
|
const loomsRunEvents = pgTable('looms_run_events', loomsRunEventsColumns(), (table) => [
|
|
96
100
|
primaryKey({ columns: [table.runId, table.seq] }),
|
|
97
101
|
index('looms_run_events_type_ts').on(table.type, table.ts),
|