@segmentstream/ontology 0.106.1 → 0.106.3
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 +15 -0
- package/dist/email.d.ts +13 -0
- package/dist/email.js +7 -0
- package/dist/migrate/apply.d.ts +6 -0
- package/dist/migrate/apply.js +17 -4
- package/dist/replication/shadow.d.ts +4 -2
- package/dist/replication/shadow.js +1 -1
- package/dist/replication/store.js +4 -0
- package/dist/runtime/service-binding.js +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.106.3
|
|
4
|
+
|
|
5
|
+
The ontology service reads less from the workspace database. Its status endpoint reads the hash of
|
|
6
|
+
the applied ontology instead of the whole applied manifest, and warehouse replication skips its
|
|
7
|
+
bookkeeping reads when it has nothing to deliver. Responses and replication results are unchanged.
|
|
8
|
+
|
|
9
|
+
## 0.106.2
|
|
10
|
+
|
|
11
|
+
`emailReplyMessage` from `@segmentstream/ontology/email` takes two more options:
|
|
12
|
+
|
|
13
|
+
- `autoSubmitted` marks the reply `Auto-Submitted: auto-replied`. Another agent's mail channel, an
|
|
14
|
+
autoresponder or a mailing list then never answers it.
|
|
15
|
+
- `replyKey` names the reply in an `X-SegmentStream-Reply` header. A sender that retries after an
|
|
16
|
+
uncertain failure can then find the reply in the thread instead of sending it twice.
|
|
17
|
+
|
|
3
18
|
## 0.106.1
|
|
4
19
|
|
|
5
20
|
Workflow maps read more workflows in full. A promise's `.catch(…)` or `.finally(…)` now reads as a
|
package/dist/email.d.ts
CHANGED
|
@@ -20,7 +20,20 @@ export interface EmailReply {
|
|
|
20
20
|
/** The reply as plain text, and the same reply as HTML. */
|
|
21
21
|
readonly text: string;
|
|
22
22
|
readonly html: string;
|
|
23
|
+
/**
|
|
24
|
+
* Marks the reply `Auto-Submitted: auto-replied` (RFC 3834), as a reply a program sent: another
|
|
25
|
+
* agent's mail channel, an autoresponder or a mailing list then never answers it, so two agents
|
|
26
|
+
* cannot reply to each other without end.
|
|
27
|
+
*/
|
|
28
|
+
readonly autoSubmitted?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Names this reply (`X-SegmentStream-Reply`), so a sender that retries after an uncertain
|
|
31
|
+
* failure can find it in the thread instead of sending it twice. Letters, digits, `-` and `_`.
|
|
32
|
+
*/
|
|
33
|
+
readonly replyKey?: string;
|
|
23
34
|
}
|
|
35
|
+
/** The header that names a reply, as {@link EmailReply.replyKey} sets it. */
|
|
36
|
+
export declare const REPLY_KEY_HEADER = "X-SegmentStream-Reply";
|
|
24
37
|
/**
|
|
25
38
|
* The reply as an RFC 5322 message with a plain-text and an HTML part, for a mailbox to send in
|
|
26
39
|
* the same thread. It names no sender: the mailbox sends from its own address.
|
package/dist/email.js
CHANGED
|
@@ -48,6 +48,8 @@ function base64Lines(text) {
|
|
|
48
48
|
.match(/.{1,76}/g)
|
|
49
49
|
?.join("\r\n") ?? "");
|
|
50
50
|
}
|
|
51
|
+
/** The header that names a reply, as {@link EmailReply.replyKey} sets it. */
|
|
52
|
+
export const REPLY_KEY_HEADER = "X-SegmentStream-Reply";
|
|
51
53
|
/**
|
|
52
54
|
* The reply as an RFC 5322 message with a plain-text and an HTML part, for a mailbox to send in
|
|
53
55
|
* the same thread. It names no sender: the mailbox sends from its own address.
|
|
@@ -56,6 +58,9 @@ export function emailReplyMessage(reply) {
|
|
|
56
58
|
if (!/^[^\s<>@,;:"]+@[^\s<>@,;:"]+$/.test(reply.to)) {
|
|
57
59
|
throw new Error("The reply's recipient is not a plain address.");
|
|
58
60
|
}
|
|
61
|
+
if (reply.replyKey !== undefined && !/^[A-Za-z0-9_-]{1,128}$/.test(reply.replyKey)) {
|
|
62
|
+
throw new Error("The reply's key holds characters a header cannot carry.");
|
|
63
|
+
}
|
|
59
64
|
const boundary = `segmentstream-${crypto.randomUUID()}`;
|
|
60
65
|
const parent = messageId(reply.inReplyTo);
|
|
61
66
|
const references = [
|
|
@@ -71,6 +76,8 @@ export function emailReplyMessage(reply) {
|
|
|
71
76
|
`Subject: ${headerText(replySubject(reply.subject))}`,
|
|
72
77
|
...(parent === undefined ? [] : [`In-Reply-To: ${parent}`]),
|
|
73
78
|
...(references.length === 0 ? [] : [`References: ${[...new Set(references)].join(" ")}`]),
|
|
79
|
+
...(reply.autoSubmitted === true ? ["Auto-Submitted: auto-replied"] : []),
|
|
80
|
+
...(reply.replyKey === undefined ? [] : [`${REPLY_KEY_HEADER}: ${reply.replyKey}`]),
|
|
74
81
|
"MIME-Version: 1.0",
|
|
75
82
|
`Content-Type: multipart/alternative; boundary="${boundary}"`,
|
|
76
83
|
];
|
package/dist/migrate/apply.d.ts
CHANGED
|
@@ -47,6 +47,12 @@ export type ApplyMigrationError = MigrationRefused | CatalogMismatch | CatalogIn
|
|
|
47
47
|
* decoded with the manifest contract, so fields this SDK does not know are dropped.
|
|
48
48
|
*/
|
|
49
49
|
export declare const readCatalog: (input: CatalogInput) => Effect.Effect<OntologyManifest | undefined, CatalogInvalid | SqlError>;
|
|
50
|
+
/**
|
|
51
|
+
* The hash recorded by the last applied migration, or undefined when none was applied. A migration
|
|
52
|
+
* writes it in the statement that writes the manifest it names, so this reads the hash alone, not
|
|
53
|
+
* the manifest that `readCatalog` reads and checks, which is megabytes for a large ontology.
|
|
54
|
+
*/
|
|
55
|
+
export declare const readCatalogHash: (input: CatalogInput) => Effect.Effect<string | undefined, CatalogInvalid | SqlError>;
|
|
50
56
|
/**
|
|
51
57
|
* The storage the catalog records as kept: what removals retained, which declaring the entity or
|
|
52
58
|
* @legacy ontology.pre-upgrade-database-tolerance
|
package/dist/migrate/apply.js
CHANGED
|
@@ -36,13 +36,12 @@ const DEFAULT_STATEMENT_TIMEOUT = "5 minutes";
|
|
|
36
36
|
const DEFAULT_LOCK_TIMEOUT = "5 seconds";
|
|
37
37
|
const Presence = Schema.Struct({ present: Schema.Boolean });
|
|
38
38
|
const CatalogRow = Schema.Struct({ hash: Schema.String, manifest: Schema.String });
|
|
39
|
+
const CatalogHashRow = Schema.Struct({ hash: Schema.String });
|
|
39
40
|
const RetainedRow = Schema.Struct({ retained: Schema.NullOr(Schema.String) });
|
|
40
41
|
const decodeManifest = decodeManifestDocument;
|
|
42
|
+
const catalogPresent = (sql) => sql.unsafe(`SELECT to_regclass($1) IS NOT NULL AS present`, [CATALOG]).pipe(Effect.flatMap(Schema.decodeUnknownEffect(Schema.Array(Presence))), Effect.map((presence) => presence[0]?.present === true));
|
|
41
43
|
const readCatalogRow = (sql, options) => Effect.gen(function* () {
|
|
42
|
-
|
|
43
|
-
.unsafe(`SELECT to_regclass($1) IS NOT NULL AS present`, [CATALOG])
|
|
44
|
-
.pipe(Effect.flatMap(Schema.decodeUnknownEffect(Schema.Array(Presence))));
|
|
45
|
-
if (presence[0]?.present !== true) {
|
|
44
|
+
if (!(yield* catalogPresent(sql))) {
|
|
46
45
|
return undefined;
|
|
47
46
|
}
|
|
48
47
|
const lock = options.forUpdate ? "FOR UPDATE" : "";
|
|
@@ -82,6 +81,20 @@ export const readCatalog = (input) => Effect.gen(function* () {
|
|
|
82
81
|
}
|
|
83
82
|
return manifest;
|
|
84
83
|
}).pipe(Effect.withSpan("ontology.migrate.readCatalog"));
|
|
84
|
+
/**
|
|
85
|
+
* The hash recorded by the last applied migration, or undefined when none was applied. A migration
|
|
86
|
+
* writes it in the statement that writes the manifest it names, so this reads the hash alone, not
|
|
87
|
+
* the manifest that `readCatalog` reads and checks, which is megabytes for a large ontology.
|
|
88
|
+
*/
|
|
89
|
+
export const readCatalogHash = (input) => Effect.gen(function* () {
|
|
90
|
+
if (!(yield* catalogPresent(input.sql))) {
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
const rows = yield* input.sql
|
|
94
|
+
.unsafe(`SELECT "hash" FROM ${CATALOG} WHERE "id"`)
|
|
95
|
+
.pipe(Effect.flatMap(Schema.decodeUnknownEffect(Schema.Array(CatalogHashRow))));
|
|
96
|
+
return rows[0]?.hash;
|
|
97
|
+
}).pipe(Effect.catchTag("SchemaError", (cause) => Effect.fail(new CatalogInvalid({ message: "The _ontology catalog has an unexpected shape.", cause }))), Effect.withSpan("ontology.migrate.readCatalogHash"));
|
|
85
98
|
/**
|
|
86
99
|
* The storage the catalog records as kept: what removals retained, which declaring the entity or
|
|
87
100
|
* @legacy ontology.pre-upgrade-database-tolerance
|
|
@@ -112,8 +112,10 @@ export declare const replaceDestroyedShadowDestination: (sql: SqlClient.SqlClien
|
|
|
112
112
|
export declare const installShadowEpoch: (sql: SqlClient.SqlClient, id: string, owner: string) => Effect.Effect<boolean, import("effect/unstable/sql/SqlError").SqlError, never>;
|
|
113
113
|
/** Strict warehouse job completion, not Pub/Sub acceptance, is the publication prerequisite. */
|
|
114
114
|
export declare const shadowPublicationReady: (sql: SqlClient.SqlClient, epoch: ShadowEpoch, owner: string) => Effect.Effect<boolean, import("effect/unstable/sql/SqlError").SqlError, never>;
|
|
115
|
-
|
|
116
|
-
export
|
|
115
|
+
/** A retired segment is settled by its load job alone; its events are never loaded again. */
|
|
116
|
+
export type RetiredShadowSegment = Pick<ShadowSegment, "id" | "job_id">;
|
|
117
|
+
export declare const unfinishedRetiredSegments: (sql: SqlClient.SqlClient) => import("effect/unstable/sql/Statement").Statement<RetiredShadowSegment>;
|
|
118
|
+
export declare const settleRetiredSegment: (sql: SqlClient.SqlClient, segment: RetiredShadowSegment, committed: boolean) => import("effect/unstable/sql/Statement").Statement<object>;
|
|
117
119
|
/** Restriction-only refresh is independent of build leases and cannot confer publication eligibility. */
|
|
118
120
|
export declare const shadowPolicyViewOwnership: (sql: SqlClient.SqlClient, generation: string, source: string, exclusions: unknown) => Effect.Effect<boolean, import("effect/unstable/sql/SqlError").SqlError, never>;
|
|
119
121
|
export declare const recordShadowPolicyViews: (sql: SqlClient.SqlClient, generation: string, source: string, exclusions: unknown) => import("effect/unstable/sql/Statement").Statement<object>;
|
|
@@ -573,7 +573,7 @@ export const shadowPublicationReady = (sql, epoch, owner) => sql
|
|
|
573
573
|
AND NOT EXISTS(SELECT 1 FROM _ontology_replication_delivery WHERE generation=e.id
|
|
574
574
|
AND revision<=e.boundary AND committed_at IS NULL AND suppressed_at IS NULL)) AS ready`, [epoch.id, owner, epoch.token, epoch.boundary])
|
|
575
575
|
.pipe(Effect.map((rows) => rows[0].ready));
|
|
576
|
-
export const unfinishedRetiredSegments = (sql) => sql.unsafe(`SELECT
|
|
576
|
+
export const unfinishedRetiredSegments = (sql) => sql.unsafe(`SELECT id::text, job_id FROM _ontology_replication_segments
|
|
577
577
|
WHERE state='pending' AND created_at<now()-interval '7 days' AND epoch IN (
|
|
578
578
|
SELECT id FROM _ontology_replication_epochs WHERE state IN ('retired','cancelled'))
|
|
579
579
|
ORDER BY created_at,id LIMIT 10`);
|
|
@@ -166,6 +166,10 @@ export const pendingReplicationEvents = (sql, target, options = {}) => Effect.ge
|
|
|
166
166
|
ORDER BY revision,event_id LIMIT ${REPLICATION_BATCH_SIZE}`, shadow
|
|
167
167
|
? [target.generation, options.bulk ?? false, options.through ?? null]
|
|
168
168
|
: [target.generation]);
|
|
169
|
+
// An idle pass ends here: the bindings and the export policy below shape only queued events.
|
|
170
|
+
if (references.length === 0) {
|
|
171
|
+
return [];
|
|
172
|
+
}
|
|
169
173
|
const groups = new Map();
|
|
170
174
|
for (const reference of references) {
|
|
171
175
|
if (reference.payload) {
|
|
@@ -9,7 +9,7 @@ import { attachmentRuntime } from "../storage/attachments.js";
|
|
|
9
9
|
import { blobRuntime } from "../storage/sessions.js";
|
|
10
10
|
import { FileAccess, unavailableFiles } from "../storage/file-access.js";
|
|
11
11
|
import { validateDeploymentStorage } from "../storage/provider.js";
|
|
12
|
-
import {
|
|
12
|
+
import { readCatalogHash } from "../migrate/apply.js";
|
|
13
13
|
import { RuntimeDeployment } from "./deployment.js";
|
|
14
14
|
import { NotInvited, OntologyBackend, } from "../service/runtime-contract.js";
|
|
15
15
|
import { WorkflowRecoveryUnavailable } from "./errors.js";
|
|
@@ -228,7 +228,7 @@ export function backendLayer(ontology, blobStorage, workflowStarter, deployment,
|
|
|
228
228
|
: withSql(checkSignIn(ontology, email)),
|
|
229
229
|
resolveApiKey: (key) => withSql(resolvePrincipalByApiKey(ontology, Redacted.value(key))).pipe(Effect.catchTag("PrincipalRejected", rejectedAs("api_key"))),
|
|
230
230
|
resolveApiKeyCredential: (key) => withSql(resolveApiKeyCredential(ontology, Redacted.value(key))).pipe(Effect.catchTag("PrincipalRejected", rejectedAs("api_key"))),
|
|
231
|
-
appliedHash:
|
|
231
|
+
appliedHash: readCatalogHash({ sql }).pipe(Effect.orDie),
|
|
232
232
|
replicationEnabled: Effect.gen(function* () {
|
|
233
233
|
const [presence] = yield* sql.unsafe("SELECT to_regclass('_ontology_replication') IS NOT NULL AS present");
|
|
234
234
|
if (!presence?.present) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/ontology",
|
|
3
|
-
"version": "0.106.
|
|
3
|
+
"version": "0.106.3",
|
|
4
4
|
"description": "Define a SegmentStream workspace app's ontology: entities, relationships, roles and actions, written with Effect.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "SegmentStream",
|