@athrio/loom 0.0.11 → 0.0.13

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.
@@ -0,0 +1,245 @@
1
+ #!/usr/bin/env node
2
+ import { An as forEach, Bt as Struct, Fi as flatMap$1, Gi as liftThrowable, Gr as findFirst, Gt as Unknown, Hn as mapError, Ji as none, Ki as map$1, Kt as decodeUnknownEffect, Li as fromNullishOr, Mi as contains, Nr as TaggedError, On as flatMap$2, Pn as gen, Pr as taggedEnum, Pt as Literals, Qt as optional, Rt as Record, Tn as fail, Xi as some, Yr as flatMap, Zi as toArray, _ as orElse, _a as pipe, ar as sync, b as when, cr as tryPromise, g as exhaustive, li as map, lr as try_, qi as match, qt as decodeUnknownOption, rr as succeed, y as value, zi as getOrElse, zt as String } from "./dist-LBqwqmSY.js";
3
+ import { execFile } from "node:child_process";
4
+ import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
5
+ import { dirname, join } from "node:path";
6
+ import { gunzipSync } from "node:zlib";
7
+ import { promisify } from "node:util";
8
+ Literals([
9
+ "headingTitle",
10
+ "sectionAnchor",
11
+ "warpAnchor",
12
+ "warpDef",
13
+ "specifier",
14
+ "sink",
15
+ "arrow",
16
+ "tilde",
17
+ "prose",
18
+ "frontmatterMembership",
19
+ "frontmatterValue",
20
+ "frontmatterTitle",
21
+ "frontmatterPart",
22
+ "frontmatterPartName",
23
+ "tocPart",
24
+ "tocEntry"
25
+ ]);
26
+ var SemanticTokenSchema = Literals([
27
+ "namespace",
28
+ "variable",
29
+ "keyword",
30
+ "string",
31
+ "operator"
32
+ ]);
33
+ var profile = (semantic, features) => ({
34
+ semantic,
35
+ features
36
+ });
37
+ var profileOf = (kind) => value(kind).pipe(when("headingTitle", () => profile(some("namespace"), {
38
+ navigation: true,
39
+ structure: true
40
+ })), when("sectionAnchor", () => profile(some("namespace"), {
41
+ navigation: true,
42
+ structure: true,
43
+ verification: true
44
+ })), when("warpAnchor", () => profile(some("variable"), {
45
+ navigation: true,
46
+ verification: true
47
+ })), when("warpDef", () => profile(some("variable"), { navigation: true })), when("specifier", () => profile(some("keyword"), { verification: true })), when("sink", () => profile(some("string"), { verification: true })), when("arrow", () => profile(some("operator"), {})), when("tilde", () => profile(some("operator"), {})), when("prose", () => profile(none(), { structure: true })), when("frontmatterMembership", () => profile(some("namespace"), { structure: true })), when("frontmatterValue", () => profile(some("string"), { structure: true })), when("frontmatterTitle", () => profile(some("namespace"), {
48
+ navigation: true,
49
+ structure: true
50
+ })), when("frontmatterPart", () => profile(some("namespace"), {
51
+ navigation: true,
52
+ structure: true
53
+ })), when("frontmatterPartName", () => profile(some("namespace"), {
54
+ navigation: true,
55
+ structure: true
56
+ })), when("tocPart", () => profile(some("namespace"), {
57
+ navigation: true,
58
+ structure: true
59
+ })), when("tocEntry", () => profile(some("namespace"), {
60
+ navigation: true,
61
+ structure: true,
62
+ verification: true
63
+ })), exhaustive);
64
+ var anchorKind = (warpsInScope, anchor) => warpsInScope.has(anchor.name.value) ? "warpAnchor" : "sectionAnchor";
65
+ var namesOf = (warps) => map(warps, (warp) => warp.name.value);
66
+ var at = (kind, position) => ({
67
+ kind,
68
+ position
69
+ });
70
+ var optSymbol = (kind, token) => toArray(map$1(fromNullishOr(token), (t) => at(kind, t.position)));
71
+ var frontmatterSymbols = (fm) => [
72
+ ...optSymbol("frontmatterPart", fm.part),
73
+ ...optSymbol("frontmatterPartName", fm.partName),
74
+ ...optSymbol("frontmatterMembership", fm.chapter),
75
+ ...optSymbol("frontmatterTitle", fm.title),
76
+ ...optSymbol("frontmatterValue", fm.package),
77
+ ...optSymbol("frontmatterValue", fm.language)
78
+ ];
79
+ var tocSymbols = (weft) => [...optSymbol("tocPart", weft.part), ...optSymbol("tocEntry", weft.title)];
80
+ var headingSymbols = (heading) => [
81
+ ...toArray(map$1(fromNullishOr(heading.title), (t) => at("headingTitle", t.position))),
82
+ ...toArray(map$1(fromNullishOr(heading.specifier), (s) => at("specifier", s.label.position))),
83
+ ...toArray(map$1(fromNullishOr(heading.sink), (s) => at("sink", s.position)))
84
+ ];
85
+ var delimiterOf = (weft) => value(weft).pipe(when({ type: "ArrowWeft" }, (w) => [at("arrow", w.arrow.position)]), when({ type: "TildeWeft" }, (w) => [at("tilde", w.tilde.position)]), orElse(() => []));
86
+ var sectionSymbols = (section, documentWarps) => {
87
+ const warps = flatMap(section.preamble, (weft) => weft.warps);
88
+ const scope = /* @__PURE__ */ new Set([...documentWarps, ...namesOf(warps)]);
89
+ const anchors = [...flatMap(section.preamble, (weft) => weft.anchors), ...flatMap(section.code, (weft) => weft.anchors)];
90
+ return [
91
+ ...headingSymbols(section.heading),
92
+ ...map(warps, (warp) => at("warpDef", warp.name.position)),
93
+ ...map(anchors, (anchor) => at(anchorKind(scope, anchor), anchor.name.position)),
94
+ ...flatMap(section.code, delimiterOf),
95
+ ...flatMap(section.entries ?? [], tocSymbols)
96
+ ];
97
+ };
98
+ var symbolsOf = (doc) => {
99
+ const warps = flatMap(doc.preamble, (weft) => weft.warps);
100
+ const scope = new Set(namesOf(warps));
101
+ return [
102
+ ...flatMap(toArray(fromNullishOr(doc.frontmatter)), frontmatterSymbols),
103
+ ...map(warps, (warp) => at("warpDef", warp.name.position)),
104
+ ...map(flatMap(doc.preamble, (weft) => weft.anchors), (anchor) => at(anchorKind(scope, anchor), anchor.name.position)),
105
+ ...flatMap(doc.sections, (section) => sectionSymbols(section, namesOf(warps)))
106
+ ];
107
+ };
108
+ var symbolAt = (doc, offset) => findFirst(symbolsOf(doc), (symbol) => symbol.position.start.offset <= offset && offset <= symbol.position.end.offset);
109
+ //#endregion
110
+ //#region ../loom-lang-services/src/LoomStore.ts
111
+ var run = promisify(execFile);
112
+ var servicePackage = (id) => `@athrio/loom-service-${id}`;
113
+ var workspaceOf = (dir) => {
114
+ if (existsSync(join(dir, ".loom"))) return some(dir);
115
+ const parent = dirname(dir);
116
+ return parent === dir ? none() : workspaceOf(parent);
117
+ };
118
+ var workspaceRoot = (dir) => getOrElse(workspaceOf(dir), () => dir);
119
+ var storeDir = (dir) => process.env.LOOM_HOME === void 0 ? join(workspaceRoot(dir), ".loom", "services") : join(process.env.LOOM_HOME, "services");
120
+ var ServiceManifestSchema = Struct({
121
+ version: optional(String),
122
+ main: optional(String),
123
+ exports: optional(Unknown)
124
+ });
125
+ var serviceDir = (id, dir) => join(storeDir(dir), "node_modules", servicePackage(id));
126
+ var serviceManifest = (id, dir) => pipe(liftThrowable(() => readFileSync(join(serviceDir(id, dir), "package.json"), "utf8"))(), flatMap$1(liftThrowable((text) => JSON.parse(text))), flatMap$1(decodeUnknownOption(ServiceManifestSchema)));
127
+ var serviceVersion = "0.0.13";
128
+ var installedVersion = (id, dir) => flatMap$1(serviceManifest(id, dir), (manifest) => fromNullishOr(manifest.version));
129
+ var standalone = /[\\/](\$bunfs|~BUN)[\\/]/.test(import.meta.url);
130
+ var embeddedFile = (name) => pipe(fromNullishOr(globalThis.Bun?.embeddedFiles), flatMap$1(findFirst((file) => file.name === name)));
131
+ var StoreError = class extends TaggedError("StoreError") {};
132
+ var prepareStore = (store) => {
133
+ mkdirSync(store, { recursive: true });
134
+ const manifest = join(store, "package.json");
135
+ if (!existsSync(manifest)) writeFileSync(manifest, `${JSON.stringify({
136
+ name: "loom-services",
137
+ private: true
138
+ }, null, 2)}\n`);
139
+ };
140
+ var packageManager = (store, spec) => standalone ? {
141
+ command: process.execPath,
142
+ args: [
143
+ "add",
144
+ spec,
145
+ "--cwd",
146
+ store,
147
+ "--omit",
148
+ "peer"
149
+ ],
150
+ env: {
151
+ ...process.env,
152
+ BUN_BE_BUN: "1"
153
+ }
154
+ } : {
155
+ command: "npm",
156
+ args: [
157
+ "install",
158
+ spec,
159
+ "--prefix",
160
+ store,
161
+ "--omit=peer",
162
+ "--no-audit",
163
+ "--no-fund"
164
+ ],
165
+ env: process.env
166
+ };
167
+ var installPackage = (dir, packageName, range) => gen(function* () {
168
+ const store = storeDir(dir);
169
+ yield* sync(() => prepareStore(store));
170
+ const manager = packageManager(store, `${packageName}@${range}`);
171
+ yield* tryPromise({
172
+ try: () => run(manager.command, [...manager.args], { env: manager.env }),
173
+ catch: (cause) => new StoreError({
174
+ packageName,
175
+ cause
176
+ })
177
+ });
178
+ });
179
+ var ServiceInstall = taggedEnum();
180
+ var installService = (id, dir) => gen(function* () {
181
+ const installed = installedVersion(id, dir);
182
+ if (contains(installed, "0.0.13")) return ServiceInstall.Current();
183
+ yield* installPackage(dir, servicePackage(id), serviceVersion);
184
+ return match(installed, {
185
+ onNone: () => ServiceInstall.Installed(),
186
+ onSome: (from) => ServiceInstall.Updated({ from })
187
+ });
188
+ });
189
+ var storeTypeScript = (dir) => {
190
+ const file = join(storeDir(dir), "node_modules", "typescript", "lib", "typescript.js");
191
+ return existsSync(file) ? some(file) : none();
192
+ };
193
+ var typeScriptAsset = "typescript.json.gz";
194
+ var PackedTypeScriptSchema = Struct({ files: Record(String, String) });
195
+ var typeScriptError = (cause) => new StoreError({
196
+ packageName: "typescript",
197
+ cause
198
+ });
199
+ var unpackTypeScript = (dir, packed) => gen(function* () {
200
+ const archive = yield* tryPromise({
201
+ try: async () => new Uint8Array(await packed.arrayBuffer()),
202
+ catch: typeScriptError
203
+ });
204
+ const json = yield* try_({
205
+ try: () => JSON.parse(gunzipSync(archive).toString("utf8")),
206
+ catch: typeScriptError
207
+ });
208
+ const { files } = yield* decodeUnknownEffect(PackedTypeScriptSchema)(json).pipe(mapError(typeScriptError));
209
+ const store = storeDir(dir);
210
+ const modules = join(store, "node_modules");
211
+ const partial = join(modules, `.typescript-${process.pid}`);
212
+ yield* sync(() => prepareStore(store));
213
+ yield* forEach(Object.entries(files), ([path, text]) => try_({
214
+ try: () => {
215
+ mkdirSync(dirname(join(partial, path)), { recursive: true });
216
+ writeFileSync(join(partial, path), text);
217
+ },
218
+ catch: typeScriptError
219
+ }), { discard: true });
220
+ yield* try_({
221
+ try: () => {
222
+ rmSync(join(modules, "typescript"), {
223
+ recursive: true,
224
+ force: true
225
+ });
226
+ renameSync(partial, join(modules, "typescript"));
227
+ },
228
+ catch: typeScriptError
229
+ });
230
+ });
231
+ var installTypeScript = (dir) => match(embeddedFile(typeScriptAsset), {
232
+ onSome: (packed) => unpackTypeScript(dir, packed),
233
+ onNone: () => installPackage(dir, "typescript", "^6")
234
+ }).pipe(flatMap$2(() => match(storeTypeScript(dir), {
235
+ onNone: () => fail(typeScriptError("the store holds no lib/typescript.js")),
236
+ onSome: succeed
237
+ })));
238
+ var removeService = (id, dir) => sync(() => rmSync(serviceDir(id, dir), {
239
+ recursive: true,
240
+ force: true
241
+ }));
242
+ //#endregion
243
+ export { profileOf as _, installedVersion as a, serviceManifest as c, standalone as d, storeDir as f, SemanticTokenSchema as g, workspaceRoot as h, installTypeScript as i, servicePackage as l, workspaceOf as m, embeddedFile as n, removeService as o, storeTypeScript as p, installService as r, serviceDir as s, ServiceInstall as t, serviceVersion as u, symbolAt as v, symbolsOf as y };
244
+
245
+ //# sourceMappingURL=LoomStore-axDgE8RF.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LoomStore-axDgE8RF.js","names":[],"sources":["../../loom-ast/src/ast/LoomSymbol.ts","../../loom-lang-services/src/LoomStore.ts"],"sourcesContent":["import { Array, Match, Option, Schema } from 'effect'\nimport { type Position } from '#ast/LoomNode'\nimport {\n type LoomDocument,\n type LoomFrontmatter,\n type LoomHeading,\n type LoomSection,\n} from '#ast/LoomAst'\nimport { type SectionBodyWeft, type TocWeft } from '#ast/Weft'\nimport { type WarpAnchorToken, type WarpToken } from '#ast/LoomTokens'\n\nexport const SymbolKindSchema = Schema.Literals([\n 'headingTitle',\n 'sectionAnchor',\n 'warpAnchor',\n 'warpDef',\n 'specifier',\n 'sink',\n 'arrow',\n 'tilde',\n 'prose',\n 'frontmatterMembership',\n 'frontmatterValue',\n 'frontmatterTitle',\n 'frontmatterPart',\n 'frontmatterPartName',\n 'tocPart',\n 'tocEntry',\n])\nexport type SymbolKind = typeof SymbolKindSchema.Type\n\nexport interface SpanFeatures {\n readonly navigation?: boolean\n readonly semantic?: boolean\n readonly structure?: boolean\n readonly verification?: boolean\n readonly completion?: boolean\n}\n\nexport const SemanticTokenSchema = Schema.Literals([\n 'namespace',\n 'variable',\n 'keyword',\n 'string',\n 'operator',\n])\nexport type SemanticToken = typeof SemanticTokenSchema.Type\n\nexport interface SymbolProfile {\n readonly semantic: Option.Option<SemanticToken>\n readonly features: SpanFeatures\n}\n\nconst profile = (\n semantic: Option.Option<SemanticToken>,\n features: SpanFeatures,\n): SymbolProfile => ({ semantic, features })\n\nexport const profileOf = (kind: SymbolKind): SymbolProfile =>\n Match.value(kind).pipe(\n Match.when('headingTitle', () =>\n profile(Option.some('namespace'), { navigation: true, structure: true }),\n ),\n Match.when('sectionAnchor', () =>\n profile(Option.some('namespace'), {\n navigation: true,\n structure: true,\n verification: true,\n }),\n ),\n Match.when('warpAnchor', () =>\n profile(Option.some('variable'), { navigation: true, verification: true }),\n ),\n Match.when('warpDef', () => profile(Option.some('variable'), { navigation: true })),\n Match.when('specifier', () => profile(Option.some('keyword'), { verification: true })),\n Match.when('sink', () => profile(Option.some('string'), { verification: true })),\n Match.when('arrow', () => profile(Option.some('operator'), {})),\n Match.when('tilde', () => profile(Option.some('operator'), {})),\n Match.when('prose', () => profile(Option.none(), { structure: true })),\n Match.when('frontmatterMembership', () =>\n profile(Option.some('namespace'), { structure: true }),\n ),\n Match.when('frontmatterValue', () => profile(Option.some('string'), { structure: true })),\n Match.when('frontmatterTitle', () =>\n profile(Option.some('namespace'), { navigation: true, structure: true }),\n ),\n Match.when('frontmatterPart', () =>\n profile(Option.some('namespace'), { navigation: true, structure: true }),\n ),\n Match.when('frontmatterPartName', () =>\n profile(Option.some('namespace'), { navigation: true, structure: true }),\n ),\n Match.when('tocPart', () =>\n profile(Option.some('namespace'), { navigation: true, structure: true }),\n ),\n Match.when('tocEntry', () =>\n profile(Option.some('namespace'), {\n navigation: true,\n structure: true,\n verification: true,\n }),\n ),\n Match.exhaustive,\n )\n\nexport interface Symbol {\n readonly kind: SymbolKind\n readonly position: Position\n}\n\nconst anchorKind = (warpsInScope: ReadonlySet<string>, anchor: WarpAnchorToken): SymbolKind =>\n warpsInScope.has(anchor.name.value) ? 'warpAnchor' : 'sectionAnchor'\n\nconst namesOf = (warps: ReadonlyArray<WarpToken>): ReadonlyArray<string> =>\n Array.map(warps, (warp) => warp.name.value)\n\nconst at = (kind: SymbolKind, position: Position): Symbol => ({ kind, position })\n\nconst optSymbol = (\n kind: SymbolKind,\n token: { readonly position: Position } | undefined,\n): ReadonlyArray<Symbol> =>\n Option.toArray(Option.map(Option.fromNullishOr(token), (t) => at(kind, t.position)))\n\nconst frontmatterSymbols = (fm: LoomFrontmatter): ReadonlyArray<Symbol> => [\n ...optSymbol('frontmatterPart', fm.part),\n ...optSymbol('frontmatterPartName', fm.partName),\n ...optSymbol('frontmatterMembership', fm.chapter),\n ...optSymbol('frontmatterTitle', fm.title),\n ...optSymbol('frontmatterValue', fm.package),\n ...optSymbol('frontmatterValue', fm.language),\n]\n\nconst tocSymbols = (weft: TocWeft): ReadonlyArray<Symbol> => [\n ...optSymbol('tocPart', weft.part),\n ...optSymbol('tocEntry', weft.title),\n]\n\nconst headingSymbols = (heading: LoomHeading): ReadonlyArray<Symbol> => [\n ...Option.toArray(\n Option.map(Option.fromNullishOr(heading.title), (t) => at('headingTitle', t.position)),\n ),\n ...Option.toArray(\n Option.map(Option.fromNullishOr(heading.specifier), (s) => at('specifier', s.label.position)),\n ),\n ...Option.toArray(Option.map(Option.fromNullishOr(heading.sink), (s) => at('sink', s.position))),\n]\n\nconst delimiterOf = (weft: SectionBodyWeft): ReadonlyArray<Symbol> =>\n Match.value(weft).pipe(\n Match.when({ type: 'ArrowWeft' }, (w) => [at('arrow', w.arrow.position)]),\n Match.when({ type: 'TildeWeft' }, (w) => [at('tilde', w.tilde.position)]),\n Match.orElse(() => []),\n )\n\nconst sectionSymbols = (\n section: LoomSection,\n documentWarps: ReadonlyArray<string>,\n): ReadonlyArray<Symbol> => {\n const warps = Array.flatMap(section.preamble, (weft) => weft.warps)\n const scope = new Set([...documentWarps, ...namesOf(warps)])\n const anchors = [\n ...Array.flatMap(section.preamble, (weft) => weft.anchors),\n ...Array.flatMap(section.code, (weft) => weft.anchors),\n ]\n return [\n ...headingSymbols(section.heading),\n ...Array.map(warps, (warp) => at('warpDef', warp.name.position)),\n ...Array.map(anchors, (anchor) => at(anchorKind(scope, anchor), anchor.name.position)),\n ...Array.flatMap(section.code, delimiterOf),\n ...Array.flatMap(section.entries ?? [], tocSymbols),\n ]\n}\n\nexport const symbolsOf = (doc: LoomDocument): ReadonlyArray<Symbol> => {\n const warps = Array.flatMap(doc.preamble, (weft) => weft.warps)\n const scope = new Set(namesOf(warps))\n return [\n ...Array.flatMap(Option.toArray(Option.fromNullishOr(doc.frontmatter)), frontmatterSymbols),\n ...Array.map(warps, (warp) => at('warpDef', warp.name.position)),\n ...Array.map(\n Array.flatMap(doc.preamble, (weft) => weft.anchors),\n (anchor) => at(anchorKind(scope, anchor), anchor.name.position),\n ),\n ...Array.flatMap(doc.sections, (section) => sectionSymbols(section, namesOf(warps))),\n ]\n}\n\nexport const symbolAt = (doc: LoomDocument, offset: number): Option.Option<Symbol> =>\n Array.findFirst(\n symbolsOf(doc),\n (symbol) => symbol.position.start.offset <= offset && offset <= symbol.position.end.offset,\n )\n","import { Array, Data, Effect, Option, Schema, pipe } from 'effect'\nimport { execFile } from 'node:child_process'\nimport {\n existsSync,\n mkdirSync,\n readdirSync,\n readFileSync,\n renameSync,\n rmSync,\n writeFileSync,\n} from 'node:fs'\nimport { dirname, join } from 'node:path'\nimport { promisify } from 'node:util'\nimport { gunzipSync } from 'node:zlib'\n\nconst run = promisify(execFile)\n\nexport const servicePackage = (id: string): string => `@athrio/loom-service-${id}`\n\nexport const workspaceOf = (dir: string): Option.Option<string> => {\n if (existsSync(join(dir, '.loom'))) return Option.some(dir)\n const parent = dirname(dir)\n return parent === dir ? Option.none() : workspaceOf(parent)\n}\n\nexport const workspaceRoot = (dir: string): string => Option.getOrElse(workspaceOf(dir), () => dir)\n\nexport const storeDir = (dir: string): string =>\n process.env.LOOM_HOME === undefined\n ? join(workspaceRoot(dir), '.loom', 'services')\n : join(process.env.LOOM_HOME, 'services')\n\nconst servicePrefix = 'loom-service-'\n\nexport const installedServices = (dir: string): Effect.Effect<ReadonlyArray<string>> =>\n Effect.sync(() => {\n const scope = join(storeDir(dir), 'node_modules', '@athrio')\n if (!existsSync(scope)) return []\n return readdirSync(scope)\n .filter((name) => name.startsWith(servicePrefix))\n .map((name) => name.slice(servicePrefix.length))\n })\n\nexport const ServiceManifestSchema = Schema.Struct({\n version: Schema.optional(Schema.String),\n main: Schema.optional(Schema.String),\n exports: Schema.optional(Schema.Unknown),\n})\n\nexport type ServiceManifest = typeof ServiceManifestSchema.Type\n\nexport const serviceDir = (id: string, dir: string): string =>\n join(storeDir(dir), 'node_modules', servicePackage(id))\n\nexport const serviceManifest = (id: string, dir: string): Option.Option<ServiceManifest> =>\n pipe(\n Option.liftThrowable(() => readFileSync(join(serviceDir(id, dir), 'package.json'), 'utf8'))(),\n Option.flatMap(Option.liftThrowable((text: string): unknown => JSON.parse(text))),\n Option.flatMap(Schema.decodeUnknownOption(ServiceManifestSchema)),\n )\n\nexport const serviceVersion = '0.0.13'\n\nexport const installedVersion = (id: string, dir: string): Option.Option<string> =>\n Option.flatMap(serviceManifest(id, dir), (manifest) => Option.fromNullishOr(manifest.version))\n\nexport const standalone: boolean = /[\\\\/](\\$bunfs|~BUN)[\\\\/]/.test(import.meta.url)\n\ninterface EmbeddedFile extends Blob {\n readonly name?: string\n}\n\nexport const embeddedFile = (name: string): Option.Option<EmbeddedFile> =>\n pipe(\n Option.fromNullishOr(\n (globalThis as { readonly Bun?: { readonly embeddedFiles?: ReadonlyArray<EmbeddedFile> } })\n .Bun?.embeddedFiles,\n ),\n Option.flatMap(Array.findFirst((file) => file.name === name)),\n )\n\nexport class StoreError extends Data.TaggedError('StoreError')<{\n readonly packageName: string\n readonly cause: unknown\n}> {}\n\nconst prepareStore = (store: string): void => {\n mkdirSync(store, { recursive: true })\n const manifest = join(store, 'package.json')\n if (!existsSync(manifest))\n writeFileSync(\n manifest,\n `${JSON.stringify({ name: 'loom-services', private: true }, null, 2)}\\n`,\n )\n}\n\ninterface PackageManager {\n readonly command: string\n readonly args: ReadonlyArray<string>\n readonly env: NodeJS.ProcessEnv\n}\n\nconst packageManager = (store: string, spec: string): PackageManager =>\n standalone\n ? {\n command: process.execPath,\n args: ['add', spec, '--cwd', store, '--omit', 'peer'],\n env: { ...process.env, BUN_BE_BUN: '1' },\n }\n : {\n command: 'npm',\n args: ['install', spec, '--prefix', store, '--omit=peer', '--no-audit', '--no-fund'],\n env: process.env,\n }\n\nconst installPackage = (\n dir: string,\n packageName: string,\n range: string,\n): Effect.Effect<void, StoreError> =>\n Effect.gen(function* () {\n const store = storeDir(dir)\n yield* Effect.sync(() => prepareStore(store))\n const manager = packageManager(store, `${packageName}@${range}`)\n yield* Effect.tryPromise({\n try: () => run(manager.command, [...manager.args], { env: manager.env }),\n catch: (cause) => new StoreError({ packageName, cause }),\n })\n })\n\nexport type ServiceInstall = Data.TaggedEnum<{\n Current: {}\n Installed: {}\n Updated: { readonly from: string }\n}>\nexport const ServiceInstall = Data.taggedEnum<ServiceInstall>()\n\nexport const installService = (id: string, dir: string): Effect.Effect<ServiceInstall, StoreError> =>\n Effect.gen(function* () {\n const installed = installedVersion(id, dir)\n if (Option.contains(installed, serviceVersion)) return ServiceInstall.Current()\n yield* installPackage(dir, servicePackage(id), serviceVersion)\n return Option.match(installed, {\n onNone: () => ServiceInstall.Installed(),\n onSome: (from) => ServiceInstall.Updated({ from }),\n })\n })\n\nexport const typeScriptRange = '^6'\n\nexport const storeTypeScript = (dir: string): Option.Option<string> => {\n const file = join(storeDir(dir), 'node_modules', 'typescript', 'lib', 'typescript.js')\n return existsSync(file) ? Option.some(file) : Option.none()\n}\n\nconst typeScriptAsset = 'typescript.json.gz'\n\nconst PackedTypeScriptSchema = Schema.Struct({\n files: Schema.Record(Schema.String, Schema.String),\n})\n\nconst typeScriptError = (cause: unknown): StoreError =>\n new StoreError({ packageName: 'typescript', cause })\n\nconst unpackTypeScript = (dir: string, packed: Blob): Effect.Effect<void, StoreError> =>\n Effect.gen(function* () {\n const archive = yield* Effect.tryPromise({\n try: async () => new Uint8Array(await packed.arrayBuffer()),\n catch: typeScriptError,\n })\n const json = yield* Effect.try({\n try: (): unknown => JSON.parse(gunzipSync(archive).toString('utf8')),\n catch: typeScriptError,\n })\n const { files } = yield* Schema.decodeUnknownEffect(PackedTypeScriptSchema)(json).pipe(\n Effect.mapError(typeScriptError),\n )\n const store = storeDir(dir)\n const modules = join(store, 'node_modules')\n const partial = join(modules, `.typescript-${process.pid}`)\n yield* Effect.sync(() => prepareStore(store))\n yield* Effect.forEach(\n Object.entries(files),\n ([path, text]) =>\n Effect.try({\n try: () => {\n mkdirSync(dirname(join(partial, path)), { recursive: true })\n writeFileSync(join(partial, path), text)\n },\n catch: typeScriptError,\n }),\n { discard: true },\n )\n yield* Effect.try({\n try: () => {\n rmSync(join(modules, 'typescript'), { recursive: true, force: true })\n renameSync(partial, join(modules, 'typescript'))\n },\n catch: typeScriptError,\n })\n })\n\nexport const installTypeScript = (dir: string): Effect.Effect<string, StoreError> =>\n Option.match(embeddedFile(typeScriptAsset), {\n onSome: (packed) => unpackTypeScript(dir, packed),\n onNone: () => installPackage(dir, 'typescript', typeScriptRange),\n }).pipe(\n Effect.flatMap(() =>\n Option.match(storeTypeScript(dir), {\n onNone: () => Effect.fail(typeScriptError('the store holds no lib/typescript.js')),\n onSome: Effect.succeed,\n }),\n ),\n )\n\nexport const removeService = (id: string, dir: string): Effect.Effect<void> =>\n Effect.sync(() => rmSync(serviceDir(id, dir), { recursive: true, force: true }))\n"],"mappings":";;;;;;;AAWgC,SAAgB;CAC9C;CACA;CACA;CACA;CACA;CACA;CACA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AO;CACT,CAAC,GACH,EAAE,SAAS,KAAK,CAClB;CACA,OAAO,KAAW;EAChB,WAAW;GACT,OAAO,KAAK,SAAS,YAAY,GAAG;IAAE,WAAW;IAAM,OAAO;GAAK,CAAC;GACpE,WAAW,SAAS,KAAK,SAAS,YAAY,CAAC;EACjD;EACA,OAAO;CACT,CAAC;AACH,CAAC;AAEH,IAAa,qBAAqB,QAChC,MAAa,aAAa,eAAe,GAAG;CAC1C,SAAS,WAAW,iBAAiB,KAAK,MAAM;CAChD,cAAc,eAAe,KAAK,cAAA,IAA6B;AACjE,CAAC,CAAC,CAAC,KACD,gBACE,MAAa,gBAAgB,GAAG,GAAG;CACjC,cAAc,KAAY,gBAAgB,sCAAsC,CAAC;CACjF,QAAQ;AACV,CAAC,CACH,CACF;AAEF,IAAa,iBAAiB,IAAY,QACxC,WAAkB,OAAO,WAAW,IAAI,GAAG,GAAG;CAAE,WAAW;CAAM,OAAO;AAAK,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import { i as runtimeVersion, n as runtimeKey, r as runtimeSpecifiers, t as installHostRuntime } from "./Runtime-D4WijrpR.js";
3
+ export { installHostRuntime, runtimeKey, runtimeSpecifiers, runtimeVersion };
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env node
2
+ import { t as dist_exports } from "./dist-LBqwqmSY.js";
3
+ import { r as LanguageService_exports } from "./LanguageService-CcElIYBZ.js";
4
+ //#region ../loom-lang-services/src/Runtime.ts
5
+ var runtimeKey = "__loomRuntime";
6
+ var runtimeVersion = "1";
7
+ var runtimeSpecifiers = [
8
+ "effect",
9
+ "@athrio/loom-lang-services/LanguageService",
10
+ "typescript"
11
+ ];
12
+ var installHostRuntime = (tsdk) => {
13
+ globalThis[runtimeKey] = {
14
+ version: "1",
15
+ modules: {
16
+ effect: dist_exports,
17
+ "@athrio/loom-lang-services/LanguageService": LanguageService_exports,
18
+ typescript: tsdk
19
+ }
20
+ };
21
+ };
22
+ //#endregion
23
+ export { runtimeVersion as i, runtimeKey as n, runtimeSpecifiers as r, installHostRuntime as t };
24
+
25
+ //# sourceMappingURL=Runtime-D4WijrpR.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Runtime-D4WijrpR.js","names":[],"sources":["../../loom-lang-services/src/Runtime.ts"],"sourcesContent":["export const runtimeKey = '__loomRuntime'\n\nexport const runtimeVersion = '1'\n\nexport const runtimeSpecifiers: ReadonlyArray<string> = [\n 'effect',\n '@athrio/loom-lang-services/LanguageService',\n 'typescript',\n]\n\nimport * as EffectNS from 'effect'\nimport * as LanguageServiceNS from './LanguageService'\n\ninterface HostRuntime {\n readonly version: string\n readonly modules: Record<string, unknown>\n}\n\nexport const installHostRuntime = (tsdk: typeof import('typescript')): void => {\n ;(globalThis as Record<string, unknown>)[runtimeKey] = {\n version: runtimeVersion,\n modules: {\n effect: EffectNS,\n '@athrio/loom-lang-services/LanguageService': LanguageServiceNS,\n typescript: tsdk,\n },\n } satisfies HostRuntime\n}\n"],"mappings":";;;;AAAA,IAAa,aAAa;AAE1B,IAAa,iBAAiB;AAE9B,IAAa,oBAA2C;CACtD;CACA;CACA;AACF;AAUA,IAAa,sBAAsB,SAA4C;CAC5E,WAAwC,cAAc;EACrD,SAAA;EACA,SAAS;GACP,QAAQ;GACR,8CAA8C;GAC9C,YAAY;EACd;CACF;AACF"}