@particle-academy/holy-sheet 2.2.1 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -103,7 +103,7 @@ interface BuilderOptions {
103
103
  }
104
104
 
105
105
  /** This package's own version, pinned to package.json by `version.test.ts`. */
106
- declare const VERSION = "2.2.1";
106
+ declare const VERSION = "2.3.1";
107
107
  type Any$5 = any;
108
108
  /**
109
109
  * Agent — the structured-tool surface for Holy Sheet. Mirrors PHP `Agent`.
@@ -119,9 +119,13 @@ declare const Agent: {
119
119
  write(schema: Any$5, path: string): Promise<WriteResult>;
120
120
  /** JSON Schema for LLM tool-use. */
121
121
  toolDefinition(): Record<string, unknown>;
122
- /** Round-trip xlsx bytes back to a schema. Universal. */
122
+ /**
123
+ * Round-trip xlsx or ods bytes back to a schema. Universal. The format is
124
+ * told apart by content, never by name, and both describe to the same
125
+ * schema. Throws `UnsupportedFormatException` for anything else.
126
+ */
123
127
  read(input: Uint8Array | ArrayBuffer): Record<string, unknown>;
124
- /** Round-trip an xlsx file on disk back to a schema (Node only). */
128
+ /** Round-trip an xlsx or ods file on disk back to a schema (Node only). */
125
129
  describe(path: string): Promise<Record<string, unknown>>;
126
130
  /** Validate + conservative repairs in one call. */
127
131
  validateAndRepair(schema: Any$5): RepairResult;
@@ -140,7 +144,7 @@ type Any$4 = any;
140
144
  * over `Agent`. Provided for parity / DI ergonomics; most callers use `Agent`.
141
145
  */
