@weasel-js/registry 1.15.1 → 1.16.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/dist/index.d.ts CHANGED
@@ -125,6 +125,13 @@ interface DeepEqualOptions {
125
125
  */
126
126
  declare function deepEqual(a: unknown, b: unknown, opts?: DeepEqualOptions): boolean;
127
127
 
128
+ /**
129
+ * Whether `a` and `b` hold equal elements in the same order: the same length,
130
+ * and `same` true at every index. `same` defaults to `===`. Order counts; for
131
+ * two lists holding the same members in any order, compare them as sets.
132
+ */
133
+ declare function sameList<T>(a: readonly T[], b: readonly T[], same?: (x: T, y: T) => boolean): boolean;
134
+
128
135
  /**
129
136
  * The kit-wide "these values disagree" sentinel. Used wherever a value is
130
137
  * aggregated across more than one source and the sources don't agree — e.g.
@@ -162,4 +169,4 @@ declare function matchQuery(query: string, entry: Findable): QueryMatch | null;
162
169
  * carrying one, where `matchQuery` is the test for a person's search. */
163
170
  declare function hasTag(tags: readonly string[] | undefined, tag: string): boolean;
164
171
 
165
- export { type DeepEqualOptions, type Emitter, type Findable, MIXED, type Mixed, type QueryMatch, type Reflectable, type ReflectedEntry, type Reflection, type RegisterOptions, type Registrant, createEmitter, createReflectable, deepEqual, hasTag, isDev, isPlainObject, isPlainPrototype, matchQuery };
172
+ export { type DeepEqualOptions, type Emitter, type Findable, MIXED, type Mixed, type QueryMatch, type Reflectable, type ReflectedEntry, type Reflection, type RegisterOptions, type Registrant, createEmitter, createReflectable, deepEqual, hasTag, isDev, isPlainObject, isPlainPrototype, matchQuery, sameList };
package/dist/index.js CHANGED
@@ -132,6 +132,14 @@ function deepEqual(a, b, opts = {}) {
132
132
  return keys.length === Object.keys(b).length && keys.every((k) => Object.hasOwn(b, k) && deepEqual(a[k], b[k], opts));
133
133
  }
134
134
 
135
+ // src/sameList.ts
136
+ function sameList(a, b, same = (x, y) => x === y) {
137
+ if (a === b) return true;
138
+ if (a.length !== b.length) return false;
139
+ for (let i = 0; i < a.length; i++) if (!same(a[i], b[i])) return false;
140
+ return true;
141
+ }
142
+
135
143
  // src/mixed.ts
136
144
  var MIXED = /* @__PURE__ */ Symbol("weasel:mixed");
137
145
 
@@ -148,6 +156,6 @@ function hasTag(tags, tag) {
148
156
  return tags?.includes(tag) ?? false;
149
157
  }
150
158
 
151
- export { MIXED, createEmitter, createReflectable, deepEqual, hasTag, isDev, isPlainObject, isPlainPrototype, matchQuery };
159
+ export { MIXED, createEmitter, createReflectable, deepEqual, hasTag, isDev, isPlainObject, isPlainPrototype, matchQuery, sameList };
152
160
  //# sourceMappingURL=index.js.map
153
161
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/emitter.ts","../src/reflectable.ts","../src/isDev.ts","../src/isPlainObject.ts","../src/deepEqual.ts","../src/mixed.ts","../src/match.ts"],"names":[],"mappings":";AAoBO,SAAS,aAAA,GAA8D;AAC5E,EAAA,MAAM,SAAA,uBAAgB,GAAA,EAA8B;AACpD,EAAA,OAAO;AAAA,IACL,UAAU,QAAA,EAAU;AAClB,MAAA,SAAA,CAAU,IAAI,QAAQ,CAAA;AACtB,MAAA,OAAO,MAAM;AAAE,QAAA,SAAA,CAAU,OAAO,QAAQ,CAAA;AAAA,MAAG,CAAA;AAAA,IAC7C,CAAA;AAAA,IACA,QAAQ,IAAA,EAAM;AACZ,MAAA,IAAI,SAAA,CAAU,SAAS,CAAA,EAAG;AAC1B,MAAA,KAAA,MAAW,QAAA,IAAY,CAAC,GAAG,SAAS,CAAA,EAAG;AACrC,QAAA,IAAI,CAAC,SAAA,CAAU,GAAA,CAAI,QAAQ,CAAA,EAAG;AAC9B,QAAA,IAAI;AACF,UAAA,QAAA,CAAS,GAAG,IAAI,CAAA;AAAA,QAClB,SAAS,GAAA,EAAK;AACZ,UAAA,OAAA,CAAQ,KAAA,CAAM,8BAA8B,GAAG,CAAA;AAAA,QACjD;AAAA,MACF;AAAA,IACF,CAAA;AAA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AG,IAAI,CAAC,CAAA;AAC3E;;;ACnBO,IAAM,KAAA,0BAA8B,cAAc;;;ACQzD,IAAM,OAAA,GAAsB,EAAE,EAAA,EAAI,MAAA,EAAO;AAKlC,SAAS,UAAA,CAAW,OAAe,KAAA,EAAoC;AAC5E,EAAA,MAAM,CAAA,GAAI,KAAA,CAAM,IAAA,EAAK,CAAE,WAAA,EAAY;AACnC,EAAA,IAAI,CAAA,KAAM,IAAI,OAAO,OAAA;AACrB,EAAA,IAAI,KAAA,CAAM,IAAA,CAAK,IAAA,CAAK,CAAC,MAAM,CAAA,KAAM,MAAA,IAAa,CAAA,CAAE,WAAA,EAAY,CAAE,QAAA,CAAS,CAAC,CAAC,GAAG,OAAO,OAAA;AACnF,EAAA,MAAM,GAAA,GAAM,KAAA,CAAM,IAAA,EAAM,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,WAAA,EAAY,CAAE,QAAA,CAAS,CAAC,CAAC,CAAA;AAC/D,EAAA,OAAO,QAAQ,MAAA,GAAY,IAAA,GAAO,EAAE,EAAA,EAAI,OAAO,GAAA,EAAI;AACrD;AAIO,SAAS,MAAA,CAAO,MAAqC,GAAA,EAAsB;AAChF,EAAA,OAAO,IAAA,EAAM,QAAA,CAAS,GAAG,CAAA,IAAK,KAAA;AAChC","file":"index.js","sourcesContent":["/** A set of listeners and the one way the kit notifies them. See {@link createEmitter}. */\nexport interface Emitter<TArgs extends unknown[] = []> {\n /** Add `listener`; a listener already held is held once. Returns the unsubscribe. */\n subscribe(listener: (...args: TArgs) => void): () => void;\n /** Call every listener held when the call began. */\n emit(...args: TArgs): void;\n /** How many listeners are held. */\n readonly size: number;\n}\n\n/**\n * A subscribe/notify pair with stated semantics, for a store to build on\n * instead of keeping its own listener set:\n *\n * - `emit` walks the listeners held when it began, in subscription order. One\n * that subscribes during a pass waits for the next; one unsubscribed before\n * its turn is not called.\n * - A listener that throws does not stop the others, and does not throw into\n * whatever caused the notify: the error goes to `console.error`.\n */\nexport function createEmitter<TArgs extends unknown[] = []>(): Emitter<TArgs> {\n const listeners = new Set<(...args: TArgs) => void>();\n return {\n subscribe(listener) {\n listeners.add(listener);\n return () => { listeners.delete(listener); };\n },\n emit(...args) {\n if (listeners.size === 0) return;\n for (const listener of [...listeners]) {\n if (!listeners.has(listener)) continue;\n try {\n listener(...args);\n } catch (err) {\n console.error('weasel: a subscriber threw', err);\n }\n }\n },\n get size() {\n return listeners.size;\n },\n };\n}\n","import { createEmitter } from './emitter';\n\n/** One registrant of a key: its value and, when the registrant named one, where it came from. */\nexport interface Registrant<V> {\n readonly value: V;\n readonly source: string | undefined;\n}\n\n/** One key as a reflection reports it. */\nexport interface ReflectedEntry<V, K = string> extends Registrant<V> {\n readonly key: K;\n /** The registrant whose `value` and `source` this entry carries. The same\n * object across snapshots, and the one `shadowed` lists once it is\n * displaced, so it identifies the registrant to {@link Reflectable.release}. */\n readonly live: Registrant<V>;\n /** The registrants this one displaced, oldest first. Non-empty means two\n * registrants claimed one key — a conflict, resolved newest-wins. */\n readonly shadowed: readonly Registrant<V>[];\n}\n\n/**\n * The read-only face of a registry: what is registered, what displaced what,\n * and a way to hear about changes. Every kit registry that embeds a\n * {@link Reflectable} hands this out, so a debug overlay or a conflict check\n * can walk any of them the same way.\n *\n * `subscribe` and `getVersion` are shaped for `useSyncExternalStore`; so is\n * `entries`, which returns the same frozen array until the next change.\n */\nexport interface Reflection<V, K = string> {\n get(key: K): V | undefined;\n has(key: K): boolean;\n /** Every key's live registrant, in the order each key was first registered. */\n entries(): readonly ReflectedEntry<V, K>[];\n /** Called after every change. Returns the unsubscribe. */\n subscribe(listener: () => void): () => void;\n /** Advances on every change. */\n getVersion(): number;\n}\n\n/** Options for {@link Reflectable.push} and {@link Reflectable.set}. */\nexport interface RegisterOptions {\n /** Who registered this — `'kit'`, a package, a plugin id. Reported, never interpreted. */\n source?: string;\n}\n\n/**\n * A keyed store that keeps its own {@link Reflection}. The registry owning it\n * writes through `push` / `set` / `delete` and hands out `reflection`.\n */\nexport interface Reflectable<V, K = string> extends Reflection<V, K> {\n /** Register `value` over whatever `key` holds and return its release.\n * Registrants stack, newest live: releasing the live one uncovers the one\n * it displaced, and releasing a displaced one removes only it. Double-release safe. */\n push(key: K, value: V, options?: RegisterOptions): () => void;\n /** Replace `key`'s live registrant in place, the way `Map.set` does — for\n * registries where a second registration means \"newer version\", not\n * \"override\". Records no conflict. */\n set(key: K, value: V, options?: RegisterOptions): void;\n /** Remove exactly `registrant` — one a reflection reported under `key`, live\n * or shadowed, written by `push` or by `set`. Removing the live one uncovers\n * the one beneath. Returns whether it was there; the release `push` returned\n * for it does nothing afterward, and the reverse. */\n release(key: K, registrant: Registrant<V>): boolean;\n /** Drop every registrant of `key`. Returns whether there was one. */\n delete(key: K): boolean;\n clear(): void;\n /** Announce a change the store cannot see — a registered value mutated in place. */\n bump(): void;\n /** This store as a {@link Reflection}, with no write methods on it. */\n readonly reflection: Reflection<V, K>;\n}\n\n/**\n * Create a keyed store with a uniform reflection surface.\n *\n * Deliberately only the cross-cutting part of a registry: validation, lookup\n * fallbacks and lifecycle stay with the registry that embeds it.\n */\nexport function createReflectable<V, K = string>(): Reflectable<V, K> {\n const stacks = new Map<K, Registrant<V>[]>();\n const listeners = createEmitter();\n let version = 0;\n let snapshot: { version: number; entries: readonly ReflectedEntry<V, K>[] } | null = null;\n\n function changed(): void {\n version++;\n listeners.emit();\n }\n\n const reflection: Reflection<V, K> = {\n get: (key) => stacks.get(key)?.at(-1)?.value,\n has: (key) => stacks.has(key),\n entries() {\n if (snapshot?.version === version) return snapshot.entries;\n const entries: ReflectedEntry<V, K>[] = [];\n for (const [key, stack] of stacks) {\n const live = stack.at(-1)!;\n entries.push(Object.freeze({\n key, live, value: live.value, source: live.source, shadowed: Object.freeze(stack.slice(0, -1)),\n }));\n }\n snapshot = { version, entries: Object.freeze(entries) };\n return snapshot.entries;\n },\n subscribe: listeners.subscribe,\n getVersion: () => version,\n };\n\n function release(key: K, registrant: Registrant<V>): boolean {\n const stack = stacks.get(key);\n const i = stack ? stack.lastIndexOf(registrant) : -1;\n if (i === -1) return false;\n stack!.splice(i, 1);\n if (stack!.length === 0) stacks.delete(key);\n changed();\n return true;\n }\n\n return {\n ...reflection,\n reflection,\n release,\n push(key, value, options) {\n const registrant: Registrant<V> = Object.freeze({ value, source: options?.source });\n const stack = stacks.get(key);\n if (stack) stack.push(registrant);\n else stacks.set(key, [registrant]);\n changed();\n return () => {\n release(key, registrant);\n };\n },\n set(key, value, options) {\n const registrant: Registrant<V> = Object.freeze({ value, source: options?.source });\n const stack = stacks.get(key);\n if (stack) stack[stack.length - 1] = registrant;\n else stacks.set(key, [registrant]);\n changed();\n },\n delete(key) {\n if (!stacks.delete(key)) return false;\n changed();\n return true;\n },\n clear() {\n if (stacks.size === 0) return;\n stacks.clear();\n changed();\n },\n bump: changed,\n };\n}\n","/**\n * Whether to emit development diagnostics. Dev is the default when nothing\n * says otherwise.\n *\n * The read is the bare member expression `process.env.NODE_ENV` because that is\n * the only form a bundler's define replaces; a production build then folds this\n * to `false`. A `typeof process` guard or an optional chain would survive the\n * define and read as dev in every browser. Where nothing defined it (published\n * ESM loaded from a CDN, say) `process` is absent, the read throws, and the\n * answer is dev.\n */\nexport function isDev(): boolean {\n try {\n return process.env.NODE_ENV !== 'production';\n } catch {\n return true;\n }\n}\n","/** Whether `proto` is the prototype a plain object has: `null`, or some\n * realm's `Object.prototype`. Comparing against this realm's alone misses\n * objects made in an iframe, a VM context, or by `structuredClone` under jsdom. */\nexport function isPlainPrototype(proto: object | null): boolean {\n return proto === Object.prototype || proto === null || Object.getPrototypeOf(proto) === null;\n}\n\n/** Whether `value` is a plain object — a literal or `Object.create(null)` — from any realm. */\nexport function isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && isPlainPrototype(Object.getPrototypeOf(value));\n}\n","import { isPlainObject } from './isPlainObject';\n\n/** Options for {@link deepEqual}. */\nexport interface DeepEqualOptions {\n /** Read a key holding `undefined` the same as one that is absent. Default `false`. */\n undefinedAsAbsent?: boolean;\n}\n\n/**\n * Structural equality over arrays and plain objects from any realm. Every other\n * value — a function, a class instance, a `Date`, a `Map` — equals only itself\n * (`Object.is`).\n */\nexport function deepEqual(a: unknown, b: unknown, opts: DeepEqualOptions = {}): boolean {\n if (Object.is(a, b)) return true;\n if (Array.isArray(a) || Array.isArray(b)) {\n return Array.isArray(a) && Array.isArray(b) && a.length === b.length\n && a.every((v, i) => deepEqual(v, b[i], opts));\n }\n if (!isPlainObject(a) || !isPlainObject(b)) return false;\n if (opts.undefinedAsAbsent) {\n return [...new Set([...Object.keys(a), ...Object.keys(b)])].every((k) => deepEqual(a[k], b[k], opts));\n }\n const keys = Object.keys(a);\n return keys.length === Object.keys(b).length\n && keys.every((k) => Object.hasOwn(b, k) && deepEqual(a[k], b[k], opts));\n}\n","/**\n * The kit-wide \"these values disagree\" sentinel. Used wherever a value is\n * aggregated across more than one source and the sources don't agree — e.g.\n * a UI panel aggregating a property across a multi-node selection, or text\n * styling aggregated across the runs in a character range. One symbol, one\n * `isMixed` check, regardless of what's being aggregated.\n */\nexport const MIXED: unique symbol = Symbol('weasel:mixed');\n/** The type of {@link MIXED}. Property panels use it to say \"the selection\n * does not agree on this value\" without colliding with any real value. */\nexport type Mixed = typeof MIXED;\n","/**\n * The one text search every registry's finder shares, so a query reaches a\n * command palette's actions and a settings form's prefs the same way.\n */\n\n/** What a search can find an entry by: the words it reads as, and its tags. */\nexport interface Findable {\n /** Label, description, path: whatever the entry is called. Absent fields are skipped. */\n readonly text: readonly (string | undefined)[];\n readonly tags?: readonly string[];\n}\n\n/** Why an entry answered a query: its text, or one of its tags. */\nexport type QueryMatch = { readonly by: 'text' } | { readonly by: 'tag'; readonly tag: string };\n\nconst BY_TEXT: QueryMatch = { by: 'text' };\n\n/** Whether `entry` answers `query`, and by what. Each field matches when it\n * contains the query, ignoring case; text is tried before tags. An empty or\n * whitespace query matches everything, by text. */\nexport function matchQuery(query: string, entry: Findable): QueryMatch | null {\n const q = query.trim().toLowerCase();\n if (q === '') return BY_TEXT;\n if (entry.text.some((t) => t !== undefined && t.toLowerCase().includes(q))) return BY_TEXT;\n const tag = entry.tags?.find((t) => t.toLowerCase().includes(q));\n return tag === undefined ? null : { by: 'tag', tag };\n}\n\n/** Whether `tags` holds `tag` exactly: the test for gathering every entry\n * carrying one, where `matchQuery` is the test for a person's search. */\nexport function hasTag(tags: readonly string[] | undefined, tag: string): boolean {\n return tags?.includes(tag) ?? false;\n}\n"]}
1
+ {"version":3,"sources":["../src/emitter.ts","../src/reflectable.ts","../src/isDev.ts","../src/isPlainObject.ts","../src/deepEqual.ts","../src/sameList.ts","../src/mixed.ts","../src/match.ts"],"names":[],"mappings":";AAoBO,SAAS,aAAA,GAA8D;AAC5E,EAAA,MAAM,SAAA,uBAAgB,GAAA,EAA8B;AACpD,EAAA,OAAO;AAAA,IACL,UAAU,QAAA,EAAU;AAClB,MAAA,SAAA,CAAU,IAAI,QAAQ,CAAA;AACtB,MAAA,OAAO,MAAM;AAAE,QAAA,SAAA,CAAU,OAAO,QAAQ,CAAA;AAAA,MAAG,CAAA;AAAA,IAC7C,CAAA;AAAA,IACA,QAAQ,IAAA,EAAM;AACZ,MAAA,IAAI,SAAA,CAAU,SAAS,CAAA,EAAG;AAC1B,MAAA,KAAA,MAAW,QAAA,IAAY,CAAC,GAAG,SAAS,CAAA,EAAG;AACrC,QAAA,IAAI,CAAC,SAAA,CAAU,GAAA,CAAI,QAAQ,CAAA,EAAG;AAC9B,QAAA,IAAI;AACF,UAAA,QAAA,CAAS,GAAG,IAAI,CAAA;AAAA,QAClB,SAAS,GAAA,EAAK;AACZ,UAAA,OAAA,CAAQ,KAAA,CAAM,8BAA8B,GAAG,CAAA;AAAA,QACjD;AAAA,MACF;AAAA,IACF,CAAA;AAAA,IACA,IAAI,IAAA,GAAO;AACT,MAAA,OAAO,SAAA,CAAU,IAAA;AAAA,IACnB;AAAA,GACF;AACF;;;ACqCO,SAAS,iBA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,KAAM,MAAM,CAAA,EACvC;AACT,EAAA,IAAI,CAAA,KAAM,GAAG,OAAO,IAAA;AACpB,EAAA,IAAI,CAAA,CAAE,MAAA,KAAW,CAAA,CAAE,MAAA,EAAQ,OAAO,KAAA;AAClC,EAAA,KAAA,IAAS,IAAI,CAAA,EAAG,CAAA,GAAI,CAAA,CAAE,MAAA,EAAQ,KAAK,IAAI,CAAC,IAAA,CAAK,CAAA,CAAE,CAAC,CAAA,EAAI,CAAA,CAAE,CAAC,CAAE,GAAG,OAAO,KAAA;AACnE,EAAA,OAAO,IAAA;AACT;;;ACPO,IAAM,KAAA,0BAA8B,cAAc;;;ACQzD,IAAM,OAAA,GAAsB,EAAE,EAAA,EAAI,MAAA,EAAO;AAKlC,SAAS,UAAA,CAAW,OAAe,KAAA,EAAoC;AAC5E,EAAA,MAAM,CAAA,GAAI,KAAA,CAAM,IAAA,EAAK,CAAE,WAAA,EAAY;AACnC,EAAA,IAAI,CAAA,KAAM,IAAI,OAAO,OAAA;AACrB,EAAA,IAAI,KAAA,CAAM,IAAA,CAAK,IAAA,CAAK,CAAC,MAAM,CAAA,KAAM,MAAA,IAAa,CAAA,CAAE,WAAA,EAAY,CAAE,QAAA,CAAS,CAAC,CAAC,GAAG,OAAO,OAAA;AACnF,EAAA,MAAM,GAAA,GAAM,KAAA,CAAM,IAAA,EAAM,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,WAAA,EAAY,CAAE,QAAA,CAAS,CAAC,CAAC,CAAA;AAC/D,EAAA,OAAO,QAAQ,MAAA,GAAY,IAAA,GAAO,EAAE,EAAA,EAAI,OAAO,GAAA,EAAI;AACrD;AAIO,SAAS,MAAA,CAAO,MAAqC,GAAA,EAAsB;AAChF,EAAA,OAAO,IAAA,EAAM,QAAA,CAAS,GAAG,CAAA,IAAK,KAAA;AAChC","file":"index.js","sourcesContent":["/** A set of listeners and the one way the kit notifies them. See {@link createEmitter}. */\nexport interface Emitter<TArgs extends unknown[] = []> {\n /** Add `listener`; a listener already held is held once. Returns the unsubscribe. */\n subscribe(listener: (...args: TArgs) => void): () => void;\n /** Call every listener held when the call began. */\n emit(...args: TArgs): void;\n /** How many listeners are held. */\n readonly size: number;\n}\n\n/**\n * A subscribe/notify pair with stated semantics, for a store to build on\n * instead of keeping its own listener set:\n *\n * - `emit` walks the listeners held when it began, in subscription order. One\n * that subscribes during a pass waits for the next; one unsubscribed before\n * its turn is not called.\n * - A listener that throws does not stop the others, and does not throw into\n * whatever caused the notify: the error goes to `console.error`.\n */\nexport function createEmitter<TArgs extends unknown[] = []>(): Emitter<TArgs> {\n const listeners = new Set<(...args: TArgs) => void>();\n return {\n subscribe(listener) {\n listeners.add(listener);\n return () => { listeners.delete(listener); };\n },\n emit(...args) {\n if (listeners.size === 0) return;\n for (const listener of [...listeners]) {\n if (!listeners.has(listener)) continue;\n try {\n listener(...args);\n } catch (err) {\n console.error('weasel: a subscriber threw', err);\n }\n }\n },\n get size() {\n return listeners.size;\n },\n };\n}\n","import { createEmitter } from './emitter';\n\n/** One registrant of a key: its value and, when the registrant named one, where it came from. */\nexport interface Registrant<V> {\n readonly value: V;\n readonly source: string | undefined;\n}\n\n/** One key as a reflection reports it. */\nexport interface ReflectedEntry<V, K = string> extends Registrant<V> {\n readonly key: K;\n /** The registrant whose `value` and `source` this entry carries. The same\n * object across snapshots, and the one `shadowed` lists once it is\n * displaced, so it identifies the registrant to {@link Reflectable.release}. */\n readonly live: Registrant<V>;\n /** The registrants this one displaced, oldest first. Non-empty means two\n * registrants claimed one key — a conflict, resolved newest-wins. */\n readonly shadowed: readonly Registrant<V>[];\n}\n\n/**\n * The read-only face of a registry: what is registered, what displaced what,\n * and a way to hear about changes. Every kit registry that embeds a\n * {@link Reflectable} hands this out, so a debug overlay or a conflict check\n * can walk any of them the same way.\n *\n * `subscribe` and `getVersion` are shaped for `useSyncExternalStore`; so is\n * `entries`, which returns the same frozen array until the next change.\n */\nexport interface Reflection<V, K = string> {\n get(key: K): V | undefined;\n has(key: K): boolean;\n /** Every key's live registrant, in the order each key was first registered. */\n entries(): readonly ReflectedEntry<V, K>[];\n /** Called after every change. Returns the unsubscribe. */\n subscribe(listener: () => void): () => void;\n /** Advances on every change. */\n getVersion(): number;\n}\n\n/** Options for {@link Reflectable.push} and {@link Reflectable.set}. */\nexport interface RegisterOptions {\n /** Who registered this — `'kit'`, a package, a plugin id. Reported, never interpreted. */\n source?: string;\n}\n\n/**\n * A keyed store that keeps its own {@link Reflection}. The registry owning it\n * writes through `push` / `set` / `delete` and hands out `reflection`.\n */\nexport interface Reflectable<V, K = string> extends Reflection<V, K> {\n /** Register `value` over whatever `key` holds and return its release.\n * Registrants stack, newest live: releasing the live one uncovers the one\n * it displaced, and releasing a displaced one removes only it. Double-release safe. */\n push(key: K, value: V, options?: RegisterOptions): () => void;\n /** Replace `key`'s live registrant in place, the way `Map.set` does — for\n * registries where a second registration means \"newer version\", not\n * \"override\". Records no conflict. */\n set(key: K, value: V, options?: RegisterOptions): void;\n /** Remove exactly `registrant` — one a reflection reported under `key`, live\n * or shadowed, written by `push` or by `set`. Removing the live one uncovers\n * the one beneath. Returns whether it was there; the release `push` returned\n * for it does nothing afterward, and the reverse. */\n release(key: K, registrant: Registrant<V>): boolean;\n /** Drop every registrant of `key`. Returns whether there was one. */\n delete(key: K): boolean;\n clear(): void;\n /** Announce a change the store cannot see — a registered value mutated in place. */\n bump(): void;\n /** This store as a {@link Reflection}, with no write methods on it. */\n readonly reflection: Reflection<V, K>;\n}\n\n/**\n * Create a keyed store with a uniform reflection surface.\n *\n * Deliberately only the cross-cutting part of a registry: validation, lookup\n * fallbacks and lifecycle stay with the registry that embeds it.\n */\nexport function createReflectable<V, K = string>(): Reflectable<V, K> {\n const stacks = new Map<K, Registrant<V>[]>();\n const listeners = createEmitter();\n let version = 0;\n let snapshot: { version: number; entries: readonly ReflectedEntry<V, K>[] } | null = null;\n\n function changed(): void {\n version++;\n listeners.emit();\n }\n\n const reflection: Reflection<V, K> = {\n get: (key) => stacks.get(key)?.at(-1)?.value,\n has: (key) => stacks.has(key),\n entries() {\n if (snapshot?.version === version) return snapshot.entries;\n const entries: ReflectedEntry<V, K>[] = [];\n for (const [key, stack] of stacks) {\n const live = stack.at(-1)!;\n entries.push(Object.freeze({\n key, live, value: live.value, source: live.source, shadowed: Object.freeze(stack.slice(0, -1)),\n }));\n }\n snapshot = { version, entries: Object.freeze(entries) };\n return snapshot.entries;\n },\n subscribe: listeners.subscribe,\n getVersion: () => version,\n };\n\n function release(key: K, registrant: Registrant<V>): boolean {\n const stack = stacks.get(key);\n const i = stack ? stack.lastIndexOf(registrant) : -1;\n if (i === -1) return false;\n stack!.splice(i, 1);\n if (stack!.length === 0) stacks.delete(key);\n changed();\n return true;\n }\n\n return {\n ...reflection,\n reflection,\n release,\n push(key, value, options) {\n const registrant: Registrant<V> = Object.freeze({ value, source: options?.source });\n const stack = stacks.get(key);\n if (stack) stack.push(registrant);\n else stacks.set(key, [registrant]);\n changed();\n return () => {\n release(key, registrant);\n };\n },\n set(key, value, options) {\n const registrant: Registrant<V> = Object.freeze({ value, source: options?.source });\n const stack = stacks.get(key);\n if (stack) stack[stack.length - 1] = registrant;\n else stacks.set(key, [registrant]);\n changed();\n },\n delete(key) {\n if (!stacks.delete(key)) return false;\n changed();\n return true;\n },\n clear() {\n if (stacks.size === 0) return;\n stacks.clear();\n changed();\n },\n bump: changed,\n };\n}\n","/**\n * Whether to emit development diagnostics. Dev is the default when nothing\n * says otherwise.\n *\n * The read is the bare member expression `process.env.NODE_ENV` because that is\n * the only form a bundler's define replaces; a production build then folds this\n * to `false`. A `typeof process` guard or an optional chain would survive the\n * define and read as dev in every browser. Where nothing defined it (published\n * ESM loaded from a CDN, say) `process` is absent, the read throws, and the\n * answer is dev.\n */\nexport function isDev(): boolean {\n try {\n return process.env.NODE_ENV !== 'production';\n } catch {\n return true;\n }\n}\n","/** Whether `proto` is the prototype a plain object has: `null`, or some\n * realm's `Object.prototype`. Comparing against this realm's alone misses\n * objects made in an iframe, a VM context, or by `structuredClone` under jsdom. */\nexport function isPlainPrototype(proto: object | null): boolean {\n return proto === Object.prototype || proto === null || Object.getPrototypeOf(proto) === null;\n}\n\n/** Whether `value` is a plain object — a literal or `Object.create(null)` — from any realm. */\nexport function isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && isPlainPrototype(Object.getPrototypeOf(value));\n}\n","import { isPlainObject } from './isPlainObject';\n\n/** Options for {@link deepEqual}. */\nexport interface DeepEqualOptions {\n /** Read a key holding `undefined` the same as one that is absent. Default `false`. */\n undefinedAsAbsent?: boolean;\n}\n\n/**\n * Structural equality over arrays and plain objects from any realm. Every other\n * value — a function, a class instance, a `Date`, a `Map` — equals only itself\n * (`Object.is`).\n */\nexport function deepEqual(a: unknown, b: unknown, opts: DeepEqualOptions = {}): boolean {\n if (Object.is(a, b)) return true;\n if (Array.isArray(a) || Array.isArray(b)) {\n return Array.isArray(a) && Array.isArray(b) && a.length === b.length\n && a.every((v, i) => deepEqual(v, b[i], opts));\n }\n if (!isPlainObject(a) || !isPlainObject(b)) return false;\n if (opts.undefinedAsAbsent) {\n return [...new Set([...Object.keys(a), ...Object.keys(b)])].every((k) => deepEqual(a[k], b[k], opts));\n }\n const keys = Object.keys(a);\n return keys.length === Object.keys(b).length\n && keys.every((k) => Object.hasOwn(b, k) && deepEqual(a[k], b[k], opts));\n}\n","/**\n * Whether `a` and `b` hold equal elements in the same order: the same length,\n * and `same` true at every index. `same` defaults to `===`. Order counts; for\n * two lists holding the same members in any order, compare them as sets.\n */\nexport function sameList<T>(\n a: readonly T[],\n b: readonly T[],\n same: (x: T, y: T) => boolean = (x, y) => x === y,\n): boolean {\n if (a === b) return true;\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) if (!same(a[i]!, b[i]!)) return false;\n return true;\n}\n","/**\n * The kit-wide \"these values disagree\" sentinel. Used wherever a value is\n * aggregated across more than one source and the sources don't agree — e.g.\n * a UI panel aggregating a property across a multi-node selection, or text\n * styling aggregated across the runs in a character range. One symbol, one\n * `isMixed` check, regardless of what's being aggregated.\n */\nexport const MIXED: unique symbol = Symbol('weasel:mixed');\n/** The type of {@link MIXED}. Property panels use it to say \"the selection\n * does not agree on this value\" without colliding with any real value. */\nexport type Mixed = typeof MIXED;\n","/**\n * The one text search every registry's finder shares, so a query reaches a\n * command palette's actions and a settings form's prefs the same way.\n */\n\n/** What a search can find an entry by: the words it reads as, and its tags. */\nexport interface Findable {\n /** Label, description, path: whatever the entry is called. Absent fields are skipped. */\n readonly text: readonly (string | undefined)[];\n readonly tags?: readonly string[];\n}\n\n/** Why an entry answered a query: its text, or one of its tags. */\nexport type QueryMatch = { readonly by: 'text' } | { readonly by: 'tag'; readonly tag: string };\n\nconst BY_TEXT: QueryMatch = { by: 'text' };\n\n/** Whether `entry` answers `query`, and by what. Each field matches when it\n * contains the query, ignoring case; text is tried before tags. An empty or\n * whitespace query matches everything, by text. */\nexport function matchQuery(query: string, entry: Findable): QueryMatch | null {\n const q = query.trim().toLowerCase();\n if (q === '') return BY_TEXT;\n if (entry.text.some((t) => t !== undefined && t.toLowerCase().includes(q))) return BY_TEXT;\n const tag = entry.tags?.find((t) => t.toLowerCase().includes(q));\n return tag === undefined ? null : { by: 'tag', tag };\n}\n\n/** Whether `tags` holds `tag` exactly: the test for gathering every entry\n * carrying one, where `matchQuery` is the test for a person's search. */\nexport function hasTag(tags: readonly string[] | undefined, tag: string): boolean {\n return tags?.includes(tag) ?? false;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weasel-js/registry",
3
- "version": "1.15.1",
3
+ "version": "1.16.0",
4
4
  "description": "Keyed registries with a uniform reflection surface: enumerate the entries, see which ones displaced others, release any one of them, and subscribe to changes. Also the small shared pieces registries are built from: an emitter, a plain-object test, and the MIXED sentinel. No React, no DOM.",
5
5
  "license": "MIT",
6
6
  "type": "module",