0field 0.19.0 → 0.19.2
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/0field.js +164 -10
- package/bin/0field.jsonld +1 -1
- package/bin/o.jsonld +1 -1
- package/package.json +1 -1
package/0field.js
CHANGED
|
@@ -799,6 +799,13 @@ var Workbench = class Workbench extends GitRepository {
|
|
|
799
799
|
own(id) {
|
|
800
800
|
return id === this.#named ? this.folder : void 0;
|
|
801
801
|
}
|
|
802
|
+
/**
|
|
803
|
+
* Whether this repository is the one a SmartObject, `<namespace>/<Name>`, names: by the `@id` of its root's
|
|
804
|
+
* `workbench.jsonld`, or, where that names none, by its `origin` remote.
|
|
805
|
+
*/
|
|
806
|
+
names(id) {
|
|
807
|
+
return id === (this.#named ?? this.id);
|
|
808
|
+
}
|
|
802
809
|
/** The branch of a SmartObject's one checkout; none where it has none, refused where it has several, so a ref is named. */
|
|
803
810
|
branch(id) {
|
|
804
811
|
const branches = this.#branches(id);
|
|
@@ -2024,6 +2031,103 @@ var NodeNpmHook = class NodeNpmHook extends TypedSmartObject {
|
|
|
2024
2031
|
const RESOLVE = /\bimport\.meta\.resolve\s*\(/;
|
|
2025
2032
|
const RESOLVER = "metatrom.oField.resolve";
|
|
2026
2033
|
//#endregion
|
|
2034
|
+
//#region dependencies/metatrom-ag/Manu/main/common/0field/BuiltWorkbench.ts
|
|
2035
|
+
/**
|
|
2036
|
+
* Purpose: let a SmartObject run where no store is, from the workbench its
|
|
2037
|
+
* build carries.
|
|
2038
|
+
*
|
|
2039
|
+
* Intention: one is the {@link Workbench} a built SmartObject carries —
|
|
2040
|
+
* its `workbench.jsonld` as text, the classes it lists and its data files —
|
|
2041
|
+
* registered by the build as it loads, for the realm. In Node, Deno and
|
|
2042
|
+
* Bun the kernel asks it for a type's class and fills none of it, and the
|
|
2043
|
+
* storage reads, finds and lists its texts there, before any store.
|
|
2044
|
+
*/
|
|
2045
|
+
var BuiltWorkbench = class BuiltWorkbench extends TypedSmartObject {
|
|
2046
|
+
static #registered = /* @__PURE__ */ new Map();
|
|
2047
|
+
#carried = {
|
|
2048
|
+
files: /* @__PURE__ */ new Map(),
|
|
2049
|
+
classes: /* @__PURE__ */ new Map()
|
|
2050
|
+
};
|
|
2051
|
+
/**
|
|
2052
|
+
* Registers the workbench a built SmartObject carries, called by the build as it loads: its `workbench.jsonld` as
|
|
2053
|
+
* text, the class of each descriptor that lists in `classes` — `X.descriptor.jsonld`'s by `X`, the path its type names
|
|
2054
|
+
* within the workbench — and each data file by its path. In Node, Deno and Bun what it carries is then read from here
|
|
2055
|
+
* before any store, and counted as held when the kernel fills the stores. Each text is kept as a stored one is read, a
|
|
2056
|
+
* leading byte order mark dropped, and the one registered holds in its model the `@id` and the version its text
|
|
2057
|
+
* names. Refused, naming it, where the text names no workbench by an oField IRI of its own
|
|
2058
|
+
* or lists its classes as anything but descriptor paths, where a class it lists is not carried, where a file's path is
|
|
2059
|
+
* no plain path within the workbench — `./`, `..`, `\`, a leading or a doubled `/` — or is its `workbench.jsonld`,
|
|
2060
|
+
* and where another text of that workbench is registered already; the same texts again leave the first registration
|
|
2061
|
+
* as it is, its classes the ones answered.
|
|
2062
|
+
*/
|
|
2063
|
+
static use({ workbench: given, classes, files = {} }) {
|
|
2064
|
+
const workbench = unmarked(given);
|
|
2065
|
+
let model;
|
|
2066
|
+
try {
|
|
2067
|
+
model = JSON.parse(workbench);
|
|
2068
|
+
} catch (cause) {
|
|
2069
|
+
throw new Error("a built workbench.jsonld is JSON", { cause });
|
|
2070
|
+
}
|
|
2071
|
+
if (typeof model !== "object" || model === null || Array.isArray(model)) throw new Error(`a built workbench.jsonld is a JSON object: ${workbench}`);
|
|
2072
|
+
const { "@id": id, classes: listed } = model;
|
|
2073
|
+
const named = typeof id === "string" ? OFieldIri.of(id)?.model : void 0;
|
|
2074
|
+
if (typeof id !== "string" || named === void 0 || named.namespace === "npm" || named.source !== void 0 || named.ref !== void 0 || named.subpath !== void 0) throw new Error(`a built workbench.jsonld names its workbench by an @id, ofield://<namespace>/<Name>: ${String(id)}`);
|
|
2075
|
+
if (listed !== void 0 && !(Array.isArray(listed) && listed.every((each) => typeof each === "string"))) throw new Error(`${id} lists its classes as descriptor paths`);
|
|
2076
|
+
for (const descriptor of listed ?? []) {
|
|
2077
|
+
const path = descriptor.replace(/\.descriptor\.jsonld$/, "");
|
|
2078
|
+
if (!Object.hasOwn(classes, path) || typeof classes[path] !== "function") throw new Error(`${id} lists the class ${path}, which its build does not carry`);
|
|
2079
|
+
}
|
|
2080
|
+
for (const path of Object.keys(files)) {
|
|
2081
|
+
if (path === "workbench.jsonld") throw new Error(`${id} carries its workbench.jsonld as its workbench, not among its files`);
|
|
2082
|
+
if (path.includes("\\") || path.split("/").some((segment) => segment === "" || segment === "." || segment === "..")) throw new Error(`${id} carries a file at ${path}, no plain path within it`);
|
|
2083
|
+
}
|
|
2084
|
+
const carried = new Map([...Object.entries(files).map(([path, text]) => [path, unmarked(text)]), ["workbench.jsonld", workbench]]);
|
|
2085
|
+
const key = `${named.namespace}/${named.name}`;
|
|
2086
|
+
const held = BuiltWorkbench.#registered.get(key)?.files;
|
|
2087
|
+
if (held !== void 0) {
|
|
2088
|
+
if (held.size === carried.size && [...carried].every(([path, text]) => held.get(path) === text)) return;
|
|
2089
|
+
throw new Error(`${id} is registered already by another build, which carries other texts`);
|
|
2090
|
+
}
|
|
2091
|
+
const { version } = model;
|
|
2092
|
+
const built = new BuiltWorkbench({
|
|
2093
|
+
"@id": id,
|
|
2094
|
+
...typeof version === "string" ? { version } : {}
|
|
2095
|
+
});
|
|
2096
|
+
built.#carried = {
|
|
2097
|
+
files: carried,
|
|
2098
|
+
classes: new Map(Object.entries(classes))
|
|
2099
|
+
};
|
|
2100
|
+
BuiltWorkbench.#registered.set(key, built);
|
|
2101
|
+
}
|
|
2102
|
+
/**
|
|
2103
|
+
* The workbench a build registered that an oField IRI names, by its `@id`: at no ref, at `latest`, or at its own
|
|
2104
|
+
* version's tag, `v<version>`, or a range holding that version; none for any other ref, a branch, a sha or a data ref
|
|
2105
|
+
* among them, and for an IRI of no registered workbench.
|
|
2106
|
+
*/
|
|
2107
|
+
static of(iri) {
|
|
2108
|
+
const named = OFieldIri.of(iri)?.model;
|
|
2109
|
+
if (named === void 0 || named.source !== void 0) return void 0;
|
|
2110
|
+
const built = BuiltWorkbench.#registered.get(`${named.namespace}/${named.name}`);
|
|
2111
|
+
if (built === void 0) return void 0;
|
|
2112
|
+
const { ref } = named;
|
|
2113
|
+
if (ref === void 0 || ref === "latest") return built;
|
|
2114
|
+
const { version } = built.model;
|
|
2115
|
+
const tag = `v${version}`;
|
|
2116
|
+
return typeof version === "string" && new Releases([tag]).named(ref) === tag ? built : void 0;
|
|
2117
|
+
}
|
|
2118
|
+
/** The texts its build carries, by their path within the workbench — its `workbench.jsonld` among them. */
|
|
2119
|
+
get files() {
|
|
2120
|
+
return this.#carried.files;
|
|
2121
|
+
}
|
|
2122
|
+
/** The classes its build carries, by the path a type names within the workbench. */
|
|
2123
|
+
get classes() {
|
|
2124
|
+
return this.#carried.classes;
|
|
2125
|
+
}
|
|
2126
|
+
};
|
|
2127
|
+
function unmarked(text) {
|
|
2128
|
+
return text.startsWith("") ? text.slice(1) : text;
|
|
2129
|
+
}
|
|
2130
|
+
//#endregion
|
|
2027
2131
|
//#region dependencies/metatrom-ag/Manu/main/common/file-system/git/GitNotes.ts
|
|
2028
2132
|
/**
|
|
2029
2133
|
* Purpose: say where in a notes tree the note of a commit stands, whether git
|
|
@@ -2210,6 +2314,8 @@ function descriptorBeside(path) {
|
|
|
2210
2314
|
* through the {@link NodeOFieldHook}, an npm package's version through
|
|
2211
2315
|
* {@link NodeStores} and {@link Releases}, realizes a repository's root as
|
|
2212
2316
|
* its {@link Workbench}, and finds a note of a notes ref through {@link GitNotes}.
|
|
2317
|
+
* What a build carries of a workbench it registered, a
|
|
2318
|
+
* {@link BuiltWorkbench}, is read from there, before any tree.
|
|
2213
2319
|
*/
|
|
2214
2320
|
var ReadOnlyNodeStorage = class ReadOnlyNodeStorage extends TypedSmartObject {
|
|
2215
2321
|
/**
|
|
@@ -2230,13 +2336,18 @@ var ReadOnlyNodeStorage = class ReadOnlyNodeStorage extends TypedSmartObject {
|
|
|
2230
2336
|
url.hash = "";
|
|
2231
2337
|
return url.href;
|
|
2232
2338
|
}
|
|
2233
|
-
/**
|
|
2339
|
+
/**
|
|
2340
|
+
* Whether a text is stored at a location; none is where this host holds no tree the location names. A location in a
|
|
2341
|
+
* workbench a build registered is answered by what that build carries alone.
|
|
2342
|
+
*/
|
|
2234
2343
|
async has(location) {
|
|
2235
2344
|
return this.hasSync(location);
|
|
2236
2345
|
}
|
|
2237
2346
|
/** {@link ReadOnlyNodeStorage.has}, answered at once. */
|
|
2238
2347
|
hasSync(location) {
|
|
2239
2348
|
if (!location.startsWith("ofield:")) return new ReadOnlyNodeFile(ReadOnlyNodeFolder.fromUrl(location).path).exists;
|
|
2349
|
+
const built = this.#built(location);
|
|
2350
|
+
if (built !== void 0) return built.path !== void 0 && built.files.has(built.path);
|
|
2240
2351
|
const npm = ReadOnlyNodeStorage.#npm(location);
|
|
2241
2352
|
if (npm !== void 0) return this.#described(npm) !== void 0;
|
|
2242
2353
|
const { subpath, tree: address } = this.#parsed(location);
|
|
@@ -2286,13 +2397,20 @@ var ReadOnlyNodeStorage = class ReadOnlyNodeStorage extends TypedSmartObject {
|
|
|
2286
2397
|
* it from the started file's place: a tag or a sha in the stores, a branch in its repository. An npm package's,
|
|
2287
2398
|
* `ofield://npm/<name>@<ref>`, names instead the node describing a version, `npm/<name>/<version>.descriptor.jsonld`,
|
|
2288
2399
|
* beside the version folder its ref names among those the stores describe: exact, the highest within a range, the
|
|
2289
|
-
* latest for none, as {@link Releases} reads a ref. A file of the package names none.
|
|
2400
|
+
* latest for none, as {@link Releases} reads a ref. A file of the package names none. A location in a workbench a
|
|
2401
|
+
* build registered is the text that build carries there, refused where it carries none.
|
|
2290
2402
|
*/
|
|
2291
2403
|
async get(location) {
|
|
2292
2404
|
return this.getSync(location);
|
|
2293
2405
|
}
|
|
2294
2406
|
/** {@link ReadOnlyNodeStorage.get}, answered at once. */
|
|
2295
2407
|
getSync(location) {
|
|
2408
|
+
const built = this.#built(location);
|
|
2409
|
+
if (built !== void 0) {
|
|
2410
|
+
const text = built.path === void 0 ? void 0 : built.files.get(built.path);
|
|
2411
|
+
if (text === void 0) throw new Error(`no model at ${location}`);
|
|
2412
|
+
return text;
|
|
2413
|
+
}
|
|
2296
2414
|
const file = this.#file(location);
|
|
2297
2415
|
if (!file.exists) {
|
|
2298
2416
|
const folder = location.startsWith("ofield:") ? void 0 : this.#folder(location);
|
|
@@ -2308,7 +2426,8 @@ var ReadOnlyNodeStorage = class ReadOnlyNodeStorage extends TypedSmartObject {
|
|
|
2308
2426
|
}
|
|
2309
2427
|
/**
|
|
2310
2428
|
* The location of every text below an address, sorted: every name beginning with `.` skipped — a worktree's `.git`
|
|
2311
|
-
* among them — and, in a tree, every name an oField IRI cannot hold as it stands, one with `#`, `%` or `?`.
|
|
2429
|
+
* among them — and, in a tree, every name an oField IRI cannot hold as it stands, one with `#`, `%` or `?`. Below an
|
|
2430
|
+
* address in a workbench a build registered, what that build carries there, refused where it carries nothing.
|
|
2312
2431
|
*/
|
|
2313
2432
|
async list(address) {
|
|
2314
2433
|
return this.listSync(address);
|
|
@@ -2316,6 +2435,17 @@ var ReadOnlyNodeStorage = class ReadOnlyNodeStorage extends TypedSmartObject {
|
|
|
2316
2435
|
/** {@link ReadOnlyNodeStorage.list}, answered at once. */
|
|
2317
2436
|
listSync(address) {
|
|
2318
2437
|
const located = this.location(address);
|
|
2438
|
+
const built = this.#built(located);
|
|
2439
|
+
if (built !== void 0) {
|
|
2440
|
+
const { tree } = this.#parsed(located);
|
|
2441
|
+
const below = built.path === void 0 ? "" : `${built.path}/`;
|
|
2442
|
+
const paths = [...built.files.keys()].filter((path) => path.startsWith(below) && !/(^|\/)\.|[#%?]/.test(path));
|
|
2443
|
+
if (paths.length === 0) throw new Error(`no folder at ${located}`);
|
|
2444
|
+
return paths.map((path) => new OFieldIri({
|
|
2445
|
+
...tree,
|
|
2446
|
+
subpath: path
|
|
2447
|
+
}).toString()).sort();
|
|
2448
|
+
}
|
|
2319
2449
|
const { folder, at, held } = located.startsWith("ofield:") ? this.#oFieldFolder(located) : {
|
|
2320
2450
|
folder: ReadOnlyNodeFolder.fromUrl(located),
|
|
2321
2451
|
at: (file) => ReadOnlyNodeFolder.urlOf(file),
|
|
@@ -2324,6 +2454,14 @@ var ReadOnlyNodeStorage = class ReadOnlyNodeStorage extends TypedSmartObject {
|
|
|
2324
2454
|
if (!folder.exists) throw new Error(`no folder at ${located}`);
|
|
2325
2455
|
return [...new Set([...stored(folder)].filter(held).map(at))].sort();
|
|
2326
2456
|
}
|
|
2457
|
+
#built(location) {
|
|
2458
|
+
if (!location.startsWith("ofield:")) return void 0;
|
|
2459
|
+
const built = BuiltWorkbench.of(location);
|
|
2460
|
+
return built === void 0 ? void 0 : {
|
|
2461
|
+
files: built.files,
|
|
2462
|
+
path: this.#parsed(location).subpath
|
|
2463
|
+
};
|
|
2464
|
+
}
|
|
2327
2465
|
#file(location) {
|
|
2328
2466
|
if (!location.startsWith("ofield:")) return new ReadOnlyNodeFile(ReadOnlyNodeFolder.fromUrl(location).path);
|
|
2329
2467
|
const npm = ReadOnlyNodeStorage.#npm(location);
|
|
@@ -3075,8 +3213,10 @@ var __rewriteRelativeImportExtension$1 = function(path, preserveJsx) {
|
|
|
3075
3213
|
* {@link NodeReleaseHook}, {@link NodeOFieldHook} and {@link NodeNpmHook}.
|
|
3076
3214
|
* Its storage, which a Persistence reads, is a {@link ReadOnlyNodeStorage};
|
|
3077
3215
|
* what a model names and no store holds, or what that uses, the
|
|
3078
|
-
* {@link NodeOFieldHook} asked, it fills through {@link NodeInstaller}
|
|
3079
|
-
*
|
|
3216
|
+
* {@link NodeOFieldHook} asked, it fills through {@link NodeInstaller},
|
|
3217
|
+
* leaving to the {@link Workbench} that holds the model what it names; it
|
|
3218
|
+
* answers a type of a workbench a build registered from that
|
|
3219
|
+
* {@link BuiltWorkbench}. Its model names the 0field it loads for.
|
|
3080
3220
|
*/
|
|
3081
3221
|
var NodeKernel = class NodeKernel extends TypedSmartObject {
|
|
3082
3222
|
static #registered = false;
|
|
@@ -3156,7 +3296,17 @@ var NodeKernel = class NodeKernel extends TypedSmartObject {
|
|
|
3156
3296
|
storage(place) {
|
|
3157
3297
|
return new ReadOnlyNodeStorage({ main: this.anchor(place) });
|
|
3158
3298
|
}
|
|
3299
|
+
/**
|
|
3300
|
+
* The default export of the module a type IRI names, as the place resolves it; where a build registered the workbench
|
|
3301
|
+
* it names, the class that build carries, from any place, refused, naming the type, where it carries none.
|
|
3302
|
+
*/
|
|
3159
3303
|
async classOf(type, place) {
|
|
3304
|
+
const built = BuiltWorkbench.of(type);
|
|
3305
|
+
if (built !== void 0) {
|
|
3306
|
+
const path = OFieldIri.of(type)?.model.subpath ?? "";
|
|
3307
|
+
if (!built.classes.has(path)) throw new Error(`the build carrying ${built.model["@id"]} carries no class ${path}: ${type}`);
|
|
3308
|
+
return built.classes.get(path);
|
|
3309
|
+
}
|
|
3160
3310
|
const url = this.hooks.moduleOf(type, this.anchor(place));
|
|
3161
3311
|
if ([...new URL(url).pathname.matchAll(/\/dependencies\/[^/]+\/[^/]+\/(?=(.*))/g)].some(([, ref]) => OFieldIri.isDataRef(ref))) throw new Error(`no class is loaded from a data ref: ${type}`);
|
|
3162
3312
|
return (await import(__rewriteRelativeImportExtension$1(url))).default;
|
|
@@ -3166,19 +3316,22 @@ var NodeKernel = class NodeKernel extends TypedSmartObject {
|
|
|
3166
3316
|
* and no store or working tree holds — its `@context`, its `@type` and each `{"@id"}` it references — and every
|
|
3167
3317
|
* release those use, as the `uses` and `realizes` of the descriptors the stores hold say, all the way down; a plain
|
|
3168
3318
|
* string is data and fills nothing, and its own `@id`, an npm package, a branch and a data ref — what no installer
|
|
3169
|
-
* installs, a release being what it installs — are left to restoring
|
|
3319
|
+
* installs, a release being what it installs — are left to restoring, as is a `{"@id"}` naming a ref of the repository that
|
|
3320
|
+
* holds the model — by the `@id` of its `workbench.jsonld`, else by its `origin` — which git reads there. Where the address is a module's `file:` URL,
|
|
3170
3321
|
* it fills, the same way, what the descriptor beside that module uses and realizes, a relative path read within the
|
|
3171
3322
|
* folder of the nearest `workbench.jsonld` above it, or its own folder where none is. Nothing
|
|
3172
3323
|
* where each is held, or where no model or descriptor is there; refused, naming the file, where a descriptor it reads
|
|
3173
|
-
* is no JSON object.
|
|
3324
|
+
* is no JSON object. What a build registered through {@link BuiltWorkbench.use} counts as held.
|
|
3174
3325
|
*/
|
|
3175
3326
|
async fill(address) {
|
|
3176
3327
|
const module = address.startsWith("file:") && descriptorBeside(address) !== void 0 ? ReadOnlyNodeFolder.fromUrl(address) : void 0;
|
|
3177
3328
|
let node;
|
|
3329
|
+
let holder;
|
|
3178
3330
|
if (module === void 0) {
|
|
3179
3331
|
const storage = this.storage();
|
|
3180
3332
|
const location = storage.location(address);
|
|
3181
3333
|
if (!await storage.has(location)) return;
|
|
3334
|
+
holder = Workbench.above(location.startsWith("file:") ? ReadOnlyNodeFolder.fromUrl(location).parent : new NodeOFieldHook({}).find(location, this.anchor()));
|
|
3182
3335
|
try {
|
|
3183
3336
|
node = JSON.parse(await storage.get(location));
|
|
3184
3337
|
} catch {
|
|
@@ -3205,7 +3358,8 @@ var NodeKernel = class NodeKernel extends TypedSmartObject {
|
|
|
3205
3358
|
if (Array.isArray(value)) value.forEach((each) => reference(each, depth + 1));
|
|
3206
3359
|
else if (typeof value === "object" && value !== null) {
|
|
3207
3360
|
const { "@id": id, ...rest } = value;
|
|
3208
|
-
|
|
3361
|
+
const link = typeof id === "string" ? OFieldIri.of(id) : void 0;
|
|
3362
|
+
if (link?.model.ref === void 0 || holder?.names(`${link.model.namespace}/${link.model.name}`) !== true) take(id);
|
|
3209
3363
|
Object.values(rest).forEach((each) => reference(each, depth + 1));
|
|
3210
3364
|
}
|
|
3211
3365
|
};
|
|
@@ -3227,7 +3381,7 @@ var NodeKernel = class NodeKernel extends TypedSmartObject {
|
|
|
3227
3381
|
}
|
|
3228
3382
|
};
|
|
3229
3383
|
const reach = (iri) => {
|
|
3230
|
-
if (iri.model.namespace === "npm") return;
|
|
3384
|
+
if (iri.model.namespace === "npm" || BuiltWorkbench.of(iri.toString()) !== void 0) return;
|
|
3231
3385
|
const tree = find(iri.toString());
|
|
3232
3386
|
if (tree === null) return;
|
|
3233
3387
|
if (tree === void 0) {
|
|
@@ -4117,4 +4271,4 @@ const oField = new OField();
|
|
|
4117
4271
|
/** The kernel, once each program the realm was started with has finished its start; never awaited here, as a service worker forbids top-level await. */
|
|
4118
4272
|
const started = oField.start().then(() => loaded.promise);
|
|
4119
4273
|
//#endregion
|
|
4120
|
-
export { Entry, GitNotes, ModuleHookChain, NodeStores, OField, OFieldIri, Persistence, Program, ReadOnlyGitFolder, ReadOnlyNodeFile, ReadOnlyNodeFolder, ReadOnlyNodeStorage, Relation, RelationList, RelationMap, RelationSet, Releases, RootedTreeNode, TypedSmartObject as SmartObject, StringMap, TypedView as View, Workbench, hooks, isFile, isFolder, oField, persistence, started, words };
|
|
4274
|
+
export { BuiltWorkbench, Entry, GitNotes, ModuleHookChain, NodeStores, OField, OFieldIri, Persistence, Program, ReadOnlyGitFolder, ReadOnlyNodeFile, ReadOnlyNodeFolder, ReadOnlyNodeStorage, Relation, RelationList, RelationMap, RelationSet, Releases, RootedTreeNode, TypedSmartObject as SmartObject, StringMap, TypedView as View, Workbench, hooks, isFile, isFolder, oField, persistence, started, words };
|
package/bin/0field.jsonld
CHANGED
package/bin/o.jsonld
CHANGED