PageSourceSearch

https://invoicecraftly.com/_assets/js/features/workspace-domain/document-projection.b3643b37819c.js

js invoicecraftly.com collected 2026-10-02 01:33:37 UTC 1,417 bytes, 40 lines download raw bytes

1import { computeInvoiceCalc } from '../invoice-calc/totals.1d66d63531e0.js';
2import {
3  buildDocumentIndexEntry,
4  validateWorkspaceDocument
5} from '../local-workspace/workspace-contract.e511908e4763.js';
6
7const DOCUMENT_KEY_PREFIX = 'invoice:';
8const PROJECTION_KEY = 'invoices-index';
9
10export async function buildDocumentProjection(storage) {
11  if (!storage || typeof storage.entries !== 'function') {
12    throw new Error('Enumerable workspace storage is required.');
13  }
14
15  const entries = await storage.entries(DOCUMENT_KEY_PREFIX);
16  const projection = [];
17  for (const [key, value] of entries) {
18    if (!key.startsWith(DOCUMENT_KEY_PREFIX)) continue;
19    try {
20      const document = validateWorkspaceDocument(value, 'Stored document');
21      if (document.deletedAt) continue;
22      projection.push(buildDocumentIndexEntry(document, computeInvoiceCalc(document).grandTotal));
23    } catch {
24      // Corrupt records are excluded from the disposable projection; the source record remains untouched.
25    }
26  }
27
28  return projection.sort((a, b) => String(b.updatedAt).localeCompare(String(a.updatedAt)));
29}
30
31export async function rebuildDocumentProjection(storage) {
32  const projection = await buildDocumentProjection(storage);
33  await storage.set(PROJECTION_KEY, projection);
34  return projection;
35}
36
37export const DOCUMENT_PROJECTION = Object.freeze({
38  key: PROJECTION_KEY,
39  sourcePrefix: DOCUMENT_KEY_PREFIX
40});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.