@enspirit/opspicy 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +281 -2
- package/bin/entry.js +27 -0
- package/bin/opspicy +19 -0
- package/dist/addresses.js +27 -0
- package/dist/behind.js +64 -0
- package/dist/citizens.js +71 -0
- package/dist/configuration.d.ts +56 -0
- package/dist/configuration.js +66 -0
- package/dist/explorer/afresh.js +43 -0
- package/dist/explorer/api.js +101 -0
- package/dist/explorer/asking.js +59 -0
- package/dist/explorer/build.js +11 -0
- package/dist/explorer/calls.js +42 -0
- package/dist/explorer/document.js +109 -0
- package/dist/explorer/elo-refs.js +153 -0
- package/dist/explorer/elo.js +95 -0
- package/dist/explorer/fonts/OFL.txt +93 -0
- package/dist/explorer/fonts/dm-sans-latin.woff2 +0 -0
- package/dist/explorer/html.js +59 -0
- package/dist/explorer/index.js +61 -0
- package/dist/explorer/json.js +33 -0
- package/dist/explorer/machine.js +34 -0
- package/dist/explorer/masking.js +57 -0
- package/dist/explorer/operation.js +94 -0
- package/dist/explorer/pages.js +132 -0
- package/dist/explorer/script/base.js +103 -0
- package/dist/explorer/script/call.js +161 -0
- package/dist/explorer/script/calling.js +103 -0
- package/dist/explorer/script/connection.js +83 -0
- package/dist/explorer/script/copying.js +75 -0
- package/dist/explorer/script/filter.js +56 -0
- package/dist/explorer/script/formaldef.js +37 -0
- package/dist/explorer/script/main.js +82 -0
- package/dist/explorer/script/markdown.js +143 -0
- package/dist/explorer/script/notes.js +184 -0
- package/dist/explorer/script/noting.js +38 -0
- package/dist/explorer/script/peek.js +62 -0
- package/dist/explorer/script/peeking.js +19 -0
- package/dist/explorer/script/ranking.js +91 -0
- package/dist/explorer/script/review.js +126 -0
- package/dist/explorer/script/rows.js +58 -0
- package/dist/explorer/script/run.js +168 -0
- package/dist/explorer/script/running.js +66 -0
- package/dist/explorer/script/search.js +122 -0
- package/dist/explorer/script/sending.js +64 -0
- package/dist/explorer/script/served.js +51 -0
- package/dist/explorer/serve.js +41 -0
- package/dist/explorer/server.js +143 -0
- package/dist/explorer/site.js +77 -0
- package/dist/explorer/style.css +241 -0
- package/dist/explorer/telling.js +30 -0
- package/dist/explorer/tests.js +78 -0
- package/dist/explorer/wiki.js +76 -0
- package/dist/files.js +176 -0
- package/dist/finding.js +17 -0
- package/dist/judging.js +75 -0
- package/dist/lines.js +30 -0
- package/dist/main.js +128 -0
- package/dist/meaning.js +100 -0
- package/dist/modelling.js +115 -0
- package/dist/naming.js +84 -0
- package/dist/notation.js +119 -0
- package/dist/planning.js +32 -0
- package/dist/reading.js +120 -0
- package/dist/report-file.js +42 -0
- package/dist/report.js +62 -0
- package/dist/running.js +102 -0
- package/dist/selecting.js +71 -0
- package/dist/starting.js +41 -0
- package/dist/suite.js +29 -0
- package/dist/words.js +103 -0
- package/dist/world.js +128 -0
- package/package.json +57 -4
package/dist/world.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// What a suite does to the world and sees of it: it sets a Background, calls the front door as
|
|
2
|
+
// somebody, and observes. Everything that specifies anything goes through the front door; the
|
|
3
|
+
// Background is set as the configuration says; the relations are read from the database,
|
|
4
|
+
// behind the front door, and never written.
|
|
5
|
+
import pg from 'pg';
|
|
6
|
+
import { Unrunnable } from './finding.js';
|
|
7
|
+
function remember(jar, cookies) {
|
|
8
|
+
for (const cookie of cookies) {
|
|
9
|
+
const [name = '', ...value] = (cookie.split(';')[0] ?? '').split('=');
|
|
10
|
+
if (value.join('='))
|
|
11
|
+
jar.set(name.trim(), value.join('='));
|
|
12
|
+
else
|
|
13
|
+
jar.delete(name.trim());
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
async function bodyOf(response) {
|
|
17
|
+
const told = await response.text();
|
|
18
|
+
const type = response.headers.get('content-type') ?? '';
|
|
19
|
+
if (!type.includes('json'))
|
|
20
|
+
return type.startsWith('text/') ? told : null;
|
|
21
|
+
try {
|
|
22
|
+
return JSON.parse(told);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** A browser nobody is signed in on, calling from an origin when the system is told one. */
|
|
29
|
+
export function browser({ api, originHeader }, origin, hears) {
|
|
30
|
+
const jar = new Map();
|
|
31
|
+
const call = async (method, path, body) => {
|
|
32
|
+
const headers = { cookie: [...jar].map(([name, value]) => `${name}=${value}`).join('; ') };
|
|
33
|
+
if (originHeader)
|
|
34
|
+
headers[originHeader] = origin;
|
|
35
|
+
if (body !== undefined)
|
|
36
|
+
headers['content-type'] = 'application/json';
|
|
37
|
+
const started = Date.now();
|
|
38
|
+
const response = await fetch(`${api}${path}`, { method, headers, body: body === undefined ? undefined : JSON.stringify(body), redirect: 'manual' });
|
|
39
|
+
remember(jar, response.headers.getSetCookie());
|
|
40
|
+
const answer = { status: response.status, body: await bodyOf(response) };
|
|
41
|
+
hears?.({ method, path, sent: body, ...answer, ms: Date.now() - started });
|
|
42
|
+
return answer;
|
|
43
|
+
};
|
|
44
|
+
return { call };
|
|
45
|
+
}
|
|
46
|
+
/** The browser of an actor: signed in when they have something to sign in with, as a visitor's otherwise. */
|
|
47
|
+
export async function browserOf(config, origin, name, actor, hears) {
|
|
48
|
+
const theirs = browser(config, origin, hears);
|
|
49
|
+
if (actor)
|
|
50
|
+
await signedIn(config, theirs, actor, name);
|
|
51
|
+
return theirs;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Signs somebody in, as the configuration does it. What it throws when they cannot is not told:
|
|
55
|
+
* it was written for who wrote the configuration, and may hold what the actor signs in with or
|
|
56
|
+
* what the system answered. The call itself is on the wire, with its status, for who asks to see.
|
|
57
|
+
*/
|
|
58
|
+
async function signedIn(config, theirs, actor, name) {
|
|
59
|
+
try {
|
|
60
|
+
await config.signIn(theirs, actor, name);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
throw new Unrunnable(`"${name}" could not be signed in`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** The database, to read and nothing else. */
|
|
67
|
+
export async function reader(url) {
|
|
68
|
+
const client = new pg.Client({ connectionString: url, options: '-c default_transaction_read_only=on' });
|
|
69
|
+
await client.connect();
|
|
70
|
+
// A connection that drops while nothing is asked of it says so to whoever listens, and stops the
|
|
71
|
+
// run where it stands when nobody does. It is heard, and told by what is next asked of it: a
|
|
72
|
+
// case that could not be run.
|
|
73
|
+
client.on('error', () => { });
|
|
74
|
+
return client;
|
|
75
|
+
}
|
|
76
|
+
const pause = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
77
|
+
/**
|
|
78
|
+
* Waits for the server to have nothing under way, as the configuration tells it. Some
|
|
79
|
+
* operations start work that outlives their answer: seen at rest twice in a row, since such
|
|
80
|
+
* work may begin a moment after the answer.
|
|
81
|
+
*/
|
|
82
|
+
export async function atRest({ config, database }, forMs = 15_000) {
|
|
83
|
+
if (!database || !config.atRest)
|
|
84
|
+
return;
|
|
85
|
+
const ask = async (sql) => (await database.query(sql)).rows;
|
|
86
|
+
const until = Date.now() + forMs;
|
|
87
|
+
let seenAtRest = 0;
|
|
88
|
+
while (seenAtRest < 2) {
|
|
89
|
+
if (Date.now() > until)
|
|
90
|
+
throw new Unrunnable('the server still has work under way');
|
|
91
|
+
seenAtRest = (await config.atRest(ask)) ? seenAtRest + 1 : 0;
|
|
92
|
+
if (seenAtRest < 2)
|
|
93
|
+
await pause(25);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async function tuples(database, { table, key, attributes }) {
|
|
97
|
+
const { rows } = await database.query(`SELECT ${[...key, ...attributes].join(', ')} FROM ${table} ORDER BY ${key.join(', ')}`);
|
|
98
|
+
return JSON.parse(JSON.stringify(rows));
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* What a route of the state tells somebody: what it answers, and nothing where it refuses them.
|
|
102
|
+
* A route that fails (a 5xx) refused nobody and told nothing: read as nothing, "nothing changed"
|
|
103
|
+
* would hold of a system that is broken, before and after. The state was not observed, and the
|
|
104
|
+
* case cannot be judged.
|
|
105
|
+
*/
|
|
106
|
+
export function toldBy({ name, path }, answer) {
|
|
107
|
+
if (answer.status >= 500)
|
|
108
|
+
throw new Unrunnable(`the state "${name}" could not be observed: GET ${path} answered ${answer.status}`);
|
|
109
|
+
return answer.status === 200 ? answer.body : null;
|
|
110
|
+
}
|
|
111
|
+
/** What one browser is told by the routes of the state. */
|
|
112
|
+
async function seenBy(model, theirs) {
|
|
113
|
+
const seen = {};
|
|
114
|
+
for (const one of model.state)
|
|
115
|
+
seen[one.name] = toldBy(one, await theirs.call('GET', one.path));
|
|
116
|
+
return seen;
|
|
117
|
+
}
|
|
118
|
+
/** The state, now: as the requester sees it, as the witnesses do, and the relations of the database. */
|
|
119
|
+
export async function observe(reach, model, requester, witnesses) {
|
|
120
|
+
const state = await seenBy(model, requester);
|
|
121
|
+
const others = {};
|
|
122
|
+
for (const [name, theirs] of Object.entries(witnesses))
|
|
123
|
+
others[name] = await seenBy(model, theirs);
|
|
124
|
+
const db = {};
|
|
125
|
+
for (const relation of model.relations)
|
|
126
|
+
db[relation.name] = reach.database && reach.relations ? await tuples(reach.database, relation) : null;
|
|
127
|
+
return { ...state, seenBy: others, db };
|
|
128
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enspirit/opspicy",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "Specifies the operations of a system by their clauses, as sentences that Elo gives a meaning, and runs them black-box",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/enspirit/opspicy.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/enspirit/opspicy",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/enspirit/opspicy/issues"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=22.18"
|
|
17
|
+
},
|
|
18
|
+
"bin": {
|
|
19
|
+
"opspicy": "bin/opspicy"
|
|
20
|
+
},
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/configuration.d.ts",
|
|
24
|
+
"default": "./dist/configuration.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"bin",
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
36
|
+
"test": "node --test --test-reporter=spec \"test/*.test.ts\"",
|
|
37
|
+
"test:browser": "node --test --test-reporter=spec \"test/browser/*.test.ts\"",
|
|
38
|
+
"test:package": "node --test --test-reporter=spec \"test/package/*.test.ts\"",
|
|
39
|
+
"build": "node build.ts",
|
|
40
|
+
"prepack": "npm run build",
|
|
41
|
+
"example": "node example/keeper.ts"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@enspirit/elo": "1.2.4",
|
|
45
|
+
"@enspirit/elo-form": "0.3.0",
|
|
46
|
+
"@enspirit/highlightjs-elo": "1.0.0",
|
|
47
|
+
"highlight.js": "11.12.0",
|
|
48
|
+
"luxon": "3.7.2",
|
|
49
|
+
"pg": "8.23.1",
|
|
50
|
+
"yaml": "2.9.1"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@types/luxon": "3.7.6",
|
|
54
|
+
"@types/node": "22.20.7",
|
|
55
|
+
"@types/pg": "8.23.1",
|
|
56
|
+
"playwright-core": "1.65.1",
|
|
57
|
+
"typescript": "7.0.2"
|
|
58
|
+
}
|
|
59
|
+
}
|