Initial electronics inventory webapp
KV-store backed Express 5 app for tracking electronic components, their arbitrary fields, and inventory locations (physical, BOM, digital). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
node_modules/
|
||||
data/
|
||||
3
lib/ids.mjs
Normal file
3
lib/ids.mjs
Normal file
@@ -0,0 +1,3 @@
|
||||
export function generate_id() {
|
||||
return Date.now().toString(36) + Math.random().toString(36).slice(2, 8);
|
||||
}
|
||||
201
lib/kv-store.mjs
Normal file
201
lib/kv-store.mjs
Normal file
@@ -0,0 +1,201 @@
|
||||
import fs from 'node:fs';
|
||||
|
||||
function DEFAULT_SERIALIZER_FACTORY() {
|
||||
const s = new Serializer();
|
||||
|
||||
//TODO - buffers and possibly typed arrays
|
||||
s.register_constructor(BigInt, 'Bi', (raw) => raw.toString(), (stored) => BigInt(stored));
|
||||
s.register_constructor(Buffer, 'Bu', (raw) => raw.toString('base64'), (stored) => Buffer.from(stored, 'base64'));
|
||||
s.register_default('P', (raw) => (JSON.stringify(raw), raw), (stored) => stored);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
class Serializer {
|
||||
constructor(constructor_lut=new Map(), identity_lut=new Map(), type_lut=new Map()) {
|
||||
Object.assign(this, { constructor_lut, identity_lut, type_lut, default: null });
|
||||
}
|
||||
|
||||
serialize(value) {
|
||||
const { constructor_lut, identity_lut } = this;
|
||||
|
||||
const by_identity = identity_lut.get(value);
|
||||
if (by_identity) {
|
||||
const { type_id, serialize_value } = by_identity;
|
||||
return [ type_id, serialize_value(value) ];
|
||||
}
|
||||
|
||||
const by_constructor = constructor_lut.get(value.constructor);
|
||||
if (by_constructor) {
|
||||
const { type_id, serialize_value } = by_constructor;
|
||||
return [ type_id, serialize_value(value) ];
|
||||
}
|
||||
|
||||
return [this.default.type_id, this.default.serialize_value(value)];
|
||||
}
|
||||
|
||||
deserialize(value) {
|
||||
if (value === undefined) {
|
||||
throw new Error(`Deserialize called without value`);
|
||||
}
|
||||
const [ type_id, raw_value ] = value;
|
||||
const { type_lut } = this;
|
||||
|
||||
const operation = type_lut.get(type_id);
|
||||
if (!operation) {
|
||||
throw new Error(`Unknown type_id: ${type_id}`);
|
||||
}
|
||||
const { deserialize_value } = operation;
|
||||
return deserialize_value(raw_value);
|
||||
}
|
||||
|
||||
register_default(type_id, serialize_value, deserialize_value) {
|
||||
const { type_lut } = this;
|
||||
const operation = { selector: 'default', type_id, serialize_value, deserialize_value };
|
||||
type_lut.set(type_id, operation);
|
||||
this.default = operation;
|
||||
}
|
||||
|
||||
register_constructor(constructor, type_id, serialize_value, deserialize_value) {
|
||||
const { constructor_lut, type_lut } = this;
|
||||
const operation = { selector: 'constructor', constructor, type_id, serialize_value, deserialize_value };
|
||||
constructor_lut.set(constructor, operation);
|
||||
type_lut.set(type_id, operation);
|
||||
}
|
||||
|
||||
register_identity(identity, type_id, serialize_value, deserialize_value) {
|
||||
const { identity_lut, type_lut } = this;
|
||||
const operation = { selector: 'identity', identity, type_id, serialize_value, deserialize_value };
|
||||
identity_lut.set(identity, operation);
|
||||
type_lut.set(type_id, operation);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
const DEFAULT_SETTINGS = {
|
||||
auto_load: false,
|
||||
auto_store: false,
|
||||
auto_store_events: [
|
||||
'SIGINT',
|
||||
'SIGTERM',
|
||||
'exit',
|
||||
],
|
||||
debounce_flush_timeout: null,
|
||||
}
|
||||
|
||||
|
||||
export class Simple_KeyValue_Store {
|
||||
#flush_debounce_timer = null
|
||||
|
||||
constructor(storage_path, settings=DEFAULT_SETTINGS, data=new Map(), serializer=DEFAULT_SERIALIZER_FACTORY()) {
|
||||
|
||||
const actual_settings = { ...DEFAULT_SETTINGS, ...settings };
|
||||
Object.assign(this, { storage_path, data, serializer, ...actual_settings });
|
||||
|
||||
if (this.auto_load) {
|
||||
this.load();
|
||||
}
|
||||
|
||||
if (this.auto_store) {
|
||||
for (const event of this.auto_store_events) {
|
||||
process.on(event, () => (this.store(), process.exit()) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
trigger_flush_debouncer() {
|
||||
if (this.#flush_debounce_timer) {
|
||||
clearTimeout(this.#flush_debounce_timer);
|
||||
this.#flush_debounce_timer = null;
|
||||
}
|
||||
|
||||
const { debounce_flush_timeout } = this;
|
||||
if (debounce_flush_timeout) {
|
||||
this.#flush_debounce_timer = setTimeout(() => {
|
||||
this.#flush_debounce_timer = null;
|
||||
this.store();
|
||||
}, debounce_flush_timeout);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
create_pending_filename() {
|
||||
const suffix = process.hrtime.bigint().toString(16);
|
||||
const { storage_path } = this;
|
||||
return `${storage_path}-${suffix}.tmp`;
|
||||
}
|
||||
|
||||
get(key) {
|
||||
const { serializer } = this;
|
||||
const raw_entry = this.data.get(key);
|
||||
if (raw_entry !== undefined) {
|
||||
return serializer.deserialize(raw_entry);
|
||||
}
|
||||
}
|
||||
|
||||
set(key, value) {
|
||||
const { serializer } = this;
|
||||
this.data.set(key, serializer.serialize(value));
|
||||
this.trigger_flush_debouncer();
|
||||
}
|
||||
|
||||
delete(key) {
|
||||
const result = this.data.delete(key);
|
||||
if (result) {
|
||||
this.trigger_flush_debouncer();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
load() {
|
||||
const { data, storage_path } = this;
|
||||
if (!fs.existsSync(storage_path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const file_contents = fs.readFileSync(storage_path, 'utf-8');
|
||||
|
||||
for (const line of file_contents.split('\n')) {
|
||||
if (!line) continue;
|
||||
const [key, value] = JSON.parse(line);
|
||||
data.set(key, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
store() {
|
||||
if (this.#flush_debounce_timer) {
|
||||
clearTimeout(this.#flush_debounce_timer);
|
||||
this.#flush_debounce_timer = null;
|
||||
}
|
||||
const { data, storage_path } = this;
|
||||
const pending_out_path = this.create_pending_filename();
|
||||
const out_fd = fs.openSync(pending_out_path, 'w');
|
||||
try {
|
||||
for (const [key, value] of data.entries()) {
|
||||
fs.writeSync(out_fd, JSON.stringify([key, value]) + '\n');
|
||||
}
|
||||
fs.closeSync(out_fd);
|
||||
fs.renameSync(pending_out_path, storage_path);
|
||||
} finally {
|
||||
try { fs.closeSync(out_fd); } catch {}
|
||||
try { fs.unlinkSync(pending_out_path); } catch {}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
const kvs = new Simple_KeyValue_Store('./data.ndjson', { auto_load: true, auto_store: true, debounce_flush_timeout: 10_000 });
|
||||
|
||||
console.log(kvs.get('hello'), kvs.get('shello'), kvs.get('Path'));
|
||||
kvs.set('hello', 123456789n)
|
||||
|
||||
console.log(Buffer.from([123, 10, 20]));
|
||||
kvs.set('Path', Buffer.from([123, 10, 20]));
|
||||
|
||||
process.exit() //Exit immediately instead of waiting for debounce_timer (this also prevents double store - we should document this properly)
|
||||
*/
|
||||
82
lib/storage.mjs
Normal file
82
lib/storage.mjs
Normal file
@@ -0,0 +1,82 @@
|
||||
import { mkdirSync } from 'node:fs';
|
||||
import { Simple_KeyValue_Store } from './kv-store.mjs';
|
||||
|
||||
mkdirSync('./data', { recursive: true });
|
||||
|
||||
const store = new Simple_KeyValue_Store('./data/inventory.ndjson', {
|
||||
auto_load: true,
|
||||
auto_store: true,
|
||||
debounce_flush_timeout: 5000,
|
||||
});
|
||||
|
||||
// --- Field definitions ---
|
||||
|
||||
export function list_fields() {
|
||||
const result = [];
|
||||
for (const [key] of store.data.entries()) {
|
||||
if (key.startsWith('f:')) {
|
||||
result.push(store.get(key));
|
||||
}
|
||||
}
|
||||
return result.sort((a, b) => a.name.localeCompare(b.name));
|
||||
}
|
||||
|
||||
export function get_field(id) {
|
||||
return store.get(`f:${id}`) ?? null;
|
||||
}
|
||||
|
||||
export function set_field(field) {
|
||||
store.set(`f:${field.id}`, field);
|
||||
}
|
||||
|
||||
export function delete_field(id) {
|
||||
return store.delete(`f:${id}`);
|
||||
}
|
||||
|
||||
// --- Components ---
|
||||
|
||||
export function list_components() {
|
||||
const result = [];
|
||||
for (const [key] of store.data.entries()) {
|
||||
if (key.startsWith('c:')) {
|
||||
result.push(store.get(key));
|
||||
}
|
||||
}
|
||||
return result.sort((a, b) => a.name.localeCompare(b.name));
|
||||
}
|
||||
|
||||
export function get_component(id) {
|
||||
return store.get(`c:${id}`) ?? null;
|
||||
}
|
||||
|
||||
export function set_component(component) {
|
||||
store.set(`c:${component.id}`, component);
|
||||
}
|
||||
|
||||
export function delete_component(id) {
|
||||
return store.delete(`c:${id}`);
|
||||
}
|
||||
|
||||
// --- Inventory entries ---
|
||||
|
||||
export function list_inventory() {
|
||||
const result = [];
|
||||
for (const [key] of store.data.entries()) {
|
||||
if (key.startsWith('i:')) {
|
||||
result.push(store.get(key));
|
||||
}
|
||||
}
|
||||
return result.sort((a, b) => a.created_at - b.created_at);
|
||||
}
|
||||
|
||||
export function get_inventory_entry(id) {
|
||||
return store.get(`i:${id}`) ?? null;
|
||||
}
|
||||
|
||||
export function set_inventory_entry(entry) {
|
||||
store.set(`i:${entry.id}`, entry);
|
||||
}
|
||||
|
||||
export function delete_inventory_entry(id) {
|
||||
return store.delete(`i:${id}`);
|
||||
}
|
||||
829
package-lock.json
generated
Normal file
829
package-lock.json
generated
Normal file
@@ -0,0 +1,829 @@
|
||||
{
|
||||
"name": "electronics-inventory",
|
||||
"version": "0.1.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "electronics-inventory",
|
||||
"version": "0.1.0",
|
||||
"dependencies": {
|
||||
"express": "^5.2.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=25"
|
||||
}
|
||||
},
|
||||
"node_modules/accepts": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz",
|
||||
"integrity": "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"mime-types": "^3.0.0",
|
||||
"negotiator": "^1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/body-parser": {
|
||||
"version": "2.2.2",
|
||||
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.2.2.tgz",
|
||||
"integrity": "sha512-oP5VkATKlNwcgvxi0vM0p/D3n2C3EReYVX+DNYs5TjZFn/oQt2j+4sVJtSMr18pdRr8wjTcBl6LoV+FUwzPmNA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"bytes": "^3.1.2",
|
||||
"content-type": "^1.0.5",
|
||||
"debug": "^4.4.3",
|
||||
"http-errors": "^2.0.0",
|
||||
"iconv-lite": "^0.7.0",
|
||||
"on-finished": "^2.4.1",
|
||||
"qs": "^6.14.1",
|
||||
"raw-body": "^3.0.1",
|
||||
"type-is": "^2.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/express"
|
||||
}
|
||||
},
|
||||
"node_modules/bytes": {
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz",
|
||||
"integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/call-bind-apply-helpers": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
|
||||
"integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"es-errors": "^1.3.0",
|
||||
"function-bind": "^1.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/call-bound": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz",
|
||||
"integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"call-bind-apply-helpers": "^1.0.2",
|
||||
"get-intrinsic": "^1.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/content-disposition": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-1.0.1.tgz",
|
||||
"integrity": "sha512-oIXISMynqSqm241k6kcQ5UwttDILMK4BiurCfGEREw6+X9jkkpEe5T9FZaApyLGGOnFuyMWZpdolTXMtvEJ08Q==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/express"
|
||||
}
|
||||
},
|
||||
"node_modules/content-type": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz",
|
||||
"integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/cookie": {
|
||||
"version": "0.7.2",
|
||||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz",
|
||||
"integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/cookie-signature": {
|
||||
"version": "1.2.2",
|
||||
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.2.2.tgz",
|
||||
"integrity": "sha512-D76uU73ulSXrD1UXF4KE2TMxVVwhsnCgfAyTg9k8P6KGZjlXKrOLe4dJQKI3Bxi5wjesZoFXJWElNWBjPZMbhg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=6.6.0"
|
||||
}
|
||||
},
|
||||
"node_modules/debug": {
|
||||
"version": "4.4.3",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
|
||||
"integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ms": "^2.1.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"supports-color": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/depd": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
|
||||
"integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/dunder-proto": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
|
||||
"integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"call-bind-apply-helpers": "^1.0.1",
|
||||
"es-errors": "^1.3.0",
|
||||
"gopd": "^1.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/ee-first": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
|
||||
"integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/encodeurl": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz",
|
||||
"integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/es-define-property": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",
|
||||
"integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/es-errors": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
|
||||
"integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/es-object-atoms": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz",
|
||||
"integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"es-errors": "^1.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/escape-html": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
|
||||
"integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/etag": {
|
||||
"version": "1.8.1",
|
||||
"resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
|
||||
"integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/express": {
|
||||
"version": "5.2.1",
|
||||
"resolved": "https://registry.npmjs.org/express/-/express-5.2.1.tgz",
|
||||
"integrity": "sha512-hIS4idWWai69NezIdRt2xFVofaF4j+6INOpJlVOLDO8zXGpUVEVzIYk12UUi2JzjEzWL3IOAxcTubgz9Po0yXw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"accepts": "^2.0.0",
|
||||
"body-parser": "^2.2.1",
|
||||
"content-disposition": "^1.0.0",
|
||||
"content-type": "^1.0.5",
|
||||
"cookie": "^0.7.1",
|
||||
"cookie-signature": "^1.2.1",
|
||||
"debug": "^4.4.0",
|
||||
"depd": "^2.0.0",
|
||||
"encodeurl": "^2.0.0",
|
||||
"escape-html": "^1.0.3",
|
||||
"etag": "^1.8.1",
|
||||
"finalhandler": "^2.1.0",
|
||||
"fresh": "^2.0.0",
|
||||
"http-errors": "^2.0.0",
|
||||
"merge-descriptors": "^2.0.0",
|
||||
"mime-types": "^3.0.0",
|
||||
"on-finished": "^2.4.1",
|
||||
"once": "^1.4.0",
|
||||
"parseurl": "^1.3.3",
|
||||
"proxy-addr": "^2.0.7",
|
||||
"qs": "^6.14.0",
|
||||
"range-parser": "^1.2.1",
|
||||
"router": "^2.2.0",
|
||||
"send": "^1.1.0",
|
||||
"serve-static": "^2.2.0",
|
||||
"statuses": "^2.0.1",
|
||||
"type-is": "^2.0.1",
|
||||
"vary": "^1.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 18"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/express"
|
||||
}
|
||||
},
|
||||
"node_modules/finalhandler": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-2.1.1.tgz",
|
||||
"integrity": "sha512-S8KoZgRZN+a5rNwqTxlZZePjT/4cnm0ROV70LedRHZ0p8u9fRID0hJUZQpkKLzro8LfmC8sx23bY6tVNxv8pQA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"debug": "^4.4.0",
|
||||
"encodeurl": "^2.0.0",
|
||||
"escape-html": "^1.0.3",
|
||||
"on-finished": "^2.4.1",
|
||||
"parseurl": "^1.3.3",
|
||||
"statuses": "^2.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 18.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/express"
|
||||
}
|
||||
},
|
||||
"node_modules/forwarded": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
|
||||
"integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/fresh": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/fresh/-/fresh-2.0.0.tgz",
|
||||
"integrity": "sha512-Rx/WycZ60HOaqLKAi6cHRKKI7zxWbJ31MhntmtwMoaTeF7XFH9hhBp8vITaMidfljRQ6eYWCKkaTK+ykVJHP2A==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/function-bind": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
|
||||
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/get-intrinsic": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
|
||||
"integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"call-bind-apply-helpers": "^1.0.2",
|
||||
"es-define-property": "^1.0.1",
|
||||
"es-errors": "^1.3.0",
|
||||
"es-object-atoms": "^1.1.1",
|
||||
"function-bind": "^1.1.2",
|
||||
"get-proto": "^1.0.1",
|
||||
"gopd": "^1.2.0",
|
||||
"has-symbols": "^1.1.0",
|
||||
"hasown": "^2.0.2",
|
||||
"math-intrinsics": "^1.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/get-proto": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz",
|
||||
"integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"dunder-proto": "^1.0.1",
|
||||
"es-object-atoms": "^1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/gopd": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
|
||||
"integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/has-symbols": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz",
|
||||
"integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/hasown": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz",
|
||||
"integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"function-bind": "^1.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/http-errors": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz",
|
||||
"integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"depd": "~2.0.0",
|
||||
"inherits": "~2.0.4",
|
||||
"setprototypeof": "~1.2.0",
|
||||
"statuses": "~2.0.2",
|
||||
"toidentifier": "~1.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/express"
|
||||
}
|
||||
},
|
||||
"node_modules/iconv-lite": {
|
||||
"version": "0.7.2",
|
||||
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.2.tgz",
|
||||
"integrity": "sha512-im9DjEDQ55s9fL4EYzOAv0yMqmMBSZp6G0VvFyTMPKWxiSBHUj9NW/qqLmXUwXrrM7AvqSlTCfvqRb0cM8yYqw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"safer-buffer": ">= 2.1.2 < 3.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/express"
|
||||
}
|
||||
},
|
||||
"node_modules/inherits": {
|
||||
"version": "2.0.4",
|
||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
|
||||
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/ipaddr.js": {
|
||||
"version": "1.9.1",
|
||||
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
|
||||
"integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/is-promise": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz",
|
||||
"integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/math-intrinsics": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
|
||||
"integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/media-typer": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.0.tgz",
|
||||
"integrity": "sha512-aisnrDP4GNe06UcKFnV5bfMNPBUw4jsLGaWwWfnH3v02GnBuXX2MCVn5RbrWo0j3pczUilYblq7fQ7Nw2t5XKw==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/merge-descriptors": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-2.0.0.tgz",
|
||||
"integrity": "sha512-Snk314V5ayFLhp3fkUREub6WtjBfPdCPY1Ln8/8munuLuiYhsABgBVWsozAG+MWMbVEvcdcpbi9R7ww22l9Q3g==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/mime-db": {
|
||||
"version": "1.54.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.54.0.tgz",
|
||||
"integrity": "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/mime-types": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.2.tgz",
|
||||
"integrity": "sha512-Lbgzdk0h4juoQ9fCKXW4by0UJqj+nOOrI9MJ1sSj4nI8aI2eo1qmvQEie4VD1glsS250n15LsWsYtCugiStS5A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"mime-db": "^1.54.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/express"
|
||||
}
|
||||
},
|
||||
"node_modules/ms": {
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
||||
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/negotiator": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz",
|
||||
"integrity": "sha512-8Ofs/AUQh8MaEcrlq5xOX0CQ9ypTF5dl78mjlMNfOK08fzpgTHQRQPBxcPlEtIw0yRpws+Zo/3r+5WRby7u3Gg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/object-inspect": {
|
||||
"version": "1.13.4",
|
||||
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz",
|
||||
"integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/on-finished": {
|
||||
"version": "2.4.1",
|
||||
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz",
|
||||
"integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ee-first": "1.1.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/once": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||
"integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"wrappy": "1"
|
||||
}
|
||||
},
|
||||
"node_modules/parseurl": {
|
||||
"version": "1.3.3",
|
||||
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
|
||||
"integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/path-to-regexp": {
|
||||
"version": "8.3.0",
|
||||
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.3.0.tgz",
|
||||
"integrity": "sha512-7jdwVIRtsP8MYpdXSwOS0YdD0Du+qOoF/AEPIt88PcCFrZCzx41oxku1jD88hZBwbNUIEfpqvuhjFaMAqMTWnA==",
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/express"
|
||||
}
|
||||
},
|
||||
"node_modules/proxy-addr": {
|
||||
"version": "2.0.7",
|
||||
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
|
||||
"integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"forwarded": "0.2.0",
|
||||
"ipaddr.js": "1.9.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/qs": {
|
||||
"version": "6.15.0",
|
||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.15.0.tgz",
|
||||
"integrity": "sha512-mAZTtNCeetKMH+pSjrb76NAM8V9a05I9aBZOHztWy/UqcJdQYNsf59vrRKWnojAT9Y+GbIvoTBC++CPHqpDBhQ==",
|
||||
"license": "BSD-3-Clause",
|
||||
"dependencies": {
|
||||
"side-channel": "^1.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.6"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/range-parser": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",
|
||||
"integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/raw-body": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-3.0.2.tgz",
|
||||
"integrity": "sha512-K5zQjDllxWkf7Z5xJdV0/B0WTNqx6vxG70zJE4N0kBs4LovmEYWJzQGxC9bS9RAKu3bgM40lrd5zoLJ12MQ5BA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"bytes": "~3.1.2",
|
||||
"http-errors": "~2.0.1",
|
||||
"iconv-lite": "~0.7.0",
|
||||
"unpipe": "~1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/router": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/router/-/router-2.2.0.tgz",
|
||||
"integrity": "sha512-nLTrUKm2UyiL7rlhapu/Zl45FwNgkZGaCpZbIHajDYgwlJCOzLSk+cIPAnsEqV955GjILJnKbdQC1nVPz+gAYQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"debug": "^4.4.0",
|
||||
"depd": "^2.0.0",
|
||||
"is-promise": "^4.0.0",
|
||||
"parseurl": "^1.3.3",
|
||||
"path-to-regexp": "^8.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 18"
|
||||
}
|
||||
},
|
||||
"node_modules/safer-buffer": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
||||
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/send": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/send/-/send-1.2.1.tgz",
|
||||
"integrity": "sha512-1gnZf7DFcoIcajTjTwjwuDjzuz4PPcY2StKPlsGAQ1+YH20IRVrBaXSWmdjowTJ6u8Rc01PoYOGHXfP1mYcZNQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"debug": "^4.4.3",
|
||||
"encodeurl": "^2.0.0",
|
||||
"escape-html": "^1.0.3",
|
||||
"etag": "^1.8.1",
|
||||
"fresh": "^2.0.0",
|
||||
"http-errors": "^2.0.1",
|
||||
"mime-types": "^3.0.2",
|
||||
"ms": "^2.1.3",
|
||||
"on-finished": "^2.4.1",
|
||||
"range-parser": "^1.2.1",
|
||||
"statuses": "^2.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 18"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/express"
|
||||
}
|
||||
},
|
||||
"node_modules/serve-static": {
|
||||
"version": "2.2.1",
|
||||
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-2.2.1.tgz",
|
||||
"integrity": "sha512-xRXBn0pPqQTVQiC8wyQrKs2MOlX24zQ0POGaj0kultvoOCstBQM5yvOhAVSUwOMjQtTvsPWoNCHfPGwaaQJhTw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"encodeurl": "^2.0.0",
|
||||
"escape-html": "^1.0.3",
|
||||
"parseurl": "^1.3.3",
|
||||
"send": "^1.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 18"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/express"
|
||||
}
|
||||
},
|
||||
"node_modules/setprototypeof": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
|
||||
"integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/side-channel": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz",
|
||||
"integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"es-errors": "^1.3.0",
|
||||
"object-inspect": "^1.13.3",
|
||||
"side-channel-list": "^1.0.0",
|
||||
"side-channel-map": "^1.0.1",
|
||||
"side-channel-weakmap": "^1.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/side-channel-list": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.0.tgz",
|
||||
"integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"es-errors": "^1.3.0",
|
||||
"object-inspect": "^1.13.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/side-channel-map": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz",
|
||||
"integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"call-bound": "^1.0.2",
|
||||
"es-errors": "^1.3.0",
|
||||
"get-intrinsic": "^1.2.5",
|
||||
"object-inspect": "^1.13.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/side-channel-weakmap": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz",
|
||||
"integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"call-bound": "^1.0.2",
|
||||
"es-errors": "^1.3.0",
|
||||
"get-intrinsic": "^1.2.5",
|
||||
"object-inspect": "^1.13.3",
|
||||
"side-channel-map": "^1.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/statuses": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz",
|
||||
"integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/toidentifier": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz",
|
||||
"integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/type-is": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/type-is/-/type-is-2.0.1.tgz",
|
||||
"integrity": "sha512-OZs6gsjF4vMp32qrCbiVSkrFmXtG/AZhY3t0iAMrMBiAZyV9oALtXO8hsrHbMXF9x6L3grlFuwW2oAz7cav+Gw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"content-type": "^1.0.5",
|
||||
"media-typer": "^1.1.0",
|
||||
"mime-types": "^3.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/unpipe": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
|
||||
"integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/vary": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
|
||||
"integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/wrappy": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==",
|
||||
"license": "ISC"
|
||||
}
|
||||
}
|
||||
}
|
||||
12
package.json
Normal file
12
package.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "electronics-inventory",
|
||||
"version": "0.1.0",
|
||||
"type": "module",
|
||||
"engines": { "node": ">=25" },
|
||||
"scripts": {
|
||||
"start": "node server.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"express": "^5.2.1"
|
||||
}
|
||||
}
|
||||
621
public/app.mjs
Normal file
621
public/app.mjs
Normal file
@@ -0,0 +1,621 @@
|
||||
import { qs, clone, set_text } from './lib/dom.mjs';
|
||||
import * as api from './lib/api.mjs';
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// State
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
let section = 'components';
|
||||
let all_components = [];
|
||||
let all_fields = [];
|
||||
let all_inventory = [];
|
||||
let component_search = '';
|
||||
let inventory_search = '';
|
||||
let inventory_type_filter = '';
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Data loading
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function load_all() {
|
||||
const [cf, ci, cmp] = await Promise.all([
|
||||
api.get_fields(),
|
||||
api.get_inventory(),
|
||||
api.get_components(),
|
||||
]);
|
||||
all_fields = cf.fields;
|
||||
all_inventory = ci.entries;
|
||||
all_components = cmp.components;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const LOCATION_TYPE_LABEL = { physical: 'Physical', bom: 'BOM', digital: 'Digital' };
|
||||
const LOCATION_TYPE_ICON = { physical: '📦', bom: '📋', digital: '💡' };
|
||||
|
||||
function ref_label_for_type(type) {
|
||||
if (type === 'physical') return 'Location (drawer, bin, shelf…)';
|
||||
if (type === 'bom') return 'Document / project name';
|
||||
return 'Note / description';
|
||||
}
|
||||
|
||||
function inventory_for_component(component_id) {
|
||||
return all_inventory.filter(e => e.component_id === component_id);
|
||||
}
|
||||
|
||||
function component_by_id(id) {
|
||||
return all_components.find(c => c.id === id);
|
||||
}
|
||||
|
||||
function field_by_id(id) {
|
||||
return all_fields.find(f => f.id === id);
|
||||
}
|
||||
|
||||
function matches_search(component, query) {
|
||||
if (!query) return true;
|
||||
const q = query.toLowerCase();
|
||||
if (component.name.toLowerCase().includes(q)) return true;
|
||||
if (component.description.toLowerCase().includes(q)) return true;
|
||||
for (const val of Object.values(component.fields ?? {})) {
|
||||
if (String(val).toLowerCase().includes(q)) return true;
|
||||
}
|
||||
// Also search inventory locations for this component
|
||||
for (const entry of inventory_for_component(component.id)) {
|
||||
if (entry.location_ref.toLowerCase().includes(q)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function matches_inventory_search(entry, query, type_filter) {
|
||||
if (type_filter && entry.location_type !== type_filter) return false;
|
||||
if (!query) return true;
|
||||
const q = query.toLowerCase();
|
||||
const comp = component_by_id(entry.component_id);
|
||||
if (comp && comp.name.toLowerCase().includes(q)) return true;
|
||||
if (entry.location_ref.toLowerCase().includes(q)) return true;
|
||||
if (entry.notes.toLowerCase().includes(q)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Render: Components section
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function render_components() {
|
||||
const main = document.getElementById('main');
|
||||
let section_el = document.getElementById('section-components');
|
||||
if (!section_el) {
|
||||
const frag = document.getElementById('t-section-components').content.cloneNode(true);
|
||||
main.replaceChildren(frag);
|
||||
section_el = document.getElementById('section-components');
|
||||
|
||||
qs(section_el, '#component-search').addEventListener('input', (e) => {
|
||||
component_search = e.target.value;
|
||||
render_component_list();
|
||||
});
|
||||
qs(section_el, '#btn-add-component').addEventListener('click', () => open_component_dialog());
|
||||
}
|
||||
|
||||
qs(section_el, '#component-search').value = component_search;
|
||||
render_component_list();
|
||||
}
|
||||
|
||||
function render_component_list() {
|
||||
const list_el = document.getElementById('component-list');
|
||||
const query = component_search.trim();
|
||||
const visible = all_components.filter(c => matches_search(c, query));
|
||||
|
||||
if (visible.length === 0) {
|
||||
const empty = document.createElement('div');
|
||||
empty.className = 'empty-state';
|
||||
empty.textContent = query ? 'No components match your search.' : 'No components yet. Add one!';
|
||||
list_el.replaceChildren(empty);
|
||||
return;
|
||||
}
|
||||
|
||||
list_el.replaceChildren(...visible.map(build_component_row));
|
||||
}
|
||||
|
||||
function build_component_row(comp) {
|
||||
const row = clone('t-component-row');
|
||||
set_text(row, '.component-name', comp.name);
|
||||
set_text(row, '.component-description', comp.description || '');
|
||||
|
||||
// Field tags
|
||||
const fields_el = qs(row, '.component-fields');
|
||||
const field_entries = Object.entries(comp.fields ?? {});
|
||||
if (field_entries.length > 0) {
|
||||
fields_el.replaceChildren(...field_entries.map(([fid, val]) => {
|
||||
const tag = clone('t-field-tag');
|
||||
const def = field_by_id(fid);
|
||||
const label = def ? def.name : fid;
|
||||
const display_val = def?.unit ? `${val} ${def.unit}` : String(val);
|
||||
set_text(tag, '.tag-name', label);
|
||||
set_text(tag, '.tag-value', display_val);
|
||||
return tag;
|
||||
}));
|
||||
}
|
||||
|
||||
// Location badges
|
||||
const locs_el = qs(row, '.component-locations');
|
||||
const entries = inventory_for_component(comp.id);
|
||||
if (entries.length > 0) {
|
||||
locs_el.replaceChildren(...entries.map(entry => {
|
||||
const badge = clone('t-location-badge');
|
||||
badge.classList.add(`type-${entry.location_type}`);
|
||||
set_text(badge, '.badge-icon', LOCATION_TYPE_ICON[entry.location_type] ?? '');
|
||||
const ref_text = entry.location_ref || LOCATION_TYPE_LABEL[entry.location_type];
|
||||
const qty_text = entry.quantity ? ` ×${entry.quantity}` : '';
|
||||
set_text(badge, '.badge-text', ref_text + qty_text);
|
||||
return badge;
|
||||
}));
|
||||
}
|
||||
|
||||
qs(row, '.btn-edit').addEventListener('click', () => open_component_dialog(comp));
|
||||
qs(row, '.btn-delete').addEventListener('click', () => confirm_delete(
|
||||
`Delete component "${comp.name}"? Inventory entries for it will remain but become orphaned.`,
|
||||
async () => {
|
||||
await api.delete_component(comp.id);
|
||||
all_components = all_components.filter(c => c.id !== comp.id);
|
||||
render_component_list();
|
||||
}
|
||||
));
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Render: Inventory section
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function render_inventory() {
|
||||
const main = document.getElementById('main');
|
||||
let section_el = document.getElementById('section-inventory');
|
||||
if (!section_el) {
|
||||
const frag = document.getElementById('t-section-inventory').content.cloneNode(true);
|
||||
main.replaceChildren(frag);
|
||||
section_el = document.getElementById('section-inventory');
|
||||
|
||||
qs(section_el, '#inventory-search').addEventListener('input', (e) => {
|
||||
inventory_search = e.target.value;
|
||||
render_inventory_list();
|
||||
});
|
||||
qs(section_el, '#inventory-type-filter').addEventListener('change', (e) => {
|
||||
inventory_type_filter = e.target.value;
|
||||
render_inventory_list();
|
||||
});
|
||||
qs(section_el, '#btn-add-inventory').addEventListener('click', () => open_inventory_dialog());
|
||||
}
|
||||
|
||||
qs(section_el, '#inventory-search').value = inventory_search;
|
||||
qs(section_el, '#inventory-type-filter').value = inventory_type_filter;
|
||||
render_inventory_list();
|
||||
}
|
||||
|
||||
function render_inventory_list() {
|
||||
const list_el = document.getElementById('inventory-list');
|
||||
const visible = all_inventory.filter(e => matches_inventory_search(e, inventory_search.trim(), inventory_type_filter));
|
||||
|
||||
if (visible.length === 0) {
|
||||
const empty = document.createElement('div');
|
||||
empty.className = 'empty-state';
|
||||
empty.textContent = 'No inventory entries match your filter.';
|
||||
list_el.replaceChildren(empty);
|
||||
return;
|
||||
}
|
||||
|
||||
list_el.replaceChildren(...visible.map(build_inventory_row));
|
||||
}
|
||||
|
||||
function build_inventory_row(entry) {
|
||||
const row = clone('t-inventory-row');
|
||||
const comp = component_by_id(entry.component_id);
|
||||
set_text(row, '.inv-component-name', comp ? comp.name : '(deleted component)');
|
||||
|
||||
const pill = document.createElement('span');
|
||||
pill.className = `type-pill type-${entry.location_type}`;
|
||||
pill.textContent = LOCATION_TYPE_LABEL[entry.location_type] ?? entry.location_type;
|
||||
qs(row, '.inv-type-badge').replaceChildren(pill);
|
||||
|
||||
set_text(row, '.inv-location-ref', entry.location_ref);
|
||||
set_text(row, '.inv-quantity', entry.quantity);
|
||||
set_text(row, '.inv-notes', entry.notes);
|
||||
|
||||
qs(row, '.btn-edit').addEventListener('click', () => open_inventory_dialog(entry));
|
||||
qs(row, '.btn-delete').addEventListener('click', () => confirm_delete(
|
||||
`Delete this inventory entry (${LOCATION_TYPE_LABEL[entry.location_type]}: ${entry.location_ref || '—'})?`,
|
||||
async () => {
|
||||
await api.delete_inventory(entry.id);
|
||||
all_inventory = all_inventory.filter(e => e.id !== entry.id);
|
||||
render_inventory_list();
|
||||
}
|
||||
));
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Render: Fields section
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function render_fields() {
|
||||
const main = document.getElementById('main');
|
||||
let section_el = document.getElementById('section-fields');
|
||||
if (!section_el) {
|
||||
const frag = document.getElementById('t-section-fields').content.cloneNode(true);
|
||||
main.replaceChildren(frag);
|
||||
section_el = document.getElementById('section-fields');
|
||||
qs(section_el, '#btn-add-field').addEventListener('click', () => open_field_dialog());
|
||||
}
|
||||
render_field_list();
|
||||
}
|
||||
|
||||
function render_field_list() {
|
||||
const list_el = document.getElementById('field-list');
|
||||
|
||||
if (all_fields.length === 0) {
|
||||
const empty = document.createElement('div');
|
||||
empty.className = 'empty-state';
|
||||
empty.textContent = 'No field definitions yet. Add some!';
|
||||
list_el.replaceChildren(empty);
|
||||
return;
|
||||
}
|
||||
|
||||
list_el.replaceChildren(...all_fields.map(build_field_row));
|
||||
}
|
||||
|
||||
function build_field_row(fdef) {
|
||||
const row = clone('t-field-row');
|
||||
set_text(row, '.fdef-name', fdef.name);
|
||||
set_text(row, '.fdef-unit', fdef.unit || '—');
|
||||
set_text(row, '.fdef-description', fdef.description || '');
|
||||
|
||||
qs(row, '.btn-edit').addEventListener('click', () => open_field_dialog(fdef));
|
||||
qs(row, '.btn-delete').addEventListener('click', () => confirm_delete(
|
||||
`Delete field definition "${fdef.name}"? This will not remove values already stored on components.`,
|
||||
async () => {
|
||||
await api.delete_field(fdef.id);
|
||||
all_fields = all_fields.filter(f => f.id !== fdef.id);
|
||||
render_field_list();
|
||||
}
|
||||
));
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Dialog: Component
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
let component_dialog_callback = null;
|
||||
|
||||
function open_component_dialog(comp = null) {
|
||||
const dlg = document.getElementById('dialog-component');
|
||||
const title = qs(dlg, '.dialog-title');
|
||||
const name_input = qs(dlg, '#c-name');
|
||||
const desc_input = qs(dlg, '#c-description');
|
||||
const field_rows_el = qs(dlg, '#c-field-rows');
|
||||
const add_field_sel = qs(dlg, '#c-add-field-select');
|
||||
|
||||
title.textContent = comp ? `Edit component` : 'Add component';
|
||||
name_input.value = comp?.name ?? '';
|
||||
desc_input.value = comp?.description ?? '';
|
||||
|
||||
// Build field rows from component's existing values
|
||||
const active_fields = new Map(Object.entries(comp?.fields ?? {}));
|
||||
|
||||
function rebuild_field_rows() {
|
||||
field_rows_el.replaceChildren(...[...active_fields.entries()].map(([fid, val]) => {
|
||||
const def = field_by_id(fid);
|
||||
const label_text = def ? def.name : fid;
|
||||
const unit_text = def?.unit ? ` [${def.unit}]` : '';
|
||||
|
||||
const row_el = document.createElement('div');
|
||||
row_el.className = 'c-field-input-row';
|
||||
|
||||
const label_el = document.createElement('div');
|
||||
label_el.className = 'c-field-input-label';
|
||||
label_el.textContent = label_text;
|
||||
if (unit_text) {
|
||||
const unit_span = document.createElement('span');
|
||||
unit_span.className = 'c-field-unit-hint';
|
||||
unit_span.textContent = unit_text;
|
||||
label_el.appendChild(unit_span);
|
||||
}
|
||||
|
||||
const input_el = document.createElement('input');
|
||||
input_el.type = 'text';
|
||||
input_el.className = 'c-field-value';
|
||||
input_el.value = val;
|
||||
input_el.autocomplete = 'off';
|
||||
input_el.dataset.field_id = fid;
|
||||
input_el.addEventListener('input', (e) => {
|
||||
active_fields.set(fid, e.target.value);
|
||||
});
|
||||
|
||||
const remove_btn = document.createElement('button');
|
||||
remove_btn.type = 'button';
|
||||
remove_btn.className = 'btn-icon btn-danger';
|
||||
remove_btn.textContent = '✕';
|
||||
remove_btn.title = 'Remove field value';
|
||||
remove_btn.addEventListener('click', () => {
|
||||
active_fields.delete(fid);
|
||||
rebuild_field_rows();
|
||||
rebuild_add_select();
|
||||
});
|
||||
|
||||
row_el.appendChild(label_el);
|
||||
row_el.appendChild(input_el);
|
||||
row_el.appendChild(remove_btn);
|
||||
return row_el;
|
||||
}));
|
||||
}
|
||||
|
||||
function rebuild_add_select() {
|
||||
const available = all_fields.filter(f => !active_fields.has(f.id));
|
||||
add_field_sel.replaceChildren(
|
||||
Object.assign(document.createElement('option'), { value: '', textContent: '— add a field —' }),
|
||||
...available.map(f => Object.assign(document.createElement('option'), {
|
||||
value: f.id,
|
||||
textContent: f.name + (f.unit ? ` [${f.unit}]` : ''),
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
rebuild_field_rows();
|
||||
rebuild_add_select();
|
||||
|
||||
// Wire add-field select
|
||||
const old_handler = add_field_sel._change_handler;
|
||||
if (old_handler) add_field_sel.removeEventListener('change', old_handler);
|
||||
add_field_sel._change_handler = (e) => {
|
||||
const fid = e.target.value;
|
||||
if (!fid) return;
|
||||
active_fields.set(fid, '');
|
||||
rebuild_field_rows();
|
||||
rebuild_add_select();
|
||||
// Focus the new input
|
||||
const inputs = field_rows_el.querySelectorAll(`[data-field_id="${fid}"]`);
|
||||
if (inputs.length) inputs[inputs.length - 1].focus();
|
||||
};
|
||||
add_field_sel.addEventListener('change', add_field_sel._change_handler);
|
||||
|
||||
component_dialog_callback = async () => {
|
||||
const name = name_input.value.trim();
|
||||
if (!name) return;
|
||||
const fields = {};
|
||||
for (const [fid, val] of active_fields.entries()) {
|
||||
if (val.trim()) fields[fid] = val.trim();
|
||||
}
|
||||
const body = { name, description: desc_input.value.trim(), fields };
|
||||
if (comp) {
|
||||
const result = await api.update_component(comp.id, body);
|
||||
const idx = all_components.findIndex(c => c.id === comp.id);
|
||||
if (idx !== -1) all_components[idx] = result.component;
|
||||
} else {
|
||||
const result = await api.create_component(body);
|
||||
all_components.push(result.component);
|
||||
all_components.sort((a, b) => a.name.localeCompare(b.name));
|
||||
}
|
||||
};
|
||||
|
||||
dlg.showModal();
|
||||
name_input.focus();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Dialog: Inventory entry
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
let inventory_dialog_callback = null;
|
||||
|
||||
function open_inventory_dialog(entry = null) {
|
||||
const dlg = document.getElementById('dialog-inventory');
|
||||
const title = qs(dlg, '.dialog-title');
|
||||
const comp_sel = qs(dlg, '#i-component');
|
||||
const type_sel = qs(dlg, '#i-type');
|
||||
const ref_input = qs(dlg, '#i-ref');
|
||||
const ref_label = qs(dlg, '#i-ref-label');
|
||||
const qty_input = qs(dlg, '#i-qty');
|
||||
const notes_input = qs(dlg, '#i-notes');
|
||||
|
||||
title.textContent = entry ? 'Edit inventory entry' : 'Add inventory entry';
|
||||
|
||||
// Populate component dropdown
|
||||
comp_sel.replaceChildren(
|
||||
Object.assign(document.createElement('option'), { value: '', textContent: '— select component —' }),
|
||||
...all_components.map(c => Object.assign(document.createElement('option'), {
|
||||
value: c.id,
|
||||
textContent: c.name,
|
||||
}))
|
||||
);
|
||||
comp_sel.value = entry?.component_id ?? '';
|
||||
type_sel.value = entry?.location_type ?? 'physical';
|
||||
ref_input.value = entry?.location_ref ?? '';
|
||||
qty_input.value = entry?.quantity ?? '';
|
||||
notes_input.value = entry?.notes ?? '';
|
||||
|
||||
function update_ref_label() {
|
||||
ref_label.textContent = ref_label_for_type(type_sel.value);
|
||||
}
|
||||
update_ref_label();
|
||||
|
||||
const old_type_handler = type_sel._change_handler;
|
||||
if (old_type_handler) type_sel.removeEventListener('change', old_type_handler);
|
||||
type_sel._change_handler = update_ref_label;
|
||||
type_sel.addEventListener('change', type_sel._change_handler);
|
||||
|
||||
inventory_dialog_callback = async () => {
|
||||
const body = {
|
||||
component_id: comp_sel.value,
|
||||
location_type: type_sel.value,
|
||||
location_ref: ref_input.value.trim(),
|
||||
quantity: qty_input.value.trim(),
|
||||
notes: notes_input.value.trim(),
|
||||
};
|
||||
if (entry) {
|
||||
const result = await api.update_inventory(entry.id, body);
|
||||
const idx = all_inventory.findIndex(e => e.id === entry.id);
|
||||
if (idx !== -1) all_inventory[idx] = result.entry;
|
||||
} else {
|
||||
const result = await api.create_inventory(body);
|
||||
all_inventory.push(result.entry);
|
||||
}
|
||||
};
|
||||
|
||||
dlg.showModal();
|
||||
comp_sel.focus();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Dialog: Field definition
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
let field_dialog_callback = null;
|
||||
|
||||
function open_field_dialog(fdef = null) {
|
||||
const dlg = document.getElementById('dialog-field');
|
||||
const title = qs(dlg, '.dialog-title');
|
||||
const name_input = qs(dlg, '#f-name');
|
||||
const unit_input = qs(dlg, '#f-unit');
|
||||
const desc_input = qs(dlg, '#f-description');
|
||||
|
||||
title.textContent = fdef ? 'Edit field' : 'Add field';
|
||||
name_input.value = fdef?.name ?? '';
|
||||
unit_input.value = fdef?.unit ?? '';
|
||||
desc_input.value = fdef?.description ?? '';
|
||||
|
||||
field_dialog_callback = async () => {
|
||||
const body = {
|
||||
name: name_input.value.trim(),
|
||||
unit: unit_input.value.trim(),
|
||||
description: desc_input.value.trim(),
|
||||
};
|
||||
if (fdef) {
|
||||
const result = await api.update_field(fdef.id, body);
|
||||
const idx = all_fields.findIndex(f => f.id === fdef.id);
|
||||
if (idx !== -1) all_fields[idx] = result.field;
|
||||
all_fields.sort((a, b) => a.name.localeCompare(b.name));
|
||||
} else {
|
||||
const result = await api.create_field(body);
|
||||
all_fields.push(result.field);
|
||||
all_fields.sort((a, b) => a.name.localeCompare(b.name));
|
||||
}
|
||||
};
|
||||
|
||||
dlg.showModal();
|
||||
name_input.focus();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Dialog: Confirm delete
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
let confirm_callback = null;
|
||||
|
||||
function confirm_delete(message, on_confirm) {
|
||||
const dlg = document.getElementById('dialog-confirm');
|
||||
document.getElementById('confirm-message').textContent = message;
|
||||
confirm_callback = on_confirm;
|
||||
dlg.showModal();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Render dispatcher
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function render() {
|
||||
if (section === 'components') render_components();
|
||||
else if (section === 'inventory') render_inventory();
|
||||
else if (section === 'fields') render_fields();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Init
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function init() {
|
||||
// Load templates
|
||||
const html = await fetch('/templates.html').then(r => r.text());
|
||||
document.body.insertAdjacentHTML('beforeend', html);
|
||||
|
||||
// Clone and mount dialogs
|
||||
for (const id of ['t-dialog-component', 't-dialog-inventory', 't-dialog-field', 't-dialog-confirm']) {
|
||||
const frag = document.getElementById(id).content.cloneNode(true);
|
||||
document.body.appendChild(frag);
|
||||
}
|
||||
|
||||
// Wire dialog form submissions
|
||||
document.getElementById('form-component').addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
try {
|
||||
await component_dialog_callback?.();
|
||||
document.getElementById('dialog-component').close();
|
||||
render();
|
||||
} catch (err) {
|
||||
alert(`Error: ${err.message}`);
|
||||
}
|
||||
});
|
||||
document.getElementById('c-cancel').addEventListener('click', () => {
|
||||
document.getElementById('dialog-component').close();
|
||||
});
|
||||
|
||||
document.getElementById('form-inventory').addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
try {
|
||||
await inventory_dialog_callback?.();
|
||||
document.getElementById('dialog-inventory').close();
|
||||
render();
|
||||
} catch (err) {
|
||||
alert(`Error: ${err.message}`);
|
||||
}
|
||||
});
|
||||
document.getElementById('i-cancel').addEventListener('click', () => {
|
||||
document.getElementById('dialog-inventory').close();
|
||||
});
|
||||
|
||||
document.getElementById('form-field').addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
try {
|
||||
await field_dialog_callback?.();
|
||||
document.getElementById('dialog-field').close();
|
||||
render();
|
||||
} catch (err) {
|
||||
alert(`Error: ${err.message}`);
|
||||
}
|
||||
});
|
||||
document.getElementById('f-cancel').addEventListener('click', () => {
|
||||
document.getElementById('dialog-field').close();
|
||||
});
|
||||
|
||||
document.getElementById('confirm-ok').addEventListener('click', async () => {
|
||||
try {
|
||||
await confirm_callback?.();
|
||||
document.getElementById('dialog-confirm').close();
|
||||
render();
|
||||
} catch (err) {
|
||||
alert(`Error: ${err.message}`);
|
||||
}
|
||||
});
|
||||
document.getElementById('confirm-cancel').addEventListener('click', () => {
|
||||
document.getElementById('dialog-confirm').close();
|
||||
});
|
||||
|
||||
// Nav wiring
|
||||
document.querySelectorAll('.nav-btn').forEach(btn => {
|
||||
btn.addEventListener('click', () => {
|
||||
document.querySelectorAll('.nav-btn').forEach(b => b.classList.remove('active'));
|
||||
btn.classList.add('active');
|
||||
section = btn.dataset.section;
|
||||
render();
|
||||
});
|
||||
});
|
||||
|
||||
// Load data
|
||||
await load_all();
|
||||
render();
|
||||
}
|
||||
|
||||
init();
|
||||
22
public/index.html
Normal file
22
public/index.html
Normal file
@@ -0,0 +1,22 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Electronics Inventory</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<link rel="preload" as="fetch" href="/templates.html" crossorigin>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<div class="app-title">Electronics Inventory</div>
|
||||
<nav>
|
||||
<button class="nav-btn active" data-section="components">Components</button>
|
||||
<button class="nav-btn" data-section="inventory">Inventory</button>
|
||||
<button class="nav-btn" data-section="fields">Fields</button>
|
||||
</nav>
|
||||
</header>
|
||||
<main id="main"></main>
|
||||
<script type="module" src="app.mjs"></script>
|
||||
</body>
|
||||
</html>
|
||||
29
public/lib/api.mjs
Normal file
29
public/lib/api.mjs
Normal file
@@ -0,0 +1,29 @@
|
||||
async function req(method, path, body) {
|
||||
const opts = { method, headers: {} };
|
||||
if (body !== undefined) {
|
||||
opts.headers['Content-Type'] = 'application/json';
|
||||
opts.body = JSON.stringify(body);
|
||||
}
|
||||
const res = await fetch(path, opts);
|
||||
const data = await res.json();
|
||||
if (!data.ok) throw new Error(data.error ?? 'Request failed');
|
||||
return data;
|
||||
}
|
||||
|
||||
// Fields
|
||||
export const get_fields = () => req('GET', '/api/fields');
|
||||
export const create_field = (body) => req('POST', '/api/fields', body);
|
||||
export const update_field = (id, body) => req('PUT', `/api/fields/${id}`, body);
|
||||
export const delete_field = (id) => req('DELETE', `/api/fields/${id}`);
|
||||
|
||||
// Components
|
||||
export const get_components = () => req('GET', '/api/components');
|
||||
export const create_component = (body) => req('POST', '/api/components', body);
|
||||
export const update_component = (id, body) => req('PUT', `/api/components/${id}`, body);
|
||||
export const delete_component = (id) => req('DELETE', `/api/components/${id}`);
|
||||
|
||||
// Inventory
|
||||
export const get_inventory = () => req('GET', '/api/inventory');
|
||||
export const create_inventory = (body) => req('POST', '/api/inventory', body);
|
||||
export const update_inventory = (id, body) => req('PUT', `/api/inventory/${id}`, body);
|
||||
export const delete_inventory = (id) => req('DELETE', `/api/inventory/${id}`);
|
||||
16
public/lib/dom.mjs
Normal file
16
public/lib/dom.mjs
Normal file
@@ -0,0 +1,16 @@
|
||||
export function qs(scope, selector) {
|
||||
if (typeof scope === 'string') return document.querySelector(scope);
|
||||
return scope.querySelector(selector);
|
||||
}
|
||||
|
||||
export function clone(template_id) {
|
||||
return document.getElementById(template_id).content.cloneNode(true).firstElementChild;
|
||||
}
|
||||
|
||||
export function set_text(el, selector, text) {
|
||||
const target = typeof selector === 'string' ? el.querySelector(selector) : selector;
|
||||
target.textContent = text;
|
||||
}
|
||||
|
||||
export function show(el) { el.hidden = false; }
|
||||
export function hide(el) { el.hidden = true; }
|
||||
592
public/style.css
Normal file
592
public/style.css
Normal file
@@ -0,0 +1,592 @@
|
||||
*, *::before, *::after {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
:root {
|
||||
--bg: #141414;
|
||||
--surface: #1e1e1e;
|
||||
--surface-raised: #252525;
|
||||
--border: #2d2d2d;
|
||||
--border-focus: #4a7fc1;
|
||||
--text: #e0e0e0;
|
||||
--text-dim: #888;
|
||||
--text-faint: #555;
|
||||
--accent: #5b9cf6;
|
||||
--accent-hover: #7ab3ff;
|
||||
--danger: #e05555;
|
||||
--danger-hover: #f07070;
|
||||
--success: #4caf50;
|
||||
--warning: #ff9800;
|
||||
--purple: #ab7de8;
|
||||
|
||||
--badge-physical-bg: #1a3320;
|
||||
--badge-physical-text: #6fcf97;
|
||||
--badge-bom-bg: #332a10;
|
||||
--badge-bom-text: #f2c94c;
|
||||
--badge-digital-bg: #251a33;
|
||||
--badge-digital-text: #bb6bd9;
|
||||
|
||||
--font: 'Segoe UI', system-ui, sans-serif;
|
||||
--font-mono: 'Fira Code', 'Cascadia Code', monospace;
|
||||
}
|
||||
|
||||
body {
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
font-family: var(--font);
|
||||
font-size: 0.95rem;
|
||||
line-height: 1.5;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
/* ===== HEADER ===== */
|
||||
|
||||
header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 2rem;
|
||||
padding: 0.75rem 1.5rem;
|
||||
background: var(--surface);
|
||||
border-bottom: 1px solid var(--border);
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.app-title {
|
||||
font-size: 1.1rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.04em;
|
||||
color: var(--accent);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
nav {
|
||||
display: flex;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.nav-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--text-dim);
|
||||
padding: 0.4rem 1rem;
|
||||
cursor: pointer;
|
||||
border-radius: 4px;
|
||||
font-size: 0.9rem;
|
||||
font-family: inherit;
|
||||
transition: color 0.1s, background 0.1s;
|
||||
}
|
||||
|
||||
.nav-btn:hover {
|
||||
color: var(--text);
|
||||
background: var(--surface-raised);
|
||||
}
|
||||
|
||||
.nav-btn.active {
|
||||
color: var(--accent);
|
||||
background: rgba(91, 156, 246, 0.12);
|
||||
}
|
||||
|
||||
/* ===== MAIN ===== */
|
||||
|
||||
#main {
|
||||
flex: 1;
|
||||
padding: 1.5rem;
|
||||
max-width: 1200px;
|
||||
width: 100%;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
/* ===== SECTION TOOLBAR ===== */
|
||||
|
||||
.section-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.section-note {
|
||||
flex: 1;
|
||||
color: var(--text-dim);
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
/* ===== SEARCH & FILTER ===== */
|
||||
|
||||
.search-input {
|
||||
flex: 1;
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
color: var(--text);
|
||||
padding: 0.45rem 0.75rem;
|
||||
border-radius: 4px;
|
||||
font-size: 0.9rem;
|
||||
font-family: inherit;
|
||||
transition: border-color 0.1s;
|
||||
}
|
||||
|
||||
.search-input:focus {
|
||||
outline: none;
|
||||
border-color: var(--border-focus);
|
||||
}
|
||||
|
||||
.filter-select {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
color: var(--text);
|
||||
padding: 0.45rem 0.75rem;
|
||||
border-radius: 4px;
|
||||
font-size: 0.9rem;
|
||||
font-family: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.filter-select.wide {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.filter-select:focus {
|
||||
outline: none;
|
||||
border-color: var(--border-focus);
|
||||
}
|
||||
|
||||
/* ===== TABLE HEADERS ===== */
|
||||
|
||||
.table-header {
|
||||
display: grid;
|
||||
padding: 0.4rem 0.75rem;
|
||||
font-size: 0.75rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.07em;
|
||||
color: var(--text-faint);
|
||||
border-bottom: 1px solid var(--border);
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
.inventory-grid {
|
||||
grid-template-columns: 1fr 7rem 1fr 5rem 1fr 4.5rem;
|
||||
gap: 0.5rem;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.fields-grid {
|
||||
grid-template-columns: 1fr 6rem 2fr 4.5rem;
|
||||
gap: 0.5rem;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
/* ===== ITEM LIST ===== */
|
||||
|
||||
.item-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
color: var(--text-faint);
|
||||
text-align: center;
|
||||
padding: 3rem 1rem;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
/* ===== COMPONENT ROWS ===== */
|
||||
|
||||
.component-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.75rem;
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
padding: 0.75rem 1rem;
|
||||
transition: border-color 0.1s;
|
||||
}
|
||||
|
||||
.component-row:hover {
|
||||
border-color: #3d3d3d;
|
||||
}
|
||||
|
||||
.component-main {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.35rem;
|
||||
}
|
||||
|
||||
.component-header {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 0.75rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.component-name {
|
||||
font-weight: 600;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.component-description {
|
||||
color: var(--text-dim);
|
||||
font-size: 0.85rem;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
max-width: 40ch;
|
||||
}
|
||||
|
||||
.component-fields {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.35rem;
|
||||
}
|
||||
|
||||
.component-locations {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.35rem;
|
||||
}
|
||||
|
||||
/* ===== FIELD TAGS ===== */
|
||||
|
||||
.field-tag {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
background: var(--surface-raised);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 3px;
|
||||
font-size: 0.78rem;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.tag-name {
|
||||
padding: 0.1rem 0.4rem;
|
||||
color: var(--text-dim);
|
||||
border-right: 1px solid var(--border);
|
||||
font-family: var(--font-mono);
|
||||
}
|
||||
|
||||
.tag-value {
|
||||
padding: 0.1rem 0.4rem;
|
||||
color: var(--text);
|
||||
font-family: var(--font-mono);
|
||||
}
|
||||
|
||||
/* ===== LOCATION BADGES ===== */
|
||||
|
||||
.location-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.3rem;
|
||||
border-radius: 3px;
|
||||
font-size: 0.8rem;
|
||||
padding: 0.15rem 0.5rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.location-badge.type-physical {
|
||||
background: var(--badge-physical-bg);
|
||||
color: var(--badge-physical-text);
|
||||
}
|
||||
|
||||
.location-badge.type-bom {
|
||||
background: var(--badge-bom-bg);
|
||||
color: var(--badge-bom-text);
|
||||
}
|
||||
|
||||
.location-badge.type-digital {
|
||||
background: var(--badge-digital-bg);
|
||||
color: var(--badge-digital-text);
|
||||
}
|
||||
|
||||
/* ===== INVENTORY ROWS ===== */
|
||||
|
||||
.inventory-row {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 4px;
|
||||
padding: 0.5rem 0.75rem;
|
||||
transition: border-color 0.1s;
|
||||
}
|
||||
|
||||
.inventory-row:hover {
|
||||
border-color: #3d3d3d;
|
||||
}
|
||||
|
||||
.inv-type-badge {
|
||||
display: inline-flex;
|
||||
}
|
||||
|
||||
.type-pill {
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
padding: 0.1rem 0.5rem;
|
||||
border-radius: 10px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.04em;
|
||||
}
|
||||
|
||||
.type-pill.type-physical { background: var(--badge-physical-bg); color: var(--badge-physical-text); }
|
||||
.type-pill.type-bom { background: var(--badge-bom-bg); color: var(--badge-bom-text); }
|
||||
.type-pill.type-digital { background: var(--badge-digital-bg); color: var(--badge-digital-text); }
|
||||
|
||||
.inv-quantity {
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.inv-notes {
|
||||
color: var(--text-dim);
|
||||
font-size: 0.85rem;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
/* ===== FIELD DEF ROWS ===== */
|
||||
|
||||
.field-def-row {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 4px;
|
||||
padding: 0.5rem 0.75rem;
|
||||
transition: border-color 0.1s;
|
||||
}
|
||||
|
||||
.field-def-row:hover {
|
||||
border-color: #3d3d3d;
|
||||
}
|
||||
|
||||
.fdef-name {
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.fdef-unit {
|
||||
color: var(--text-dim);
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
.fdef-description {
|
||||
color: var(--text-dim);
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
/* ===== ACTION BUTTONS ===== */
|
||||
|
||||
.row-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.btn-icon {
|
||||
background: none;
|
||||
border: 1px solid transparent;
|
||||
color: var(--text-dim);
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 1rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: color 0.1s, border-color 0.1s, background 0.1s;
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
.btn-icon:hover {
|
||||
color: var(--text);
|
||||
border-color: var(--border);
|
||||
background: var(--surface-raised);
|
||||
}
|
||||
|
||||
.btn-icon.btn-danger:hover {
|
||||
color: var(--danger);
|
||||
border-color: var(--danger);
|
||||
}
|
||||
|
||||
/* ===== BUTTONS ===== */
|
||||
|
||||
.btn {
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
padding: 0.45rem 1rem;
|
||||
cursor: pointer;
|
||||
font-size: 0.9rem;
|
||||
font-family: inherit;
|
||||
font-weight: 500;
|
||||
transition: background 0.1s, color 0.1s;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: var(--accent);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background: var(--accent-hover);
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background: var(--surface-raised);
|
||||
color: var(--text);
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.btn-secondary:hover {
|
||||
background: #333;
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
background: var(--danger);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.btn-danger:hover {
|
||||
background: var(--danger-hover);
|
||||
}
|
||||
|
||||
/* ===== DIALOGS ===== */
|
||||
|
||||
.app-dialog {
|
||||
background: var(--surface);
|
||||
color: var(--text);
|
||||
border: 1px solid #3a3a3a;
|
||||
border-radius: 8px;
|
||||
padding: 1.5rem;
|
||||
width: min(500px, 95vw);
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
.app-dialog-sm {
|
||||
width: min(360px, 95vw);
|
||||
}
|
||||
|
||||
.app-dialog::backdrop {
|
||||
background: rgba(0, 0, 0, 0.65);
|
||||
}
|
||||
|
||||
.dialog-title {
|
||||
font-size: 1.05rem;
|
||||
font-weight: 600;
|
||||
margin-bottom: 1.25rem;
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.form-row {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.3rem;
|
||||
margin-bottom: 0.9rem;
|
||||
}
|
||||
|
||||
.form-row label {
|
||||
font-size: 0.8rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.06em;
|
||||
color: var(--text-dim);
|
||||
}
|
||||
|
||||
.label-hint {
|
||||
text-transform: none;
|
||||
letter-spacing: normal;
|
||||
font-style: italic;
|
||||
color: var(--text-faint);
|
||||
}
|
||||
|
||||
.form-row input[type="text"],
|
||||
.form-row input[type="search"] {
|
||||
background: var(--bg);
|
||||
border: 1px solid var(--border);
|
||||
color: var(--text);
|
||||
padding: 0.45rem 0.75rem;
|
||||
border-radius: 4px;
|
||||
font-size: 0.9rem;
|
||||
font-family: inherit;
|
||||
transition: border-color 0.1s;
|
||||
}
|
||||
|
||||
.form-row input:focus {
|
||||
outline: none;
|
||||
border-color: var(--border-focus);
|
||||
}
|
||||
|
||||
.form-section-label {
|
||||
font-size: 0.75rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.07em;
|
||||
color: var(--text-faint);
|
||||
margin-bottom: 0.5rem;
|
||||
margin-top: 0.25rem;
|
||||
border-top: 1px solid var(--border);
|
||||
padding-top: 0.75rem;
|
||||
}
|
||||
|
||||
/* Field input rows inside component dialog */
|
||||
.c-field-input-row {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr auto;
|
||||
gap: 0.5rem;
|
||||
align-items: center;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.c-field-input-label {
|
||||
font-size: 0.85rem;
|
||||
color: var(--text-dim);
|
||||
font-family: var(--font-mono);
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 0.3rem;
|
||||
}
|
||||
|
||||
.c-field-unit-hint {
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-faint);
|
||||
}
|
||||
|
||||
.c-field-value {
|
||||
background: var(--bg);
|
||||
border: 1px solid var(--border);
|
||||
color: var(--text);
|
||||
padding: 0.35rem 0.6rem;
|
||||
border-radius: 4px;
|
||||
font-size: 0.85rem;
|
||||
font-family: var(--font-mono);
|
||||
transition: border-color 0.1s;
|
||||
}
|
||||
|
||||
.c-field-value:focus {
|
||||
outline: none;
|
||||
border-color: var(--border-focus);
|
||||
}
|
||||
|
||||
.add-field-row {
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
|
||||
.dialog-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 0.5rem;
|
||||
margin-top: 1.25rem;
|
||||
padding-top: 1rem;
|
||||
border-top: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.confirm-message {
|
||||
color: var(--text-dim);
|
||||
margin-bottom: 0.5rem;
|
||||
font-size: 0.95rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
207
public/templates.html
Normal file
207
public/templates.html
Normal file
@@ -0,0 +1,207 @@
|
||||
<!-- ===== COMPONENTS SECTION ===== -->
|
||||
<template id="t-section-components">
|
||||
<section class="section" id="section-components">
|
||||
<div class="section-toolbar">
|
||||
<input type="search" id="component-search" class="search-input" placeholder="Search components…">
|
||||
<button class="btn btn-primary" id="btn-add-component">+ Add component</button>
|
||||
</div>
|
||||
<div id="component-list" class="item-list"></div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<template id="t-component-row">
|
||||
<div class="component-row">
|
||||
<div class="component-main">
|
||||
<div class="component-header">
|
||||
<span class="component-name"></span>
|
||||
<span class="component-description"></span>
|
||||
</div>
|
||||
<div class="component-fields"></div>
|
||||
<div class="component-locations"></div>
|
||||
</div>
|
||||
<div class="row-actions">
|
||||
<button class="btn-icon btn-edit" title="Edit">✎</button>
|
||||
<button class="btn-icon btn-danger btn-delete" title="Delete">✕</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template id="t-field-tag">
|
||||
<span class="field-tag"><span class="tag-name"></span><span class="tag-value"></span></span>
|
||||
</template>
|
||||
|
||||
<template id="t-location-badge">
|
||||
<span class="location-badge"><span class="badge-icon"></span><span class="badge-text"></span></span>
|
||||
</template>
|
||||
|
||||
<!-- ===== INVENTORY SECTION ===== -->
|
||||
<template id="t-section-inventory">
|
||||
<section class="section" id="section-inventory">
|
||||
<div class="section-toolbar">
|
||||
<input type="search" id="inventory-search" class="search-input" placeholder="Search by component or location…">
|
||||
<select id="inventory-type-filter" class="filter-select">
|
||||
<option value="">All types</option>
|
||||
<option value="physical">Physical</option>
|
||||
<option value="bom">BOM / Drawing</option>
|
||||
<option value="digital">Digital / Note</option>
|
||||
</select>
|
||||
<button class="btn btn-primary" id="btn-add-inventory">+ Add entry</button>
|
||||
</div>
|
||||
<div class="table-header inventory-grid">
|
||||
<span>Component</span>
|
||||
<span>Type</span>
|
||||
<span>Location / Reference</span>
|
||||
<span>Qty</span>
|
||||
<span>Notes</span>
|
||||
<span></span>
|
||||
</div>
|
||||
<div id="inventory-list" class="item-list"></div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<template id="t-inventory-row">
|
||||
<div class="inventory-row inventory-grid">
|
||||
<span class="inv-component-name"></span>
|
||||
<span class="inv-type-badge"></span>
|
||||
<span class="inv-location-ref"></span>
|
||||
<span class="inv-quantity"></span>
|
||||
<span class="inv-notes"></span>
|
||||
<span class="row-actions">
|
||||
<button class="btn-icon btn-edit" title="Edit">✎</button>
|
||||
<button class="btn-icon btn-danger btn-delete" title="Delete">✕</button>
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- ===== FIELDS SECTION ===== -->
|
||||
<template id="t-section-fields">
|
||||
<section class="section" id="section-fields">
|
||||
<div class="section-toolbar">
|
||||
<span class="section-note">Master field index — fields available for all components</span>
|
||||
<button class="btn btn-primary" id="btn-add-field">+ Add field</button>
|
||||
</div>
|
||||
<div class="table-header fields-grid">
|
||||
<span>Field name</span>
|
||||
<span>Unit</span>
|
||||
<span>Description</span>
|
||||
<span></span>
|
||||
</div>
|
||||
<div id="field-list" class="item-list"></div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<template id="t-field-row">
|
||||
<div class="field-def-row fields-grid">
|
||||
<span class="fdef-name"></span>
|
||||
<span class="fdef-unit"></span>
|
||||
<span class="fdef-description"></span>
|
||||
<span class="row-actions">
|
||||
<button class="btn-icon btn-edit" title="Edit">✎</button>
|
||||
<button class="btn-icon btn-danger btn-delete" title="Delete">✕</button>
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- ===== DIALOG: COMPONENT ===== -->
|
||||
<template id="t-dialog-component">
|
||||
<dialog id="dialog-component" class="app-dialog">
|
||||
<h2 class="dialog-title"></h2>
|
||||
<form method="dialog" id="form-component">
|
||||
<div class="form-row">
|
||||
<label for="c-name">Name</label>
|
||||
<input type="text" id="c-name" required autocomplete="off">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="c-description">Description</label>
|
||||
<input type="text" id="c-description" autocomplete="off">
|
||||
</div>
|
||||
<div class="form-section-label">Field values</div>
|
||||
<div id="c-field-rows"></div>
|
||||
<div class="form-row add-field-row">
|
||||
<select id="c-add-field-select" class="filter-select">
|
||||
<option value="">— add a field —</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="dialog-actions">
|
||||
<button type="button" class="btn btn-secondary" id="c-cancel">Cancel</button>
|
||||
<button type="submit" class="btn btn-primary" id="c-save">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</dialog>
|
||||
</template>
|
||||
|
||||
<!-- ===== DIALOG: INVENTORY ENTRY ===== -->
|
||||
<template id="t-dialog-inventory">
|
||||
<dialog id="dialog-inventory" class="app-dialog">
|
||||
<h2 class="dialog-title"></h2>
|
||||
<form method="dialog" id="form-inventory">
|
||||
<div class="form-row">
|
||||
<label for="i-component">Component</label>
|
||||
<select id="i-component" required class="filter-select wide">
|
||||
<option value="">— select component —</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="i-type">Location type</label>
|
||||
<select id="i-type" required class="filter-select wide">
|
||||
<option value="physical">Physical location</option>
|
||||
<option value="bom">BOM / Drawing</option>
|
||||
<option value="digital">Digital / Note</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="i-ref" id="i-ref-label">Location reference</label>
|
||||
<input type="text" id="i-ref" autocomplete="off">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="i-qty">Quantity</label>
|
||||
<input type="text" id="i-qty" autocomplete="off" placeholder="e.g. 10, ~50, see BOM">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="i-notes">Notes</label>
|
||||
<input type="text" id="i-notes" autocomplete="off">
|
||||
</div>
|
||||
<div class="dialog-actions">
|
||||
<button type="button" class="btn btn-secondary" id="i-cancel">Cancel</button>
|
||||
<button type="submit" class="btn btn-primary" id="i-save">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</dialog>
|
||||
</template>
|
||||
|
||||
<!-- ===== DIALOG: FIELD DEFINITION ===== -->
|
||||
<template id="t-dialog-field">
|
||||
<dialog id="dialog-field" class="app-dialog">
|
||||
<h2 class="dialog-title"></h2>
|
||||
<form method="dialog" id="form-field">
|
||||
<div class="form-row">
|
||||
<label for="f-name">Field name</label>
|
||||
<input type="text" id="f-name" required autocomplete="off" placeholder="e.g. capacitance, mouser_order_no">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="f-unit">Unit <span class="label-hint">(optional, informational)</span></label>
|
||||
<input type="text" id="f-unit" autocomplete="off" placeholder="e.g. F, V, Ω, mm">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="f-description">Description</label>
|
||||
<input type="text" id="f-description" autocomplete="off">
|
||||
</div>
|
||||
<div class="dialog-actions">
|
||||
<button type="button" class="btn btn-secondary" id="f-cancel">Cancel</button>
|
||||
<button type="submit" class="btn btn-primary" id="f-save">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</dialog>
|
||||
</template>
|
||||
|
||||
<!-- ===== DIALOG: CONFIRM ===== -->
|
||||
<template id="t-dialog-confirm">
|
||||
<dialog id="dialog-confirm" class="app-dialog app-dialog-sm">
|
||||
<h2 class="dialog-title">Confirm</h2>
|
||||
<p id="confirm-message" class="confirm-message"></p>
|
||||
<div class="dialog-actions">
|
||||
<button type="button" class="btn btn-secondary" id="confirm-cancel">Cancel</button>
|
||||
<button type="button" class="btn btn-danger" id="confirm-ok">Delete</button>
|
||||
</div>
|
||||
</dialog>
|
||||
</template>
|
||||
152
server.mjs
Normal file
152
server.mjs
Normal file
@@ -0,0 +1,152 @@
|
||||
import express from 'express';
|
||||
import { generate_id } from './lib/ids.mjs';
|
||||
import {
|
||||
list_fields, get_field, set_field, delete_field,
|
||||
list_components, get_component, set_component, delete_component,
|
||||
list_inventory, get_inventory_entry, set_inventory_entry, delete_inventory_entry,
|
||||
} from './lib/storage.mjs';
|
||||
|
||||
const app = express();
|
||||
app.use(express.json());
|
||||
app.use(express.static(new URL('./public/', import.meta.url).pathname));
|
||||
|
||||
const PORT = process.env.PORT ?? 3020;
|
||||
|
||||
function ok(res, data = {}) { res.json({ ok: true, ...data }); }
|
||||
function fail(res, msg, status = 400) { res.status(status).json({ ok: false, error: msg }); }
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Field definitions
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
app.get('/api/fields', (req, res) => {
|
||||
ok(res, { fields: list_fields() });
|
||||
});
|
||||
|
||||
app.post('/api/fields', (req, res) => {
|
||||
const { name, unit = '', description = '' } = req.body;
|
||||
if (!name?.trim()) return fail(res, 'name is required');
|
||||
const field = {
|
||||
id: generate_id(),
|
||||
name: name.trim(),
|
||||
unit: unit.trim(),
|
||||
description: description.trim(),
|
||||
created_at: Date.now(),
|
||||
};
|
||||
set_field(field);
|
||||
ok(res, { field });
|
||||
});
|
||||
|
||||
app.put('/api/fields/:id', (req, res) => {
|
||||
const existing = get_field(req.params.id);
|
||||
if (!existing) return fail(res, 'not found', 404);
|
||||
const { name, unit, description } = req.body;
|
||||
const updated = { ...existing };
|
||||
if (name !== undefined) updated.name = name.trim();
|
||||
if (unit !== undefined) updated.unit = unit.trim();
|
||||
if (description !== undefined) updated.description = description.trim();
|
||||
set_field(updated);
|
||||
ok(res, { field: updated });
|
||||
});
|
||||
|
||||
app.delete('/api/fields/:id', (req, res) => {
|
||||
if (!delete_field(req.params.id)) return fail(res, 'not found', 404);
|
||||
ok(res);
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Components
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
app.get('/api/components', (req, res) => {
|
||||
ok(res, { components: list_components() });
|
||||
});
|
||||
|
||||
app.post('/api/components', (req, res) => {
|
||||
const { name, description = '', fields = {} } = req.body;
|
||||
if (!name?.trim()) return fail(res, 'name is required');
|
||||
const now = Date.now();
|
||||
const component = {
|
||||
id: generate_id(),
|
||||
name: name.trim(),
|
||||
description: description.trim(),
|
||||
fields,
|
||||
created_at: now,
|
||||
updated_at: now,
|
||||
};
|
||||
set_component(component);
|
||||
ok(res, { component });
|
||||
});
|
||||
|
||||
app.get('/api/components/:id', (req, res) => {
|
||||
const component = get_component(req.params.id);
|
||||
if (!component) return fail(res, 'not found', 404);
|
||||
ok(res, { component });
|
||||
});
|
||||
|
||||
app.put('/api/components/:id', (req, res) => {
|
||||
const existing = get_component(req.params.id);
|
||||
if (!existing) return fail(res, 'not found', 404);
|
||||
const { name, description, fields } = req.body;
|
||||
const updated = { ...existing, updated_at: Date.now() };
|
||||
if (name !== undefined) updated.name = name.trim();
|
||||
if (description !== undefined) updated.description = description.trim();
|
||||
if (fields !== undefined) updated.fields = fields;
|
||||
set_component(updated);
|
||||
ok(res, { component: updated });
|
||||
});
|
||||
|
||||
app.delete('/api/components/:id', (req, res) => {
|
||||
if (!delete_component(req.params.id)) return fail(res, 'not found', 404);
|
||||
ok(res);
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Inventory entries
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
app.get('/api/inventory', (req, res) => {
|
||||
ok(res, { entries: list_inventory() });
|
||||
});
|
||||
|
||||
app.post('/api/inventory', (req, res) => {
|
||||
const { component_id, location_type, location_ref = '', quantity = '', notes = '' } = req.body;
|
||||
if (!component_id) return fail(res, 'component_id is required');
|
||||
if (!location_type) return fail(res, 'location_type is required');
|
||||
if (!get_component(component_id)) return fail(res, 'component not found', 404);
|
||||
const now = Date.now();
|
||||
const entry = {
|
||||
id: generate_id(),
|
||||
component_id,
|
||||
location_type,
|
||||
location_ref: String(location_ref).trim(),
|
||||
quantity: String(quantity).trim(),
|
||||
notes: String(notes).trim(),
|
||||
created_at: now,
|
||||
updated_at: now,
|
||||
};
|
||||
set_inventory_entry(entry);
|
||||
ok(res, { entry });
|
||||
});
|
||||
|
||||
app.put('/api/inventory/:id', (req, res) => {
|
||||
const existing = get_inventory_entry(req.params.id);
|
||||
if (!existing) return fail(res, 'not found', 404);
|
||||
const { location_type, location_ref, quantity, notes } = req.body;
|
||||
const updated = { ...existing, updated_at: Date.now() };
|
||||
if (location_type !== undefined) updated.location_type = location_type;
|
||||
if (location_ref !== undefined) updated.location_ref = String(location_ref).trim();
|
||||
if (quantity !== undefined) updated.quantity = String(quantity).trim();
|
||||
if (notes !== undefined) updated.notes = String(notes).trim();
|
||||
set_inventory_entry(updated);
|
||||
ok(res, { entry: updated });
|
||||
});
|
||||
|
||||
app.delete('/api/inventory/:id', (req, res) => {
|
||||
if (!delete_inventory_entry(req.params.id)) return fail(res, 'not found', 404);
|
||||
ok(res);
|
||||
});
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Electronics Inventory running on http://localhost:${PORT}`);
|
||||
});
|
||||
Reference in New Issue
Block a user