@bjornpagen/bumbledb-log 0.20.2 → 1.0.0
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/README.md +275 -114
- package/dist/admin.d.ts +24 -0
- package/dist/admin.d.ts.map +1 -0
- package/dist/admin.js +12 -0
- package/dist/admin.js.map +1 -0
- package/dist/bridge.d.ts +30 -0
- package/dist/bridge.d.ts.map +1 -0
- package/dist/bridge.js +92 -0
- package/dist/bridge.js.map +1 -0
- package/dist/codes.d.ts +11 -0
- package/dist/codes.d.ts.map +1 -0
- package/dist/codes.js +53 -0
- package/dist/codes.js.map +1 -0
- package/dist/command.d.ts +21 -0
- package/dist/command.d.ts.map +1 -0
- package/dist/command.js +12 -0
- package/dist/command.js.map +1 -0
- package/dist/errors.d.ts +78 -197
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +144 -114
- package/dist/errors.js.map +1 -1
- package/dist/history.d.ts +22 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +12 -0
- package/dist/history.js.map +1 -0
- package/dist/identity.d.ts +144 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +223 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +24 -31
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -21
- package/dist/index.js.map +1 -1
- package/dist/machine.d.ts +151 -0
- package/dist/machine.d.ts.map +1 -0
- package/dist/machine.js +1128 -0
- package/dist/machine.js.map +1 -0
- package/dist/migration-ops.d.ts +20 -0
- package/dist/migration-ops.d.ts.map +1 -0
- package/dist/migration-ops.js +7 -0
- package/dist/migration-ops.js.map +1 -0
- package/dist/migrations/bin.d.ts +3 -0
- package/dist/migrations/bin.d.ts.map +1 -0
- package/dist/migrations/bin.js +43 -0
- package/dist/migrations/bin.js.map +1 -0
- package/dist/migrations/canonical.d.ts +40 -0
- package/dist/migrations/canonical.d.ts.map +1 -0
- package/dist/migrations/canonical.js +156 -0
- package/dist/migrations/canonical.js.map +1 -0
- package/dist/migrations/cli.d.ts +32 -0
- package/dist/migrations/cli.d.ts.map +1 -0
- package/dist/migrations/cli.js +147 -0
- package/dist/migrations/cli.js.map +1 -0
- package/dist/migrations/codec.d.ts +74 -0
- package/dist/migrations/codec.d.ts.map +1 -0
- package/dist/migrations/codec.js +2 -0
- package/dist/migrations/codec.js.map +1 -0
- package/dist/migrations/decode.d.ts +16 -0
- package/dist/migrations/decode.d.ts.map +1 -0
- package/dist/migrations/decode.js +302 -0
- package/dist/migrations/decode.js.map +1 -0
- package/dist/migrations/diff.d.ts +39 -0
- package/dist/migrations/diff.d.ts.map +1 -0
- package/dist/migrations/diff.js +385 -0
- package/dist/migrations/diff.js.map +1 -0
- package/dist/migrations/expr.d.ts +22 -0
- package/dist/migrations/expr.d.ts.map +1 -0
- package/dist/migrations/expr.js +228 -0
- package/dist/migrations/expr.js.map +1 -0
- package/dist/migrations/fail.d.ts +34 -0
- package/dist/migrations/fail.d.ts.map +1 -0
- package/dist/migrations/fail.js +69 -0
- package/dist/migrations/fail.js.map +1 -0
- package/dist/migrations/fsops.d.ts +37 -0
- package/dist/migrations/fsops.d.ts.map +1 -0
- package/dist/migrations/fsops.js +222 -0
- package/dist/migrations/fsops.js.map +1 -0
- package/dist/migrations/generate.d.ts +11 -0
- package/dist/migrations/generate.d.ts.map +1 -0
- package/dist/migrations/generate.js +479 -0
- package/dist/migrations/generate.js.map +1 -0
- package/dist/migrations/index.d.ts +25 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/dist/migrations/index.js +6 -0
- package/dist/migrations/index.js.map +1 -0
- package/dist/migrations/intent.d.ts +86 -0
- package/dist/migrations/intent.d.ts.map +1 -0
- package/dist/migrations/intent.js +97 -0
- package/dist/migrations/intent.js.map +1 -0
- package/dist/migrations/lock.d.ts +27 -0
- package/dist/migrations/lock.d.ts.map +1 -0
- package/dist/migrations/lock.js +14 -0
- package/dist/migrations/lock.js.map +1 -0
- package/dist/migrations/native.d.ts +37 -0
- package/dist/migrations/native.d.ts.map +1 -0
- package/dist/migrations/native.js +135 -0
- package/dist/migrations/native.js.map +1 -0
- package/dist/migrations/repo.d.ts +38 -0
- package/dist/migrations/repo.d.ts.map +1 -0
- package/dist/migrations/repo.js +191 -0
- package/dist/migrations/repo.js.map +1 -0
- package/dist/migrations/theory.d.ts +21 -0
- package/dist/migrations/theory.d.ts.map +1 -0
- package/dist/migrations/theory.js +107 -0
- package/dist/migrations/theory.js.map +1 -0
- package/dist/migrations/types.d.ts +243 -0
- package/dist/migrations/types.d.ts.map +1 -0
- package/dist/migrations/types.js +2 -0
- package/dist/migrations/types.js.map +1 -0
- package/dist/migrations/workflow.d.ts +11 -0
- package/dist/migrations/workflow.d.ts.map +1 -0
- package/dist/migrations/workflow.js +14 -0
- package/dist/migrations/workflow.js.map +1 -0
- package/dist/native.d.ts +600 -0
- package/dist/native.d.ts.map +1 -0
- package/dist/native.js +8 -0
- package/dist/native.js.map +1 -0
- package/dist/options.d.ts +106 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +2 -0
- package/dist/options.js.map +1 -0
- package/dist/outcome.d.ts +291 -0
- package/dist/outcome.d.ts.map +1 -0
- package/dist/outcome.js +2 -0
- package/dist/outcome.js.map +1 -0
- package/dist/production.d.ts +12 -0
- package/dist/production.d.ts.map +1 -0
- package/dist/production.js +29 -0
- package/dist/production.js.map +1 -0
- package/dist/schema.d.ts +10 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +9 -0
- package/dist/schema.js.map +1 -0
- package/dist/surface.d.ts +80 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +2 -0
- package/dist/surface.js.map +1 -0
- package/dist/tenants.d.ts +20 -52
- package/dist/tenants.d.ts.map +1 -1
- package/dist/tenants.js +11 -330
- package/dist/tenants.js.map +1 -1
- package/pack-provenance.json +7 -0
- package/package.json +20 -23
- package/dist/braids.d.ts +0 -28
- package/dist/braids.d.ts.map +0 -1
- package/dist/braids.js +0 -45
- package/dist/braids.js.map +0 -1
- package/dist/bytes.d.ts +0 -26
- package/dist/bytes.d.ts.map +0 -1
- package/dist/bytes.js +0 -86
- package/dist/bytes.js.map +0 -1
- package/dist/chain.d.ts +0 -56
- package/dist/chain.d.ts.map +0 -1
- package/dist/chain.js +0 -137
- package/dist/chain.js.map +0 -1
- package/dist/codec.d.ts +0 -71
- package/dist/codec.d.ts.map +0 -1
- package/dist/codec.js +0 -179
- package/dist/codec.js.map +0 -1
- package/dist/descriptor.d.ts +0 -61
- package/dist/descriptor.d.ts.map +0 -1
- package/dist/descriptor.js +0 -160
- package/dist/descriptor.js.map +0 -1
- package/dist/keys.d.ts +0 -52
- package/dist/keys.d.ts.map +0 -1
- package/dist/keys.js +0 -166
- package/dist/keys.js.map +0 -1
- package/dist/manifest.d.ts +0 -42
- package/dist/manifest.d.ts.map +0 -1
- package/dist/manifest.js +0 -116
- package/dist/manifest.js.map +0 -1
- package/dist/replica.d.ts +0 -154
- package/dist/replica.d.ts.map +0 -1
- package/dist/replica.js +0 -820
- package/dist/replica.js.map +0 -1
- package/dist/store-s3.d.ts +0 -31
- package/dist/store-s3.d.ts.map +0 -1
- package/dist/store-s3.js +0 -299
- package/dist/store-s3.js.map +0 -1
- package/dist/store.d.ts +0 -129
- package/dist/store.d.ts.map +0 -1
- package/dist/store.js +0 -577
- package/dist/store.js.map +0 -1
- package/dist/tilde-family.json +0 -21
- package/dist/vector.d.ts +0 -31
- package/dist/vector.d.ts.map +0 -1
- package/dist/vector.js +0 -87
- package/dist/vector.js.map +0 -1
- package/dist/writer.d.ts +0 -106
- package/dist/writer.d.ts.map +0 -1
- package/dist/writer.js +0 -677
- package/dist/writer.js.map +0 -1
package/dist/tenants.d.ts
CHANGED
|
@@ -1,56 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* open, so a second live replica on that dir is unrepresentable
|
|
12
|
-
* (findings 39, 48).
|
|
2
|
+
* One native-backed typed tenant registry. `TenantCache.make(schema,
|
|
3
|
+
* options)` acquires the scoped cache; `acquire(binding, work)` returns a
|
|
4
|
+
* DISTINCT scoped `HistoryBorrow<S>` whose release frees only that borrow —
|
|
5
|
+
* never the shared owner. The native registry owns slots, kernel directory
|
|
6
|
+
* locks, opening-work accounting, byte/count pressure and joined close.
|
|
7
|
+
* There is deliberately no renewable wall-clock TTL, pre-lock cleanup,
|
|
8
|
+
* `_shared` magic tenant, JS LRU, timer, or second cache authority here:
|
|
9
|
+
* the successor deleted them. Different tenant schemas use separately
|
|
10
|
+
* constructed typed caches, not casts through one untyped cache.
|
|
13
11
|
*/
|
|
14
|
-
import type {
|
|
15
|
-
import type {
|
|
16
|
-
import type {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
* measured once at each tenant's open — a replica that grows after
|
|
24
|
-
* admission is not re-weighed until it is evicted and re-opened. */
|
|
25
|
-
readonly budgetBytes?: number;
|
|
26
|
-
readonly maxOpen?: number;
|
|
27
|
-
/** Directory-lease TTL. Renewed at one-third this value while the
|
|
28
|
-
* replica is open. Default 300_000. */
|
|
29
|
-
readonly dirLeaseMs?: number;
|
|
30
|
-
}
|
|
31
|
-
declare const liveHandleBrand: unique symbol;
|
|
32
|
-
declare const disposedHandleBrand: unique symbol;
|
|
33
|
-
type LiveHandle<Rels extends SchemaRelations> = Replica<Rels> & {
|
|
34
|
-
readonly [liveHandleBrand]: typeof liveHandleBrand;
|
|
35
|
-
/** Drop one borrow. LRU and `evict` become legal only when `refs`
|
|
36
|
-
* reaches 0 — not when `get` returns. */
|
|
37
|
-
release(): void;
|
|
12
|
+
import type { AnySchema, NativeRuntime } from "@bjornpagen/bumbledb";
|
|
13
|
+
import type { Effect, Scope } from "effect";
|
|
14
|
+
import type { LogError } from "./errors.js";
|
|
15
|
+
import type { TenantCacheOptions } from "./options.js";
|
|
16
|
+
import type { TenantCache as TenantCacheInterface } from "./surface.js";
|
|
17
|
+
/** The scoped typed cache value an app service can own with Layer.effect. */
|
|
18
|
+
export type TenantCache<S extends AnySchema> = TenantCacheInterface<S>;
|
|
19
|
+
export declare const TenantCache: {
|
|
20
|
+
make<S extends AnySchema>(schema: S, options: TenantCacheOptions): Effect.Effect<TenantCache<S>, LogError, NativeRuntime | Scope.Scope>;
|
|
38
21
|
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
* disposed replica is a type error. */
|
|
42
|
-
type DisposedHandle = {
|
|
43
|
-
readonly [disposedHandleBrand]: typeof disposedHandleBrand;
|
|
44
|
-
};
|
|
45
|
-
interface Tenants<Rels extends SchemaRelations> extends AsyncDisposable {
|
|
46
|
-
get(tenant: string): Promise<LiveHandle<Rels>>;
|
|
47
|
-
/** Evicts one tenant: closes the replica and deletes its directory.
|
|
48
|
-
* `_shared` and a still-pinned borrow refuse by doing nothing. */
|
|
49
|
-
evict(tenant: string): Promise<DisposedHandle | null>;
|
|
50
|
-
/** Drop one `get` borrow for `tenant`. */
|
|
51
|
-
release(tenant: string): void;
|
|
52
|
-
}
|
|
53
|
-
declare function openTenants<Rels extends SchemaRelations>(options: OpenTenantsOptions<Rels>): Tenants<Rels>;
|
|
54
|
-
export type { OpenTenantsOptions, Tenants };
|
|
55
|
-
export { openTenants };
|
|
22
|
+
export type { TenantCacheOptions } from "./options.js";
|
|
23
|
+
export type { HistoryBorrow } from "./surface.js";
|
|
56
24
|
//# sourceMappingURL=tenants.d.ts.map
|
package/dist/tenants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tenants.d.ts","sourceRoot":"","sources":["../src/tenants.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"tenants.d.ts","sourceRoot":"","sources":["../src/tenants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACpE,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AAC3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAErD,OAAO,KAAK,EAAE,WAAW,IAAI,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAEtE,6EAA6E;AAC7E,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,SAAS,IAAI,oBAAoB,CAAC,CAAC,CAAC,CAAA;AAEtE,eAAO,MAAM,WAAW,EAAE;IACzB,IAAI,CAAC,CAAC,SAAS,SAAS,EACvB,MAAM,EAAE,CAAC,EACT,OAAO,EAAE,kBAAkB,GACzB,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,aAAa,GAAG,KAAK,CAAC,KAAK,CAAC,CAAA;CACrD,CAAA;AAEnB,YAAY,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AACrD,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA"}
|
package/dist/tenants.js
CHANGED
|
@@ -1,333 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* open, so a second live replica on that dir is unrepresentable
|
|
12
|
-
* (findings 39, 48).
|
|
2
|
+
* One native-backed typed tenant registry. `TenantCache.make(schema,
|
|
3
|
+
* options)` acquires the scoped cache; `acquire(binding, work)` returns a
|
|
4
|
+
* DISTINCT scoped `HistoryBorrow<S>` whose release frees only that borrow —
|
|
5
|
+
* never the shared owner. The native registry owns slots, kernel directory
|
|
6
|
+
* locks, opening-work accounting, byte/count pressure and joined close.
|
|
7
|
+
* There is deliberately no renewable wall-clock TTL, pre-lock cleanup,
|
|
8
|
+
* `_shared` magic tenant, JS LRU, timer, or second cache authority here:
|
|
9
|
+
* the successor deleted them. Different tenant schemas use separately
|
|
10
|
+
* constructed typed caches, not casts through one untyped cache.
|
|
13
11
|
*/
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
import * as errors from "@superbuilders/errors";
|
|
17
|
-
import { regex } from "arkregex";
|
|
18
|
-
import { TEMP_NAMESPACE, tenantPrefix } from "#keys.ts";
|
|
19
|
-
import { openReplica } from "#replica.ts";
|
|
20
|
-
import { acquireFsLease, encodeLease, parseLease, releaseFsLease, sweepStaleTemps, syncedTemp } from "#store.ts";
|
|
21
|
-
const PINNED_TENANT = "_shared";
|
|
22
|
-
const TENANT_ID = regex("^[A-Za-z0-9._-]+$");
|
|
23
|
-
/** Directory-lease lifetime: one owner per replica directory. The pool
|
|
24
|
-
* CAS-extends `expires` at one-third this TTL while the slot is open,
|
|
25
|
-
* so expiry cannot mint a second owner under a live replica. */
|
|
26
|
-
const DIR_LEASE_MS = 300_000;
|
|
27
|
-
const liveHandleBrand = Symbol("liveHandle");
|
|
28
|
-
const disposedHandleBrand = Symbol("disposedHandle");
|
|
29
|
-
function codeOf(error) {
|
|
30
|
-
return error.code;
|
|
31
|
-
}
|
|
32
|
-
async function fsyncDir(dir) {
|
|
33
|
-
const handle = await fs.open(dir, "r");
|
|
34
|
-
const synced = await errors.try(handle.sync());
|
|
35
|
-
await handle.close();
|
|
36
|
-
if (synced.error) {
|
|
37
|
-
throw errors.wrap(synced.error, `fsync directory ${dir}`);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
/** CAS-extend `expires` of a token we already hold. A new token would
|
|
41
|
-
* be a second owner; we rewrite the same path so identity does not
|
|
42
|
-
* change. */
|
|
43
|
-
async function renewDirLease(held, ttlMs) {
|
|
44
|
-
const read = await errors.try(fs.readFile(held.path, "utf8"));
|
|
45
|
-
if (read.error) {
|
|
46
|
-
if (codeOf(read.error) === "ENOENT") {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
throw read.error;
|
|
50
|
-
}
|
|
51
|
-
const lease = parseLease(read.data);
|
|
52
|
-
if (lease === null || lease.holder !== held.holder || lease.token !== held.token) {
|
|
53
|
-
throw errors.new("directory lease is no longer ours");
|
|
54
|
-
}
|
|
55
|
-
const body = encodeLease({ holder: held.holder, token: held.token, expires: BigInt(Date.now() + ttlMs) });
|
|
56
|
-
// The temp lives under the reserved `{root}/~tmp` namespace, where a
|
|
57
|
-
// crash strands sweepable litter — never beside the lease path.
|
|
58
|
-
const temp = await syncedTemp(held.root, body);
|
|
59
|
-
const replaced = await errors.try(fs.rename(temp, held.path));
|
|
60
|
-
if (replaced.error) {
|
|
61
|
-
await fs.rm(temp, { force: true });
|
|
62
|
-
if (codeOf(replaced.error) === "ENOENT") {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
throw replaced.error;
|
|
66
|
-
}
|
|
67
|
-
await fsyncDir(held.dir);
|
|
68
|
-
}
|
|
69
|
-
async function directoryBytes(dir) {
|
|
70
|
-
let total = 0;
|
|
71
|
-
const listed = await errors.try(fs.readdir(dir, { withFileTypes: true, recursive: true }));
|
|
72
|
-
if (listed.error) {
|
|
73
|
-
return 0;
|
|
74
|
-
}
|
|
75
|
-
for (const entry of listed.data) {
|
|
76
|
-
if (entry.isFile()) {
|
|
77
|
-
const stat = await errors.try(fs.stat(path.join(entry.parentPath, entry.name)));
|
|
78
|
-
if (stat.error === undefined) {
|
|
79
|
-
total += stat.data.size;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return total;
|
|
84
|
-
}
|
|
85
|
-
function checkTenantId(tenant) {
|
|
86
|
-
if (!TENANT_ID.test(tenant)) {
|
|
87
|
-
throw errors.new(`tenant id is not a single path segment: ${tenant}`);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
function asDisposed() {
|
|
91
|
-
return { [disposedHandleBrand]: disposedHandleBrand };
|
|
92
|
-
}
|
|
93
|
-
async function disposeSlot(slot) {
|
|
94
|
-
await slot.replica[Symbol.asyncDispose]();
|
|
95
|
-
await fs.rm(slot.dir, { recursive: true, force: true });
|
|
96
|
-
await releaseFsLease(slot.lease);
|
|
97
|
-
}
|
|
98
|
-
function openTenants(options) {
|
|
99
|
-
const budgetBytes = options.budgetBytes ?? 400_000_000;
|
|
100
|
-
const maxOpen = options.maxOpen ?? 32;
|
|
101
|
-
const dirLeaseMs = options.dirLeaseMs ?? DIR_LEASE_MS;
|
|
102
|
-
if (dirLeaseMs <= 0) {
|
|
103
|
-
throw errors.new("dirLeaseMs must be positive");
|
|
104
|
-
}
|
|
105
|
-
const renewEveryMs = Math.max(1, Math.floor(dirLeaseMs / 3));
|
|
106
|
-
const open = new Map();
|
|
107
|
-
const opening = new Map();
|
|
108
|
-
/** The pool root's `~tmp` holds lease mint/renew/release temps; stale
|
|
109
|
-
* ones are crash litter swept once per pool open, best-effort. */
|
|
110
|
-
const swept = errors.try(sweepStaleTemps(path.join(options.dir, TEMP_NAMESPACE)));
|
|
111
|
-
let tick = 0;
|
|
112
|
-
let closed = false;
|
|
113
|
-
let renewTimer;
|
|
114
|
-
let leaseGate = Promise.resolve();
|
|
115
|
-
function withLeaseGate(body) {
|
|
116
|
-
const run = leaseGate.then(body, body);
|
|
117
|
-
leaseGate = run.then(function absorb() {
|
|
118
|
-
return undefined;
|
|
119
|
-
}, function absorbFailure() {
|
|
120
|
-
return undefined;
|
|
121
|
-
});
|
|
122
|
-
return run;
|
|
123
|
-
}
|
|
124
|
-
function dropBorrow(tenant) {
|
|
125
|
-
if (closed) {
|
|
126
|
-
throw errors.new("tenants pool is disposed");
|
|
127
|
-
}
|
|
128
|
-
const slot = open.get(tenant);
|
|
129
|
-
if (slot === undefined || slot.refs <= 0) {
|
|
130
|
-
throw errors.new(`no live borrow for tenant ${tenant}`);
|
|
131
|
-
}
|
|
132
|
-
slot.refs -= 1;
|
|
133
|
-
}
|
|
134
|
-
function brandLive(replica, tenant) {
|
|
135
|
-
const handle = replica;
|
|
136
|
-
Object.defineProperty(handle, liveHandleBrand, { value: liveHandleBrand });
|
|
137
|
-
Object.defineProperty(handle, "release", {
|
|
138
|
-
value: function release() {
|
|
139
|
-
dropBorrow(tenant);
|
|
140
|
-
},
|
|
141
|
-
enumerable: false
|
|
142
|
-
});
|
|
143
|
-
return handle;
|
|
144
|
-
}
|
|
145
|
-
function armRenew() {
|
|
146
|
-
if (renewTimer !== undefined) {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
renewTimer = setInterval(function tickRenew() {
|
|
150
|
-
void errors.try(renewAllOpen());
|
|
151
|
-
}, renewEveryMs);
|
|
152
|
-
}
|
|
153
|
-
function disarmRenew() {
|
|
154
|
-
if (open.size > 0 || renewTimer === undefined) {
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
clearInterval(renewTimer);
|
|
158
|
-
renewTimer = undefined;
|
|
159
|
-
}
|
|
160
|
-
async function renewAllOpen() {
|
|
161
|
-
await withLeaseGate(async function renewHeld() {
|
|
162
|
-
for (const [tenant, slot] of open) {
|
|
163
|
-
const result = await errors.try(renewDirLease(slot.lease, dirLeaseMs));
|
|
164
|
-
if (result.error !== undefined && open.get(tenant) === slot) {
|
|
165
|
-
slot.leaseLost = result.error;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
async function evictUntilWithin(keep) {
|
|
171
|
-
for (;;) {
|
|
172
|
-
let bytes = 0;
|
|
173
|
-
for (const slot of open.values()) {
|
|
174
|
-
bytes += slot.bytes;
|
|
175
|
-
}
|
|
176
|
-
if (open.size <= maxOpen && bytes <= budgetBytes) {
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
let victim = null;
|
|
180
|
-
let oldest = Number.POSITIVE_INFINITY;
|
|
181
|
-
for (const [tenant, slot] of open) {
|
|
182
|
-
if (tenant === PINNED_TENANT || tenant === keep || slot.refs > 0) {
|
|
183
|
-
continue;
|
|
184
|
-
}
|
|
185
|
-
if (slot.lastUsed < oldest) {
|
|
186
|
-
oldest = slot.lastUsed;
|
|
187
|
-
victim = tenant;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
if (victim === null) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
const slot = open.get(victim);
|
|
194
|
-
open.delete(victim);
|
|
195
|
-
if (slot !== undefined) {
|
|
196
|
-
await withLeaseGate(function disposeVictim() {
|
|
197
|
-
return disposeSlot(slot);
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
/** Increment the borrow. The pin outlives `get` — a `finally`
|
|
203
|
-
* decrement here would make LRU/`evict` legal while the caller
|
|
204
|
-
* still holds the LiveHandle (finding 38). Decrement only if this
|
|
205
|
-
* `get` fails before the handle is in the caller's hands. */
|
|
206
|
-
async function pin(slot, tenant) {
|
|
207
|
-
if (slot.leaseLost !== undefined) {
|
|
208
|
-
throw slot.leaseLost;
|
|
209
|
-
}
|
|
210
|
-
slot.refs += 1;
|
|
211
|
-
slot.lastUsed = tick;
|
|
212
|
-
try {
|
|
213
|
-
await evictUntilWithin(tenant);
|
|
214
|
-
const kept = open.get(tenant);
|
|
215
|
-
if (kept === undefined) {
|
|
216
|
-
throw errors.new("tenants pool evicted the handle it is returning");
|
|
217
|
-
}
|
|
218
|
-
await withLeaseGate(function renewOnPin() {
|
|
219
|
-
return renewDirLease(kept.lease, dirLeaseMs);
|
|
220
|
-
});
|
|
221
|
-
return kept.replica;
|
|
222
|
-
}
|
|
223
|
-
catch (error) {
|
|
224
|
-
slot.refs -= 1;
|
|
225
|
-
throw error;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
async function openOne(tenant) {
|
|
229
|
-
await swept;
|
|
230
|
-
const dir = path.join(options.dir, tenant);
|
|
231
|
-
/** The dir-lease mirrors Rust `acquire_named`: tokens live at
|
|
232
|
-
* `{options.dir}/~lease/{tenant}`, outside the disposable replica
|
|
233
|
-
* directory `{options.dir}/{tenant}` — the replica-open sweep
|
|
234
|
-
* rm-rfs the replica dir's own `~lease` and must not touch the
|
|
235
|
-
* held tenant lease. */
|
|
236
|
-
const lease = await acquireFsLease(options.dir, tenant, dirLeaseMs, "refuse");
|
|
237
|
-
let replica;
|
|
238
|
-
try {
|
|
239
|
-
replica = brandLive(await openReplica({
|
|
240
|
-
store: options.store,
|
|
241
|
-
prefix: tenantPrefix(options.root, tenant),
|
|
242
|
-
dir,
|
|
243
|
-
theory: options.theory
|
|
244
|
-
}), tenant);
|
|
245
|
-
}
|
|
246
|
-
catch (error) {
|
|
247
|
-
await releaseFsLease(lease);
|
|
248
|
-
throw error;
|
|
249
|
-
}
|
|
250
|
-
const slot = {
|
|
251
|
-
replica,
|
|
252
|
-
dir,
|
|
253
|
-
lease,
|
|
254
|
-
bytes: await directoryBytes(dir),
|
|
255
|
-
lastUsed: tick,
|
|
256
|
-
refs: 0
|
|
257
|
-
};
|
|
258
|
-
open.set(tenant, slot);
|
|
259
|
-
armRenew();
|
|
260
|
-
return await pin(slot, tenant);
|
|
261
|
-
}
|
|
262
|
-
return {
|
|
263
|
-
async get(tenant) {
|
|
264
|
-
if (closed) {
|
|
265
|
-
throw errors.new("tenants pool is disposed");
|
|
266
|
-
}
|
|
267
|
-
checkTenantId(tenant);
|
|
268
|
-
tick += 1;
|
|
269
|
-
const hit = open.get(tenant);
|
|
270
|
-
if (hit !== undefined) {
|
|
271
|
-
return await pin(hit, tenant);
|
|
272
|
-
}
|
|
273
|
-
const inflight = opening.get(tenant);
|
|
274
|
-
if (inflight !== undefined) {
|
|
275
|
-
const ran = await errors.try(inflight);
|
|
276
|
-
if (ran.error) {
|
|
277
|
-
throw ran.error;
|
|
278
|
-
}
|
|
279
|
-
const slot = open.get(tenant);
|
|
280
|
-
if (slot === undefined) {
|
|
281
|
-
throw errors.new("tenants pool dropped the tenant during open");
|
|
282
|
-
}
|
|
283
|
-
return await pin(slot, tenant);
|
|
284
|
-
}
|
|
285
|
-
const pending = openOne(tenant);
|
|
286
|
-
opening.set(tenant, pending);
|
|
287
|
-
const ran = await errors.try(pending);
|
|
288
|
-
opening.delete(tenant);
|
|
289
|
-
if (ran.error) {
|
|
290
|
-
throw ran.error;
|
|
291
|
-
}
|
|
292
|
-
return ran.data;
|
|
293
|
-
},
|
|
294
|
-
async evict(tenant) {
|
|
295
|
-
if (closed) {
|
|
296
|
-
throw errors.new("tenants pool is disposed");
|
|
297
|
-
}
|
|
298
|
-
checkTenantId(tenant);
|
|
299
|
-
if (tenant === PINNED_TENANT) {
|
|
300
|
-
return null;
|
|
301
|
-
}
|
|
302
|
-
const slot = open.get(tenant);
|
|
303
|
-
if (slot === undefined || slot.refs > 0) {
|
|
304
|
-
return null;
|
|
305
|
-
}
|
|
306
|
-
open.delete(tenant);
|
|
307
|
-
await withLeaseGate(function disposeEvicted() {
|
|
308
|
-
return disposeSlot(slot);
|
|
309
|
-
});
|
|
310
|
-
disarmRenew();
|
|
311
|
-
return asDisposed();
|
|
312
|
-
},
|
|
313
|
-
release(tenant) {
|
|
314
|
-
dropBorrow(tenant);
|
|
315
|
-
},
|
|
316
|
-
async [Symbol.asyncDispose]() {
|
|
317
|
-
closed = true;
|
|
318
|
-
if (renewTimer !== undefined) {
|
|
319
|
-
clearInterval(renewTimer);
|
|
320
|
-
renewTimer = undefined;
|
|
321
|
-
}
|
|
322
|
-
await withLeaseGate(async function disposePool() {
|
|
323
|
-
for (const slot of open.values()) {
|
|
324
|
-
await releaseFsLease(slot.lease);
|
|
325
|
-
await slot.replica[Symbol.asyncDispose]();
|
|
326
|
-
}
|
|
327
|
-
open.clear();
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
};
|
|
331
|
-
}
|
|
332
|
-
export { openTenants };
|
|
12
|
+
import { log } from "#production.ts";
|
|
13
|
+
export const TenantCache = log.TenantCache;
|
|
333
14
|
//# sourceMappingURL=tenants.js.map
|
package/dist/tenants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tenants.js","sourceRoot":"","sources":["../src/tenants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAA;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAChC,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAEvD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAEhH,MAAM,aAAa,GAAG,SAAS,CAAA;AAC/B,MAAM,SAAS,GAAG,KAAK,CAAC,mBAAmB,CAAC,CAAA;AAE5C;;iEAEiE;AACjE,MAAM,YAAY,GAAG,OAAO,CAAA;AAiB5B,MAAM,eAAe,GAAkB,MAAM,CAAC,YAAY,CAAC,CAAA;AAC3D,MAAM,mBAAmB,GAAkB,MAAM,CAAC,gBAAgB,CAAC,CAAA;AAmCnE,SAAS,MAAM,CAAC,KAAY;IAC3B,OAAQ,KAA+B,CAAC,IAAI,CAAA;AAC7C,CAAC;AAED,KAAK,UAAU,QAAQ,CAAC,GAAW;IAClC,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;IACtC,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAA;IAC9C,MAAM,MAAM,CAAC,KAAK,EAAE,CAAA;IACpB,IAAI,MAAM,CAAC,KAAK,EAAE,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C,YAAY,CAAC,EAAE,CAAA;gBAC1C,CAAC;gBACD,IAAI,CAAC,KAAK,EAAE,CAAA;YACb,CAAC,CAAC,CAAA;QACH,CAAC;KACD,CAAA;AACF,CAAC;AAGD,OAAO,EAAE,WAAW,EAAE,CAAA"}
|
|
1
|
+
{"version":3,"file":"tenants.js","sourceRoot":"","sources":["../src/tenants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAMH,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AAMpC,MAAM,CAAC,MAAM,WAAW,GAKpB,GAAG,CAAC,WAAW,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"candidateSourceDigest": "5be8ac5be0ecb3d44502dd24f7aeabe72aac867999f224f61eecf5a19cdce83d",
|
|
3
|
+
"specificationRevision": "87e9a83ee21d1f843c73ac6e7057b2b740db75aae70a553b8053b4f38e87bd2d",
|
|
4
|
+
"stagedAt": "2026-09-07T01:48:49.168Z",
|
|
5
|
+
"package": "@bjornpagen/bumbledb-log",
|
|
6
|
+
"version": "1.0.0"
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bjornpagen/bumbledb-log",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Durable named application commands over bumbledb: LocalHistory, HostedHistory, sealed commands with retained refs, published snapshots, one native TenantCache, and explicit maintenance/migration operations (Effect-only)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"default": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./schema": {
|
|
12
|
+
"types": "./dist/schema.d.ts",
|
|
13
|
+
"default": "./dist/schema.js"
|
|
14
|
+
},
|
|
15
|
+
"./migrations": {
|
|
16
|
+
"types": "./dist/migrations/index.d.ts",
|
|
17
|
+
"default": "./dist/migrations/index.js"
|
|
10
18
|
}
|
|
11
19
|
},
|
|
20
|
+
"bin": {
|
|
21
|
+
"bumbledb-log": "./dist/migrations/bin.js"
|
|
22
|
+
},
|
|
12
23
|
"imports": {
|
|
13
24
|
"#test/*.ts": "./test/*.ts",
|
|
14
25
|
"#*.ts": {
|
|
@@ -18,13 +29,15 @@
|
|
|
18
29
|
}
|
|
19
30
|
},
|
|
20
31
|
"files": [
|
|
32
|
+
"pack-provenance.json",
|
|
21
33
|
"dist",
|
|
22
34
|
"README.md"
|
|
23
35
|
],
|
|
24
36
|
"keywords": [
|
|
25
37
|
"database",
|
|
26
|
-
"
|
|
27
|
-
"
|
|
38
|
+
"commands",
|
|
39
|
+
"history",
|
|
40
|
+
"migrations",
|
|
28
41
|
"bumbledb"
|
|
29
42
|
],
|
|
30
43
|
"author": "Bjorn Pagen",
|
|
@@ -35,19 +48,9 @@
|
|
|
35
48
|
"directory": "ts-log"
|
|
36
49
|
},
|
|
37
50
|
"homepage": "https://github.com/bjornpagen/bumbledb#readme",
|
|
38
|
-
"dependencies": {
|
|
39
|
-
"@aws-sdk/client-s3": "^3.1116.0",
|
|
40
|
-
"@superbuilders/errors": "^4.0.2",
|
|
41
|
-
"arkregex": "^0.0.8"
|
|
42
|
-
},
|
|
43
51
|
"peerDependencies": {
|
|
44
|
-
"@bjornpagen/bumbledb": "
|
|
45
|
-
|
|
46
|
-
"devDependencies": {
|
|
47
|
-
"@biomejs/biome": "2.5.4",
|
|
48
|
-
"@bjornpagen/bumbledb": "link:../ts",
|
|
49
|
-
"@types/node": "26.1.1",
|
|
50
|
-
"typescript": "7.0.2"
|
|
52
|
+
"@bjornpagen/bumbledb": "1.0.0",
|
|
53
|
+
"effect": "4.0.0-rc.112"
|
|
51
54
|
},
|
|
52
55
|
"engines": {
|
|
53
56
|
"node": ">=24"
|
|
@@ -55,11 +58,5 @@
|
|
|
55
58
|
"publishConfig": {
|
|
56
59
|
"access": "public"
|
|
57
60
|
},
|
|
58
|
-
"private": false
|
|
59
|
-
"scripts": {
|
|
60
|
-
"build": "node scripts/build.ts",
|
|
61
|
-
"typecheck": "tsc --noEmit",
|
|
62
|
-
"lint": "biome check .",
|
|
63
|
-
"test": "pnpm run build && node --test 'test/**/*.test.ts'"
|
|
64
|
-
}
|
|
61
|
+
"private": false
|
|
65
62
|
}
|
package/dist/braids.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Braid derivation as data (10/20): connected components of the
|
|
3
|
-
* statement graph over ordinary relations, the braid id the smallest
|
|
4
|
-
* RelationId in the component rendered `c{id:08x}`. The one derivation
|
|
5
|
-
* lives in `crates/bumbledb-log` and reaches the descriptor parse
|
|
6
|
-
* through the engine bridge (`internalLogBraidsOf`); this façade names
|
|
7
|
-
* that derivation in the driver's vocabulary.
|
|
8
|
-
*/
|
|
9
|
-
import type { Braid, SerialStatement, Theory } from "./descriptor.js";
|
|
10
|
-
import { braid } from "./descriptor.js";
|
|
11
|
-
/** The schema's own shard map: ordinary relation name → braid id. */
|
|
12
|
-
declare function braidsOf(theory: Theory): ReadonlyMap<string, Braid>;
|
|
13
|
-
/**
|
|
14
|
-
* The degenerate-serial roster (15): key or capacity statements whose
|
|
15
|
-
* determinant projection is empty name one global group, so their braid
|
|
16
|
-
* serializes at that statement. The statement ids are the log core's
|
|
17
|
-
* own roster, read off the descriptor's derivation.
|
|
18
|
-
*/
|
|
19
|
-
declare function serialAtStatementsOf(theory: Theory): readonly SerialStatement[];
|
|
20
|
-
/**
|
|
21
|
-
* Parses a wire u32 into a braid id: valid only when the relation it
|
|
22
|
-
* names is the smallest in its own component. An unknown, closed, or
|
|
23
|
-
* non-head id is not a braid — the caller refuses, it is not ignored.
|
|
24
|
-
*/
|
|
25
|
-
declare function parse(theory: Theory, raw: number): Braid | undefined;
|
|
26
|
-
export type { Braid };
|
|
27
|
-
export { braid, braidsOf, parse, serialAtStatementsOf };
|
|
28
|
-
//# sourceMappingURL=braids.d.ts.map
|
package/dist/braids.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"braids.d.ts","sourceRoot":"","sources":["../src/braids.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACpE,OAAO,EAAE,KAAK,EAA0B,MAAM,gBAAgB,CAAA;AAI9D,qEAAqE;AACrE,iBAAS,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAU5D;AAED;;;;;GAKG;AACH,iBAAS,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,eAAe,EAAE,CAExE;AAED;;;;GAIG;AACH,iBAAS,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS,CAM7D;AAED,YAAY,EAAE,KAAK,EAAE,CAAA;AACrB,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,oBAAoB,EAAE,CAAA"}
|
package/dist/braids.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Braid derivation as data (10/20): connected components of the
|
|
3
|
-
* statement graph over ordinary relations, the braid id the smallest
|
|
4
|
-
* RelationId in the component rendered `c{id:08x}`. The one derivation
|
|
5
|
-
* lives in `crates/bumbledb-log` and reaches the descriptor parse
|
|
6
|
-
* through the engine bridge (`internalLogBraidsOf`); this façade names
|
|
7
|
-
* that derivation in the driver's vocabulary.
|
|
8
|
-
*/
|
|
9
|
-
import { braid, braidHex, descriptorOf } from "#descriptor.ts";
|
|
10
|
-
const U32_MAX = 0xffffffff;
|
|
11
|
-
/** The schema's own shard map: ordinary relation name → braid id. */
|
|
12
|
-
function braidsOf(theory) {
|
|
13
|
-
const descriptor = descriptorOf(theory);
|
|
14
|
-
const out = new Map();
|
|
15
|
-
for (const relation of descriptor.relations) {
|
|
16
|
-
const braid = descriptor.braidOfRelation.get(relation.id);
|
|
17
|
-
if (braid !== undefined) {
|
|
18
|
-
out.set(relation.name, braid);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return out;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* The degenerate-serial roster (15): key or capacity statements whose
|
|
25
|
-
* determinant projection is empty name one global group, so their braid
|
|
26
|
-
* serializes at that statement. The statement ids are the log core's
|
|
27
|
-
* own roster, read off the descriptor's derivation.
|
|
28
|
-
*/
|
|
29
|
-
function serialAtStatementsOf(theory) {
|
|
30
|
-
return descriptorOf(theory).serialAtStatements;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Parses a wire u32 into a braid id: valid only when the relation it
|
|
34
|
-
* names is the smallest in its own component. An unknown, closed, or
|
|
35
|
-
* non-head id is not a braid — the caller refuses, it is not ignored.
|
|
36
|
-
*/
|
|
37
|
-
function parse(theory, raw) {
|
|
38
|
-
if (!Number.isInteger(raw) || raw < 0 || raw > U32_MAX) {
|
|
39
|
-
return undefined;
|
|
40
|
-
}
|
|
41
|
-
const name = braidHex(raw);
|
|
42
|
-
return descriptorOf(theory).braidMembers.has(name) ? name : undefined;
|
|
43
|
-
}
|
|
44
|
-
export { braid, braidsOf, parse, serialAtStatementsOf };
|
|
45
|
-
//# sourceMappingURL=braids.js.map
|
package/dist/braids.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"braids.js","sourceRoot":"","sources":["../src/braids.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE9D,MAAM,OAAO,GAAG,UAAU,CAAA;AAE1B,qEAAqE;AACrE,SAAS,QAAQ,CAAC,MAAc;IAC/B,MAAM,UAAU,GAAG,YAA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