@yaks/cli 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 +1059 -2
- package/_dist/account-forward.d.ts +12 -0
- package/_dist/account-forward.d.ts.map +1 -0
- package/_dist/accounts.d.ts +23 -0
- package/_dist/accounts.d.ts.map +1 -0
- package/_dist/answer.d.ts +88 -0
- package/_dist/answer.d.ts.map +1 -0
- package/_dist/apply.d.ts +17 -0
- package/_dist/apply.d.ts.map +1 -0
- package/_dist/args.d.ts +86 -0
- package/_dist/args.d.ts.map +1 -0
- package/_dist/commands.d.ts +15 -0
- package/_dist/commands.d.ts.map +1 -0
- package/_dist/complete.d.ts +15 -0
- package/_dist/complete.d.ts.map +1 -0
- package/_dist/config.d.ts +37 -0
- package/_dist/config.d.ts.map +1 -0
- package/_dist/dependencies.d.ts +6 -0
- package/_dist/dependencies.d.ts.map +1 -0
- package/_dist/facets.d.ts +71 -0
- package/_dist/facets.d.ts.map +1 -0
- package/_dist/grammar.d.ts +5 -0
- package/_dist/grammar.d.ts.map +1 -0
- package/_dist/host.d.ts +164 -0
- package/_dist/host.d.ts.map +1 -0
- package/_dist/install.d.ts +43 -0
- package/_dist/install.d.ts.map +1 -0
- package/_dist/main.d.ts +16 -0
- package/_dist/main.d.ts.map +1 -0
- package/_dist/memo.d.ts +60 -0
- package/_dist/memo.d.ts.map +1 -0
- package/_dist/mod.d.ts +46 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/page.d.ts +73 -0
- package/_dist/page.d.ts.map +1 -0
- package/_dist/platform.d.ts +27 -0
- package/_dist/platform.d.ts.map +1 -0
- package/_dist/reader.d.ts +10 -0
- package/_dist/reader.d.ts.map +1 -0
- package/_dist/release.d.ts +48 -0
- package/_dist/release.d.ts.map +1 -0
- package/_dist/remote.d.ts +13 -0
- package/_dist/remote.d.ts.map +1 -0
- package/_dist/reported.d.ts +11 -0
- package/_dist/reported.d.ts.map +1 -0
- package/_dist/roles.d.ts +2 -0
- package/_dist/roles.d.ts.map +1 -0
- package/_dist/roster.d.ts +41 -0
- package/_dist/roster.d.ts.map +1 -0
- package/_dist/rpc.d.ts +29 -0
- package/_dist/rpc.d.ts.map +1 -0
- package/_dist/run.d.ts +164 -0
- package/_dist/run.d.ts.map +1 -0
- package/_dist/runtime.d.ts +4 -0
- package/_dist/runtime.d.ts.map +1 -0
- package/_dist/searching.d.ts +7 -0
- package/_dist/searching.d.ts.map +1 -0
- package/_dist/show.d.ts +22 -0
- package/_dist/show.d.ts.map +1 -0
- package/_dist/store.d.ts +25 -0
- package/_dist/store.d.ts.map +1 -0
- package/_dist/terminal.d.ts +17 -0
- package/_dist/terminal.d.ts.map +1 -0
- package/_dist/tool.d.ts +55 -0
- package/_dist/tool.d.ts.map +1 -0
- package/_dist/tty.d.ts +3 -0
- package/_dist/tty.d.ts.map +1 -0
- package/_dist/vault.d.ts +9 -0
- package/_dist/vault.d.ts.map +1 -0
- package/_dist/words.d.ts +11 -0
- package/_dist/words.d.ts.map +1 -0
- package/_dist/yak.d.ts +10 -0
- package/_dist/yak.d.ts.map +1 -0
- package/account-forward.js +40 -0
- package/account-forward.js.map +1 -0
- package/account-forward.ts +50 -0
- package/accounts.js +162 -0
- package/accounts.js.map +1 -0
- package/accounts.ts +228 -0
- package/answer.js +394 -0
- package/answer.js.map +1 -0
- package/answer.ts +569 -0
- package/apply.js +49 -0
- package/apply.js.map +1 -0
- package/apply.ts +54 -0
- package/args.js +420 -0
- package/args.js.map +1 -0
- package/args.ts +494 -0
- package/code.js +209 -0
- package/code.js.map +1 -0
- package/code.ts +227 -0
- package/commands.js +131 -0
- package/commands.js.map +1 -0
- package/commands.ts +142 -0
- package/complete.js +104 -0
- package/complete.js.map +1 -0
- package/complete.ts +152 -0
- package/config.js +125 -0
- package/config.js.map +1 -0
- package/config.ts +180 -0
- package/declarations.js +67 -0
- package/declarations.js.map +1 -0
- package/declarations.ts +84 -0
- package/deno.json +1 -0
- package/dependencies.js +126 -0
- package/dependencies.js.map +1 -0
- package/dependencies.ts +141 -0
- package/derive.js +102 -0
- package/derive.js.map +1 -0
- package/derive.ts +125 -0
- package/drain.js +83 -0
- package/drain.js.map +1 -0
- package/drain.ts +115 -0
- package/duties.ts +17 -0
- package/exports.json +1486 -0
- package/external.js +373 -0
- package/external.js.map +1 -0
- package/external.ts +435 -0
- package/facets.js +214 -0
- package/facets.js.map +1 -0
- package/facets.ts +232 -0
- package/feedback.js +54 -0
- package/feedback.js.map +1 -0
- package/feedback.ts +57 -0
- package/files.js +84 -0
- package/files.js.map +1 -0
- package/files.ts +112 -0
- package/get_starts.js +31 -0
- package/get_starts.js.map +1 -0
- package/get_starts.ts +34 -0
- package/git-credential.js +79 -0
- package/git-credential.js.map +1 -0
- package/git-credential.ts +77 -0
- package/grammar.js +4 -0
- package/grammar.js.map +1 -0
- package/grammar.ts +5 -0
- package/held.js +51 -0
- package/held.js.map +1 -0
- package/held.ts +66 -0
- package/host.js +1174 -0
- package/host.js.map +1 -0
- package/host.ts +1343 -0
- package/init.js +138 -0
- package/init.js.map +1 -0
- package/init.ts +139 -0
- package/install.js +216 -0
- package/install.js.map +1 -0
- package/install.ts +223 -0
- package/lifetime.js +56 -0
- package/lifetime.js.map +1 -0
- package/lifetime.ts +66 -0
- package/local-page.ts +114 -0
- package/local.js +417 -0
- package/local.js.map +1 -0
- package/local.ts +537 -0
- package/lockfile.js +20 -0
- package/lockfile.js.map +1 -0
- package/lockfile.ts +32 -0
- package/machines.js +33 -0
- package/machines.js.map +1 -0
- package/machines.ts +51 -0
- package/made/4f855610bdabcd736100d34e4e467ea5.json +1 -0
- package/main.js +534 -0
- package/main.js.map +1 -0
- package/main.ts +547 -0
- package/mcp.js +108 -0
- package/mcp.js.map +1 -0
- package/mcp.ts +113 -0
- package/member.js +103 -0
- package/member.js.map +1 -0
- package/member.ts +133 -0
- package/memo.js +503 -0
- package/memo.js.map +1 -0
- package/memo.ts +634 -0
- package/mod.js +46 -0
- package/mod.js.map +1 -0
- package/mod.ts +99 -0
- package/operations.js +53 -0
- package/operations.js.map +1 -0
- package/operations.ts +68 -0
- package/package.json +115 -4
- package/page.js +211 -0
- package/page.js.map +1 -0
- package/page.ts +308 -0
- package/parser.js +45 -0
- package/parser.js.map +1 -0
- package/parser.ts +77 -0
- package/people-search.js +112 -0
- package/people-search.js.map +1 -0
- package/people-search.ts +162 -0
- package/platform.js +184 -0
- package/platform.js.map +1 -0
- package/platform.ts +224 -0
- package/platform_effects.js +5 -0
- package/platform_effects.js.map +1 -0
- package/platform_effects.ts +13 -0
- package/prepare.js +40 -0
- package/prepare.js.map +1 -0
- package/prepare.ts +46 -0
- package/read_activity.js +54 -0
- package/read_activity.js.map +1 -0
- package/read_activity.ts +61 -0
- package/read_thread.js +387 -0
- package/read_thread.js.map +1 -0
- package/read_thread.ts +506 -0
- package/read_worker.ts +164 -0
- package/reader.js +48 -0
- package/reader.js.map +1 -0
- package/reader.ts +57 -0
- package/release.js +82 -0
- package/release.js.map +1 -0
- package/release.json +127 -0
- package/release.ts +98 -0
- package/remote-page.ts +70 -0
- package/remote.js +96 -0
- package/remote.js.map +1 -0
- package/remote.ts +153 -0
- package/report.js +83 -0
- package/report.js.map +1 -0
- package/report.ts +101 -0
- package/reported.js +32 -0
- package/reported.js.map +1 -0
- package/reported.ts +38 -0
- package/restart.js +349 -0
- package/restart.js.map +1 -0
- package/restart.ts +478 -0
- package/restore.js +32 -0
- package/restore.js.map +1 -0
- package/restore.ts +38 -0
- package/roles.js +32 -0
- package/roles.js.map +1 -0
- package/roles.ts +49 -0
- package/roster.js +65 -0
- package/roster.js.map +1 -0
- package/roster.ts +84 -0
- package/rpc.js +113 -0
- package/rpc.js.map +1 -0
- package/rpc.ts +159 -0
- package/run.js +533 -0
- package/run.js.map +1 -0
- package/run.ts +741 -0
- package/runtime.js +381 -0
- package/runtime.js.map +1 -0
- package/runtime.ts +433 -0
- package/sandboxes.js +26 -0
- package/sandboxes.js.map +1 -0
- package/sandboxes.ts +30 -0
- package/searching.js +33 -0
- package/searching.js.map +1 -0
- package/searching.ts +50 -0
- package/show.js +109 -0
- package/show.js.map +1 -0
- package/show.ts +144 -0
- package/shown.js +13 -0
- package/shown.js.map +1 -0
- package/shown.ts +44 -0
- package/stall.js +90 -0
- package/stall.js.map +1 -0
- package/stall.ts +156 -0
- package/stall_profile.js +113 -0
- package/stall_profile.js.map +1 -0
- package/stall_profile.ts +142 -0
- package/stall_wait.js +183 -0
- package/stall_wait.js.map +1 -0
- package/stall_wait.ts +249 -0
- package/stall_wait_worker.ts +11 -0
- package/start.js +349 -0
- package/start.js.map +1 -0
- package/start.ts +343 -0
- package/starvation.js +147 -0
- package/starvation.js.map +1 -0
- package/starvation.ts +224 -0
- package/store.js +118 -0
- package/store.js.map +1 -0
- package/store.ts +193 -0
- package/subcommands.js +62 -0
- package/subcommands.js.map +1 -0
- package/subcommands.ts +77 -0
- package/terminal.js +93 -0
- package/terminal.js.map +1 -0
- package/terminal.ts +128 -0
- package/text.js +20 -0
- package/text.js.map +1 -0
- package/text.ts +37 -0
- package/tool.js +76 -0
- package/tool.js.map +1 -0
- package/tool.ts +157 -0
- package/trace_control.js +231 -0
- package/trace_control.js.map +1 -0
- package/trace_control.ts +233 -0
- package/traces.js +138 -0
- package/traces.js.map +1 -0
- package/traces.ts +160 -0
- package/tracker.js +22 -0
- package/tracker.js.map +1 -0
- package/tracker.ts +27 -0
- package/tty.js +82 -0
- package/tty.js.map +1 -0
- package/tty.ts +142 -0
- package/unit_failure.js +178 -0
- package/unit_failure.js.map +1 -0
- package/unit_failure.ts +191 -0
- package/upkeep_thread.js +32 -0
- package/upkeep_thread.js.map +1 -0
- package/upkeep_thread.ts +35 -0
- package/upkeep_worker.ts +27 -0
- package/vault.js +186 -0
- package/vault.js.map +1 -0
- package/vault.ts +220 -0
- package/vocab-ids.js +63 -0
- package/vocab-ids.js.map +1 -0
- package/vocab-ids.ts +62 -0
- package/vocab.json +35 -0
- package/warm.js +138 -0
- package/warm.js.map +1 -0
- package/warm.ts +171 -0
- package/watch_revision.js +25 -0
- package/watch_revision.js.map +1 -0
- package/watch_revision.ts +30 -0
- package/words.js +29 -0
- package/words.js.map +1 -0
- package/words.ts +41 -0
- package/workspaces.js +40 -0
- package/workspaces.js.map +1 -0
- package/workspaces.ts +58 -0
- package/yak-unit-failure.conf +6 -0
- package/yak-unit-handoff.conf +2 -0
- package/yak.js +123 -0
- package/yak.js.map +1 -0
- package/yak.ts +136 -0
package/page.ts
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A page a plugin serves, exported as `@yaks/cli/page`: what a plugin's
|
|
3
|
+
* routes answer with besides the graph's doors, in the process that serves
|
|
4
|
+
* them. `kept` answers an address with a body made once and kept for the life
|
|
5
|
+
* of the process (a stylesheet, a document); `bundle` makes one such body, a
|
|
6
|
+
* page's script and everything it imports as one browser module. @yaks/web's
|
|
7
|
+
* app and @yaks/inspect's page are each one.
|
|
8
|
+
*
|
|
9
|
+
* Making a body is bounded: one that has not settled within the limit is
|
|
10
|
+
* aborted, cancelling the work it owns, and counts as a failure. A failure
|
|
11
|
+
* is never kept: it is reported once, where it happened, and the next request
|
|
12
|
+
* makes the body again. So a build that hangs heals on its own, without
|
|
13
|
+
* anybody restarting the host. A make still going when its host closes is
|
|
14
|
+
* aborted too, so nothing it spawned outlives the host.
|
|
15
|
+
*
|
|
16
|
+
* A release makes some bodies ahead: what a fresh install serves, made from
|
|
17
|
+
* the release's own checkout as it publishes (bin/publish.ts) and shipped in
|
|
18
|
+
* `./made/`, each under the hash of a key naming what it was made of. `ahead`
|
|
19
|
+
* finds one, so a host composed the same way answers with it instead of making
|
|
20
|
+
* it on the person's machine. A checkout ships none, and makes every body.
|
|
21
|
+
*
|
|
22
|
+
* @module
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { fault } from '@yaks/api/refuse'
|
|
26
|
+
import * as disk from '@yaks/file/io'
|
|
27
|
+
import { importing } from '@yaks/fp/imports'
|
|
28
|
+
import { settling } from './held.js'
|
|
29
|
+
|
|
30
|
+
/** A body a page loads. */
|
|
31
|
+
export type Body = string | Uint8Array<ArrayBuffer>
|
|
32
|
+
|
|
33
|
+
/** How long a body may take to make before it is given up on. A bundle from a
|
|
34
|
+
* checkout takes a few seconds, one from JSR far longer (./remote-page.ts),
|
|
35
|
+
* which is why a release makes a fresh install's ahead; a hung one never
|
|
36
|
+
* finishes (T-38240). */
|
|
37
|
+
export let LIMIT = 60_000
|
|
38
|
+
|
|
39
|
+
let sha = async (body: Body) =>
|
|
40
|
+
[
|
|
41
|
+
...new Uint8Array(
|
|
42
|
+
await crypto.subtle.digest(
|
|
43
|
+
'SHA-256',
|
|
44
|
+
typeof body == 'string' ? new TextEncoder().encode(body) : body,
|
|
45
|
+
),
|
|
46
|
+
),
|
|
47
|
+
]
|
|
48
|
+
.map((b) => b.toString(16).padStart(2, '0')).join('').slice(0, 32)
|
|
49
|
+
|
|
50
|
+
/** Where a release keeps the bodies it made ahead. */
|
|
51
|
+
export let MADE: URL = new URL('./made/', import.meta.url)
|
|
52
|
+
|
|
53
|
+
let made = async (key: string, at: URL) => new URL(`${await sha(key)}.json`, at)
|
|
54
|
+
|
|
55
|
+
/** The body made ahead for `key`, or undefined where none was. */
|
|
56
|
+
export let ahead = async (
|
|
57
|
+
key: string,
|
|
58
|
+
at: URL = MADE,
|
|
59
|
+
): Promise<string | undefined> => {
|
|
60
|
+
try {
|
|
61
|
+
let { default: { body } } = await import((await made(key, at)).href, {
|
|
62
|
+
with: { type: 'json' },
|
|
63
|
+
})
|
|
64
|
+
return body
|
|
65
|
+
} catch (e) {
|
|
66
|
+
if ((e as { code?: string }).code == 'ERR_MODULE_NOT_FOUND') return
|
|
67
|
+
throw e
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Keep `body` in `dir` (a release's `./made/`) where `ahead(key)` finds it. */
|
|
72
|
+
export let keep = async (
|
|
73
|
+
dir: URL,
|
|
74
|
+
key: string,
|
|
75
|
+
body: string,
|
|
76
|
+
): Promise<void> => {
|
|
77
|
+
await disk.mkdir(dir, { recursive: true })
|
|
78
|
+
await disk.writeTextFile(await made(key, dir), JSON.stringify({ body }))
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// A body the browser may keep, revalidated on each load by its hash.
|
|
82
|
+
type Made = { body: Body; tag: string }
|
|
83
|
+
let tagged = (request: Request, { body, tag }: Made, type: string) => {
|
|
84
|
+
let headers = { 'content-type': type, 'cache-control': 'no-cache', etag: tag }
|
|
85
|
+
return request.headers.get('if-none-match') == tag
|
|
86
|
+
? new Response(null, { status: 304, headers })
|
|
87
|
+
: new Response(body, { headers })
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** `make(signal)`, given up on (and `signal` aborted) after `limit` ms, or
|
|
91
|
+
* once `closing` aborts. */
|
|
92
|
+
export let within = <T>(
|
|
93
|
+
limit: number,
|
|
94
|
+
make: (signal: AbortSignal) => Promise<T>,
|
|
95
|
+
closing?: AbortSignal,
|
|
96
|
+
): Promise<T> =>
|
|
97
|
+
new Promise((resolve, reject) => {
|
|
98
|
+
let stop = new AbortController()
|
|
99
|
+
let made: Promise<void> | undefined
|
|
100
|
+
// Answered at once when given up on, and let finish what it spawned
|
|
101
|
+
// before the process ends (./held.ts). Only a make it stopped: one still
|
|
102
|
+
// going is its own host's, not a closing process's to wait on.
|
|
103
|
+
let quit = (why: string) => {
|
|
104
|
+
stop.abort()
|
|
105
|
+
if (made) settling.add(made)
|
|
106
|
+
reject(new Error(why))
|
|
107
|
+
}
|
|
108
|
+
if (closing?.aborted) return quit('the host is closing')
|
|
109
|
+
let timer = setTimeout(
|
|
110
|
+
() => quit(`not made within ${limit / 1000}s`),
|
|
111
|
+
limit,
|
|
112
|
+
)
|
|
113
|
+
let close = () => quit('the host is closing')
|
|
114
|
+
closing?.addEventListener('abort', close, { once: true })
|
|
115
|
+
made = make(stop.signal).then(resolve, reject).finally(() => {
|
|
116
|
+
clearTimeout(timer)
|
|
117
|
+
closing?.removeEventListener('abort', close)
|
|
118
|
+
settling.delete(made!)
|
|
119
|
+
})
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
/** The handler that answers `where` with the body `make` makes. `early` is
|
|
123
|
+
* handed its making, to start ahead of the first request (@yaks/host
|
|
124
|
+
* `Host.early`), which then finds it made; `closing` is the host's own signal,
|
|
125
|
+
* which ends a make still going. Its `tag()` is the etag of the body made,
|
|
126
|
+
* undefined until one is. */
|
|
127
|
+
export let kept = (
|
|
128
|
+
where: string,
|
|
129
|
+
type: string,
|
|
130
|
+
make: (signal: AbortSignal) => Promise<Body>,
|
|
131
|
+
{ early, limit = LIMIT, closing }: {
|
|
132
|
+
early?: (make: () => Promise<unknown>) => void
|
|
133
|
+
limit?: number
|
|
134
|
+
closing?: AbortSignal
|
|
135
|
+
} = {},
|
|
136
|
+
): Kept => {
|
|
137
|
+
let made: Promise<Made> | undefined
|
|
138
|
+
let tag: string | undefined
|
|
139
|
+
let attempt = () => {
|
|
140
|
+
let now = within(limit, make, closing).then(async (value) => {
|
|
141
|
+
let body = typeof value == 'string' ? value : new Uint8Array(value)
|
|
142
|
+
tag = `"${await sha(body)}"`
|
|
143
|
+
return { body, tag }
|
|
144
|
+
})
|
|
145
|
+
made = now
|
|
146
|
+
now.catch((e) => {
|
|
147
|
+
if (made == now) made = undefined
|
|
148
|
+
if (!closing?.aborted) fault(e, `GET ${where}`)
|
|
149
|
+
})
|
|
150
|
+
return now
|
|
151
|
+
}
|
|
152
|
+
early?.(() => made ?? attempt())
|
|
153
|
+
let handle = async (request: Request) => {
|
|
154
|
+
try {
|
|
155
|
+
return await tagged(request, await (made ?? attempt()), type)
|
|
156
|
+
} catch (e) {
|
|
157
|
+
return new Response(String((e as Error).message ?? e), { status: 500 })
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return Object.assign(handle, { tag: () => tag })
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** What {@link kept} answers with: the handler, and the tag of what it made. */
|
|
164
|
+
export type Kept = ((request: Request) => Promise<Response>) & {
|
|
165
|
+
tag: () => string | undefined
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** An entry written where it is bundled rather than read from a file: its
|
|
169
|
+
* `code`, whose imports resolve as they would in a module at `at`. */
|
|
170
|
+
export type Written = { code: string; at: URL }
|
|
171
|
+
|
|
172
|
+
/** What a build made: its output, and what it read where it says. */
|
|
173
|
+
export type Built = {
|
|
174
|
+
outputFiles?: { path: string; text: string }[]
|
|
175
|
+
metafile?: { inputs: { [path: string]: unknown } }
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** The operations one build owns, independent of its compiler's service. */
|
|
179
|
+
export type Build = {
|
|
180
|
+
rebuild: () => Promise<Built>
|
|
181
|
+
cancel: () => Promise<void>
|
|
182
|
+
dispose: () => Promise<void>
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Finish or cancel one build, always releasing its context: what it
|
|
186
|
+
* made. */
|
|
187
|
+
export let finished = async (
|
|
188
|
+
build: Build,
|
|
189
|
+
signal?: AbortSignal,
|
|
190
|
+
): Promise<Built> => {
|
|
191
|
+
let cancel = () => {
|
|
192
|
+
void build.cancel()
|
|
193
|
+
}
|
|
194
|
+
signal?.addEventListener('abort', cancel, { once: true })
|
|
195
|
+
try {
|
|
196
|
+
if (signal?.aborted) throw new Error('browser bundle was stopped')
|
|
197
|
+
let result = await build.rebuild()
|
|
198
|
+
if (signal?.aborted) throw new Error('browser bundle was stopped')
|
|
199
|
+
return result
|
|
200
|
+
} finally {
|
|
201
|
+
signal?.removeEventListener('abort', cancel)
|
|
202
|
+
await build.dispose()
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** Finish or cancel one build of one module, always releasing its context:
|
|
207
|
+
* the module it made. */
|
|
208
|
+
export let compiled = async (
|
|
209
|
+
build: Build,
|
|
210
|
+
signal?: AbortSignal,
|
|
211
|
+
done: (built: Built) => void = () => {},
|
|
212
|
+
): Promise<string> => {
|
|
213
|
+
let result = await finished(build, signal)
|
|
214
|
+
done(result)
|
|
215
|
+
return result.outputFiles![0].text
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** How one browser module is bundled: the bare specifiers it leaves to the
|
|
219
|
+
* page to resolve (its import map), so every module on the page that imports
|
|
220
|
+
* one shares the one copy the page loads. */
|
|
221
|
+
export type Bundling = {
|
|
222
|
+
external?: string[]
|
|
223
|
+
alias?: Record<string, string>
|
|
224
|
+
format?: 'esm' | 'cjs'
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** Import maps name exact specifiers. An external root does not cover its subpaths. */
|
|
228
|
+
export let pageExternals = (
|
|
229
|
+
specifiers: string[] = [],
|
|
230
|
+
): import('npm:esbuild@0.28.1').Plugin => {
|
|
231
|
+
let exact = specifiers.map((specifier) =>
|
|
232
|
+
specifier.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
233
|
+
)
|
|
234
|
+
return {
|
|
235
|
+
name: 'page-externals',
|
|
236
|
+
setup(build: import('npm:esbuild@0.28.1').PluginBuild) {
|
|
237
|
+
if (!exact.length) return
|
|
238
|
+
build.onResolve(
|
|
239
|
+
{ filter: new RegExp(`^(${exact.join('|')})$`) },
|
|
240
|
+
(args) =>
|
|
241
|
+
args.kind == 'entry-point'
|
|
242
|
+
? undefined
|
|
243
|
+
: { path: args.path, external: true },
|
|
244
|
+
)
|
|
245
|
+
},
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Deno fetches every import it can read in a module's source with the module
|
|
250
|
+
// graph, a dynamic one that never runs included, so the bundlers are imported
|
|
251
|
+
// by a computed address: a host serving only bodies made ahead downloads no
|
|
252
|
+
// esbuild.
|
|
253
|
+
let bundlers = {
|
|
254
|
+
local: new URL('./local-page.ts', import.meta.url),
|
|
255
|
+
remote: new URL('./remote-page.ts', import.meta.url),
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** One browser module: from a checkout, resolved through the npm workspace
|
|
259
|
+
* (./local-page.ts); from JSR, through Deno's resolver (./remote-page.ts).
|
|
260
|
+
* Every build owns its cancellation and cleanup, so concurrent builds stay
|
|
261
|
+
* independent. */
|
|
262
|
+
export let bundle = async (
|
|
263
|
+
entry: URL | Written,
|
|
264
|
+
signal?: AbortSignal,
|
|
265
|
+
opts: Bundling = {},
|
|
266
|
+
): Promise<string> => {
|
|
267
|
+
if (signal?.aborted) throw new Error('browser bundle was stopped')
|
|
268
|
+
let at = entry instanceof URL ? entry : entry.at
|
|
269
|
+
let from = at.protocol == 'file:' ? bundlers.local : bundlers.remote
|
|
270
|
+
let bundler: { bundle: typeof bundle } = await importing(from.href)
|
|
271
|
+
return bundler.bundle(entry, signal, opts)
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/** Browser modules bundled together, from a checkout: each entry's module by
|
|
275
|
+
* its name, and the modules two or more of them import once, in chunks named
|
|
276
|
+
* by their bytes (`chunks`, by path), which every entry imports from the
|
|
277
|
+
* site's `/${CHUNKS}/`. A page loading several of them runs each shared
|
|
278
|
+
* module once, and a browser keeps the chunks for good. */
|
|
279
|
+
export let split = async (
|
|
280
|
+
entries: Record<string, URL>,
|
|
281
|
+
signal?: AbortSignal,
|
|
282
|
+
opts: Bundling = {},
|
|
283
|
+
): Promise<
|
|
284
|
+
{ entries: Record<string, string>; chunks: Record<string, string> }
|
|
285
|
+
> => {
|
|
286
|
+
if (signal?.aborted) throw new Error('browser bundle was stopped')
|
|
287
|
+
if (Object.values(entries).some((at) => at.protocol != 'file:')) {
|
|
288
|
+
throw new Error('only modules in a checkout are bundled together')
|
|
289
|
+
}
|
|
290
|
+
let bundler: { split: typeof split } = await importing(bundlers.local.href)
|
|
291
|
+
return bundler.split(entries, signal, opts)
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** Where split bundles keep their shared chunks, below the site's root. */
|
|
295
|
+
export let CHUNKS = '_yak'
|
|
296
|
+
export let CHUNK = `${CHUNKS}/chunk`
|
|
297
|
+
|
|
298
|
+
/** The chunks a split module imports, by path from the site's root.
|
|
299
|
+
*
|
|
300
|
+
* ```ts
|
|
301
|
+
* import { assertEquals } from '@std/assert'
|
|
302
|
+
* assertEquals(imports('import{a}from"/_yak/chunk.A.js";import"/_yak/chunk.B.js"'), ['_yak/chunk.A.js', '_yak/chunk.B.js'])
|
|
303
|
+
* ```
|
|
304
|
+
*/
|
|
305
|
+
export let imports = (code: string): string[] =>
|
|
306
|
+
[...code.matchAll(
|
|
307
|
+
new RegExp(`["']/(${CHUNK}\\.[\\w-]+\\.js)["']`, 'g'),
|
|
308
|
+
)].map(([, chunk]) => chunk)
|
package/parser.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// The cold source scanner's TS/TSX fallback. The compiler arrives only when
|
|
2
|
+
// the fast module lexer cannot read a source; a memo hit imports neither.
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
/** Runtime import dependencies, including literal dynamic imports. A source's
|
|
5
|
+
* name selects its syntax: JSX in .tsx/.jsx, type assertions in .ts/.mts.
|
|
6
|
+
* Callers can exclude function-valued callbacks omitted from their derivation;
|
|
7
|
+
* only dynamic imports inside those callbacks are omitted. */ export let imports = (source, name = 'source.tsx', callbacks = [])=>{
|
|
8
|
+
let file = ts.createSourceFile(name, source, ts.ScriptTarget.Latest);
|
|
9
|
+
let found = [];
|
|
10
|
+
let ignored = new Set(callbacks);
|
|
11
|
+
let callback = (node)=>{
|
|
12
|
+
if (!ignored.size) return false;
|
|
13
|
+
if (!ts.isMethodDeclaration(node) && !ts.isPropertyAssignment(node) && !ts.isPropertyDeclaration(node)) return false;
|
|
14
|
+
let key = node.name;
|
|
15
|
+
if (ts.isComputedPropertyName(key)) {
|
|
16
|
+
if (!ts.isStringLiteralLike(key.expression)) return false;
|
|
17
|
+
key = key.expression;
|
|
18
|
+
}
|
|
19
|
+
if (!ts.isIdentifier(key) && !ts.isStringLiteralLike(key) || !ignored.has(key.text)) return false;
|
|
20
|
+
if (ts.isMethodDeclaration(node)) return true;
|
|
21
|
+
let value = node.initializer;
|
|
22
|
+
while(value && (ts.isParenthesizedExpression(value) || ts.isAsExpression(value) || ts.isTypeAssertionExpression(value) || ts.isSatisfiesExpression(value) || ts.isNonNullExpression(value)))value = value.expression;
|
|
23
|
+
return !!value && (ts.isArrowFunction(value) || ts.isFunctionExpression(value));
|
|
24
|
+
};
|
|
25
|
+
let add = (value)=>{
|
|
26
|
+
if (value && ts.isStringLiteralLike(value)) found.push(value.text);
|
|
27
|
+
};
|
|
28
|
+
let visit = (node, excluded = false)=>{
|
|
29
|
+
excluded ||= callback(node);
|
|
30
|
+
if (ts.isImportDeclaration(node)) {
|
|
31
|
+
let clause = node.importClause;
|
|
32
|
+
let named = clause?.namedBindings;
|
|
33
|
+
if (!clause?.isTypeOnly && (!named || !ts.isNamedImports(named) || clause?.name || !named.elements.length || named.elements.some((m)=>!m.isTypeOnly))) add(node.moduleSpecifier);
|
|
34
|
+
} else if (ts.isExportDeclaration(node)) {
|
|
35
|
+
let named = node.exportClause;
|
|
36
|
+
if (!node.isTypeOnly && (!named || !ts.isNamedExports(named) || !named.elements.length || named.elements.some((m)=>!m.isTypeOnly))) add(node.moduleSpecifier);
|
|
37
|
+
} else if (ts.isImportEqualsDeclaration(node) && !node.isTypeOnly && ts.isExternalModuleReference(node.moduleReference)) {
|
|
38
|
+
add(node.moduleReference.expression);
|
|
39
|
+
} else if (!excluded && ts.isCallExpression(node) && node.expression.kind == ts.SyntaxKind.ImportKeyword) add(node.arguments[0]);
|
|
40
|
+
ts.forEachChild(node, (child)=>visit(child, excluded));
|
|
41
|
+
};
|
|
42
|
+
visit(file);
|
|
43
|
+
return found;
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=parser.js.map
|
package/parser.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.js","sources":["./parser.ts"],"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AW,KAAK;IAC1C,aAAa,SAAS;IACtB,IAAI,GAAG,mBAAmB,CAAC,OAAO;MAChC,IAAI,SAAS,KAAK,YAAY;MAC9B,IAAI,QAAQ,QAAQ;MACpB,IACE,CAAC,QAAQ,cACT,CAAC,CAAC,SAAS,CAAC,GAAG,cAAc,CAAC,UAAU,QAAQ,QAC9C,CAAC,MAAM,QAAQ,CAAC,MAAM,IAAI,MAAM,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAM,CAAC,EAAE,UAAU,CAAC,GACrE,IAAI,KAAK,eAAe;IAC5B,OAAO,IAAI,GAAG,mBAAmB,CAAC,OAAO;MACvC,IAAI,QAAQ,KAAK,YAAY;MAC7B,IACE,CAAC,KAAK,UAAU,IAChB,CAAC,CAAC,SAAS,CAAC,GAAG,cAAc,CAAC,UAAU,CAAC,MAAM,QAAQ,CAAC,MAAM,IAC5D,MAAM,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAM,CAAC,EAAE,UAAU,CAAC,GAC3C,IAAI,KAAK,eAAe;IAC5B,OAAO,IACL,GAAG,yBAAyB,CAAC,SAAS,CAAC,KAAK,UAAU,IACtD,GAAG,yBAAyB,CAAC,KAAK,eAAe,GACjD;MACA,IAAI,KAAK,eAAe,CAAC,UAAU;IACrC,OAAO,IACL,CAAC,YAAY,GAAG,gBAAgB,CAAC,SACjC,KAAK,UAAU,CAAC,IAAI,IAAI,GAAG,UAAU,CAAC,aAAa,EACnD,IAAI,KAAK,SAAS,CAAC,EAAE;IACvB,GAAG,YAAY,CAAC,MAAM,CAAC,QAAU,MAAM,OAAO;EAChD;EACA,MAAM;EACN,OAAO;AACT,EAAC"}
|
package/parser.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// The cold source scanner's TS/TSX fallback. The compiler arrives only when
|
|
2
|
+
// the fast module lexer cannot read a source; a memo hit imports neither.
|
|
3
|
+
import ts from 'typescript'
|
|
4
|
+
|
|
5
|
+
/** Runtime import dependencies, including literal dynamic imports. A source's
|
|
6
|
+
* name selects its syntax: JSX in .tsx/.jsx, type assertions in .ts/.mts.
|
|
7
|
+
* Callers can exclude function-valued callbacks omitted from their derivation;
|
|
8
|
+
* only dynamic imports inside those callbacks are omitted. */
|
|
9
|
+
export let imports = (
|
|
10
|
+
source: string,
|
|
11
|
+
name = 'source.tsx',
|
|
12
|
+
callbacks: readonly string[] = [],
|
|
13
|
+
): string[] => {
|
|
14
|
+
let file = ts.createSourceFile(name, source, ts.ScriptTarget.Latest)
|
|
15
|
+
let found: string[] = []
|
|
16
|
+
let ignored = new Set(callbacks)
|
|
17
|
+
let callback = (node: ts.Node): boolean => {
|
|
18
|
+
if (!ignored.size) return false
|
|
19
|
+
if (
|
|
20
|
+
!ts.isMethodDeclaration(node) && !ts.isPropertyAssignment(node) &&
|
|
21
|
+
!ts.isPropertyDeclaration(node)
|
|
22
|
+
) return false
|
|
23
|
+
let key: ts.Node = node.name
|
|
24
|
+
if (ts.isComputedPropertyName(key)) {
|
|
25
|
+
if (!ts.isStringLiteralLike(key.expression)) return false
|
|
26
|
+
key = key.expression
|
|
27
|
+
}
|
|
28
|
+
if (
|
|
29
|
+
!ts.isIdentifier(key) && !ts.isStringLiteralLike(key) ||
|
|
30
|
+
!ignored.has(key.text)
|
|
31
|
+
) return false
|
|
32
|
+
if (ts.isMethodDeclaration(node)) return true
|
|
33
|
+
let value = node.initializer
|
|
34
|
+
while (
|
|
35
|
+
value &&
|
|
36
|
+
(ts.isParenthesizedExpression(value) || ts.isAsExpression(value) ||
|
|
37
|
+
ts.isTypeAssertionExpression(value) ||
|
|
38
|
+
ts.isSatisfiesExpression(value) ||
|
|
39
|
+
ts.isNonNullExpression(value))
|
|
40
|
+
) value = value.expression
|
|
41
|
+
return !!value &&
|
|
42
|
+
(ts.isArrowFunction(value) || ts.isFunctionExpression(value))
|
|
43
|
+
}
|
|
44
|
+
let add = (value: ts.Node | undefined) => {
|
|
45
|
+
if (value && ts.isStringLiteralLike(value)) found.push(value.text)
|
|
46
|
+
}
|
|
47
|
+
let visit = (node: ts.Node, excluded = false) => {
|
|
48
|
+
excluded ||= callback(node)
|
|
49
|
+
if (ts.isImportDeclaration(node)) {
|
|
50
|
+
let clause = node.importClause
|
|
51
|
+
let named = clause?.namedBindings
|
|
52
|
+
if (
|
|
53
|
+
!clause?.isTypeOnly &&
|
|
54
|
+
(!named || !ts.isNamedImports(named) || clause?.name ||
|
|
55
|
+
!named.elements.length || named.elements.some((m) => !m.isTypeOnly))
|
|
56
|
+
) add(node.moduleSpecifier)
|
|
57
|
+
} else if (ts.isExportDeclaration(node)) {
|
|
58
|
+
let named = node.exportClause
|
|
59
|
+
if (
|
|
60
|
+
!node.isTypeOnly &&
|
|
61
|
+
(!named || !ts.isNamedExports(named) || !named.elements.length ||
|
|
62
|
+
named.elements.some((m) => !m.isTypeOnly))
|
|
63
|
+
) add(node.moduleSpecifier)
|
|
64
|
+
} else if (
|
|
65
|
+
ts.isImportEqualsDeclaration(node) && !node.isTypeOnly &&
|
|
66
|
+
ts.isExternalModuleReference(node.moduleReference)
|
|
67
|
+
) {
|
|
68
|
+
add(node.moduleReference.expression)
|
|
69
|
+
} else if (
|
|
70
|
+
!excluded && ts.isCallExpression(node) &&
|
|
71
|
+
node.expression.kind == ts.SyntaxKind.ImportKeyword
|
|
72
|
+
) add(node.arguments[0])
|
|
73
|
+
ts.forEachChild(node, (child) => visit(child, excluded))
|
|
74
|
+
}
|
|
75
|
+
visit(file)
|
|
76
|
+
return found
|
|
77
|
+
}
|
package/people-search.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { unfound } from "@yaks/fts";
|
|
2
|
+
import { absent, and, eq, fields, limit, list, present, text } from "@yaks/query";
|
|
3
|
+
let value = (row, comp, prop)=>String(row[comp]?.[prop] ?? '');
|
|
4
|
+
let name = (row)=>value(row, 'doc', 'title');
|
|
5
|
+
let same = (a, b)=>a.toLowerCase() == b.toLowerCase();
|
|
6
|
+
let named = (title, words)=>same(title, words) || title.toLowerCase().startsWith(`${words.toLowerCase()} `);
|
|
7
|
+
let people = async (graph, words, hidden, n)=>(await graph.read(and(present('person'), text(words), fields('doc.title'), limit(n), ...hidden.map(absent)))).filter((row)=>named(name(row), words));
|
|
8
|
+
let relatives = async (graph, words, hidden, n)=>{
|
|
9
|
+
if (!graph.vocab.comp('relationship')) return [];
|
|
10
|
+
let possessive = words.match(/^(.+?)['’]s ([\p{L}-]+)$/iu);
|
|
11
|
+
let related = possessive ?? words.match(/^(.+) ([\p{L}-]+)$/u);
|
|
12
|
+
if (!related) return [];
|
|
13
|
+
let [, anchor, role] = related;
|
|
14
|
+
let anchors = await people(graph, anchor, hidden, n);
|
|
15
|
+
if (!anchors.length) return [];
|
|
16
|
+
let links = await graph.read(and(eq('relationship.role', role.toLowerCase()), eq(possessive ? 'edge.to' : 'edge.from', list(...anchors.map((row)=>row.entity.eid))), fields('edge'), limit(n), ...hidden.map(absent)));
|
|
17
|
+
let ends = new Set(links.flatMap((row)=>[
|
|
18
|
+
value(row, 'edge', 'from'),
|
|
19
|
+
value(row, 'edge', 'to')
|
|
20
|
+
]));
|
|
21
|
+
let rows = await graph.get([
|
|
22
|
+
...ends
|
|
23
|
+
], [
|
|
24
|
+
'person',
|
|
25
|
+
'doc.title',
|
|
26
|
+
...hidden
|
|
27
|
+
]);
|
|
28
|
+
let by = new Map(rows.filter((row)=>row.person && !hidden.some((c)=>row[c])).map((row)=>[
|
|
29
|
+
row.entity.eid,
|
|
30
|
+
row
|
|
31
|
+
]));
|
|
32
|
+
return links.flatMap((row)=>{
|
|
33
|
+
let from = value(row, 'edge', 'from'), to = by.get(value(row, 'edge', 'to'));
|
|
34
|
+
return by.has(from) && to ? [
|
|
35
|
+
{
|
|
36
|
+
entity: from,
|
|
37
|
+
snippet: `${name(to)}'s ${role}`
|
|
38
|
+
}
|
|
39
|
+
] : [];
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
let accounts = async (graph, words, hidden, n)=>{
|
|
43
|
+
if (!graph.vocab.comp('yaks_account')) return [];
|
|
44
|
+
let rows = await graph.read(and(present('yaks_account'), text(words), fields('yaks_account'), limit(n), ...hidden.map(absent)));
|
|
45
|
+
return rows.flatMap((row)=>{
|
|
46
|
+
let holder = value(row, 'yaks_account', 'holder');
|
|
47
|
+
let label = [
|
|
48
|
+
'name',
|
|
49
|
+
'handle'
|
|
50
|
+
].map((prop)=>value(row, 'yaks_account', prop)).find((value)=>same(value, words));
|
|
51
|
+
return holder && label ? [
|
|
52
|
+
{
|
|
53
|
+
entity: holder,
|
|
54
|
+
snippet: label
|
|
55
|
+
}
|
|
56
|
+
] : [];
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
let onYaks = async (graph, matches, hidden)=>{
|
|
60
|
+
if (!matches.length || !graph.vocab.comp('yaks_account')) return [];
|
|
61
|
+
let rows = await graph.read(and(eq('yaks_account.holder', list(...new Set(matches.map((h)=>h.entity)))), fields('yaks_account.holder', 'yaks_account.handle'), ...hidden.map(absent)));
|
|
62
|
+
let spaces = new Map();
|
|
63
|
+
for (let row of rows){
|
|
64
|
+
let holder = value(row, 'yaks_account', 'holder');
|
|
65
|
+
let handle = value(row, 'yaks_account', 'handle');
|
|
66
|
+
if (handle) {
|
|
67
|
+
spaces.set(holder, [
|
|
68
|
+
...spaces.get(holder) ?? [],
|
|
69
|
+
`${handle}.yaks.app`
|
|
70
|
+
]);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return matches.flatMap((match)=>{
|
|
74
|
+
let urls = spaces.get(match.entity);
|
|
75
|
+
return urls?.length ? [
|
|
76
|
+
{
|
|
77
|
+
...match,
|
|
78
|
+
snippet: [
|
|
79
|
+
match.snippet,
|
|
80
|
+
urls.sort().join(', ')
|
|
81
|
+
].filter(Boolean).join(' · ')
|
|
82
|
+
}
|
|
83
|
+
] : [];
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
// Resolve short name and relationship lookups from the graph before merging
|
|
87
|
+
// the general full-text and meaning ranks of documents and transcripts.
|
|
88
|
+
export let peopleSearch = async (graph, words, n)=>{
|
|
89
|
+
if (!graph.vocab.comp('person') || !graph.vocab.prop('doc', 'title')) {
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
let phrase = words.trim().replace(/^"(.*)"$/, '$1').replace(/\s+/g, ' ');
|
|
93
|
+
let withAccount = / yaks\.app(?: (?:account|space))?$/iu;
|
|
94
|
+
let subject = phrase.replace(withAccount, '');
|
|
95
|
+
if (!/^[\p{L}\p{N}][\p{L}\p{N} .&'’_-]{0,79}$/u.test(phrase) || subject.split(' ').length > 5) return [];
|
|
96
|
+
let hidden = unfound(graph.vocab).not ?? [];
|
|
97
|
+
let [names, relations, handles] = await Promise.all([
|
|
98
|
+
people(graph, subject, hidden, n),
|
|
99
|
+
relatives(graph, subject, hidden, n),
|
|
100
|
+
accounts(graph, subject, hidden, n)
|
|
101
|
+
]);
|
|
102
|
+
let matches = [
|
|
103
|
+
...names.map((row)=>({
|
|
104
|
+
entity: row.entity.eid,
|
|
105
|
+
snippet: ''
|
|
106
|
+
})),
|
|
107
|
+
...relations,
|
|
108
|
+
...handles
|
|
109
|
+
];
|
|
110
|
+
return subject == phrase ? matches : onYaks(graph, matches, hidden);
|
|
111
|
+
};
|
|
112
|
+
//# sourceMappingURL=people-search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"people-search.js","sources":["./people-search.ts"],"names":[],"mappings":"AAAA,SAAS,OAAO,yBAA8B;AAE9C,SACE,MAAM,EACN,GAAG,EACH,EAAE,EACF,MAAM,EACN,KAAK,EACL,IAAI,EACJ,OAAO,EACP,IAAI,2BACyB;AAK/B,IAAI,QAAQ,CAAC,KAAa,MAAc,OACtC,OAAO,AAAC,GAAG,CAAC,KAAK,EAAuB,CAAC,KAAK,IAAI;AAEpD,IAAI,OAAO,CAAC,MAAgB,MAAM,KAAK,OAAO;AAC9C,IAAI,OAAO,CAAC,GAAW,IAAc,EAAE,WAAW,MAAM,EA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