@athrio/loom 0.0.10 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/{LoomServer-JbCtLtxV.js → LoomServer-mL8VcuCS.js} +2 -4
- package/dist/{LoomServer-JbCtLtxV.js.map → LoomServer-mL8VcuCS.js.map} +1 -1
- package/dist/{SqlClient-BHo_uVyk.js → LoomStore-DTpgIJ9l.js} +63400 -26958
- package/dist/LoomStore-DTpgIJ9l.js.map +1 -0
- package/dist/main.js +1554 -100
- package/dist/main.js.map +1 -1
- package/package.json +3 -4
- package/dist/Cache-Dv3Qogvb.js +0 -1048
- package/dist/Cache-Dv3Qogvb.js.map +0 -1
- package/dist/LoomStore-BGlpRj6W.js +0 -8857
- package/dist/LoomStore-BGlpRj6W.js.map +0 -1
- package/dist/NodeServices-CtEw3D6F.js +0 -1564
- package/dist/NodeServices-CtEw3D6F.js.map +0 -1
- package/dist/SqlClient-BHo_uVyk.js.map +0 -1
- package/dist/SqlError-BwVJTsti.js +0 -408
- package/dist/SqlError-BwVJTsti.js.map +0 -1
- package/dist/design-S_129JVC.js +0 -18524
- package/dist/design-S_129JVC.js.map +0 -1
- package/dist/dist-3ptbWhlX.js +0 -202
- package/dist/dist-3ptbWhlX.js.map +0 -1
- package/dist/dist-CKhPOkpR.js +0 -27469
- package/dist/dist-CKhPOkpR.js.map +0 -1
- package/dist/dist-kscTHM4c.js +0 -151
- package/dist/dist-kscTHM4c.js.map +0 -1
- package/dist/identity-DvFsrt2d.js +0 -95
- package/dist/identity-DvFsrt2d.js.map +0 -1
- package/dist/overlay.js +0 -80
- package/dist/store-CtvrwAS8.js +0 -3
- package/dist/store-DgMmJ7v9.js +0 -229
- package/dist/store-DgMmJ7v9.js.map +0 -1
- package/dist/ui.html +0 -103
- package/dist/ui.js +0 -79
package/dist/dist-kscTHM4c.js
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { r as __exportAll } from "./rolldown-runtime-YU9U6SYh.js";
|
|
3
|
-
import { A as die, Ah as identity, Bs as gen, Cf as getUnsafe, Es as fail, Gc as tap, Hl as provide, Ll as effectContext, Os as flatMap, Qs as map, Ta as make$1, Vc as succeed, Wc as sync, Yl as addFinalizer$1, Zc as try_, _f as Service, a as makeCompilerSqlite, bf as get, d as unwrap, i as defaultTransforms, n as SqlClient, nl as uninterruptibleMask, o as layer$1, ql as Scope, r as make$2, rs as addFinalizer, sl as withFiber, ss as as, t as SafeIntegers, to as getCurrent, vf as add, wf as make$3 } from "./SqlClient-BHo_uVyk.js";
|
|
4
|
-
import { n as classifySqliteError, t as SqlError } from "./SqlError-BwVJTsti.js";
|
|
5
|
-
import { Database } from "bun:sqlite";
|
|
6
|
-
//#region ../../node_modules/@effect/sql-sqlite-bun/dist/SqliteClient.js
|
|
7
|
-
/**
|
|
8
|
-
* Connects Effect SQL to SQLite when running on Bun, using `bun:sqlite`.
|
|
9
|
-
*
|
|
10
|
-
* This module opens a SQLite database and exposes it as both `SqliteClient` and
|
|
11
|
-
* the generic Effect SQL client. It serializes access to the database, enables
|
|
12
|
-
* WAL mode unless disabled, and supports database export and extension loading.
|
|
13
|
-
* Streaming queries and `updateValues` are not supported by this driver.
|
|
14
|
-
*
|
|
15
|
-
* @since 4.0.0
|
|
16
|
-
*/
|
|
17
|
-
var SqliteClient_exports = /* @__PURE__ */ __exportAll({
|
|
18
|
-
SqliteClient: () => SqliteClient,
|
|
19
|
-
TypeId: () => TypeId,
|
|
20
|
-
layer: () => layer,
|
|
21
|
-
layerConfig: () => layerConfig,
|
|
22
|
-
make: () => make
|
|
23
|
-
});
|
|
24
|
-
var ATTR_DB_SYSTEM_NAME = "db.system.name";
|
|
25
|
-
var classifyError = (cause, message, operation) => classifySqliteError(cause, {
|
|
26
|
-
message,
|
|
27
|
-
operation
|
|
28
|
-
});
|
|
29
|
-
/**
|
|
30
|
-
* Runtime type identifier used to mark Bun `SqliteClient` values.
|
|
31
|
-
*
|
|
32
|
-
* @category type IDs
|
|
33
|
-
* @since 4.0.0
|
|
34
|
-
*/
|
|
35
|
-
var TypeId = "~@effect/sql-sqlite-bun/SqliteClient";
|
|
36
|
-
/**
|
|
37
|
-
* Service tag for the Bun SQLite client service.
|
|
38
|
-
*
|
|
39
|
-
* **When to use**
|
|
40
|
-
*
|
|
41
|
-
* Use to access or provide a Bun SQLite client through the Effect context.
|
|
42
|
-
*
|
|
43
|
-
* @category services
|
|
44
|
-
* @since 4.0.0
|
|
45
|
-
*/
|
|
46
|
-
var SqliteClient = /*#__PURE__*/ Service("@effect/sql-sqlite-bun/Client");
|
|
47
|
-
/**
|
|
48
|
-
* Creates a scoped Bun SQLite client for a database file, enabling WAL by default and serializing access. Streaming queries are not implemented.
|
|
49
|
-
*
|
|
50
|
-
* @category constructors
|
|
51
|
-
* @since 4.0.0
|
|
52
|
-
*/
|
|
53
|
-
var make = (options) => gen(function* () {
|
|
54
|
-
const compiler = makeCompilerSqlite(options.transformQueryNames);
|
|
55
|
-
const transformRows = options.transformResultNames ? defaultTransforms(options.transformResultNames).array : void 0;
|
|
56
|
-
const makeConnection = gen(function* () {
|
|
57
|
-
const db = new Database(options.filename, {
|
|
58
|
-
readonly: options.readonly,
|
|
59
|
-
readwrite: options.readwrite ?? true,
|
|
60
|
-
create: options.create ?? true
|
|
61
|
-
});
|
|
62
|
-
yield* addFinalizer(() => sync(() => db.close()));
|
|
63
|
-
if (options.disableWAL !== true) db.run("PRAGMA journal_mode = WAL;");
|
|
64
|
-
const prepare = (sql, useSafeIntegers) => {
|
|
65
|
-
const statement = db.query(sql);
|
|
66
|
-
statement.safeIntegers(useSafeIntegers);
|
|
67
|
-
return statement;
|
|
68
|
-
};
|
|
69
|
-
const run = (sql, params = []) => withFiber((fiber) => {
|
|
70
|
-
const useSafeIntegers = get(fiber.context, SafeIntegers);
|
|
71
|
-
try {
|
|
72
|
-
return succeed(prepare(sql, useSafeIntegers).all(...params) ?? []);
|
|
73
|
-
} catch (cause) {
|
|
74
|
-
return fail(new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") }));
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
const runValues = (sql, params = []) => withFiber((fiber) => {
|
|
78
|
-
const useSafeIntegers = get(fiber.context, SafeIntegers);
|
|
79
|
-
try {
|
|
80
|
-
return succeed(prepare(sql, useSafeIntegers).values(...params) ?? []);
|
|
81
|
-
} catch (cause) {
|
|
82
|
-
return fail(new SqlError({ reason: classifyError(cause, "Failed to execute statement", "executeValues") }));
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
return identity({
|
|
86
|
-
execute(sql, params, transformRows) {
|
|
87
|
-
return transformRows ? map(run(sql, params), transformRows) : run(sql, params);
|
|
88
|
-
},
|
|
89
|
-
executeRaw(sql, params) {
|
|
90
|
-
return run(sql, params);
|
|
91
|
-
},
|
|
92
|
-
executeValues(sql, params) {
|
|
93
|
-
return runValues(sql, params);
|
|
94
|
-
},
|
|
95
|
-
executeValuesUnprepared(sql, params) {
|
|
96
|
-
return runValues(sql, params);
|
|
97
|
-
},
|
|
98
|
-
executeUnprepared(sql, params, transformRows) {
|
|
99
|
-
return this.execute(sql, params, transformRows);
|
|
100
|
-
},
|
|
101
|
-
executeStream(_sql, _params) {
|
|
102
|
-
return die("executeStream not implemented");
|
|
103
|
-
},
|
|
104
|
-
export: try_({
|
|
105
|
-
try: () => db.serialize(),
|
|
106
|
-
catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to export database", "export") })
|
|
107
|
-
}),
|
|
108
|
-
loadExtension: (path) => try_({
|
|
109
|
-
try: () => db.loadExtension(path),
|
|
110
|
-
catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to load extension", "loadExtension") })
|
|
111
|
-
})
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
const semaphore = yield* make$1(1);
|
|
115
|
-
const connection = yield* makeConnection;
|
|
116
|
-
const acquirer = semaphore.withPermits(1)(succeed(connection));
|
|
117
|
-
const transactionAcquirer = uninterruptibleMask((restore) => {
|
|
118
|
-
const scope = getUnsafe(getCurrent().context, Scope);
|
|
119
|
-
return as(tap(restore(semaphore.take(1)), () => addFinalizer$1(scope, semaphore.release(1))), connection);
|
|
120
|
-
});
|
|
121
|
-
return Object.assign(yield* make$2({
|
|
122
|
-
acquirer,
|
|
123
|
-
compiler,
|
|
124
|
-
transactionAcquirer,
|
|
125
|
-
spanAttributes: [...options.spanAttributes ? Object.entries(options.spanAttributes) : [], [ATTR_DB_SYSTEM_NAME, "sqlite"]],
|
|
126
|
-
transformRows
|
|
127
|
-
}), {
|
|
128
|
-
[TypeId]: TypeId,
|
|
129
|
-
config: options,
|
|
130
|
-
export: flatMap(acquirer, (_) => _.export),
|
|
131
|
-
loadExtension: (path) => flatMap(acquirer, (_) => _.loadExtension(path))
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
/**
|
|
135
|
-
* Creates a layer from a `Config`-wrapped Bun SQLite client configuration, providing both `SqliteClient` and `SqlClient`.
|
|
136
|
-
*
|
|
137
|
-
* @category layers
|
|
138
|
-
* @since 4.0.0
|
|
139
|
-
*/
|
|
140
|
-
var layerConfig = (config) => effectContext(unwrap(config).pipe(flatMap(make), map((client) => make$3(SqliteClient, client).pipe(add(SqlClient, client))))).pipe(provide(layer$1));
|
|
141
|
-
/**
|
|
142
|
-
* Creates a layer from a concrete Bun SQLite client configuration, providing both `SqliteClient` and `SqlClient`.
|
|
143
|
-
*
|
|
144
|
-
* @category layers
|
|
145
|
-
* @since 4.0.0
|
|
146
|
-
*/
|
|
147
|
-
var layer = (config) => effectContext(map(make(config), (client) => make$3(SqliteClient, client).pipe(add(SqlClient, client)))).pipe(provide(layer$1));
|
|
148
|
-
//#endregion
|
|
149
|
-
export { SqliteClient_exports as SqliteClient };
|
|
150
|
-
|
|
151
|
-
//# sourceMappingURL=dist-kscTHM4c.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dist-kscTHM4c.js","names":["Effect.gen","Statement.makeCompilerSqlite","Statement.defaultTransforms","Effect.addFinalizer","Effect.sync","Effect.withFiber","Context.get","Client.SafeIntegers","Effect.succeed","Effect.fail","Effect.map","Stream.die","Effect.try","Semaphore.make","Effect.uninterruptibleMask","Fiber.getCurrent","Context.getUnsafe","Scope.Scope","Effect.as","Effect.tap","Scope.addFinalizer","Client.make","Effect.flatMap","Layer.effectContext","Config.unwrap","Context.make","Context.add","Client.SqlClient","Layer.provide","Reactivity.layer"],"sources":["../../../node_modules/@effect/sql-sqlite-bun/dist/SqliteClient.js"],"sourcesContent":["/**\n * Connects Effect SQL to SQLite when running on Bun, using `bun:sqlite`.\n *\n * This module opens a SQLite database and exposes it as both `SqliteClient` and\n * the generic Effect SQL client. It serializes access to the database, enables\n * WAL mode unless disabled, and supports database export and extension loading.\n * Streaming queries and `updateValues` are not supported by this driver.\n *\n * @since 4.0.0\n */\nimport { Database } from \"bun:sqlite\";\nimport * as Config from \"effect/Config\";\nimport * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Fiber from \"effect/Fiber\";\nimport { identity } from \"effect/Function\";\nimport * as Layer from \"effect/Layer\";\nimport * as Scope from \"effect/Scope\";\nimport * as Semaphore from \"effect/Semaphore\";\nimport * as Stream from \"effect/Stream\";\nimport * as Reactivity from \"effect/unstable/reactivity/Reactivity\";\nimport * as Client from \"effect/unstable/sql/SqlClient\";\nimport { classifySqliteError, SqlError } from \"effect/unstable/sql/SqlError\";\nimport * as Statement from \"effect/unstable/sql/Statement\";\nconst ATTR_DB_SYSTEM_NAME = \"db.system.name\";\nconst classifyError = (cause, message, operation) => classifySqliteError(cause, {\n message,\n operation\n});\n/**\n * Runtime type identifier used to mark Bun `SqliteClient` values.\n *\n * @category type IDs\n * @since 4.0.0\n */\nexport const TypeId = \"~@effect/sql-sqlite-bun/SqliteClient\";\n/**\n * Service tag for the Bun SQLite client service.\n *\n * **When to use**\n *\n * Use to access or provide a Bun SQLite client through the Effect context.\n *\n * @category services\n * @since 4.0.0\n */\nexport const SqliteClient = /*#__PURE__*/Context.Service(\"@effect/sql-sqlite-bun/Client\");\n/**\n * Creates a scoped Bun SQLite client for a database file, enabling WAL by default and serializing access. Streaming queries are not implemented.\n *\n * @category constructors\n * @since 4.0.0\n */\nexport const make = options => Effect.gen(function* () {\n const compiler = Statement.makeCompilerSqlite(options.transformQueryNames);\n const transformRows = options.transformResultNames ? Statement.defaultTransforms(options.transformResultNames).array : undefined;\n const makeConnection = Effect.gen(function* () {\n const db = new Database(options.filename, {\n readonly: options.readonly,\n readwrite: options.readwrite ?? true,\n create: options.create ?? true\n });\n yield* Effect.addFinalizer(() => Effect.sync(() => db.close()));\n if (options.disableWAL !== true) {\n db.run(\"PRAGMA journal_mode = WAL;\");\n }\n const prepare = (sql, useSafeIntegers) => {\n const statement = db.query(sql);\n // @ts-ignore bun-types missing safeIntegers method, fixed in https://github.com/oven-sh/bun/pull/26627\n statement.safeIntegers(useSafeIntegers);\n return statement;\n };\n const run = (sql, params = []) => Effect.withFiber(fiber => {\n const useSafeIntegers = Context.get(fiber.context, Client.SafeIntegers);\n try {\n return Effect.succeed(prepare(sql, useSafeIntegers).all(...params) ?? []);\n } catch (cause) {\n return Effect.fail(new SqlError({\n reason: classifyError(cause, \"Failed to execute statement\", \"execute\")\n }));\n }\n });\n const runValues = (sql, params = []) => Effect.withFiber(fiber => {\n const useSafeIntegers = Context.get(fiber.context, Client.SafeIntegers);\n try {\n return Effect.succeed(prepare(sql, useSafeIntegers).values(...params) ?? []);\n } catch (cause) {\n return Effect.fail(new SqlError({\n reason: classifyError(cause, \"Failed to execute statement\", \"executeValues\")\n }));\n }\n });\n return identity({\n execute(sql, params, transformRows) {\n return transformRows ? Effect.map(run(sql, params), transformRows) : run(sql, params);\n },\n executeRaw(sql, params) {\n return run(sql, params);\n },\n executeValues(sql, params) {\n return runValues(sql, params);\n },\n executeValuesUnprepared(sql, params) {\n return runValues(sql, params);\n },\n executeUnprepared(sql, params, transformRows) {\n return this.execute(sql, params, transformRows);\n },\n executeStream(_sql, _params) {\n return Stream.die(\"executeStream not implemented\");\n },\n export: Effect.try({\n try: () => db.serialize(),\n catch: cause => new SqlError({\n reason: classifyError(cause, \"Failed to export database\", \"export\")\n })\n }),\n loadExtension: path => Effect.try({\n try: () => db.loadExtension(path),\n catch: cause => new SqlError({\n reason: classifyError(cause, \"Failed to load extension\", \"loadExtension\")\n })\n })\n });\n });\n const semaphore = yield* Semaphore.make(1);\n const connection = yield* makeConnection;\n const acquirer = semaphore.withPermits(1)(Effect.succeed(connection));\n const transactionAcquirer = Effect.uninterruptibleMask(restore => {\n const fiber = Fiber.getCurrent();\n const scope = Context.getUnsafe(fiber.context, Scope.Scope);\n return Effect.as(Effect.tap(restore(semaphore.take(1)), () => Scope.addFinalizer(scope, semaphore.release(1))), connection);\n });\n return Object.assign(yield* Client.make({\n acquirer,\n compiler,\n transactionAcquirer,\n spanAttributes: [...(options.spanAttributes ? Object.entries(options.spanAttributes) : []), [ATTR_DB_SYSTEM_NAME, \"sqlite\"]],\n transformRows\n }), {\n [TypeId]: TypeId,\n config: options,\n export: Effect.flatMap(acquirer, _ => _.export),\n loadExtension: path => Effect.flatMap(acquirer, _ => _.loadExtension(path))\n });\n});\n/**\n * Creates a layer from a `Config`-wrapped Bun SQLite client configuration, providing both `SqliteClient` and `SqlClient`.\n *\n * @category layers\n * @since 4.0.0\n */\nexport const layerConfig = config => Layer.effectContext(Config.unwrap(config).pipe(Effect.flatMap(make), Effect.map(client => Context.make(SqliteClient, client).pipe(Context.add(Client.SqlClient, client))))).pipe(Layer.provide(Reactivity.layer));\n/**\n * Creates a layer from a concrete Bun SQLite client configuration, providing both `SqliteClient` and `SqlClient`.\n *\n * @category layers\n * @since 4.0.0\n */\nexport const layer = config => Layer.effectContext(Effect.map(make(config), client => Context.make(SqliteClient, client).pipe(Context.add(Client.SqlClient, client)))).pipe(Layer.provide(Reactivity.layer));\n//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,GAAUC,IAAW,QAAQ,UAAU,KAAK,CAAC,CAAC,SAASC,eAAmB,OAAO,UAAU,QAAQ,CAAC,CAAC,CAAC,GAAG,UAAU;CAC5H,CAAC;CACD,OAAO,OAAO,OAAO,OAAOC,OAAY;EACtC;EACA;EACA;EACA,gBAAgB,CAAC,GAAI,QAAQ,iBAAiB,OAAO,QAAQ,QAAQ,cAAc,IAAI,CAAC,GAAI,CAAC,qBAAqB,QAAQ,CAAC;EAC3H;CACF,CAAC,GAAG;GACD,SAAS;EACV,QAAQ;EACR,QAAQC,QAAe,WAAU,MAAK,EAAE,MAAM;EAC9C,gBAAe,SAAQA,QAAe,WAAU,MAAK,EAAE,cAAc,IAAI,CAAC;CAC5E,CAAC;AACH,CAAC;;;;;;;AAOD,IAAa,eAAc,WAAUC,cAAoBC,OAAc,MAAM,CAAC,CAAC,KAAKF,QAAe,IAAI,GAAGZ,KAAW,WAAUe,OAAa,cAAc,MAAM,CAAC,CAAC,KAAKC,IAAYC,WAAkB,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAKC,QAAcC,OAAgB,CAAC;;;;;;;AAOrP,IAAa,SAAQ,WAAUN,cAAoBb,IAAW,KAAK,MAAM,IAAG,WAAUe,OAAa,cAAc,MAAM,CAAC,CAAC,KAAKC,IAAYC,WAAkB,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,KAAKC,QAAcC,OAAgB,CAAC"}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { $p as map$1, Al as taggedEnum, Bs as gen, Gp as fromNullishOr, Jp as getOrThrow, Os as flatMap, Qp as isSome, Qs as map, Up as flatMap$1, Vc as succeed, Wc as sync, Xf as head, Zc as try_, Zp as isNone, al as void_, em as match, fc as orDie, fs as catchCause, hc as provide, ip as map$2, is as andThen, kl as TaggedError, qf as getSomes, qn as decodeUnknownSync, rm as some, tm as none, vn as String, yn as Struct } from "./SqlClient-BHo_uVyk.js";
|
|
3
|
-
import { _ as orElse, b as when, g as exhaustive, v as tag, y as value } from "./dist-CKhPOkpR.js";
|
|
4
|
-
import { t as NoteStore } from "./store-DgMmJ7v9.js";
|
|
5
|
-
import { execFileSync } from "node:child_process";
|
|
6
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
7
|
-
import { dirname, join } from "node:path";
|
|
8
|
-
//#region ../loom-design/src/identity.ts
|
|
9
|
-
var Identity = Struct({
|
|
10
|
-
identity: String,
|
|
11
|
-
name: String,
|
|
12
|
-
created: String
|
|
13
|
-
});
|
|
14
|
-
var identityFile = (directory) => join(directory, ".loom", "design", "project.json");
|
|
15
|
-
var readIdentity = (directory) => sync(() => identityFile(directory)).pipe(flatMap((path) => existsSync(path) ? try_(() => decodeUnknownSync(Identity)(JSON.parse(readFileSync(path, "utf8")))).pipe(map(some), catchCause(() => succeed(none()))) : succeed(none())));
|
|
16
|
-
var writeIdentity = (directory, identity) => try_({
|
|
17
|
-
try: () => {
|
|
18
|
-
const path = identityFile(directory);
|
|
19
|
-
mkdirSync(dirname(path), { recursive: true });
|
|
20
|
-
writeFileSync(path, `${JSON.stringify(identity, null, 2)}\n`);
|
|
21
|
-
},
|
|
22
|
-
catch: (cause) => new IdentityError({
|
|
23
|
-
directory,
|
|
24
|
-
cause
|
|
25
|
-
})
|
|
26
|
-
});
|
|
27
|
-
var IdentityError = class extends TaggedError("IdentityError") {};
|
|
28
|
-
var Standing = taggedEnum();
|
|
29
|
-
var standingOf = (onDisk, recorded, fresh) => value({
|
|
30
|
-
onDisk,
|
|
31
|
-
recorded
|
|
32
|
-
}).pipe(when({
|
|
33
|
-
onDisk: isNone,
|
|
34
|
-
recorded: isNone
|
|
35
|
-
}, () => Standing.New({ identity: fresh() })), when({
|
|
36
|
-
onDisk: isSome,
|
|
37
|
-
recorded: isNone
|
|
38
|
-
}, ({ onDisk }) => Standing.Adopted({ identity: onDisk.value })), when({
|
|
39
|
-
onDisk: isNone,
|
|
40
|
-
recorded: isSome
|
|
41
|
-
}, ({ recorded }) => Standing.Misplaced({ registered: recorded.value })), orElse(({ onDisk, recorded }) => {
|
|
42
|
-
const here = getOrThrow(onDisk);
|
|
43
|
-
const there = getOrThrow(recorded);
|
|
44
|
-
return here.identity === there ? Standing.Proceeding({ identity: here }) : Standing.Taken({
|
|
45
|
-
here,
|
|
46
|
-
registered: there
|
|
47
|
-
});
|
|
48
|
-
}));
|
|
49
|
-
var LOOPBACK = /^https?:\/\/(?:localhost|127\.0\.0\.1|\[::1\]|0\.0\.0\.0):(\d+)/i;
|
|
50
|
-
var loopbackPort = (address) => map$1(fromNullishOr(LOOPBACK.exec(address)), (found) => found[1]);
|
|
51
|
-
var asked = (args, keep) => try_(() => execFileSync("lsof", [...args], {
|
|
52
|
-
encoding: "utf8",
|
|
53
|
-
stdio: [
|
|
54
|
-
"ignore",
|
|
55
|
-
"pipe",
|
|
56
|
-
"ignore"
|
|
57
|
-
]
|
|
58
|
-
})).pipe(map((output) => head(getSomes(map$2(output.split("\n"), keep)))), catchCause(() => succeed(none())));
|
|
59
|
-
var listenerOn = (port) => asked([
|
|
60
|
-
"-nP",
|
|
61
|
-
`-iTCP:${port}`,
|
|
62
|
-
"-sTCP:LISTEN",
|
|
63
|
-
"-t"
|
|
64
|
-
], (line) => line.trim() === "" ? none() : some(line.trim()));
|
|
65
|
-
var workingDirectoryOf = (pid) => asked([
|
|
66
|
-
"-a",
|
|
67
|
-
"-p",
|
|
68
|
-
pid,
|
|
69
|
-
"-d",
|
|
70
|
-
"cwd",
|
|
71
|
-
"-Fn"
|
|
72
|
-
], (line) => line.startsWith("n") ? some(line.slice(1)) : none());
|
|
73
|
-
var servedFrom = (address) => match(loopbackPort(address), {
|
|
74
|
-
onNone: () => succeed(none()),
|
|
75
|
-
onSome: (port) => flatMap(listenerOn(port), match({
|
|
76
|
-
onNone: () => succeed(none()),
|
|
77
|
-
onSome: workingDirectoryOf
|
|
78
|
-
}))
|
|
79
|
-
});
|
|
80
|
-
var fresh = (name) => ({
|
|
81
|
-
identity: crypto.randomUUID(),
|
|
82
|
-
name,
|
|
83
|
-
created: (/* @__PURE__ */ new Date()).toISOString()
|
|
84
|
-
});
|
|
85
|
-
var settle = (options) => gen(function* () {
|
|
86
|
-
const store = yield* NoteStore;
|
|
87
|
-
const standing = standingOf(yield* readIdentity(options.directory), flatMap$1(yield* orDie(store.project(options.project)), (found) => fromNullishOr(found.identity)), () => fresh(options.project));
|
|
88
|
-
const record = (identity) => orDie(store.register(options.project, identity.identity, options.directory, options.address));
|
|
89
|
-
yield* value(standing).pipe(tag("New", ({ identity }) => writeIdentity(options.directory, identity).pipe(andThen(record(identity)))), tag("Adopted", ({ identity }) => record(identity)), tag("Proceeding", ({ identity }) => record(identity)), tag("Taken", () => void_), tag("Misplaced", () => void_), exhaustive);
|
|
90
|
-
return standing;
|
|
91
|
-
}).pipe(provide(options.store));
|
|
92
|
-
//#endregion
|
|
93
|
-
export { Identity, IdentityError, Standing, identityFile, readIdentity, servedFrom, settle, standingOf, writeIdentity };
|
|
94
|
-
|
|
95
|
-
//# sourceMappingURL=identity-DvFsrt2d.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"identity-DvFsrt2d.js","names":[],"sources":["../../loom-design/src/identity.ts"],"sourcesContent":["import { Array, Data, Effect, Match, Option, Schema } from 'effect'\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'\nimport { dirname, join } from 'node:path'\n\nexport const Identity = Schema.Struct({\n identity: Schema.String,\n name: Schema.String,\n created: Schema.String,\n})\nexport type Identity = typeof Identity.Type\n\nexport const identityFile = (directory: string): string =>\n join(directory, '.loom', 'design', 'project.json')\n\nexport const readIdentity = (\n directory: string,\n): Effect.Effect<Option.Option<Identity>> =>\n Effect.sync(() => identityFile(directory)).pipe(\n Effect.flatMap((path) =>\n existsSync(path)\n ? Effect.try(() =>\n Schema.decodeUnknownSync(Identity)(JSON.parse(readFileSync(path, 'utf8'))),\n ).pipe(Effect.map(Option.some), Effect.catchCause(() => Effect.succeed(Option.none<Identity>())))\n : Effect.succeed(Option.none<Identity>()),\n ),\n )\n\nexport const writeIdentity = (\n directory: string,\n identity: Identity,\n): Effect.Effect<void, IdentityError> =>\n Effect.try({\n try: () => {\n const path = identityFile(directory)\n mkdirSync(dirname(path), { recursive: true })\n writeFileSync(path, `${JSON.stringify(identity, null, 2)}\\n`)\n },\n catch: (cause) => new IdentityError({ directory, cause }),\n })\n\nexport class IdentityError extends Data.TaggedError('IdentityError')<{\n readonly directory: string\n readonly cause: unknown\n}> {}\n\nexport type Standing = Data.TaggedEnum<{\n New: { readonly identity: Identity }\n Adopted: { readonly identity: Identity }\n Proceeding: { readonly identity: Identity }\n Taken: { readonly here: Identity; readonly registered: string }\n Misplaced: { readonly registered: string }\n}>\nexport const Standing = Data.taggedEnum<Standing>()\n\nexport const standingOf = (\n onDisk: Option.Option<Identity>,\n recorded: Option.Option<string>,\n fresh: () => Identity,\n): Standing =>\n Match.value({ onDisk, recorded }).pipe(\n Match.when({ onDisk: Option.isNone, recorded: Option.isNone }, () =>\n Standing.New({ identity: fresh() }),\n ),\n Match.when({ onDisk: Option.isSome, recorded: Option.isNone }, ({ onDisk }) =>\n Standing.Adopted({ identity: onDisk.value }),\n ),\n Match.when({ onDisk: Option.isNone, recorded: Option.isSome }, ({ recorded }) =>\n Standing.Misplaced({ registered: recorded.value }),\n ),\n Match.orElse(({ onDisk, recorded }) => {\n const here = Option.getOrThrow(onDisk)\n const there = Option.getOrThrow(recorded)\n return here.identity === there\n ? Standing.Proceeding({ identity: here })\n : Standing.Taken({ here, registered: there })\n }),\n )\n\nimport { execFileSync } from 'node:child_process'\n\nconst LOOPBACK = /^https?:\\/\\/(?:localhost|127\\.0\\.0\\.1|\\[::1\\]|0\\.0\\.0\\.0):(\\d+)/i\n\nconst loopbackPort = (address: string): Option.Option<string> =>\n Option.map(Option.fromNullishOr(LOOPBACK.exec(address)), (found) => found[1])\n\nconst asked = (\n args: ReadonlyArray<string>,\n keep: (line: string) => Option.Option<string>,\n): Effect.Effect<Option.Option<string>> =>\n Effect.try(() =>\n execFileSync('lsof', [...args], {\n encoding: 'utf8',\n stdio: ['ignore', 'pipe', 'ignore'],\n }),\n ).pipe(\n Effect.map((output) =>\n Array.head(Array.getSomes(Array.map(output.split('\\n'), keep))),\n ),\n Effect.catchCause(() => Effect.succeed(Option.none<string>())),\n )\n\nconst listenerOn = (port: string): Effect.Effect<Option.Option<string>> =>\n asked(['-nP', `-iTCP:${port}`, '-sTCP:LISTEN', '-t'], (line) =>\n line.trim() === '' ? Option.none() : Option.some(line.trim()),\n )\n\nconst workingDirectoryOf = (pid: string): Effect.Effect<Option.Option<string>> =>\n asked(['-a', '-p', pid, '-d', 'cwd', '-Fn'], (line) =>\n line.startsWith('n') ? Option.some(line.slice(1)) : Option.none(),\n )\n\nexport const servedFrom = (\n address: string,\n): Effect.Effect<Option.Option<string>> =>\n Option.match(loopbackPort(address), {\n onNone: () => Effect.succeed(Option.none<string>()),\n onSome: (port) =>\n Effect.flatMap(\n listenerOn(port),\n Option.match({\n onNone: () => Effect.succeed(Option.none<string>()),\n onSome: workingDirectoryOf,\n }),\n ),\n })\n\nimport { Layer } from 'effect'\nimport { NoteStore } from './store'\n\nconst fresh = (name: string): Identity => ({\n identity: crypto.randomUUID(),\n name,\n created: new Date().toISOString(),\n})\n\nexport const settle = (options: {\n readonly project: string\n readonly directory: string\n readonly address: string\n readonly store: Layer.Layer<NoteStore>\n}): Effect.Effect<Standing, IdentityError> =>\n Effect.gen(function* () {\n const store = yield* NoteStore\n const onDisk = yield* readIdentity(options.directory)\n const row = yield* Effect.orDie(store.project(options.project))\n const recorded = Option.flatMap(row, (found) =>\n Option.fromNullishOr(found.identity),\n )\n const standing = standingOf(onDisk, recorded, () => fresh(options.project))\n const record = (identity: Identity) =>\n Effect.orDie(\n store.register(\n options.project,\n identity.identity,\n options.directory,\n options.address,\n ),\n )\n yield* Match.value(standing).pipe(\n Match.tag('New', ({ identity }) =>\n writeIdentity(options.directory, identity).pipe(\n Effect.andThen(record(identity)),\n ),\n ),\n Match.tag('Adopted', ({ identity }) => record(identity)),\n Match.tag('Proceeding', ({ identity }) => record(identity)),\n Match.tag('Taken', () => Effect.void),\n Match.tag('Misplaced', () => Effect.void),\n Match.exhaustive,\n )\n return standing\n }).pipe(Effect.provide(options.store))\n"],"mappings":";;;;;;;;AAIA,IAAa,WAAW,OAAc;CACpC,UAAU;CACV,MAAM;CACN,SAAS;AACX,CAAC;AAGD,IAAa,gBAAgB,cAC3B,KAAK,WAAW,SAAS,UAAU,cAAc;AAEnD,IAAa,gBACX,cAEA,WAAkB,aAAa,SAAS,CAAC,CAAC,CAAC,KACzC,SAAgB,SACd,WAAW,IAAI,IACX,WACE,kBAAyB,QAAQ,CAAC,CAAC,KAAK,MAAM,aAAa,MAAM,MAAM,CAAC,CAAC,CAC3E,CAAC,CAAC,KAAK,IAAW,IAAW,GAAG,iBAAwB,QAAe,KAAsB,CAAC,CAAC,CAAC,IAChG,QAAe,KAAsB,CAAC,CAC5C,CACF;AAEF,IAAa,iBACX,WACA,aAEA,KAAW;CACT,WAAW;EACT,MAAM,OAAO,aAAa,SAAS;EACnC,UAAU,QAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;EAC5C,cAAc,MAAM,GAAG,KAAK,UAAU,UAAU,MAAM,CAAC,EAAE,GAAG;CAC9D;CACA,QAAQ,UAAU,IAAI,cAAc;EAAE;EAAW;CAAM,CAAC;AAC1D,CAAC;AAEH,IAAa,gBAAb,cAAmC,YAAiB,eAAe,CAAC,CAGjE,CAAC;AASJ,IAAa,WAAW,WAA0B;AAElD,IAAa,cACX,QACA,UACA,UAEA,MAAY;CAAE;CAAQ;AAAS,CAAC,CAAC,CAAC,KAChC,KAAW;CAAE,QAAQ;CAAe,UAAU;AAAc,SAC1D,SAAS,IAAI,EAAE,UAAU,MAAM,EAAE,CAAC,CACpC,GACA,KAAW;CAAE,QAAQ;CAAe,UAA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