@noy-db/in-devtools 0.2.0-pre.9 → 0.3.0-pre.1

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/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AccessibleVault, Vault, CollectionDescriptor, CollectionStats, WriteEvent, WriteConflict, Noydb } from '@noy-db/hub';
1
+ import { AccessibleVault, Vault, WriteHook, Unsubscribe, WriteConflict, WriteQueue, CollectionDescriptor, CollectionStats, CollectionMeta, DescribedField, CollectionConfig, VaultMeta, WriteEvent } from '@noy-db/hub';
2
2
  import { MeterSnapshot } from '@noy-db/to-meter';
3
3
 
4
4
  /** Minimal structural view of a to-meter handle the inspector reads (no runtime dep). */
@@ -18,11 +18,19 @@ interface InspectorCollection {
18
18
  readonly indexes: CollectionDescriptor['indexes'];
19
19
  readonly refs: CollectionDescriptor['refs'];
20
20
  readonly stats?: CollectionStats;
21
+ /** Collection-level descriptive metadata (label/description/icon). */
22
+ readonly meta?: CollectionMeta;
23
+ /** Per-field rich descriptors from collection.describe() (label/widget/money/dict/…). */
24
+ readonly described?: readonly DescribedField[];
25
+ /** Collection-level configuration (textIndexes/embeddings/crdt/provenance/…). */
26
+ readonly config?: CollectionConfig;
21
27
  }
22
28
  /** Structure + stats for one open vault. */
23
29
  interface InspectorSnapshot {
24
30
  readonly vault: string;
25
31
  readonly collections: ReadonlyArray<InspectorCollection>;
32
+ /** Vault-level descriptive metadata (label/description/icon). */
33
+ readonly meta?: VaultMeta;
26
34
  }
27
35
  /** A page of decrypted records from one collection. */
