@segmentstream/ontology 0.189.0 → 0.189.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/CHANGELOG.md +9 -0
- package/README.md +3 -0
- package/dist/bin/check.d.ts +5 -0
- package/dist/bin/check.js +7 -0
- package/dist/bin/installed.d.ts +23 -0
- package/dist/bin/installed.js +62 -0
- package/dist/bin/main.d.ts +2 -0
- package/dist/bin.js +16 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.189.1
|
|
4
|
+
|
|
5
|
+
`segmentstream-ontology check` first compares its own release with the one the component's
|
|
6
|
+
`package-lock.json` pins, which a deployment installs. When they differ, as after a `git pull`
|
|
7
|
+
that brings a new lockfile without reinstalling `node_modules`, it checks nothing and says so,
|
|
8
|
+
naming both releases and the reinstall command, such as `npm --prefix ontology ci`. Before, it
|
|
9
|
+
judged the new code by the installed release's rules and could report errors, such as a lower
|
|
10
|
+
limit, that the deployment does not have.
|
|
11
|
+
|
|
3
12
|
## 0.189.0
|
|
4
13
|
|
|
5
14
|
A staff read of a chat may ask for what the agent kept in it for staff.
|
package/README.md
CHANGED
|
@@ -1793,6 +1793,9 @@ npx segmentstream-ontology migrate [entry] # plan and apply the migrat
|
|
|
1793
1793
|
```
|
|
1794
1794
|
|
|
1795
1795
|
- `check` prints errors and warnings on stderr with their paths. It fails on any error.
|
|
1796
|
+
When the folder's `package-lock.json` pins another release of the SDK than the one installed,
|
|
1797
|
+
which a deployment would install instead, `check` judges nothing and names the reinstall
|
|
1798
|
+
command, such as `npm --prefix ontology ci`.
|
|
1796
1799
|
- `migrate` checks the ontology, reads the catalog recorded in the database, plans the
|
|
1797
1800
|
migration and applies it with the planner and applier the deploy pipeline uses. Use
|
|
1798
1801
|
the owner connection string (`ontology_owner`, direct connection) of a Neon development
|
package/dist/bin/check.d.ts
CHANGED
|
@@ -10,6 +10,11 @@ export interface CheckInput {
|
|
|
10
10
|
export interface CheckDependencies {
|
|
11
11
|
readonly load: OntologyLoader;
|
|
12
12
|
readonly output: Output;
|
|
13
|
+
/**
|
|
14
|
+
* Why this SDK must not judge the ontology at an entry, such as another release pinned in the
|
|
15
|
+
* project's lockfile; see `lockedReleaseMismatch`. Without it, nothing is compared.
|
|
16
|
+
*/
|
|
17
|
+
readonly lockedRelease?: (entry: string) => Promise<string | undefined>;
|
|
13
18
|
}
|
|
14
19
|
type Loaded = Extract<LoadResult, {
|
|
15
20
|
readonly _tag: "Loaded";
|
package/dist/bin/check.js
CHANGED
|
@@ -78,6 +78,13 @@ export async function loadCheckedOntology(entry, dependencies) {
|
|
|
78
78
|
*/
|
|
79
79
|
export async function checkCommand(input, dependencies) {
|
|
80
80
|
const { output } = dependencies;
|
|
81
|
+
// Checked by another release than a deployment installs, the ontology could fail on rules the
|
|
82
|
+
// deployment does not have, or pass ones it does.
|
|
83
|
+
const mismatch = await dependencies.lockedRelease?.(input.entry);
|
|
84
|
+
if (mismatch !== undefined) {
|
|
85
|
+
output.stderr(`${mismatch}\n`);
|
|
86
|
+
return EXIT_CODES.failed;
|
|
87
|
+
}
|
|
81
88
|
const loaded = await loadCheckedOntology(input.entry, dependencies);
|
|
82
89
|
if (loaded === undefined) {
|
|
83
90
|
return EXIT_CODES.failed;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** The SDK's name, as a project's package-lock.json lists it. */
|
|
2
|
+
export declare const SDK_PACKAGE = "@segmentstream/ontology";
|
|
3
|
+
/** Reads a file's text, or undefined when there is none. */
|
|
4
|
+
export type ReadText = (path: string) => Promise<string | undefined>;
|
|
5
|
+
/**
|
|
6
|
+
* Why this SDK must not check the ontology at `entry`: its package's package-lock.json pins
|
|
7
|
+
* another release of the SDK, the one a deployment installs. That happens after a pull brings a
|
|
8
|
+
* new lockfile and node_modules is not reinstalled; the check would then judge the ontology by an
|
|
9
|
+
* older or newer release's rules. Undefined when they agree, when the package has no
|
|
10
|
+
* package-lock.json, and for an unreleased build of the SDK (version 0.0.0).
|
|
11
|
+
*/
|
|
12
|
+
export declare function lockedReleaseMismatch(input: {
|
|
13
|
+
readonly entry: string;
|
|
14
|
+
readonly cwd: string;
|
|
15
|
+
/**
|
|
16
|
+
* Where the person or agent ran the command, which the reinstall command is relative to:
|
|
17
|
+
* `npm --prefix ontology run check` runs in ontology/ but is typed above it. Defaults to `cwd`.
|
|
18
|
+
*/
|
|
19
|
+
readonly invokedFrom?: string | undefined;
|
|
20
|
+
/** The version of the SDK running this command. */
|
|
21
|
+
readonly version: string | undefined;
|
|
22
|
+
readonly read: ReadText;
|
|
23
|
+
}): Promise<string | undefined>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
2
|
+
/** The SDK's name, as a project's package-lock.json lists it. */
|
|
3
|
+
export const SDK_PACKAGE = "@segmentstream/ontology";
|
|
4
|
+
function record(value) {
|
|
5
|
+
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
6
|
+
? value
|
|
7
|
+
: undefined;
|
|
8
|
+
}
|
|
9
|
+
function parsed(text) {
|
|
10
|
+
if (text === undefined) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
return record(JSON.parse(text));
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/** The directory of the package that holds the entry: the nearest one with a package.json. */
|
|
21
|
+
async function packageDirectory(entry, read) {
|
|
22
|
+
let directory = dirname(entry);
|
|
23
|
+
for (;;) {
|
|
24
|
+
if ((await read(join(directory, "package.json"))) !== undefined) {
|
|
25
|
+
return directory;
|
|
26
|
+
}
|
|
27
|
+
const parent = dirname(directory);
|
|
28
|
+
if (parent === directory) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
directory = parent;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Why this SDK must not check the ontology at `entry`: its package's package-lock.json pins
|
|
36
|
+
* another release of the SDK, the one a deployment installs. That happens after a pull brings a
|
|
37
|
+
* new lockfile and node_modules is not reinstalled; the check would then judge the ontology by an
|
|
38
|
+
* older or newer release's rules. Undefined when they agree, when the package has no
|
|
39
|
+
* package-lock.json, and for an unreleased build of the SDK (version 0.0.0).
|
|
40
|
+
*/
|
|
41
|
+
export async function lockedReleaseMismatch(input) {
|
|
42
|
+
const { version, read } = input;
|
|
43
|
+
if (version === undefined || version === "0.0.0") {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
const directory = await packageDirectory(resolve(input.cwd, input.entry), read);
|
|
47
|
+
if (directory === undefined) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
const lock = parsed(await read(join(directory, "package-lock.json")));
|
|
51
|
+
const pinned = record(record(lock?.packages)?.[`node_modules/${SDK_PACKAGE}`]);
|
|
52
|
+
const locked = pinned?.version;
|
|
53
|
+
if (typeof locked !== "string" || pinned?.link === true || locked === version) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
const prefix = relative(input.invokedFrom ?? input.cwd, directory) || ".";
|
|
57
|
+
const command = prefix === "." ? "npm ci" : `npm --prefix ${prefix} ci`;
|
|
58
|
+
return (`This command runs ${SDK_PACKAGE} ${version} from node_modules, but ` +
|
|
59
|
+
`${join(prefix, "package-lock.json")} pins ${locked}, which a deployment installs. Their ` +
|
|
60
|
+
`rules can differ, so the ontology was not checked: run \`${command}\` and run the command ` +
|
|
61
|
+
"again.");
|
|
62
|
+
}
|
package/dist/bin/main.d.ts
CHANGED
|
@@ -26,6 +26,8 @@ export interface MainDependencies {
|
|
|
26
26
|
readonly output: Output;
|
|
27
27
|
readonly load: OntologyLoader;
|
|
28
28
|
readonly connect: OwnerConnection;
|
|
29
|
+
/** See `CheckDependencies.lockedRelease`. */
|
|
30
|
+
readonly lockedRelease?: (entry: string) => Promise<string | undefined>;
|
|
29
31
|
}
|
|
30
32
|
/** Runs one command line and returns the process exit code. */
|
|
31
33
|
export declare function runMain(args: ReadonlyArray<string>, dependencies: MainDependencies): Promise<ExitCode>;
|
package/dist/bin.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// The `segmentstream-ontology` binary: wires the process to the commands in ./bin/.
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import { lockedReleaseMismatch } from "./bin/installed.js";
|
|
3
5
|
import { importWithTsx, loadOntology } from "./bin/load.js";
|
|
4
6
|
import { runMain } from "./bin/main.js";
|
|
5
7
|
import { connectOwnerDatabase } from "./bin/migrate.js";
|
|
@@ -20,11 +22,25 @@ function flushed(stream) {
|
|
|
20
22
|
});
|
|
21
23
|
}
|
|
22
24
|
const cwd = process.cwd();
|
|
25
|
+
const readText = (path) => readFile(path, "utf8").catch(() => undefined);
|
|
26
|
+
// This file is dist/bin.js; the package's own package.json carries the released version.
|
|
27
|
+
const sdk = JSON.parse((await readText(new URL("../package.json", import.meta.url))) ?? "{}");
|
|
28
|
+
const version = typeof sdk === "object" && sdk !== null && "version" in sdk && typeof sdk.version === "string"
|
|
29
|
+
? sdk.version
|
|
30
|
+
: undefined;
|
|
23
31
|
const exitCode = await runMain(process.argv.slice(2), {
|
|
24
32
|
environment: process.env,
|
|
25
33
|
output: { stdout: writer(process.stdout), stderr: writer(process.stderr) },
|
|
26
34
|
load: (entry) => loadOntology({ entry, cwd }, importWithTsx),
|
|
27
35
|
connect: connectOwnerDatabase,
|
|
36
|
+
lockedRelease: (entry) => lockedReleaseMismatch({
|
|
37
|
+
entry,
|
|
38
|
+
cwd,
|
|
39
|
+
// npm names the directory a script was started from; see `invokedFrom`.
|
|
40
|
+
invokedFrom: process.env.INIT_CWD,
|
|
41
|
+
version,
|
|
42
|
+
read: readText,
|
|
43
|
+
}),
|
|
28
44
|
});
|
|
29
45
|
await Promise.all([flushed(process.stdout), flushed(process.stderr)]);
|
|
30
46
|
// The ontology's modules may hold timers or sockets open; the command is done.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/ontology",
|
|
3
|
-
"version": "0.189.
|
|
3
|
+
"version": "0.189.1",
|
|
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",
|