@yaks/host 0.0.0-stage → 0.2.36
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 +202 -0
- package/README.md +306 -2
- package/_dist/anatomy.d.ts +35 -0
- package/_dist/anatomy.d.ts.map +1 -0
- package/_dist/assembly.d.ts +94 -0
- package/_dist/assembly.d.ts.map +1 -0
- package/_dist/config.d.ts +150 -0
- package/_dist/config.d.ts.map +1 -0
- package/_dist/documents.d.ts +9 -0
- package/_dist/documents.d.ts.map +1 -0
- package/_dist/facets.d.ts +164 -0
- package/_dist/facets.d.ts.map +1 -0
- package/_dist/keepers.d.ts +15 -0
- package/_dist/keepers.d.ts.map +1 -0
- package/_dist/keywords.d.ts +3 -0
- package/_dist/keywords.d.ts.map +1 -0
- package/_dist/lending.d.ts +34 -0
- package/_dist/lending.d.ts.map +1 -0
- package/_dist/mod.d.ts +260 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/payments.d.ts +501 -0
- package/_dist/payments.d.ts.map +1 -0
- package/_dist/roles.d.ts +10 -0
- package/_dist/roles.d.ts.map +1 -0
- package/_dist/senders.d.ts +180 -0
- package/_dist/senders.d.ts.map +1 -0
- package/_dist/words.d.ts +27 -0
- package/_dist/words.d.ts.map +1 -0
- package/anatomy.js +432 -0
- package/anatomy.js.map +1 -0
- package/anatomy.ts +439 -0
- package/assembly.js +737 -0
- package/assembly.js.map +1 -0
- package/assembly.ts +930 -0
- package/config.js +149 -0
- package/config.js.map +1 -0
- package/config.ts +287 -0
- package/deno.json +1 -0
- package/documents.js +80 -0
- package/documents.js.map +1 -0
- package/documents.ts +105 -0
- package/facets.js +2 -0
- package/facets.js.map +1 -0
- package/facets.ts +236 -0
- package/keepers.js +7 -0
- package/keepers.js.map +1 -0
- package/keepers.ts +17 -0
- package/keywords.js +24 -0
- package/keywords.js.map +1 -0
- package/keywords.ts +25 -0
- package/lending.js +46 -0
- package/lending.js.map +1 -0
- package/lending.ts +77 -0
- package/mod.js +5 -0
- package/mod.js.map +1 -0
- package/mod.ts +356 -0
- package/package.json +79 -4
- package/payments.js +66 -0
- package/payments.js.map +1 -0
- package/payments.ts +665 -0
- package/roles.js +22 -0
- package/roles.js.map +1 -0
- package/roles.ts +18 -0
- package/senders.js +58 -0
- package/senders.js.map +1 -0
- package/senders.ts +272 -0
- package/words.js +134 -0
- package/words.js.map +1 -0
- package/words.ts +210 -0
package/facets.ts
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/** The subpaths a plugin contributes to a composed graph. */
|
|
2
|
+
import type {
|
|
3
|
+
Arrived,
|
|
4
|
+
Authenticate,
|
|
5
|
+
Filter,
|
|
6
|
+
Handler,
|
|
7
|
+
Offers,
|
|
8
|
+
Route,
|
|
9
|
+
Told,
|
|
10
|
+
} from 'jsr:@yaks/api@0.2.36'
|
|
11
|
+
import type { Eid, Plugin } from 'jsr:@yaks/graph@0.2.36'
|
|
12
|
+
import type { Backings, Derived, Extension, History, Stmt } from 'jsr:@yaks/sql@0.2.36'
|
|
13
|
+
import type { Handlers } from 'jsr:@yaks/effects@0.2.36'
|
|
14
|
+
import type { Reply } from 'jsr:@yaks/tools@0.2.36'
|
|
15
|
+
import type { Runs } from 'jsr:@yaks/graph@0.2.36/tools'
|
|
16
|
+
import type { Contributions } from 'jsr:@yaks/ui@0.2.36/contributions'
|
|
17
|
+
import type { Keywords, Vocab, VocabDoc } from 'jsr:@yaks/vocab@0.2.36'
|
|
18
|
+
import type { Embedding, Feed, Host } from './mod.ts'
|
|
19
|
+
import type {
|
|
20
|
+
Arrival,
|
|
21
|
+
Chatter,
|
|
22
|
+
MailDomains,
|
|
23
|
+
Notices,
|
|
24
|
+
Sender,
|
|
25
|
+
Texter,
|
|
26
|
+
} from './senders.ts'
|
|
27
|
+
import type { Payments } from './payments.ts'
|
|
28
|
+
import type { Keeper } from './keepers.ts'
|
|
29
|
+
import type { Options } from './config.ts'
|
|
30
|
+
/** `<plugin>/vocab` — what the plugin declares, and nothing that could not
|
|
31
|
+
* run in a browser tab: a page importing this must never reach SQL, a database
|
|
32
|
+
* driver or a server runtime. */
|
|
33
|
+
export type VocabFacet = {
|
|
34
|
+
/** what the plugin is: its package's own description, from its package.json,
|
|
35
|
+
* written on each of its documents beside its name */
|
|
36
|
+
description?: string
|
|
37
|
+
/** the components and tools this plugin declares */
|
|
38
|
+
docs?: VocabDoc[]
|
|
39
|
+
/** the JSON Schema keywords those documents use (@yaks/vocab `loadVocab`) */
|
|
40
|
+
keywords?: Keywords[]
|
|
41
|
+
/** properties the store computes rather than stores, written as SQL */
|
|
42
|
+
derived?: (vocab: Vocab) => Derived
|
|
43
|
+
/** the rows each computed component this plugin declares is read from
|
|
44
|
+
* (@yaks/sql `Backing`), given the store's read overrides */
|
|
45
|
+
backed?: (vocab: Vocab, derived: Derived) => Backings
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** `<plugin>/graph` — what a write means, what a query may ask for, and who
|
|
49
|
+
* is writing. `schema` says, as data, the tables of its own the plugin's store
|
|
50
|
+
* needs, which a writing host adds with the rest of its composed schema
|
|
51
|
+
* (@yaks/sqlite `follow`); `plugins` binds hooks without changing storage. `extend` contributes the clause
|
|
52
|
+
* compilers every read path consults (@yaks/sql `Extension`), which is how a
|
|
53
|
+
* package holding an index of its own — a text search, a vector, a link table
|
|
54
|
+
* — can answer a clause the compiler would otherwise reject.
|
|
55
|
+
*
|
|
56
|
+
* `authenticate` names the caller behind a request, for every door over this
|
|
57
|
+
* graph: a command line asks it about the session it speaks for exactly as an
|
|
58
|
+
* HTTP request is asked (the concrete host's signer), so it belongs to the graph role
|
|
59
|
+
* rather than to the routes. It is a factory like every other plugin export,
|
|
60
|
+
* because naming a caller is a read: @yaks/session resolves a request to the
|
|
61
|
+
* session it claims to speak for, which it can only do through the host's own
|
|
62
|
+
* graph. It is handed the host with nothing open on it yet — keep the
|
|
63
|
+
* reference, do not call it. At most one plugin may answer it. */
|
|
64
|
+
export type GraphFacet = {
|
|
65
|
+
/** The statements creating this plugin's own tables, each of which only adds
|
|
66
|
+
* what is missing; a table that stands gains the columns it lacks. */
|
|
67
|
+
schema?: (host: Host, options: Options) => Stmt[]
|
|
68
|
+
plugins?: (host: Host, options: Options) => Plugin[]
|
|
69
|
+
/** Bundles owed to a caller beside the answer to a direct tool call. */
|
|
70
|
+
reply?: (host: Host, options: Options) => Reply
|
|
71
|
+
extend?: (host: Host, options: Options) => Extension[]
|
|
72
|
+
/** Search a phrase by meaning through this plugin's own index. */
|
|
73
|
+
meaning?: (host: Host, options: Options) => Meaning
|
|
74
|
+
/** Read into memory what this plugin's reads would otherwise read from
|
|
75
|
+
* disk each time, for a process that answers many reads
|
|
76
|
+
* ({@link Host.preload}): @yaks/embedding's vectors. */
|
|
77
|
+
preload?: (host: Host, options: Options) => () => void | Promise<void>
|
|
78
|
+
/** The mail senders this plugin lends, by name ({@link Host.senders}): a
|
|
79
|
+
* provider's, built from its options. One name has one sender. */
|
|
80
|
+
senders?: (host: Host, options: Options) => Record<string, Sender>
|
|
81
|
+
/** The texters this plugin lends, by name ({@link Host.texters}). */
|
|
82
|
+
texters?: (host: Host, options: Options) => Record<string, Texter>
|
|
83
|
+
/** The chatters this plugin lends, by platform ({@link Host.chatters}). */
|
|
84
|
+
chatters?: (host: Host, options: Options) => Record<string, Chatter>
|
|
85
|
+
/** The embedders this plugin lends, by name ({@link Host.embedders}). */
|
|
86
|
+
embedders?: (host: Host, options: Options) => Record<string, Embedding>
|
|
87
|
+
/** The keepers this plugin lends, by name ({@link Host.keepers}). */
|
|
88
|
+
keepers?: (host: Host, options: Options) => Record<string, Keeper>
|
|
89
|
+
/** The readers of a provider's signed notices about the letters it
|
|
90
|
+
* carried, by name, for a host that routes them itself (./lending.ts). */
|
|
91
|
+
notices?: (host: Host, options: Options) => Record<string, Notices>
|
|
92
|
+
/** The readers of a letter a runtime handed its host, by name, for a host
|
|
93
|
+
* that receives one itself (./lending.ts). */
|
|
94
|
+
arrivals?: (host: Host, options: Options) => Record<string, Arrival>
|
|
95
|
+
/** The mail domains this plugin's provider sets up, reads and removes, by
|
|
96
|
+
* name, for a host that gives its people mail at their own domains
|
|
97
|
+
* (./lending.ts). */
|
|
98
|
+
mailDomains?: (host: Host, options: Options) => Record<string, MailDomains>
|
|
99
|
+
/** The payment providers this plugin lends, by name, for a host that takes
|
|
100
|
+
* money itself (./payments.ts). */
|
|
101
|
+
payments?: (host: Host, options: Options) => Record<string, Payments>
|
|
102
|
+
/** who a request is from, or none where these options name nobody to ask */
|
|
103
|
+
authenticate?: (host: Host, options: Options) => Authenticate | undefined
|
|
104
|
+
/** the commits other hosts make to this store (@yaks/journal's feed), or
|
|
105
|
+
* none where these options keep no feed */
|
|
106
|
+
feed?: (host: Host, options: Options) => Feed | undefined
|
|
107
|
+
/** Whether a store this plugin writes to, configured with `options`, is
|
|
108
|
+
* shaped so that only this plugin reads or writes it correctly from then
|
|
109
|
+
* on. A writing host records it in the store, and a host whose config leaves
|
|
110
|
+
* the plugin out refuses to open the store (./config.ts `meet`). */
|
|
111
|
+
required?: (options: Options) => boolean
|
|
112
|
+
/** What the store keeps every version a write replaces with, where this
|
|
113
|
+
* plugin's options ask it to (@yaks/journal's versions). Asked before the
|
|
114
|
+
* store is opened; at most one plugin answers. */
|
|
115
|
+
history?: (options: Options) => History | undefined
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** A result from a plugin's meaning index, with an excerpt of its source. */
|
|
119
|
+
export type MeaningHit = {
|
|
120
|
+
entity: Eid
|
|
121
|
+
similarity: number
|
|
122
|
+
excerpt: string
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Words → the entities nearest them in meaning, closest first, at most
|
|
126
|
+
* `limit` of them. `within` is a filter line naming the entities a hit must be
|
|
127
|
+
* among; its directives are ignored. */
|
|
128
|
+
export type Meaning = (
|
|
129
|
+
words: string,
|
|
130
|
+
opts?: { limit?: number; within?: string },
|
|
131
|
+
) => Promise<MeaningHit[]>
|
|
132
|
+
|
|
133
|
+
/** `<plugin>/tools` — the functions behind its `tool: true` declarations,
|
|
134
|
+
* keyed by tool name.
|
|
135
|
+
*
|
|
136
|
+
* A factory, like every other plugin export, because a tool function needs the
|
|
137
|
+
* same things the others do: a check over a package's own SQL table reaches it
|
|
138
|
+
* through `host.storage` (@yaks/sqlite's storage scan, @yaks/embedding's vector
|
|
139
|
+
* index), and a threshold or a relation name belongs in the config, not the
|
|
140
|
+
* code. What a tool function is handed per call — the graph, the caller, the
|
|
141
|
+
* arguments — still arrives on the tool context. */
|
|
142
|
+
export type ToolsFacet = { runs?: (host: Host, options: Options) => Runs }
|
|
143
|
+
|
|
144
|
+
/** `<plugin>/effects` — the code behind effects the composed vocabulary
|
|
145
|
+
* declares (`effect: true`), keyed by the name each is declared under. A mail
|
|
146
|
+
* sender, a process launcher: what an effect acts on is named in this
|
|
147
|
+
* plugin's options. Usually the code is the declaring plugin's own; a plugin
|
|
148
|
+
* may instead handle one another declares, lending what only it has (the
|
|
149
|
+
* machine a transcript's run is given, @yaks/harness). Each effect has one
|
|
150
|
+
* handler, and a declared effect this process gives no code owes no run. */
|
|
151
|
+
export type EffectsFacet = {
|
|
152
|
+
effects?: (host: Host, options: Options) => Handlers
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** `<plugin>/routes` — the HTTP a plugin adds, and, for the one plugin that
|
|
156
|
+
* hosts them, what answers a request at all.
|
|
157
|
+
*
|
|
158
|
+
* `handler` is exported by at most one plugin per host; it is called last,
|
|
159
|
+
* with the graph open and `host.routes` holding every listed plugin's routes,
|
|
160
|
+
* and what it returns is {@link Host.handler}. @yaks/api is that plugin, so a
|
|
161
|
+
* config naming it serves HTTP and a config leaving it out has a host that
|
|
162
|
+
* answers no request and never asks the others for routes. */
|
|
163
|
+
export type RoutesFacet = {
|
|
164
|
+
routes?: (host: Host, options: Options) => Route[]
|
|
165
|
+
/** a check every request passes before any route answers it; a plugin's
|
|
166
|
+
* word on which requests reach this host at all (@yaks/tunnel's link) */
|
|
167
|
+
filter?: (host: Host, options: Options) => Filter
|
|
168
|
+
/** who a request that came through this plugin's link is from, asked
|
|
169
|
+
* before the graph's own `authenticate` ({@link Host.who}) */
|
|
170
|
+
arrived?: (host: Host, options: Options) => Arrived
|
|
171
|
+
/** the tools a request that came through this plugin's link is offered
|
|
172
|
+
* ({@link Host.offers}) */
|
|
173
|
+
offers?: (host: Host, options: Options) => Offers
|
|
174
|
+
/** what a request that came through this plugin's link is told before a
|
|
175
|
+
* door's own instructions ({@link Host.told}) */
|
|
176
|
+
told?: (host: Host, options: Options) => Told
|
|
177
|
+
handler?: (host: Host, options: Options) => Handler
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** One duty that exactly one process at a time runs: the lease name
|
|
181
|
+
* to hold it under, and the work. `run` does at least one pass and then keeps
|
|
182
|
+
* going until the signal aborts — a loop on a timer, or a single pass followed
|
|
183
|
+
* by a wait — so the lease stays this process's for as long as it is up. */
|
|
184
|
+
export type Duty = {
|
|
185
|
+
/** the lease name it is held under: the package that owns the work */
|
|
186
|
+
name: string
|
|
187
|
+
run: (signal: AbortSignal) => void | Promise<void>
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** `<plugin>/service` — the work this plugin keeps doing while a process
|
|
191
|
+
* serving that plugin's role is up: a timer, a poll, a sweep. It is neither a
|
|
192
|
+
* request nor what a commit owes, which is why neither `routes` nor `effects`
|
|
193
|
+
* could hold it: a scheduled wake coming due, and a mailbox that has to be
|
|
194
|
+
* polled, are things nobody is calling about.
|
|
195
|
+
*
|
|
196
|
+
* It does at least one pass and then keeps going until the signal aborts, so
|
|
197
|
+
* one function serves a process of either shape: a server holds it open for as
|
|
198
|
+
* long as it is up, and a one-shot command hands it a signal that has already
|
|
199
|
+
* aborted and gets the single pass. Of the processes serving that role over
|
|
200
|
+
* one graph, which one is doing it is settled by a lease
|
|
201
|
+
* ({@link Host.duties}). */
|
|
202
|
+
export type ServiceFacet = {
|
|
203
|
+
service?: (
|
|
204
|
+
host: Host,
|
|
205
|
+
options: Options,
|
|
206
|
+
signal: AbortSignal,
|
|
207
|
+
) => void | Promise<void>
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** What each subpath a role imports is expected to export. Every field is
|
|
211
|
+
* optional: a plugin exports what it has, and the host uses what it finds. */
|
|
212
|
+
export type Facets = {
|
|
213
|
+
vocab: VocabFacet
|
|
214
|
+
graph: GraphFacet
|
|
215
|
+
tools: ToolsFacet
|
|
216
|
+
effects: EffectsFacet
|
|
217
|
+
ui: Contributions
|
|
218
|
+
routes: RoutesFacet
|
|
219
|
+
service: ServiceFacet
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** How one of a plugin's subpaths becomes a module. `null` means the package
|
|
223
|
+
* does not export that subpath. Injectable, so a test can assemble a host from
|
|
224
|
+
* modules it wrote inline rather than files on disk. */
|
|
225
|
+
export type FacetName = keyof Facets
|
|
226
|
+
|
|
227
|
+
export type Load<Extra extends object = Record<never, never>> = {
|
|
228
|
+
<F extends keyof (Facets & Extra)>(
|
|
229
|
+
plugin: string,
|
|
230
|
+
facet: F,
|
|
231
|
+
): Promise<(Facets & Extra)[F] | null>
|
|
232
|
+
/** Import exactly the selected facets in one dependency graph, if supported. */
|
|
233
|
+
together?: (
|
|
234
|
+
requests: readonly (readonly [string, keyof (Facets & Extra)])[],
|
|
235
|
+
) => Promise<unknown>
|
|
236
|
+
}
|
package/keepers.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Where a key goes besides the graph's own vault: a keeper puts a value at
|
|
2
|
+
* one of its own places (a password manager's item, a Worker's secret). A
|
|
3
|
+
* plugin lends one by name, and whoever asks for a key names the keepers and
|
|
4
|
+
* places it goes to as data (@yaks/connections `connection.keep`). The host
|
|
5
|
+
* owns the keeper's own credentials. */ /** One place a key is kept, as an ask names it: the keeper's name, and the
|
|
6
|
+
* keeper's own address for the key there. */
|
|
7
|
+
//# sourceMappingURL=keepers.js.map
|
package/keepers.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keepers.js","sources":["./keepers.ts"],"names":[],"mappings":"AAAA;;;;sCAIsC,GAEtC;2CAC2C,GAC3C"}
|
package/keepers.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Where a key goes besides the graph's own vault: a keeper puts a value at
|
|
2
|
+
* one of its own places (a password manager's item, a Worker's secret). A
|
|
3
|
+
* plugin lends one by name, and whoever asks for a key names the keepers and
|
|
4
|
+
* places it goes to as data (@yaks/connections `connection.keep`). The host
|
|
5
|
+
* owns the keeper's own credentials. */
|
|
6
|
+
|
|
7
|
+
/** One place a key is kept, as an ask names it: the keeper's name, and the
|
|
8
|
+
* keeper's own address for the key there. */
|
|
9
|
+
export type Place = { via: string; at: string }
|
|
10
|
+
|
|
11
|
+
/** Puts a value at a place of its own, resolving once it is there and
|
|
12
|
+
* rejecting with why it is not. Putting the same value again is harmless. */
|
|
13
|
+
export type Keeper = {
|
|
14
|
+
keep: (at: string, value: string) => Promise<void>
|
|
15
|
+
/** Why it cannot keep anything yet, such as its own credential not set. */
|
|
16
|
+
waiting?: () => string | undefined
|
|
17
|
+
}
|
package/keywords.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// The keywords every host understands whether or not a plugin brings them: the
|
|
2
|
+
// property that is a name somebody may type (`by_name`, @yaks/names), and the
|
|
3
|
+
// relation an edge states (`edge`, @yaks/edge), with the id vocabulary's URI
|
|
4
|
+
// (@yaks/id). Every package uses them in its `$vocabulary`, none registers them,
|
|
5
|
+
// and an unregistered keyword is silently ignored. Registering the keywords
|
|
6
|
+
// that shape what a host draws is a host's doing: a graph this process composed
|
|
7
|
+
// (@yaks/host), and a vocabulary a server reported to draw its answers with (the
|
|
8
|
+
// caller's renderer). A plugin that supplies its own copy wins; this adds only
|
|
9
|
+
// the difference, never a second registration.
|
|
10
|
+
import { edgeKeywords } from "@yaks/edge/vocab";
|
|
11
|
+
import { idKeywords } from "@yaks/id/vocab";
|
|
12
|
+
import { nameKeywords } from "@yaks/names";
|
|
13
|
+
/** The keywords brought, and the ones every host understands beside them. */ export let understood = (brought = [])=>{
|
|
14
|
+
let taken = new Set(brought.map((k)=>k.uri));
|
|
15
|
+
return [
|
|
16
|
+
...brought,
|
|
17
|
+
...[
|
|
18
|
+
idKeywords,
|
|
19
|
+
nameKeywords,
|
|
20
|
+
edgeKeywords
|
|
21
|
+
].filter((k)=>!taken.has(k.uri))
|
|
22
|
+
];
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=keywords.js.map
|
package/keywords.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keywords.js","sources":["./keywords.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,8EAA8E;AAC9E,6EAA6E;AAC7E,iFAAiF;AACjF,4EAA4E;AAC5E,gFAAgF;AAChF,iFAAiF;AACjF,+EAA+E;AAC/E,+CAA+C;AAE/C,SAAS,YAAY,gCAAqC;AAC1D,SAAS,UAAU,8BAAmC;AACtD,SAAS,YAAY,2BAAgC;AAGrD,2EAA2E,GAC3E,OAAO,IAAI,aAAa,CAAC,UAAsB,EAAE;EAC/C,IAAI,QAAQ,IAAI,IAAI,QAAQ,GAAG,CAAC,CAAC,IAAM,EAAE,GAAG;EAC5C,OAAO;OACF;OACA;MAAC;MAAY;MAAc;KAAa,CAAC,MAAM,CAAC,CAAC,IAClD,CAAC,MAAM,GAAG,CAAC,EAAE,GAAG;GAEnB;AACH,EAAC"}
|
package/keywords.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// The keywords every host understands whether or not a plugin brings them: the
|
|
2
|
+
// property that is a name somebody may type (`by_name`, @yaks/names), and the
|
|
3
|
+
// relation an edge states (`edge`, @yaks/edge), with the id vocabulary's URI
|
|
4
|
+
// (@yaks/id). Every package uses them in its `$vocabulary`, none registers them,
|
|
5
|
+
// and an unregistered keyword is silently ignored. Registering the keywords
|
|
6
|
+
// that shape what a host draws is a host's doing: a graph this process composed
|
|
7
|
+
// (@yaks/host), and a vocabulary a server reported to draw its answers with (the
|
|
8
|
+
// caller's renderer). A plugin that supplies its own copy wins; this adds only
|
|
9
|
+
// the difference, never a second registration.
|
|
10
|
+
|
|
11
|
+
import { edgeKeywords } from '@yaks/edge/vocab'
|
|
12
|
+
import { idKeywords } from '@yaks/id/vocab'
|
|
13
|
+
import { nameKeywords } from '@yaks/names'
|
|
14
|
+
import type { Keywords } from 'jsr:@yaks/vocab@0.2.36'
|
|
15
|
+
|
|
16
|
+
/** The keywords brought, and the ones every host understands beside them. */
|
|
17
|
+
export let understood = (brought: Keywords[] = []): Keywords[] => {
|
|
18
|
+
let taken = new Set(brought.map((k) => k.uri))
|
|
19
|
+
return [
|
|
20
|
+
...brought,
|
|
21
|
+
...[idKeywords, nameKeywords, edgeKeywords].filter((k) =>
|
|
22
|
+
!taken.has(k.uri)
|
|
23
|
+
),
|
|
24
|
+
]
|
|
25
|
+
}
|
package/lending.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// What plugins lend a host by name, beside what the host lends itself: mail
|
|
2
|
+
// senders, texters, chatters, embedders and keepers, which a graph host passes on
|
|
3
|
+
// (Host.senders, Host.texters, Host.chatters, Host.embedders, Host.keepers), and a provider's notice and
|
|
4
|
+
// arrival readers and a payment provider (./payments.ts), which a host that
|
|
5
|
+
// routes mail or takes money itself asks for, such as a Worker naming its
|
|
6
|
+
// providers in config. One party per name: a letter or a vector made through a name two
|
|
7
|
+
// parties answer to would depend on order.
|
|
8
|
+
import { CallError } from "@yaks/tools/errors";
|
|
9
|
+
/** The loans of one kind the graph facets make, beside the host's own
|
|
10
|
+
* `lent`, or `lent` itself where no plugin makes one. A name lent twice is
|
|
11
|
+
* refused.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { lending } from '@yaks/host/lending'
|
|
15
|
+
* import { equal, throws } from '@yaks/testing'
|
|
16
|
+
*
|
|
17
|
+
* let sender = { send: () => Promise.resolve({}) }
|
|
18
|
+
* let lends = { senders: () => ({ post: sender }) }
|
|
19
|
+
* equal(Object.keys(lending([[lends, {}, '@a/post']], {}, 'senders')!), ['post'])
|
|
20
|
+
* throws(
|
|
21
|
+
* () => lending([[lends, {}, '@a/post']], {}, 'senders', { post: sender }),
|
|
22
|
+
* 'the sender post is lent by both the host and @a/post',
|
|
23
|
+
* )
|
|
24
|
+
* ```
|
|
25
|
+
*/ export let lending = (graphs, host, kind, lent)=>{
|
|
26
|
+
let what = kind.slice(0, -1);
|
|
27
|
+
let by = new Map(Object.keys(lent ?? {}).map((name)=>[
|
|
28
|
+
name,
|
|
29
|
+
'the host'
|
|
30
|
+
]));
|
|
31
|
+
let all = {
|
|
32
|
+
...lent
|
|
33
|
+
};
|
|
34
|
+
for (let [r, options, plugin] of graphs){
|
|
35
|
+
let made = r[kind]?.(host, options);
|
|
36
|
+
for (let [name, one] of Object.entries(made ?? {})){
|
|
37
|
+
if (by.has(name)) {
|
|
38
|
+
throw new CallError('config', `the ${what} ${name} is lent by both ${by.get(name)} and ${plugin}`);
|
|
39
|
+
}
|
|
40
|
+
by.set(name, plugin);
|
|
41
|
+
all[name] = one;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return by.size ? all : lent;
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=lending.js.map
|
package/lending.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lending.js","sources":["./lending.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,kFAAkF;AAClF,yGAAyG;AACzG,4EAA4E;AAC5E,0EAA0E;AAC1E,wFAAwF;AACxF,2CAA2C;AAC3C,SAAS,SAAS,kCAAuC;AA2BzD;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,IAAI,UAAU,CACnB,QACA,MACA,MACA;EAEA,IAAI,OAAO,KAAK,KAAK,CAAC,GAAG,CAAC;EAC1B,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,GAAG,CAAC,CAAC,OAAS;MAAC;MAAM;KAAW;EACzE,IAAI,MAAgC;IAAE,GAAG,IAAI;EAAC;EAC9C,KAAK,IAAI,CAAC,GAAG,SAAS,OAAO,IAAI,OAAQ;IACvC,IAAI,OAAO,CAAC,CAAC,KAAK,GAAG,MAAc;IAGnC,KAAK,IAAI,CAAC,MAAM,IAAI,IAAI,OAAO,OAAO,CAAC,QAAQ,CAAC,GAAI;MAClD,IAAI,GAAG,GAAG,CAAC,OAAO;QAChB,MAAM,IAAI,UACR,UACA,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,KAAK,iBAAiB,EAAE,GAAG,GAAG,CAAC,MAAM,KAAK,EAAE,QAAQ;MAEvE;MACA,GAAG,GAAG,CAAC,MAAM;MACb,GAAG,CAAC,KAAK,GAAG;IACd;EACF;EACA,OAAO,GAAG,IAAI,GAAG,MAAM;AACzB,EAAC"}
|
package/lending.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// What plugins lend a host by name, beside what the host lends itself: mail
|
|
2
|
+
// senders, texters, chatters, embedders and keepers, which a graph host passes on
|
|
3
|
+
// (Host.senders, Host.texters, Host.chatters, Host.embedders, Host.keepers), and a provider's notice and
|
|
4
|
+
// arrival readers and a payment provider (./payments.ts), which a host that
|
|
5
|
+
// routes mail or takes money itself asks for, such as a Worker naming its
|
|
6
|
+
// providers in config. One party per name: a letter or a vector made through a name two
|
|
7
|
+
// parties answer to would depend on order.
|
|
8
|
+
import { CallError } from '@yaks/tools/errors'
|
|
9
|
+
import type { Embedding, Host } from './mod.ts'
|
|
10
|
+
import type {
|
|
11
|
+
Arrival,
|
|
12
|
+
Chatter,
|
|
13
|
+
MailDomains,
|
|
14
|
+
Notices,
|
|
15
|
+
Sender,
|
|
16
|
+
Texter,
|
|
17
|
+
} from './senders.ts'
|
|
18
|
+
import type { Payments } from './payments.ts'
|
|
19
|
+
import type { Keeper } from './keepers.ts'
|
|
20
|
+
import type { Taken } from './words.ts'
|
|
21
|
+
|
|
22
|
+
/** What each kind of loan is. */
|
|
23
|
+
export type Lends = {
|
|
24
|
+
senders: Sender
|
|
25
|
+
texters: Texter
|
|
26
|
+
chatters: Chatter
|
|
27
|
+
embedders: Embedding
|
|
28
|
+
notices: Notices
|
|
29
|
+
arrivals: Arrival
|
|
30
|
+
mailDomains: MailDomains
|
|
31
|
+
payments: Payments
|
|
32
|
+
keepers: Keeper
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The loans of one kind the graph facets make, beside the host's own
|
|
36
|
+
* `lent`, or `lent` itself where no plugin makes one. A name lent twice is
|
|
37
|
+
* refused.
|
|
38
|
+
*
|
|
39
|
+
* ```ts
|
|
40
|
+
* import { lending } from '@yaks/host/lending'
|
|
41
|
+
* import { equal, throws } from '@yaks/testing'
|
|
42
|
+
*
|
|
43
|
+
* let sender = { send: () => Promise.resolve({}) }
|
|
44
|
+
* let lends = { senders: () => ({ post: sender }) }
|
|
45
|
+
* equal(Object.keys(lending([[lends, {}, '@a/post']], {}, 'senders')!), ['post'])
|
|
46
|
+
* throws(
|
|
47
|
+
* () => lending([[lends, {}, '@a/post']], {}, 'senders', { post: sender }),
|
|
48
|
+
* 'the sender post is lent by both the host and @a/post',
|
|
49
|
+
* )
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export let lending = <K extends keyof Lends>(
|
|
53
|
+
graphs: Taken<'graph'>,
|
|
54
|
+
host: Partial<Host>,
|
|
55
|
+
kind: K,
|
|
56
|
+
lent?: Readonly<Record<string, Lends[K]>>,
|
|
57
|
+
): Readonly<Record<string, Lends[K]>> | undefined => {
|
|
58
|
+
let what = kind.slice(0, -1)
|
|
59
|
+
let by = new Map(Object.keys(lent ?? {}).map((name) => [name, 'the host']))
|
|
60
|
+
let all: Record<string, Lends[K]> = { ...lent }
|
|
61
|
+
for (let [r, options, plugin] of graphs) {
|
|
62
|
+
let made = r[kind]?.(host as Host, options) as
|
|
63
|
+
| Record<string, Lends[K]>
|
|
64
|
+
| undefined
|
|
65
|
+
for (let [name, one] of Object.entries(made ?? {})) {
|
|
66
|
+
if (by.has(name)) {
|
|
67
|
+
throw new CallError(
|
|
68
|
+
'config',
|
|
69
|
+
`the ${what} ${name} is lent by both ${by.get(name)} and ${plugin}`,
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
by.set(name, plugin)
|
|
73
|
+
all[name] = one
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return by.size ? all : lent
|
|
77
|
+
}
|
package/mod.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// The portable contract a host lends every plugin. Concrete hosts own drivers,
|
|
2
|
+
// directories and resource lifetime; plugins see the graph and capabilities.
|
|
3
|
+
export { assemble, assembly, prepare } from "./assembly.js";
|
|
4
|
+
export { every, ROLES } from "./roles.js";
|
|
5
|
+
//# sourceMappingURL=mod.js.map
|
package/mod.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.js","sources":["./mod.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,6EAA6E;AAyV7E,SACE,QAAQ,EAER,QAAQ,EAGR,OAAO,wBAEa;AACtB,SAAS,KAAK,EAAE,KAAK,qBAAoB"}
|