28
36
  interface RecordPage {
@@ -54,11 +62,21 @@ interface Inspector {
54
62
  /** Aggregate store-op latency snapshot, or null when the store is not metered. */
55
63
  meterSnapshot(): MeterSnapshot | null;
56
64
  }
57
- /** @internal — the hub handle the inspector reads from. */
58
- type InspectorNoydb = Noydb;
65
+ /**
66
+ * The container of vaults the inspector reads from. A `Noydb` satisfies this
67
+ * verbatim; a klum `VaultGroup` adapter conforms structurally — so the inspector
68
+ * works on a single instance OR a federation without importing either.
69
+ */
70
+ interface InspectableContainer {
71
+ listAccessibleVaults(): Promise<readonly AccessibleVault[]>;
72
+ openVault(name: string): Promise<Vault>;
73
+ onAfterWrite(handler: WriteHook): Unsubscribe;
74
+ onWriteConflict(handler: (c: WriteConflict) => void): Unsubscribe;
75
+ readonly writeQueue: WriteQueue;
76
+ }
59
77
 
60
- declare function createInspector(noydb: InspectorNoydb, opts?: {
78
+ declare function createInspector(container: InspectableContainer, opts?: {
61
79
  meter?: InspectorMeter;
62
80
  }): Inspector;
63
81
 
64
- export { type Inspector, type InspectorCollection, type InspectorMeter, type InspectorSnapshot, type InspectorWriteConflict, type InspectorWriteEvent, type PendingWrites, type RecordPage, type VaultInfo, createInspector };
82
+ export { type InspectableContainer, type Inspector, type InspectorCollection, type InspectorMeter, type InspectorSnapshot, type InspectorWriteConflict, type InspectorWriteEvent, type PendingWrites, type RecordPage, type VaultInfo, createInspector };
package/dist/index.js CHANGED
@@ -4,14 +4,30 @@ async function listVaults(noydb) {
4
4
  }
5
5
  async function snapshot(vault) {
6
6
  const dump = await vault.dumpSchema({ withStats: true });
7
- const collections = Object.entries(dump.collections).map(([name, desc]) => ({
8
- name,
9
- fields: desc.fields,
10
- indexes: desc.indexes,
11
- refs: desc.refs,
12
- ...desc.stats !== void 0 ? { stats: desc.stats } : {}
13
- }));
14
- return { vault: dump.vault, collections };
7
+ const collections = Object.entries(dump.collections).map(([name, desc]) => {
8
+ let described;
9
+ try {
10
+ const coll = vault.collection(name);
11
+ const collDesc = coll.describe();
12
+ described = collDesc.fields;
13
+ } catch {
14
+ }
15
+ return {
16
+ name,
17
+ fields: desc.fields,
18
+ indexes: desc.indexes,
19
+ refs: desc.refs,
20
+ ...desc.stats !== void 0 ? { stats: desc.stats } : {},
21
+ ...desc.meta !== void 0 ? { meta: desc.meta } : {},
22
+ ...desc.config !== void 0 ? { config: desc.config } : {},
23
+ ...described !== void 0 ? { described } : {}
24
+ };
25
+ });
26
+ return {
27
+ vault: dump.vault,
28
+ collections,
29
+ ...dump.meta !== void 0 ? { meta: dump.meta } : {}
30
+ };
15
31
  }
16
32
 
17
33
  // src/records.ts
@@ -55,14 +71,14 @@ function meterSnapshot(meter) {
55
71
  }
56
72
 
57
73
  // src/index.ts
58
- function createInspector(noydb, opts) {
74
+ function createInspector(container, opts) {
59
75
  return {
60
- listVaults: () => listVaults(noydb),
76
+ listVaults: () => listVaults(container),
61
77
  snapshot: (vault) => snapshot(vault),
62
78
  records: (vault, collection, opts2) => records(vault, collection, opts2),
63
- subscribe: (handler) => subscribe(noydb, handler),
64
- subscribeConflicts: (handler) => subscribeConflicts(noydb, handler),
65
- pendingWrites: () => pendingWrites(noydb),
79
+ subscribe: (handler) => subscribe(container, handler),
80
+ subscribeConflicts: (handler) => subscribeConflicts(container, handler),
81
+ pendingWrites: () => pendingWrites(container),
66
82
  meterSnapshot: () => meterSnapshot(opts?.meter)
67
83
  };
68
84
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/snapshot.ts","../src/records.ts","../src/events.ts","../src/meter.ts","../src/index.ts"],"sourcesContent":["import type { Vault } from '@noy-db/hub'\nimport type { InspectorSnapshot, InspectorCollection, VaultInfo, InspectorNoydb } from './types.js'\n\nexport async function listVaults(noydb: InspectorNoydb): Promise<ReadonlyArray<VaultInfo>> {\n return noydb.listAccessibleVaults()\n}\n\nexport async function snapshot(vault: Vault): Promise<InspectorSnapshot> {\n // withStats populates per-collection record/byte stats; opaque to the store.\n const dump = await vault.dumpSchema({ withStats: true })\n // Omit `stats` when absent rather than setting it to `undefined` —\n // the repo's tsconfig sets `exactOptionalPropertyTypes`, so an optional\n // `stats?` field must be omitted, not explicitly undefined.\n const collections: InspectorCollection[] = Object.entries(dump.collections).map(([name, desc]) => ({\n name,\n fields: desc.fields,\n indexes: desc.indexes,\n refs: desc.refs,\n ...(desc.stats !== undefined ? { stats: desc.stats } : {}),\n }))\n return { vault: dump.vault, collections }\n}\n","import type { Vault } from '@noy-db/hub'\nimport type { RecordPage } from './types.js'\n\nconst DEFAULT_LIMIT = 50\nconst MAX_LIMIT = 500\n\nfunction clampLimit(n: number | undefined): number {\n if (n === undefined || Number.isNaN(n)) return DEFAULT_LIMIT\n return Math.max(1, Math.min(MAX_LIMIT, Math.floor(n)))\n}\n\nfunction clampOffset(n: number | undefined): number {\n if (n === undefined || Number.isNaN(n) || n < 0) return 0\n return Math.floor(n)\n}\n\nexport async function records(\n vault: Vault,\n collection: string,\n opts: { limit?: number; offset?: number } = {},\n): Promise<RecordPage> {\n const limit = clampLimit(opts.limit)\n const offset = clampOffset(opts.offset)\n // Eager collections only — `list()` throws on lazy (prefetch:false). The\n // error propagates to the caller, which decides how to surface it.\n const all = await vault.collection(collection).list()\n return {\n rows: all.slice(offset, offset + limit),\n total: all.length,\n limit,\n offset,\n }\n}\n","import type { InspectorWriteEvent, InspectorWriteConflict, PendingWrites, InspectorNoydb } from './types.js'\n\nexport function subscribe(\n noydb: InspectorNoydb,\n handler: (event: InspectorWriteEvent) => void,\n): () => void {\n return noydb.onAfterWrite(handler)\n}\n\nexport function pendingWrites(noydb: InspectorNoydb): PendingWrites {\n const q = noydb.writeQueue\n return { pending: q.pending, depth: q.depth }\n}\n\nexport function subscribeConflicts(noydb: InspectorNoydb, handler: (c: InspectorWriteConflict) => void): () => void {\n return noydb.onWriteConflict(handler)\n}\n","import type { InspectorMeter } from './types.js'\nimport type { MeterSnapshot } from '@noy-db/to-meter'\n\nexport function meterSnapshot(meter: InspectorMeter | undefined): MeterSnapshot | null {\n return meter ? meter.snapshot() : null\n}\n","import type { Vault } from '@noy-db/hub'\nimport type { Inspector, InspectorNoydb, InspectorMeter } from './types.js'\nimport { listVaults, snapshot } from './snapshot.js'\nimport { records } from './records.js'\nimport { subscribe, subscribeConflicts, pendingWrites } from './events.js'\nimport { meterSnapshot } from './meter.js'\n\nexport function createInspector(noydb: InspectorNoydb, opts?: { meter?: InspectorMeter }): Inspector {\n return {\n listVaults: () => listVaults(noydb),\n snapshot: (vault: Vault) => snapshot(vault),\n records: (vault, collection, opts) => records(vault, collection, opts),\n subscribe: (handler) => subscribe(noydb, handler),\n subscribeConflicts: (handler) => subscribeConflicts(noydb, handler),\n pendingWrites: () => pendingWrites(noydb),\n meterSnapshot: () => meterSnapshot(opts?.meter),\n }\n}\n\nexport type {\n Inspector,\n VaultInfo,\n InspectorSnapshot,\n InspectorCollection,\n RecordPage,\n InspectorWriteEvent,\n InspectorWriteConflict,\n PendingWrites,\n InspectorMeter,\n} from './types.js'\n"],"mappings":";AAGA,eAAsB,WAAW,OAA0D;AACzF,SAAO,MAAM,qBAAqB;AACpC;AAEA,eAAsB,SAAS,OAA0C;AAEvE,QAAM,OAAO,MAAM,MAAM,WAAW,EAAE,WAAW,KAAK,CAAC;AAIvD,QAAM,cAAqC,OAAO,QAAQ,KAAK,WAAW,EAAE,IAAI,CAAC,CAAC,MAAM,IAAI,OAAO;AAAA,IACjG;AAAA,IACA,QAAQ,KAAK;AAAA,IACb,SAAS,KAAK;AAAA,IACd,MAAM,KAAK;AAAA,IACX,GAAI,KAAK,UAAU,SAAY,EAAE,OAAO,KAAK,MAAM,IAAI,CAAC;AAAA,EAC1D,EAAE;AACF,SAAO,EAAE,OAAO,KAAK,OAAO,YAAY;AAC1C;;;AClBA,IAAM,gBAAgB;AACtB,IAAM,YAAY;AAElB,SAAS,WAAW,GAA+B;AACjD,MAAI,MAAM,UAAa,OAAO,MAAM,CAAC,EAAG,QAAO;AAC/C,SAAO,KAAK,IAAI,GAAG,KAAK,IAAI,WAAW,KAAK,MAAM,CAAC,CAAC,CAAC;AACvD;AAEA,SAAS,YAAY,GAA+B;AAClD,MAAI,MAAM,UAAa,OAAO,MAAM,CAAC,KAAK,IAAI,EAAG,QAAO;AACxD,SAAO,KAAK,MAAM,CAAC;AACrB;AAEA,eAAsB,QACpB,OACA,YACA,OAA4C,CAAC,GACxB;AACrB,QAAM,QAAQ,WAAW,KAAK,KAAK;AACnC,QAAM,SAAS,YAAY,KAAK,MAAM;AAGtC,QAAM,MAAM,MAAM,MAAM,WAAW,UAAU,EAAE,KAAK;AACpD,SAAO;AAAA,IACL,MAAM,IAAI,MAAM,QAAQ,SAAS,KAAK;AAAA,IACtC,OAAO,IAAI;AAAA,IACX;AAAA,IACA;AAAA,EACF;AACF;;;AC9BO,SAAS,UACd,OACA,SACY;AACZ,SAAO,MAAM,aAAa,OAAO;AACnC;AAEO,SAAS,cAAc,OAAsC;AAClE,QAAM,IAAI,MAAM;AAChB,SAAO,EAAE,SAAS,EAAE,SAAS,OAAO,EAAE,MAAM;AAC9C;AAEO,SAAS,mBAAmB,OAAuB,SAA0D;AAClH,SAAO,MAAM,gBAAgB,OAAO;AACtC;;;ACbO,SAAS,cAAc,OAAyD;AACrF,SAAO,QAAQ,MAAM,SAAS,IAAI;AACpC;;;ACEO,SAAS,gBAAgB,OAAuB,MAA8C;AACnG,SAAO;AAAA,IACL,YAAY,MAAM,WAAW,KAAK;AAAA,IAClC,UAAU,CAAC,UAAiB,SAAS,KAAK;AAAA,IAC1C,SAAS,CAAC,OAAO,YAAYA,UAAS,QAAQ,OAAO,YAAYA,KAAI;AAAA,IACrE,WAAW,CAAC,YAAY,UAAU,OAAO,OAAO;AAAA,IAChD,oBAAoB,CAAC,YAAY,mBAAmB,OAAO,OAAO;AAAA,IAClE,eAAe,MAAM,cAAc,KAAK;AAAA,IACxC,eAAe,MAAM,cAAc,MAAM,KAAK;AAAA,EAChD;AACF;","names":["opts"]}
1
+ {"version":3,"sources":["../src/snapshot.ts","../src/records.ts","../src/events.ts","../src/meter.ts","../src/index.ts"],"sourcesContent":["import type { Vault } from '@noy-db/hub'\nimport type { InspectorSnapshot, InspectorCollection, VaultInfo, InspectableContainer } from './types.js'\n\nexport async function listVaults(noydb: InspectableContainer): Promise<ReadonlyArray<VaultInfo>> {\n return noydb.listAccessibleVaults()\n}\n\nexport async function snapshot(vault: Vault): Promise<InspectorSnapshot> {\n // withStats populates per-collection record/byte stats; opaque to the store.\n const dump = await vault.dumpSchema({ withStats: true })\n // Omit optional properties when absent rather than setting them to `undefined` —\n // the repo's tsconfig sets `exactOptionalPropertyTypes`, so optional fields must\n // be omitted, not explicitly set to undefined.\n const collections: InspectorCollection[] = Object.entries(dump.collections).map(([name, desc]) => {\n // Attempt to call describe() on the live collection to get rich field descriptors.\n // Guard: a collection that was not live-declared on this Vault instance (e.g. from a\n // prior open or a different process) may throw or return minimal output — skip\n // `described` for it without failing the whole snapshot.\n let described: InspectorCollection['described'] | undefined\n try {\n const coll = vault.collection(name)\n const collDesc = coll.describe()\n described = collDesc.fields\n } catch {\n // Not live-declared or no schema — skip described for this collection.\n }\n\n return {\n name,\n fields: desc.fields,\n indexes: desc.indexes,\n refs: desc.refs,\n ...(desc.stats !== undefined ? { stats: desc.stats } : {}),\n ...(desc.meta !== undefined ? { meta: desc.meta } : {}),\n ...(desc.config !== undefined ? { config: desc.config } : {}),\n ...(described !== undefined ? { described } : {}),\n }\n })\n\n return {\n vault: dump.vault,\n collections,\n ...(dump.meta !== undefined ? { meta: dump.meta } : {}),\n }\n}\n","import type { Vault } from '@noy-db/hub'\nimport type { RecordPage } from './types.js'\n\nconst DEFAULT_LIMIT = 50\nconst MAX_LIMIT = 500\n\nfunction clampLimit(n: number | undefined): number {\n if (n === undefined || Number.isNaN(n)) return DEFAULT_LIMIT\n return Math.max(1, Math.min(MAX_LIMIT, Math.floor(n)))\n}\n\nfunction clampOffset(n: number | undefined): number {\n if (n === undefined || Number.isNaN(n) || n < 0) return 0\n return Math.floor(n)\n}\n\nexport async function records(\n vault: Vault,\n collection: string,\n opts: { limit?: number; offset?: number } = {},\n): Promise<RecordPage> {\n const limit = clampLimit(opts.limit)\n const offset = clampOffset(opts.offset)\n // Eager collections only — `list()` throws on lazy (prefetch:false). The\n // error propagates to the caller, which decides how to surface it.\n const all = await vault.collection(collection).list()\n return {\n rows: all.slice(offset, offset + limit),\n total: all.length,\n limit,\n offset,\n }\n}\n","import type { InspectorWriteEvent, InspectorWriteConflict, PendingWrites, InspectableContainer } from './types.js'\n\nexport function subscribe(\n noydb: InspectableContainer,\n handler: (event: InspectorWriteEvent) => void,\n): () => void {\n return noydb.onAfterWrite(handler)\n}\n\nexport function pendingWrites(noydb: InspectableContainer): PendingWrites {\n const q = noydb.writeQueue\n return { pending: q.pending, depth: q.depth }\n}\n\nexport function subscribeConflicts(noydb: InspectableContainer, handler: (c: InspectorWriteConflict) => void): () => void {\n return noydb.onWriteConflict(handler)\n}\n","import type { InspectorMeter } from './types.js'\nimport type { MeterSnapshot } from '@noy-db/to-meter'\n\nexport function meterSnapshot(meter: InspectorMeter | undefined): MeterSnapshot | null {\n return meter ? meter.snapshot() : null\n}\n","import type { Vault } from '@noy-db/hub'\nimport type { Inspector, InspectableContainer, InspectorMeter } from './types.js'\nimport { listVaults, snapshot } from './snapshot.js'\nimport { records } from './records.js'\nimport { subscribe, subscribeConflicts, pendingWrites } from './events.js'\nimport { meterSnapshot } from './meter.js'\n\nexport function createInspector(container: InspectableContainer, opts?: { meter?: InspectorMeter }): Inspector {\n return {\n listVaults: () => listVaults(container),\n snapshot: (vault: Vault) => snapshot(vault),\n records: (vault, collection, opts) => records(vault, collection, opts),\n subscribe: (handler) => subscribe(container, handler),\n subscribeConflicts: (handler) => subscribeConflicts(container, handler),\n pendingWrites: () => pendingWrites(container),\n meterSnapshot: () => meterSnapshot(opts?.meter),\n }\n}\n\nexport type {\n Inspector,\n InspectableContainer,\n VaultInfo,\n InspectorSnapshot,\n InspectorCollection,\n RecordPage,\n InspectorWriteEvent,\n InspectorWriteConflict,\n PendingWrites,\n InspectorMeter,\n} from './types.js'\n"],"mappings":";AAGA,eAAsB,WAAW,OAAgE;AAC/F,SAAO,MAAM,qBAAqB;AACpC;AAEA,eAAsB,SAAS,OAA0C;AAEvE,QAAM,OAAO,MAAM,MAAM,WAAW,EAAE,WAAW,KAAK,CAAC;AAIvD,QAAM,cAAqC,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U,EAAE,KAAK;AACpD,SAAO;AAAA,IACL,MAAM,IAAI,MAAM,QAAQ,SAAS,KAAK;AAAA,IACtC,OAAO,IAAI;AAAA,IACX;AAAA,IACA;AAAA,EACF;AACF;;;AC9BO,SAAS,UACd,OACA,SACY;AACZ,SAAO,MAAM,aAAa,OAAO;AACnC;AAEO,SAAS,cAAc,OAA4C;AACxE,QAAM,IAAI,MAAM;AAChB,SAAO,EAAE,SAAS,EAAE,SAAS,OAAO,EAAE,MAAM;AAC9C;AAEO,SAAS,mBAAmB,OAA6B,SAA0D;AACxH,SAAO,MAAM,gBAAgB,OAAO;AACtC;;;ACbO,SAAS,cAAc,OAAyD;AACrF,SAAO,QAAQ,MAAM,SAAS,IAAI;AACpC;;;ACEO,SAAS,gBAAgB,WAAiC,MAA8C;AAC7G,SAAO;AAAA,IACL,YAAY,MAAM,WAAW,SAAS;AAAA,IACtC,UAAU,CAAC,UAAiB,SAAS,KAAK;AAAA,IAC1C,SAAS,CAAC,OAAO,YAAYA,UAAS,QAAQ,OAAO,YAAYA,KAAI;AAAA,IACrE,WAAW,CAAC,YAAY,UAAU,WAAW,OAAO;AAAA,IACpD,oBAAoB,CAAC,YAAY,mBAAmB,WAAW,OAAO;AAAA,IACtE,eAAe,MAAM,cAAc,SAAS;AAAA,IAC5C,eAAe,MAAM,cAAc,MAAM,KAAK;AAAA,EAChD;AACF;","names":["opts"]}
package/package.json CHANGED
@@ -1,33 +1,29 @@
1
1
  {
2
2
  "name": "@noy-db/in-devtools",
3
- "version": "0.2.0-pre.9",
3
+ "version": "0.3.0-pre.1",
4
4
  "description": "Framework-agnostic read-only inspector for a live noy-db — vaults, collections, schema, stats, records, and live writes.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
- "main": "./dist/index.cjs",
8
7
  "module": "./dist/index.js",
9
8
  "types": "./dist/index.d.ts",
10
9
  "exports": {
11
10
  ".": {
12
- "import": {
13
- "types": "./dist/index.d.ts",
14
- "default": "./dist/index.js"
15
- },
16
- "require": {
17
- "types": "./dist/index.d.cts",
18
- "default": "./dist/index.cjs"
19
- }
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
20
13
  }
21
14
  },
22
15
  "files": [
23
16
  "dist"
24
17
  ],
25
18
  "peerDependencies": {
26
- "@noy-db/hub": "0.2.0-pre.9"
19
+ "@noy-db/hub": "0.3.0-pre.1"
27
20
  },
28
21
  "devDependencies": {
29
- "@noy-db/hub": "0.2.0-pre.9",
30
- "@noy-db/to-meter": "0.2.0-pre.9"
22
+ "@noy-db/hub": "0.3.0-pre.1",
23
+ "@noy-db/to-meter": "0.3.0-pre.1"
24
+ },
25
+ "engines": {
26
+ "node": ">=22.0.0"
31
27
  },
32
28
  "scripts": {
33
29
  "build": "tsup",
package/dist/index.cjs DELETED
@@ -1,99 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- createInspector: () => createInspector
24
- });
25
- module.exports = __toCommonJS(index_exports);
26
-
27
- // src/snapshot.ts
28
- async function listVaults(noydb) {
29
- return noydb.listAccessibleVaults();
30
- }
31
- async function snapshot(vault) {
32
- const dump = await vault.dumpSchema({ withStats: true });
33
- const collections = Object.entries(dump.collections).map(([name, desc]) => ({
34
- name,
35
- fields: desc.fields,
36
- indexes: desc.indexes,
37
- refs: desc.refs,
38
- ...desc.stats !== void 0 ? { stats: desc.stats } : {}
39
- }));
40
- return { vault: dump.vault, collections };
41
- }
42
-
43
- // src/records.ts
44
- var DEFAULT_LIMIT = 50;
45
- var MAX_LIMIT = 500;
46
- function clampLimit(n) {
47
- if (n === void 0 || Number.isNaN(n)) return DEFAULT_LIMIT;
48
- return Math.max(1, Math.min(MAX_LIMIT, Math.floor(n)));
49
- }
50
- function clampOffset(n) {
51
- if (n === void 0 || Number.isNaN(n) || n < 0) return 0;
52
- return Math.floor(n);
53
- }
54
- async function records(vault, collection, opts = {}) {
55
- const limit = clampLimit(opts.limit);
56
- const offset = clampOffset(opts.offset);
57
- const all = await vault.collection(collection).list();
58
- return {
59
- rows: all.slice(offset, offset + limit),
60
- total: all.length,
61
- limit,
62
- offset
63
- };
64
- }
65
-
66
- // src/events.ts
67
- function subscribe(noydb, handler) {
68
- return noydb.onAfterWrite(handler);
69
- }
70
- function pendingWrites(noydb) {
71
- const q = noydb.writeQueue;
72
- return { pending: q.pending, depth: q.depth };
73
- }
74
- function subscribeConflicts(noydb, handler) {
75
- return noydb.onWriteConflict(handler);
76
- }
77
-
78
- // src/meter.ts
79
- function meterSnapshot(meter) {
80
- return meter ? meter.snapshot() : null;
81
- }
82
-
83
- // src/index.ts
84
- function createInspector(noydb, opts) {
85
- return {
86
- listVaults: () => listVaults(noydb),
87
- snapshot: (vault) => snapshot(vault),
88
- records: (vault, collection, opts2) => records(vault, collection, opts2),
89
- subscribe: (handler) => subscribe(noydb, handler),
90
- subscribeConflicts: (handler) => subscribeConflicts(noydb, handler),
91
- pendingWrites: () => pendingWrites(noydb),
92
- meterSnapshot: () => meterSnapshot(opts?.meter)
93
- };
94
- }
95
- // Annotate the CommonJS export names for ESM import in node:
96
- 0 && (module.exports = {
97
- createInspector
98
- });
99
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts","../src/snapshot.ts","../src/records.ts","../src/events.ts","../src/meter.ts"],"sourcesContent":["import type { Vault } from '@noy-db/hub'\nimport type { Inspector, InspectorNoydb, InspectorMeter } from './types.js'\nimport { listVaults, snapshot } from './snapshot.js'\nimport { records } from './records.js'\nimport { subscribe, subscribeConflicts, pendingWrites } from './events.js'\nimport { meterSnapshot } from './meter.js'\n\nexport function createInspector(noydb: InspectorNoydb, opts?: { meter?: InspectorMeter }): Inspector {\n return {\n listVaults: () => listVaults(noydb),\n snapshot: (vault: Vault) => snapshot(vault),\n records: (vault, collection, opts) => records(vault, collection, opts),\n subscribe: (handler) => subscribe(noydb, handler),\n subscribeConflicts: (handler) => subscribeConflicts(noydb, handler),\n pendingWrites: () => pendingWrites(noydb),\n meterSnapshot: () => meterSnapshot(opts?.meter),\n }\n}\n\nexport type {\n Inspector,\n VaultInfo,\n InspectorSnapshot,\n InspectorCollection,\n RecordPage,\n InspectorWriteEvent,\n InspectorWriteConflict,\n PendingWrites,\n InspectorMeter,\n} from './types.js'\n","import type { Vault } from '@noy-db/hub'\nimport type { InspectorSnapshot, InspectorCollection, VaultInfo, InspectorNoydb } from './types.js'\n\nexport async function listVaults(noydb: InspectorNoydb): Promise<ReadonlyArray<VaultInfo>> {\n return noydb.listAccessibleVaults()\n}\n\nexport async function snapshot(vault: Vault): Promise<InspectorSnapshot> {\n // withStats populates per-collection record/byte stats; opaque to the store.\n const dump = await vault.dumpSchema({ withStats: true })\n // Omit `stats` when absent rather than setting it to `undefined` —\n // the repo's tsconfig sets `exactOptionalPropertyTypes`, so an optional\n // `stats?` field must be omitted, not explicitly undefined.\n const collections: InspectorCollection[] = Object.entries(dump.collections).map(([name, desc]) => ({\n name,\n fields: desc.fields,\n indexes: desc.indexes,\n refs: desc.refs,\n ...(desc.stats !== undefined ? { stats: desc.stats } : {}),\n }))\n return { vault: dump.vault, collections }\n}\n","import type { Vault } from '@noy-db/hub'\nimport type { RecordPage } from './types.js'\n\nconst DEFAULT_LIMIT = 50\nconst MAX_LIMIT = 500\n\nfunction clampLimit(n: number | undefined): number {\n if (n === undefined || Number.isNaN(n)) return DEFAULT_LIMIT\n return Math.max(1, Math.min(MAX_LIMIT, Math.floor(n)))\n}\n\nfunction clampOffset(n: number | undefined): number {\n if (n === undefined || Number.isNaN(n) || n < 0) return 0\n return Math.floor(n)\n}\n\nexport async function records(\n vault: Vault,\n collection: string,\n opts: { limit?: number; offset?: number } = {},\n): Promise<RecordPage> {\n const limit = clampLimit(opts.limit)\n const offset = clampOffset(opts.offset)\n // Eager collections only — `list()` throws on lazy (prefetch:false). The\n // error propagates to the caller, which decides how to surface it.\n const all = await vault.collection(collection).list()\n return {\n rows: all.slice(offset, offset + limit),\n total: all.length,\n limit,\n offset,\n }\n}\n","import type { InspectorWriteEvent, InspectorWriteConflict, PendingWrites, InspectorNoydb } from './types.js'\n\nexport function subscribe(\n noydb: InspectorNoydb,\n handler: (event: InspectorWriteEvent) => void,\n): () => void {\n return noydb.onAfterWrite(handler)\n}\n\nexport function pendingWrites(noydb: InspectorNoydb): PendingWrites {\n const q = noydb.writeQueue\n return { pending: q.pending, depth: q.depth }\n}\n\nexport function subscribeConflicts(noydb: InspectorNoydb, handler: (c: InspectorWriteConflict) => void): () => void {\n return noydb.onWriteConflict(handler)\n}\n","import type { InspectorMeter } from './types.js'\nimport type { MeterSnapshot } from '@noy-db/to-meter'\n\nexport function meterSnapshot(meter: InspectorMeter | undefined): MeterSnapshot | null {\n return meter ? meter.snapshot() : null\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,eAAsB,WAAW,OAA0D;AACzF,SAAO,MAAM,qBAAqB;AACpC;AAEA,eAAsB,SAAS,OAA0C;AAEvE,QAAM,OAAO,MAAM,MAAM,WAAW,EAAE,WAAW,KAAK,CAAC;AAIvD,QAAM,cAAqC,OAAO,QAAQ,KAAK,WAAW,EAAE,IAAI,CAAC,CAAC,MAAM,IAAI,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A,IACL,YAAY,MAAM,WAAW,KAAK;AAAA,IAClC,UAAU,CAAC,UAAiB,SAAS,KAAK;AAAA,IAC1C,SAAS,CAAC,OAAO,YAAYA,UAAS,QAAQ,OAAO,YAAYA,KAAI;AAAA,IACrE,WAAW,CAAC,YAAY,UAAU,OAAO,OAAO;AAAA,IAChD,oBAAoB,CAAC,YAAY,mBAAmB,OAAO,OAAO;AAAA,IAClE,eAAe,MAAM,cAAc,KAAK;AAAA,IACxC,eAAe,MAAM,cAAc,MAAM,KAAK;AAAA,EAChD;AACF;","names":["opts"]}
package/dist/index.d.cts DELETED
@@ -1,64 +0,0 @@
1
- import { AccessibleVault, Vault, CollectionDescriptor, CollectionStats, WriteEvent, WriteConflict, Noydb } from '@noy-db/hub';
2
- import { MeterSnapshot } from '@noy-db/to-meter';
3
-
4
- /** Minimal structural view of a to-meter handle the inspector reads (no runtime dep). */
5
- interface InspectorMeter {
6
- snapshot(): MeterSnapshot;
7
- }
8
- /** Top-level accessible-vault entry (plain projection of the hub's AccessibleVault). */
9
- type VaultInfo = AccessibleVault;
10
- /**
11
- * One collection in a snapshot — a flattened projection of the hub's
12
- * CollectionDescriptor. Field/index/ref/stats shapes are derived directly from
13
- * the hub types so they never drift.
14
- */
15
- interface InspectorCollection {
16
- readonly name: string;
17
- readonly fields: CollectionDescriptor['fields'];
18
- readonly indexes: CollectionDescriptor['indexes'];
19
- readonly refs: CollectionDescriptor['refs'];
20
- readonly stats?: CollectionStats;
21
- }
22
- /** Structure + stats for one open vault. */
23
- interface InspectorSnapshot {
24
- readonly vault: string;
25
- readonly collections: ReadonlyArray<InspectorCollection>;
26
- }
27
- /** A page of decrypted records from one collection. */
28
- interface RecordPage {
29
- readonly rows: ReadonlyArray<unknown>;
30
- readonly total: number;
31
- readonly limit: number;
32
- readonly offset: number;
33
- }
34
- /** Live write event surfaced to subscribers (the hub's public WriteEvent, unchanged — already plain). */
35
- type InspectorWriteEvent = WriteEvent;
36
- /** Write-conflict surfaced to conflict subscribers (the hub's public WriteConflict, unchanged — already plain). */
37
- type InspectorWriteConflict = WriteConflict;
38
- /** Pending-write state. */
39
- interface PendingWrites {
40
- readonly pending: boolean;
41
- readonly depth: number;
42
- }
43
- /** The read-only inspector facade returned by createInspector(). */
44
- interface Inspector {
45
- listVaults(): Promise<ReadonlyArray<VaultInfo>>;
46
- snapshot(vault: Vault): Promise<InspectorSnapshot>;
47
- records(vault: Vault, collection: string, opts?: {
48
- limit?: number;
49
- offset?: number;
50
- }): Promise<RecordPage>;
51
- subscribe(handler: (event: InspectorWriteEvent) => void): () => void;
52
- subscribeConflicts(handler: (c: InspectorWriteConflict) => void): () => void;
53
- pendingWrites(): PendingWrites;
54
- /** Aggregate store-op latency snapshot, or null when the store is not metered. */
55
- meterSnapshot(): MeterSnapshot | null;
56
- }
57
- /** @internal — the hub handle the inspector reads from. */
58
- type InspectorNoydb = Noydb;
59
-
60
- declare function createInspector(noydb: InspectorNoydb, opts?: {
61
- meter?: InspectorMeter;
62
- }): Inspector;
63
-
64
- export { type Inspector, type InspectorCollection, type InspectorMeter, type InspectorSnapshot, type InspectorWriteConflict, type InspectorWriteEvent, type PendingWrites, type RecordPage, type VaultInfo, createInspector };