ES module and CLI to manage publicTypeIndex.json entries.
- Local dev (in this repo):
- Run scripts directly with Node, or add as a workspace package.
- When published to npm:
npm install -D typeindex(or install globally)
The CLI manages a JSON array in publicTypeIndex.json (default path is current working directory). You can override the file path with --file.
Basic usage:
# List entries
npx typeindex read --file ./typeindex/publicTypeIndex.json
# Add an entry
npx typeindex add \
--forClass Tracker \
--instance ../public/todo/new.json \
--registeredWith https://nostr.app/todo.html \
--file ./typeindex/publicTypeIndex.json
# Remove by index
npx typeindex remove --index 0 --file ./typeindex/publicTypeIndex.json
# Remove by matching fields
npx typeindex remove \
--forClass Tracker \
--instance ../public/todo/new.json \
--registeredWith https://nostr.app/todo.html \
--file ./typeindex/publicTypeIndex.jsonCommands:
read(aliases:list,ls): Prints the array as JSON. Optional--forClassfilter.add: Adds an item. Requires--forClass,--instance,--registeredWith. Optional--type(defaultTypeRegistration) and--allowDuplicate.remove(aliases:rm,delete,del): Remove by--indexor by matching fields.
Global options:
--file <path>: Path to thepublicTypeIndex.json. Defaults to./publicTypeIndex.json.
import{readTypeIndex,addTypeRegistration,removeTypeRegistration}from'typeindex';// Readconstitems=awaitreadTypeIndex({file: './typeindex/publicTypeIndex.json',filter: {forClass: 'Tracker'}});// AddawaitaddTypeRegistration({forClass: 'Tracker',instance: '../public/todo/new.json',registeredWith: 'https://nostr.app/todo.html'},{file: './typeindex/publicTypeIndex.json'});// RemoveawaitremoveTypeRegistration({forClass: 'Tracker',instance: '../public/todo/new.json'},{file: './typeindex/publicTypeIndex.json'});- The JSON file is expected to contain an array. If it doesn't exist, it will be created on first write.
- Duplicates are prevented by default (match on
type,forClass,instance,registeredWith). Use--allowDuplicateto override in CLI or{ allowDuplicate: true }in API.