142
146
  declare class HolySheet {
143
- static readonly VERSION = "2.2.1";
147
+ static readonly VERSION = "2.3.1";
144
148
  validate(schema: Any$4): ValidationError[];
145
149
  toBytes(schema: Any$4): Uint8Array;
146
150
  write(schema: Any$4, path: string): Promise<WriteResult>;
@@ -162,6 +166,23 @@ declare class SchemaException extends Error {
162
166
  static fromErrors(errors: ValidationError[]): SchemaException;
163
167
  getErrors(): ValidationError[];
164
168
  }
169
+ /**
170
+ * Thrown by `Agent.read()` / `Agent.describe()` for a file that is neither an
171
+ * xlsx workbook nor an OpenDocument spreadsheet. Mirrors PHP
172
+ * `UnsupportedFormatException`.
173
+ *
174
+ * It extends Error, which is what an unreadable file threw before it existed,
175
+ * so an existing catch still catches it. `mimetype` carries what the package
176
+ * declared about itself when it declared anything (an OpenDocument TEXT file,
177
+ * say), so a caller can say "that is a document, not a spreadsheet".
178
+ */
179
+ declare class UnsupportedFormatException extends Error {
180
+ readonly path: string | null;
181
+ readonly mimetype: string | null;
182
+ constructor(message: string, path?: string | null, mimetype?: string | null);
183
+ static notAZip(path?: string | null): UnsupportedFormatException;
184
+ static unknownPackage(path: string | null, mimetype: string | null): UnsupportedFormatException;
185
+ }
165
186
 
166
187
  type Any$3 = any;
167
188
  /** Hand-rolled schema validator. Mirrors PHP `Schema\Validator`. */
@@ -301,6 +322,12 @@ declare class Normalizer {
301
322
  declare class FormulaLinter {
302
323
  private index;
303
324
  private cache;
325
+ /**
326
+ * Every sheet name, keyed by its lower-cased form. Excel matches sheet names
327
+ * without regard to case, and a reference to a sheet that is not here is
328
+ * `#REF!` rather than a range of blanks.
329
+ */
330
+ private sheetNames;
304
331
  lint(schema: unknown): FormulaProblem[];
305
332
  private buildIndex;
306
333
  private isError;
@@ -316,6 +343,10 @@ declare class FormulaLinter {
316
343
  private parsePrimary;
317
344
  private resolveRefOrRange;
318
345
  private cleanRef;
346
+ /**
347
+ * Unwrap the single quotes Excel puts around a sheet name that needs them,
348
+ * and turn its doubled quote back into one: 'Q3 ''Final''' is Q3 'Final'.
349
+ */
319
350
  private cleanSheetName;
320
351
  private resolveCell;
321
352
  private resolveRange;
@@ -332,6 +363,7 @@ declare class FormulaLinter {
332
363
  private minMax;
333
364
  private ifFn;
334
365
  private hint;
366
+ private hintRef;
335
367
  private hintValue;
336
368
  }
337
369
 
@@ -372,12 +404,42 @@ declare class XlsxWriter {
372
404
  declare class XlsxReader {
373
405
  describe(bytes: Uint8Array): Record<string, unknown>;
374
406
  readWorkbook(bytes: Uint8Array): Workbook;
407
+ /** Read an already-unzipped package (name -> bytes), so a caller that sniffed it does not unzip twice. */
408
+ readFiles(files: Record<string, Uint8Array>): Workbook;
375
409
  private parseDocProps;
376
- private workbookToSchema;
377
- private sheetToSchema;
378
- private cellToSchema;
379
410
  }
380
411
 
412
+ /**
413
+ * OpenDocument Spreadsheet (.ods) reader — bytes → Holy Sheet schema, the same
414
+ * schema the xlsx reader returns. Mirrors PHP `Reader\OdsReader`, where what is
415
+ * and is not mapped is documented.
416
+ */
417
+ declare class OdsReader {
418
+ describe(bytes: Uint8Array): Record<string, unknown>;
419
+ readWorkbook(bytes: Uint8Array): Workbook;
420
+ /** Read an already-unzipped package (name -> bytes). */
421
+ readFiles(files: Record<string, Uint8Array>): Workbook;
422
+ private readSheet;
423
+ private walkRows;
424
+ private readRow;
425
+ }
426
+
427
+ type SpreadsheetFormat = "xlsx" | "ods";
428
+ /**
429
+ * Which reader a file needs, decided from its contents, never its extension.
430
+ * Mirrors PHP `Reader\FormatSniffer`.
431
+ *
432
+ * An OpenDocument package names itself in its `mimetype` entry; an xlsx has no
433
+ * such entry and is recognised by `xl/workbook.xml`. Anything else is refused
434
+ * by name. The unzipped entries are returned so the reader does not unzip again.
435
+ */
436
+ declare const FormatSniffer: {
437
+ sniff(bytes: Uint8Array, path?: string | null): {
438
+ format: SpreadsheetFormat;
439
+ files: Record<string, Uint8Array>;
440
+ };
441
+ };
442
+
381
443
  type Any = any;
382
444
  /**
383
445
  * Flat rows (+ optional headers) → Holy Sheet schema with inferred column types.
@@ -417,4 +479,4 @@ declare function zipSync(files: ZipFile[]): Uint8Array;
417
479
 
418
480
  declare function unzipSync(data: Uint8Array): Record<string, Uint8Array>;
419
481
 
420
- export { Agent, type AggOp, ArrayBuilder, type BuilderOptions, CellAddress, type CellData, type CellFormatInput, type CellPrimitive, type ColumnSchema, type ColumnType, type CommentInput, CsvBuilder, type DisplayFormat, FormulaLinter, type FormulaProblem, HolySheet, type HolySheetSchema, Inference, Normalizer, type RepairResult, Repairer, type RowCell, SchemaException, type SheetSchema, Theme, type ThemeKey, VERSION, type ValidationError, Validator, type WriteResult, XlsxReader, XlsxWriter, type ZipFile, unzipSync, zipSync };
482
+ export { Agent, type AggOp, ArrayBuilder, type BuilderOptions, CellAddress, type CellData, type CellFormatInput, type CellPrimitive, type ColumnSchema, type ColumnType, type CommentInput, CsvBuilder, type DisplayFormat, FormatSniffer, FormulaLinter, type FormulaProblem, HolySheet, type HolySheetSchema, Inference, Normalizer, OdsReader, type RepairResult, Repairer, type RowCell, SchemaException, type SheetSchema, type SpreadsheetFormat, Theme, type ThemeKey, UnsupportedFormatException, VERSION, type ValidationError, Validator, type WriteResult, XlsxReader, XlsxWriter, type ZipFile, unzipSync, zipSync };
package/dist/index.d.ts CHANGED
@@ -103,7 +103,7 @@ interface BuilderOptions {
103
103
  }
104
104
 
105
105
  /** This package's own version, pinned to package.json by `version.test.ts`. */
106
- declare const VERSION = "2.2.1";
106
+ declare const VERSION = "2.3.1";
107
107
  type Any$5 = any;
108
108
  /**
109
109
  * Agent — the structured-tool surface for Holy Sheet. Mirrors PHP `Agent`.
@@ -119,9 +119,13 @@ declare const Agent: {
119
119
  write(schema: Any$5, path: string): Promise<WriteResult>;
120
120
  /** JSON Schema for LLM tool-use. */
121
121
  toolDefinition(): Record<string, unknown>;
122
- /** Round-trip xlsx bytes back to a schema. Universal. */
122
+ /**
123
+ * Round-trip xlsx or ods bytes back to a schema. Universal. The format is
124
+ * told apart by content, never by name, and both describe to the same
125
+ * schema. Throws `UnsupportedFormatException` for anything else.
126
+ */
123
127
  read(input: Uint8Array | ArrayBuffer): Record<string, unknown>;
124
- /** Round-trip an xlsx file on disk back to a schema (Node only). */
128
+ /** Round-trip an xlsx or ods file on disk back to a schema (Node only). */
125
129
  describe(path: string): Promise<Record<string, unknown>>;
126
130
  /** Validate + conservative repairs in one call. */
127
131
  validateAndRepair(schema: Any$5): RepairResult;
@@ -140,7 +144,7 @@ type Any$4 = any;
140
144
  * over `Agent`. Provided for parity / DI ergonomics; most callers use `Agent`.
141
145
  */
142
146
  declare class HolySheet {
143
- static readonly VERSION = "2.2.1";
147
+ static readonly VERSION = "2.3.1";
144
148
  validate(schema: Any$4): ValidationError[];
145
149
  toBytes(schema: Any$4): Uint8Array;
146
150
  write(schema: Any$4, path: string): Promise<WriteResult>;
@@ -162,6 +166,23 @@ declare class SchemaException extends Error {
162
166
  static fromErrors(errors: ValidationError[]): SchemaException;
163
167
  getErrors(): ValidationError[];
164
168
  }
169
+ /**
170
+ * Thrown by `Agent.read()` / `Agent.describe()` for a file that is neither an
171
+ * xlsx workbook nor an OpenDocument spreadsheet. Mirrors PHP
172
+ * `UnsupportedFormatException`.
173
+ *
174
+ * It extends Error, which is what an unreadable file threw before it existed,
175
+ * so an existing catch still catches it. `mimetype` carries what the package
176
+ * declared about itself when it declared anything (an OpenDocument TEXT file,
177
+ * say), so a caller can say "that is a document, not a spreadsheet".
178
+ */
179
+ declare class UnsupportedFormatException extends Error {
180
+ readonly path: string | null;
181
+ readonly mimetype: string | null;
182
+ constructor(message: string, path?: string | null, mimetype?: string | null);
183
+ static notAZip(path?: string | null): UnsupportedFormatException;
184
+ static unknownPackage(path: string | null, mimetype: string | null): UnsupportedFormatException;
185
+ }
165
186
 
166
187
  type Any$3 = any;
167
188
  /** Hand-rolled schema validator. Mirrors PHP `Schema\Validator`. */
@@ -301,6 +322,12 @@ declare class Normalizer {
301
322
  declare class FormulaLinter {
302
323
  private index;
303
324
  private cache;
325
+ /**
326
+ * Every sheet name, keyed by its lower-cased form. Excel matches sheet names
327
+ * without regard to case, and a reference to a sheet that is not here is
328
+ * `#REF!` rather than a range of blanks.
329
+ */
330
+ private sheetNames;
304
331
  lint(schema: unknown): FormulaProblem[];
305
332
  private buildIndex;
306
333
  private isError;
@@ -316,6 +343,10 @@ declare class FormulaLinter {
316
343
  private parsePrimary;
317
344
  private resolveRefOrRange;
318
345
  private cleanRef;
346
+ /**
347
+ * Unwrap the single quotes Excel puts around a sheet name that needs them,
348
+ * and turn its doubled quote back into one: 'Q3 ''Final''' is Q3 'Final'.
349
+ */
319
350
  private cleanSheetName;
320
351
  private resolveCell;
321
352
  private resolveRange;
@@ -332,6 +363,7 @@ declare class FormulaLinter {
332
363
  private minMax;
333
364
  private ifFn;
334
365
  private hint;
366
+ private hintRef;
335
367
  private hintValue;
336
368
  }
337
369
 
@@ -372,12 +404,42 @@ declare class XlsxWriter {
372
404
  declare class XlsxReader {
373
405
  describe(bytes: Uint8Array): Record<string, unknown>;
374
406
  readWorkbook(bytes: Uint8Array): Workbook;
407
+ /** Read an already-unzipped package (name -> bytes), so a caller that sniffed it does not unzip twice. */
408
+ readFiles(files: Record<string, Uint8Array>): Workbook;
375
409
  private parseDocProps;
376
- private workbookToSchema;
377
- private sheetToSchema;
378
- private cellToSchema;
379
410
  }
380
411
 
412
+ /**
413
+ * OpenDocument Spreadsheet (.ods) reader — bytes → Holy Sheet schema, the same
414
+ * schema the xlsx reader returns. Mirrors PHP `Reader\OdsReader`, where what is
415
+ * and is not mapped is documented.
416
+ */
417
+ declare class OdsReader {
418
+ describe(bytes: Uint8Array): Record<string, unknown>;
419
+ readWorkbook(bytes: Uint8Array): Workbook;
420
+ /** Read an already-unzipped package (name -> bytes). */
421
+ readFiles(files: Record<string, Uint8Array>): Workbook;
422
+ private readSheet;
423
+ private walkRows;
424
+ private readRow;
425
+ }
426
+
427
+ type SpreadsheetFormat = "xlsx" | "ods";
428
+ /**
429
+ * Which reader a file needs, decided from its contents, never its extension.
430
+ * Mirrors PHP `Reader\FormatSniffer`.
431
+ *
432
+ * An OpenDocument package names itself in its `mimetype` entry; an xlsx has no
433
+ * such entry and is recognised by `xl/workbook.xml`. Anything else is refused
434
+ * by name. The unzipped entries are returned so the reader does not unzip again.
435
+ */
436
+ declare const FormatSniffer: {
437
+ sniff(bytes: Uint8Array, path?: string | null): {
438
+ format: SpreadsheetFormat;
439
+ files: Record<string, Uint8Array>;
440
+ };
441
+ };
442
+
381
443
  type Any = any;
382
444
  /**
383
445
  * Flat rows (+ optional headers) → Holy Sheet schema with inferred column types.
@@ -417,4 +479,4 @@ declare function zipSync(files: ZipFile[]): Uint8Array;
417
479
 
418
480
  declare function unzipSync(data: Uint8Array): Record<string, Uint8Array>;
419
481
 
420
- export { Agent, type AggOp, ArrayBuilder, type BuilderOptions, CellAddress, type CellData, type CellFormatInput, type CellPrimitive, type ColumnSchema, type ColumnType, type CommentInput, CsvBuilder, type DisplayFormat, FormulaLinter, type FormulaProblem, HolySheet, type HolySheetSchema, Inference, Normalizer, type RepairResult, Repairer, type RowCell, SchemaException, type SheetSchema, Theme, type ThemeKey, VERSION, type ValidationError, Validator, type WriteResult, XlsxReader, XlsxWriter, type ZipFile, unzipSync, zipSync };
482
+ export { Agent, type AggOp, ArrayBuilder, type BuilderOptions, CellAddress, type CellData, type CellFormatInput, type CellPrimitive, type ColumnSchema, type ColumnType, type CommentInput, CsvBuilder, type DisplayFormat, FormatSniffer, FormulaLinter, type FormulaProblem, HolySheet, type HolySheetSchema, Inference, Normalizer, OdsReader, type RepairResult, Repairer, type RowCell, SchemaException, type SheetSchema, type SpreadsheetFormat, Theme, type ThemeKey, UnsupportedFormatException, VERSION, type ValidationError, Validator, type WriteResult, XlsxReader, XlsxWriter, type ZipFile, unzipSync, zipSync };