@candidstartup/infinisheet-types 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.d.ts +148 -4
- package/dist/index.js +23 -6
- package/dist/index.js.map +1 -1
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[](https://github.com/TheCandidStartup/infinisheet/blob/main/README.md#typescript-semantic-versioning)
|
|
2
2
|
[](https://www.npmjs.com/package/@candidstartup/infinisheet-types)
|
|
3
3
|
[](https://www.npmjs.com/package/@candidstartup/infinisheet-types)
|
|
4
4
|
[](https://github.com/TheCandidStartup/infinisheet/actions/workflows/build.yml)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,116 @@
|
|
|
1
|
+
import { Ok as Ok$1, Err as Err$1 } from 'neverthrow';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* An `Ok` instance is the *successful* variant of the {@link Result} type,
|
|
5
|
+
* representing a successful outcome from an operation which may fail.
|
|
6
|
+
*
|
|
7
|
+
* Implemented using [`neverthrow`](https://github.com/supermacro/neverthrow)
|
|
8
|
+
*
|
|
9
|
+
* @typeParam T - The type of the value contained in the `Result` for the success case
|
|
10
|
+
* @typeParam E - The type of the error contained in the `Result` for the failure case
|
|
11
|
+
*/
|
|
12
|
+
interface Ok<T, E> extends Ok$1<T, E> {
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* An `Err` instance is the failure variant of the {@link Result} type,
|
|
16
|
+
* representing a failure outcome from an operation which may fail.
|
|
17
|
+
*
|
|
18
|
+
* Implemented using [`neverthrow`](https://github.com/supermacro/neverthrow)
|
|
19
|
+
*
|
|
20
|
+
* @typeParam T - The type of the value contained in the `Result` for the success case
|
|
21
|
+
* @typeParam E - The type of the error contained in the `Result` for the failure case
|
|
22
|
+
*/
|
|
23
|
+
interface Err<T, E> extends Err$1<T, E> {
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A `Result` represents success ({@link Ok}) or failure ({@link Err}).
|
|
27
|
+
*
|
|
28
|
+
* Compatible with [`neverthrow`](https://github.com/supermacro/neverthrow)
|
|
29
|
+
*
|
|
30
|
+
* @typeParam T - The type of the value contained in the `Result` for the success case
|
|
31
|
+
* @typeParam E - The type of the error contained in the `Result` for the failure case
|
|
32
|
+
*/
|
|
33
|
+
type Result<T, E> = Ok<T, E> | Err<T, E>;
|
|
34
|
+
/**
|
|
35
|
+
* Create an instance of {@link Ok}.
|
|
36
|
+
*
|
|
37
|
+
* If you need to create an instance with a specific type (as you do whenever you
|
|
38
|
+
* are not constructing immediately for a function return or as an argument to a
|
|
39
|
+
* function), you can use a type parameter:
|
|
40
|
+
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* const yayNumber = ok<number, string>(12);
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* Note: passing nothing will produce a `Result<void, E>`, passing `undefined` will
|
|
46
|
+
* produce a `Result<undefined, E>` which is compatible with `Result<void, E>`.
|
|
47
|
+
*
|
|
48
|
+
* ```ts
|
|
49
|
+
* const normalResult = ok<number, string>(42);
|
|
50
|
+
* const explicitUndefined = ok<undefined, string>(undefined);
|
|
51
|
+
* const implicitVoid = ok<void, string>();
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* In the context of an immediate function return, or an arrow function with a
|
|
55
|
+
* single expression value, you do not have to specify the types, so this can be
|
|
56
|
+
* quite convenient.
|
|
57
|
+
*
|
|
58
|
+
* ```ts
|
|
59
|
+
* const arrowValidate = (data: SomeData): Result<void, string> =>
|
|
60
|
+
* isValid(data) ? ok() : err('something was wrong!');
|
|
61
|
+
*
|
|
62
|
+
* function fnValidate(data: someData): Result<void, string> {
|
|
63
|
+
* return isValid(data) ? ok() : err('something was wrong');
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @typeParam T - The type of the value contained in the `Result` for the success case
|
|
68
|
+
* @typeParam E - The type of the error contained in the `Result` for the failure case
|
|
69
|
+
* @param value - The value to wrap in a `Result.Ok`.
|
|
70
|
+
*/
|
|
71
|
+
declare function ok<T, E = never>(value: T): Ok<T, E>;
|
|
72
|
+
declare function ok<_T extends void = void, E = never>(value: void): Ok<void, E>;
|
|
73
|
+
/**
|
|
74
|
+
* Create an instance of {@link Err}.
|
|
75
|
+
*
|
|
76
|
+
* If you need to create an instance with a specific type (as you do whenever you
|
|
77
|
+
* are not constructing immediately for a function return or as an argument to a
|
|
78
|
+
* function), you can use a type parameter:
|
|
79
|
+
*
|
|
80
|
+
* ```ts
|
|
81
|
+
* const notString = err<number, string>('something went wrong');
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* Note: passing nothing will produce a `Result<T, void>`, passing `undefined` will
|
|
85
|
+
* produce a `Result<T, undefined>` which is compatible with `Result<T, void>`.
|
|
86
|
+
*
|
|
87
|
+
* ```ts
|
|
88
|
+
* const normalResult = err<number, string>('oh no');
|
|
89
|
+
* const explicitUndefined = err<number, undefined>(undefined);
|
|
90
|
+
* const implicitVoid = err<number, void>();
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* In the context of an immediate function return, or an arrow function with a
|
|
94
|
+
* single expression value, you do not have to specify the types, so this can be
|
|
95
|
+
* quite convenient.
|
|
96
|
+
*
|
|
97
|
+
* ```ts
|
|
98
|
+
* const arrowValidate = (data: SomeData): Result<number, string> =>
|
|
99
|
+
* isValid(data) ? ok(42) : err('something went wrong');
|
|
100
|
+
*
|
|
101
|
+
* function fnValidate(data: someData): Result<number, string> {
|
|
102
|
+
* return isValid(data) ? ok(42) : err('something went wrong');
|
|
103
|
+
* }
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
106
|
+
* @typeParam T - The type of the value contained in the `Result` for the success case
|
|
107
|
+
* @typeParam E - The type of the error contained in the `Result` for the failure case
|
|
108
|
+
* @param err - The value to wrap in a `Result.Err`.
|
|
109
|
+
*/
|
|
110
|
+
declare function err<T = never, E extends string = string>(err: E): Err<T, E>;
|
|
111
|
+
declare function err<T = never, E = unknown>(err: E): Err<T, E>;
|
|
112
|
+
declare function err<T = never, _E extends void = void>(err: void): Err<T, void>;
|
|
113
|
+
|
|
1
114
|
/**
|
|
2
115
|
* Interface used to determine the size and positioning offset for items in a single dimension.
|
|
3
116
|
*/
|
|
@@ -70,6 +183,31 @@ interface CellError {
|
|
|
70
183
|
* explicitly marked as empty.
|
|
71
184
|
*/
|
|
72
185
|
type CellValue = string | number | boolean | null | undefined | CellError;
|
|
186
|
+
/** Type that represents an error when validating data to be stored in a cell */
|
|
187
|
+
interface ValidationError {
|
|
188
|
+
/** Discriminated union tag */
|
|
189
|
+
type: 'ValidationError';
|
|
190
|
+
/** End user message describing the problem */
|
|
191
|
+
message: string;
|
|
192
|
+
}
|
|
193
|
+
/** Convenience method that creates a {@link ValidationError} */
|
|
194
|
+
declare function validationError(message: string): ValidationError;
|
|
195
|
+
/** Type that represents an error when storing data in a cell */
|
|
196
|
+
interface StorageError {
|
|
197
|
+
/** Discriminated union tag */
|
|
198
|
+
type: 'StorageError';
|
|
199
|
+
/** End user message describing the problem */
|
|
200
|
+
message: string;
|
|
201
|
+
/** HTTP style status code
|
|
202
|
+
*
|
|
203
|
+
* Describes the type of problem encountered. Expected to be a 4XX or 5XX code.
|
|
204
|
+
*/
|
|
205
|
+
statusCode?: number | undefined;
|
|
206
|
+
}
|
|
207
|
+
/** Convenience method that creates a {@link StorageError} */
|
|
208
|
+
declare function storageError(message: string, statusCode?: number): StorageError;
|
|
209
|
+
/** Types of error that can be returned by {@link SpreadsheetData} methods */
|
|
210
|
+
type SpreadsheetDataError = ValidationError | StorageError;
|
|
73
211
|
/**
|
|
74
212
|
* Interface used to access the data in a spreadsheet
|
|
75
213
|
*
|
|
@@ -99,9 +237,14 @@ interface SpreadsheetData<Snapshot> {
|
|
|
99
237
|
getCellFormat(snapshot: Snapshot, row: number, column: number): string | undefined;
|
|
100
238
|
/** Set value and format of specified cell
|
|
101
239
|
*
|
|
102
|
-
* @returns
|
|
240
|
+
* @returns `Ok` if the change was successfully applied
|
|
241
|
+
*/
|
|
242
|
+
setCellValueAndFormat(row: number, column: number, value: CellValue, format: string | undefined): Result<void, SpreadsheetDataError>;
|
|
243
|
+
/** Check whether value and format are valid to set for specified cell
|
|
244
|
+
*
|
|
245
|
+
* @returns `Ok` if the value and format are valid
|
|
103
246
|
*/
|
|
104
|
-
|
|
247
|
+
isValidCellValueAndFormat(row: number, column: number, value: CellValue, format: string | undefined): Result<void, ValidationError>;
|
|
105
248
|
}
|
|
106
249
|
declare class EmptySpreadsheetData implements SpreadsheetData<number> {
|
|
107
250
|
subscribe(_onDataChange: () => void): () => void;
|
|
@@ -112,7 +255,8 @@ declare class EmptySpreadsheetData implements SpreadsheetData<number> {
|
|
|
112
255
|
getColumnItemOffsetMapping(_snapshot: number): ItemOffsetMapping;
|
|
113
256
|
getCellValue(_snapshot: number, _row: number, _column: number): CellValue;
|
|
114
257
|
getCellFormat(_snapshot: number, _row: number, _column: number): string | undefined;
|
|
115
|
-
setCellValueAndFormat(_row: number, _column: number, _value: CellValue, _format: string | undefined):
|
|
258
|
+
setCellValueAndFormat(_row: number, _column: number, _value: CellValue, _format: string | undefined): Result<void, SpreadsheetDataError>;
|
|
259
|
+
isValidCellValueAndFormat(_row: number, _column: number, _value: CellValue, _format: string | undefined): Result<void, ValidationError>;
|
|
116
260
|
}
|
|
117
261
|
|
|
118
262
|
/** Classic Spreadsheet reference to Column (e.g "A") */
|
|
@@ -132,4 +276,4 @@ declare function rowColRefToCoords(ref: RowColRef): RowColCoords;
|
|
|
132
276
|
/** Converts {@link RowColCoords} to a {@link RowColRef} */
|
|
133
277
|
declare function rowColCoordsToRef(row: number | undefined, col: number | undefined): RowColRef;
|
|
134
278
|
|
|
135
|
-
export { type CellError, type CellErrorValue, type CellValue, type ColRef, EmptySpreadsheetData, FixedSizeItemOffsetMapping, type ItemOffsetMapping, type RowColCoords, type RowColRef, type SpreadsheetData, VariableSizeItemOffsetMapping, colRefToIndex, indexToColRef, rowColCoordsToRef, rowColRefToCoords, splitRowColRef };
|
|
279
|
+
export { type CellError, type CellErrorValue, type CellValue, type ColRef, EmptySpreadsheetData, type Err, FixedSizeItemOffsetMapping, type ItemOffsetMapping, type Ok, type Result, type RowColCoords, type RowColRef, type SpreadsheetData, type SpreadsheetDataError, type StorageError, type ValidationError, VariableSizeItemOffsetMapping, colRefToIndex, err, indexToColRef, ok, rowColCoordsToRef, rowColRefToCoords, splitRowColRef, storageError, validationError };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
import { ok as ok$1, err as err$1 } from 'neverthrow';
|
|
2
|
+
|
|
3
|
+
function ok(value) {
|
|
4
|
+
return ok$1(value);
|
|
5
|
+
}
|
|
6
|
+
function err(err) {
|
|
7
|
+
return err$1(err);
|
|
8
|
+
}
|
|
9
|
+
|
|
1
10
|
/**
|
|
2
11
|
* Implementation of {@link ItemOffsetMapping} for use when all items have a fixed size
|
|
3
12
|
*/
|
|
@@ -54,9 +63,7 @@ class VariableSizeItemOffsetMapping {
|
|
|
54
63
|
}
|
|
55
64
|
offsetToItem(offset) {
|
|
56
65
|
let startOffset = 0;
|
|
57
|
-
const
|
|
58
|
-
for (let i = 0; i < length; i++) {
|
|
59
|
-
const size = this.#sizes[i];
|
|
66
|
+
for (const [i, size] of this.#sizes.entries()) {
|
|
60
67
|
if (startOffset + size > offset) {
|
|
61
68
|
return [i, startOffset];
|
|
62
69
|
}
|
|
@@ -64,12 +71,21 @@ class VariableSizeItemOffsetMapping {
|
|
|
64
71
|
}
|
|
65
72
|
const itemIndex = Math.floor((offset - startOffset) / this.#defaultItemSize);
|
|
66
73
|
startOffset += itemIndex * this.#defaultItemSize;
|
|
74
|
+
const length = this.#sizes.length;
|
|
67
75
|
return [itemIndex + length, startOffset];
|
|
68
76
|
}
|
|
69
77
|
#defaultItemSize;
|
|
70
78
|
#sizes;
|
|
71
79
|
}
|
|
72
80
|
|
|
81
|
+
/** Convenience method that creates a {@link ValidationError} */
|
|
82
|
+
function validationError(message) {
|
|
83
|
+
return { type: 'ValidationError', message };
|
|
84
|
+
}
|
|
85
|
+
/** Convenience method that creates a {@link StorageError} */
|
|
86
|
+
function storageError(message, statusCode) {
|
|
87
|
+
return { type: 'StorageError', message, statusCode };
|
|
88
|
+
}
|
|
73
89
|
const rowItemOffsetMapping = new FixedSizeItemOffsetMapping(30);
|
|
74
90
|
const columnItemOffsetMapping = new FixedSizeItemOffsetMapping(100);
|
|
75
91
|
class EmptySpreadsheetData {
|
|
@@ -81,7 +97,8 @@ class EmptySpreadsheetData {
|
|
|
81
97
|
getColumnItemOffsetMapping(_snapshot) { return columnItemOffsetMapping; }
|
|
82
98
|
getCellValue(_snapshot, _row, _column) { return null; }
|
|
83
99
|
getCellFormat(_snapshot, _row, _column) { return undefined; }
|
|
84
|
-
setCellValueAndFormat(_row, _column, _value, _format) { return
|
|
100
|
+
setCellValueAndFormat(_row, _column, _value, _format) { return err(storageError("Not implemented", 501)); }
|
|
101
|
+
isValidCellValueAndFormat(_row, _column, _value, _format) { return ok(); }
|
|
85
102
|
}
|
|
86
103
|
|
|
87
104
|
/** Converts a {@link ColRef} to the 0-based index of the column */
|
|
@@ -111,7 +128,7 @@ function splitRowColRef(ref) {
|
|
|
111
128
|
if (!found)
|
|
112
129
|
return [undefined, undefined];
|
|
113
130
|
const col = found[1];
|
|
114
|
-
const row = parseInt(found[2]);
|
|
131
|
+
const row = found[2] ? parseInt(found[2]) : 0;
|
|
115
132
|
return [(row > 0) ? row - 1 : undefined, col ? col : undefined];
|
|
116
133
|
}
|
|
117
134
|
/** Converts a {@link RowColRef} to {@link RowColCoords} */
|
|
@@ -139,5 +156,5 @@ function rowColCoordsToRef(row, col) {
|
|
|
139
156
|
}
|
|
140
157
|
}
|
|
141
158
|
|
|
142
|
-
export { EmptySpreadsheetData, FixedSizeItemOffsetMapping, VariableSizeItemOffsetMapping, colRefToIndex, indexToColRef, rowColCoordsToRef, rowColRefToCoords, splitRowColRef };
|
|
159
|
+
export { EmptySpreadsheetData, FixedSizeItemOffsetMapping, VariableSizeItemOffsetMapping, colRefToIndex, err, indexToColRef, ok, rowColCoordsToRef, rowColRefToCoords, splitRowColRef, storageError, validationError };
|
|
143
160
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/FixedSizeItemOffsetMapping.ts","../src/VariableSizeItemOffsetMapping.ts","../src/SpreadsheetData.ts","../src/RowColRef.ts"],"sourcesContent":["import type { ItemOffsetMapping } from './ItemOffsetMapping';\n\n/**\n * Implementation of {@link ItemOffsetMapping} for use when all items have a fixed size\n */\nexport class FixedSizeItemOffsetMapping implements ItemOffsetMapping {\n /**\n * @param itemSize - Size to use for all items\n */\n constructor (itemSize: number) {\n this.#fixedItemSize = itemSize;\n }\n\n itemSize(_itemIndex: number): number {\n return this.#fixedItemSize;\n }\n\n itemOffset(itemIndex: number): number {\n return itemIndex * this.#fixedItemSize;\n }\n\n offsetToItem(offset: number): [itemIndex: number, startOffset: number] {\n const itemIndex = Math.floor(offset / this.#fixedItemSize);\n const startOffset = itemIndex * this.#fixedItemSize;\n\n return [itemIndex, startOffset];\n }\n\n #fixedItemSize: number;\n}\n\n","import type { ItemOffsetMapping } from './ItemOffsetMapping';\n\n/**\n * Implementation of {@link ItemOffsetMapping} for use when initial items have variable sizes.\n */\nexport class VariableSizeItemOffsetMapping implements ItemOffsetMapping {\n /**\n * @param defaultItemSize - Size to use for all other items\n * @param sizes - Array of sizes to use for the initial items, one size per item\n */\n constructor (defaultItemSize: number, sizes: number[]) {\n this.#defaultItemSize = defaultItemSize;\n this.#sizes = sizes;\n }\n\n itemSize(itemIndex: number): number {\n return (itemIndex < this.#sizes.length) ? this.#sizes[itemIndex] : this.#defaultItemSize;\n }\n\n itemOffset(itemIndex: number): number {\n let offset = 0;\n let length = this.#sizes.length;\n if (itemIndex > length) {\n const numDefaultSize = itemIndex - length;\n offset = numDefaultSize * this.#defaultItemSize;\n } else {\n length = itemIndex;\n }\n \n for (let i = 0; i < length; i ++)\n {\n offset += this.#sizes[i];\n }\n\n return offset;\n }\n\n offsetToItem(offset: number): [itemIndex: number, startOffset: number] {\n let startOffset = 0;\n const length = this.#sizes.length;\n for (let i = 0; i < length; i ++) {\n const size = this.#sizes[i];\n if (startOffset + size > offset) {\n return [i, startOffset];\n }\n startOffset += size;\n }\n\n const itemIndex = Math.floor((offset - startOffset) / this.#defaultItemSize);\n startOffset += itemIndex * this.#defaultItemSize;\n\n return [itemIndex+length, startOffset];\n }\n\n #defaultItemSize: number;\n #sizes: number[];\n}\n","import type { ItemOffsetMapping } from \"./ItemOffsetMapping\";\nimport { FixedSizeItemOffsetMapping } from \"./FixedSizeItemOffsetMapping\";\n\n/** Possible spreadsheet error values\n * \n * Includes those that can be returned by `ERROR.TYPE` and additional values\n * introduced by more recent versions of Excel.\n*/\nexport type CellErrorValue = '#NULL!' | \n '#DIV/0!' |\n '#VALUE!' |\n '#REF!' |\n '#NAME?' |\n '#NUM!' |\n '#N/A' |\n '#GETTING_DATA' |\n '#SPILL!' |\n '#UNKNOWN!' |\n '#FIELD!' |\n '#CALC!';\n\n/** Type that represents an error value stored in a cell\n * \n * Defined as a discriminated union so that additional cell value types\n * can be added in future.\n */\nexport interface CellError {\n /** Discriminated union tag */\n type: 'CellError',\n\n /** {@link CellErrorValue | Error Value} */\n value: CellErrorValue;\n};\n\n/** Possible types for a cell value \n * \n * The native JavaScript types string, number and boolean represent the *Text*, *Number* and *Logical*\n * spreadsheet data types. {@link CellError} represents an *Error Value*.\n * \n * Undefined is used to represent a cell with no defined value. Null represents a cell that has been\n * explicitly marked as empty. \n*/\nexport type CellValue = string | number | boolean | null | undefined | CellError;\n\n/**\n * Interface used to access the data in a spreadsheet\n * \n * The data exposed through the interface may change over time outside of any changes made through the interface. The caller\n * can use the {@link subscribe} method to be notified when the data changes. When reading data, the caller must first request\n * a snapshot using {@link getSnapshot}. All values returned by gettors are relative to a specified snapshot. The values will be\n * consistent with each other as long as the same snapshot is used.\n * \n * @typeParam Snapshot - Type of snapshot. Implementations are free to use whatever type makes sense for them.\n */\nexport interface SpreadsheetData<Snapshot> {\n /** Subscribe to data changes */\n subscribe(onDataChange: () => void): () => void,\n\n /** Return a snapshot to use when accessing values at a consistent point in time */\n getSnapshot(): Snapshot,\n\n /** Number of rows in the spreadsheet */\n getRowCount(snapshot: Snapshot): number,\n\n /** {@link ItemOffsetMapping} which describes sizes and offsets to start of rows */\n getRowItemOffsetMapping(snapshot: Snapshot): ItemOffsetMapping,\n\n /** Number of columns in the spreadsheet */\n getColumnCount(snapshot: Snapshot): number,\n\n /** {@link ItemOffsetMapping} which describes sizes and offsets to start of columns */\n getColumnItemOffsetMapping(snapshot: Snapshot): ItemOffsetMapping,\n\n /** Value of specified cell using 0-based row and column indexes */\n getCellValue(snapshot: Snapshot, row: number, column: number): CellValue;\n\n /** Format of specified cell using 0-based row and column indexes */\n getCellFormat(snapshot: Snapshot, row: number, column: number): string | undefined;\n\n /** Set value and format of specified cell\n * \n * @returns True if the change was successfully applied\n */\n setCellValueAndFormat(row: number, column: number, value: CellValue, format: string | undefined): boolean;\n}\n\nconst rowItemOffsetMapping = new FixedSizeItemOffsetMapping(30);\nconst columnItemOffsetMapping = new FixedSizeItemOffsetMapping(100);\n\nexport class EmptySpreadsheetData implements SpreadsheetData<number> {\n subscribe(_onDataChange: () => void) { return () => {}; }\n getSnapshot() { return 0; }\n \n getRowCount(_snapshot: number) { return 0; }\n getRowItemOffsetMapping(_snapshot: number): ItemOffsetMapping { return rowItemOffsetMapping; }\n getColumnCount(_snapshot: number) { return 0; }\n getColumnItemOffsetMapping(_snapshot: number): ItemOffsetMapping { return columnItemOffsetMapping; }\n getCellValue(_snapshot: number, _row: number, _column: number): CellValue { return null; }\n getCellFormat(_snapshot: number, _row: number, _column: number): string|undefined { return undefined; }\n setCellValueAndFormat(_row: number, _column: number, _value: CellValue, _format: string | undefined): boolean { return false; }\n}\n\n","/** Classic Spreadsheet reference to Column (e.g \"A\") */\nexport type ColRef = string;\n\n/** Classic Spreadsheet reference to Cell (e.g. \"A1\"), Row (e.g. \"1\") or Column (e.g \"A\") */\nexport type RowColRef = string;\n\n/** Equivalent to {@link RowColRef} as coordinate pair. \"A1\" has coords [0,0], \"1\" is [0,undefined] and \"A\" is [undefined,0] */\nexport type RowColCoords = [row: number|undefined, col: number|undefined];\n\n/** Converts a {@link ColRef} to the 0-based index of the column */\nexport function colRefToIndex(col: ColRef): number {\n let n = 0;\n for (let i = 0; i < col.length; i ++) {\n n = col.charCodeAt(i) - 64 + n * 26;\n }\n return n-1;\n}\n\n/** Converts a 0-based column index to a {@link ColRef} */\nexport function indexToColRef(index: number): ColRef {\n let ret = \"\";\n index ++;\n while (index > 0) {\n index --;\n const remainder = index % 26;\n index = Math.floor(index / 26);\n ret = String.fromCharCode(65+remainder) + ret;\n }\n return ret;\n}\n\n/** Splits a RowColRef into a 0-based row index and a {@link ColRef} */\nexport function splitRowColRef(ref: RowColRef): [row: number|undefined, col: ColRef|undefined] {\n const re = /^([A-Z]*)(\\d*)$/;\n const found = ref.match(re);\n if (!found)\n return [undefined,undefined];\n\n const col = found[1];\n const row = parseInt(found[2]);\n return [(row>0) ? row-1 : undefined, col ? col : undefined];\n}\n\n/** Converts a {@link RowColRef} to {@link RowColCoords} */\nexport function rowColRefToCoords(ref: RowColRef): RowColCoords {\n const [row,col] = splitRowColRef(ref);\n return [row, col ? colRefToIndex(col) : undefined];\n}\n\n/** Converts {@link RowColCoords} to a {@link RowColRef} */\nexport function rowColCoordsToRef(row: number|undefined, col: number|undefined): RowColRef {\n if (row !== undefined) {\n if (col !== undefined) {\n return indexToColRef(col) + (row+1);\n } else {\n return (row+1).toString();\n }\n } else {\n if (col !== undefined) {\n return indexToColRef(col);\n } else {\n return \"\";\n }\n }\n}"],"names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AC;AAC3B,IAAA,IAAI,CAAC,KAAK;AACR,QAAA,OAAO,CAAC,SAAS,EAAC,SAAS,CAAC;AAE9B,IAAA,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC;IACpB,MAAM,GAAG,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC9B,OAAO,CAAC,CAAC,GAAG,GAAC,CAAC,IAAI,GAAG,GAAC,CAAC,GAAG,SAAS,EAAE,GAAG,GAAG,GAAG,GAAG,SAAS,CAAC;AAC7D;AAEA;AACM,SAAU,iBAAiB,CAAC,GAAc,EAAA;IAC9C,MAAM,CAAC,GAAG,EAAC,GAAG,CAAC,GAAG,cAAc,CAAC,GAAG,CAAC;AACrC,IAAA,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,aAAa,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;AACpD;AAEA;AACgB,SAAA,iBAAiB,CAAC,GAAqB,EAAE,GAAqB,EAAA;AAC5E,IAAA,IAAI,GAAG,KAAK,SAAS,EAAE;AACrB,QAAA,IAAI,GAAG,KAAK,SAAS,EAAE;YACrB,OAAO,aAAa,CAAC,GAAG,CAAC,IAAI,GAAG,GAAC,CAAC,CAAC;;aAC9B;YACL,OAAO,CAAC,GAAG,GAAC,CAAC,EAAE,QAAQ,EAAE;;;SAEtB;AACL,QAAA,IAAI,GAAG,KAAK,SAAS,EAAE;AACrB,YAAA,OAAO,aAAa,CAAC,GAAG,CAAC;;aACpB;AACL,YAAA,OAAO,EAAE;;;AAGf;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/Result.ts","../src/FixedSizeItemOffsetMapping.ts","../src/VariableSizeItemOffsetMapping.ts","../src/SpreadsheetData.ts","../src/RowColRef.ts"],"sourcesContent":["import type { Ok as neverthrow_Ok, Err as neverthrow_Err } from \"neverthrow\";\nimport { err as neverthrow_err, ok as neverthrow_ok } from \"neverthrow\";\n\n/**\n * An `Ok` instance is the *successful* variant of the {@link Result} type, \n * representing a successful outcome from an operation which may fail.\n * \n * Implemented using [`neverthrow`](https://github.com/supermacro/neverthrow)\n * \n * @typeParam T - The type of the value contained in the `Result` for the success case\n * @typeParam E - The type of the error contained in the `Result` for the failure case\n */\nexport interface Ok<T,E> extends neverthrow_Ok<T,E> {}\n\n/**\n * An `Err` instance is the failure variant of the {@link Result} type, \n * representing a failure outcome from an operation which may fail.\n * \n * Implemented using [`neverthrow`](https://github.com/supermacro/neverthrow)\n * \n * @typeParam T - The type of the value contained in the `Result` for the success case\n * @typeParam E - The type of the error contained in the `Result` for the failure case\n */\nexport interface Err<T,E> extends neverthrow_Err<T,E> {}\n\n/**\n * A `Result` represents success ({@link Ok}) or failure ({@link Err}).\n * \n * Compatible with [`neverthrow`](https://github.com/supermacro/neverthrow)\n * \n * @typeParam T - The type of the value contained in the `Result` for the success case\n * @typeParam E - The type of the error contained in the `Result` for the failure case\n */\nexport type Result<T,E> = Ok<T,E> | Err<T,E>;\n\n/**\n * Create an instance of {@link Ok}.\n *\n * If you need to create an instance with a specific type (as you do whenever you\n * are not constructing immediately for a function return or as an argument to a\n * function), you can use a type parameter:\n *\n * ```ts\n * const yayNumber = ok<number, string>(12);\n * ```\n *\n * Note: passing nothing will produce a `Result<void, E>`, passing `undefined` will\n * produce a `Result<undefined, E>` which is compatible with `Result<void, E>`.\n *\n * ```ts\n * const normalResult = ok<number, string>(42);\n * const explicitUndefined = ok<undefined, string>(undefined);\n * const implicitVoid = ok<void, string>();\n * ```\n *\n * In the context of an immediate function return, or an arrow function with a\n * single expression value, you do not have to specify the types, so this can be\n * quite convenient.\n *\n * ```ts\n * const arrowValidate = (data: SomeData): Result<void, string> =>\n * isValid(data) ? ok() : err('something was wrong!');\n *\n * function fnValidate(data: someData): Result<void, string> {\n * return isValid(data) ? ok() : err('something was wrong');\n * }\n * ```\n *\n * @typeParam T - The type of the value contained in the `Result` for the success case\n * @typeParam E - The type of the error contained in the `Result` for the failure case\n * @param value - The value to wrap in a `Result.Ok`.\n */\nexport function ok<T, E = never>(value: T): Ok<T, E>\nexport function ok<_T extends void = void, E = never>(value: void): Ok<void, E>\nexport function ok<T, E = never>(value: T): Ok<T, E> {\n return neverthrow_ok<T,E>(value); \n}\n\n/**\n * Create an instance of {@link Err}.\n *\n * If you need to create an instance with a specific type (as you do whenever you\n * are not constructing immediately for a function return or as an argument to a\n * function), you can use a type parameter:\n *\n * ```ts\n * const notString = err<number, string>('something went wrong');\n * ```\n *\n * Note: passing nothing will produce a `Result<T, void>`, passing `undefined` will\n * produce a `Result<T, undefined>` which is compatible with `Result<T, void>`.\n *\n * ```ts\n * const normalResult = err<number, string>('oh no');\n * const explicitUndefined = err<number, undefined>(undefined);\n * const implicitVoid = err<number, void>();\n * ```\n *\n * In the context of an immediate function return, or an arrow function with a\n * single expression value, you do not have to specify the types, so this can be\n * quite convenient.\n *\n * ```ts\n * const arrowValidate = (data: SomeData): Result<number, string> =>\n * isValid(data) ? ok(42) : err('something went wrong');\n *\n * function fnValidate(data: someData): Result<number, string> {\n * return isValid(data) ? ok(42) : err('something went wrong');\n * }\n * ```\n *\n * @typeParam T - The type of the value contained in the `Result` for the success case\n * @typeParam E - The type of the error contained in the `Result` for the failure case\n * @param err - The value to wrap in a `Result.Err`.\n */\nexport function err<T = never, E extends string = string>(err: E): Err<T, E>\nexport function err<T = never, E = unknown>(err: E): Err<T, E>\nexport function err<T = never, _E extends void = void>(err: void): Err<T, void>\nexport function err<T = never, E = unknown>(err: E): Err<T, E> {\n return neverthrow_err<T,E>(err)\n}\n","import type { ItemOffsetMapping } from './ItemOffsetMapping';\n\n/**\n * Implementation of {@link ItemOffsetMapping} for use when all items have a fixed size\n */\nexport class FixedSizeItemOffsetMapping implements ItemOffsetMapping {\n /**\n * @param itemSize - Size to use for all items\n */\n constructor (itemSize: number) {\n this.#fixedItemSize = itemSize;\n }\n\n itemSize(_itemIndex: number): number {\n return this.#fixedItemSize;\n }\n\n itemOffset(itemIndex: number): number {\n return itemIndex * this.#fixedItemSize;\n }\n\n offsetToItem(offset: number): [itemIndex: number, startOffset: number] {\n const itemIndex = Math.floor(offset / this.#fixedItemSize);\n const startOffset = itemIndex * this.#fixedItemSize;\n\n return [itemIndex, startOffset];\n }\n\n #fixedItemSize: number;\n}\n\n","import type { ItemOffsetMapping } from './ItemOffsetMapping';\n\n/**\n * Implementation of {@link ItemOffsetMapping} for use when initial items have variable sizes.\n */\nexport class VariableSizeItemOffsetMapping implements ItemOffsetMapping {\n /**\n * @param defaultItemSize - Size to use for all other items\n * @param sizes - Array of sizes to use for the initial items, one size per item\n */\n constructor (defaultItemSize: number, sizes: number[]) {\n this.#defaultItemSize = defaultItemSize;\n this.#sizes = sizes;\n }\n\n itemSize(itemIndex: number): number {\n return (itemIndex < this.#sizes.length) ? this.#sizes[itemIndex]! : this.#defaultItemSize;\n }\n\n itemOffset(itemIndex: number): number {\n let offset = 0;\n let length = this.#sizes.length;\n if (itemIndex > length) {\n const numDefaultSize = itemIndex - length;\n offset = numDefaultSize * this.#defaultItemSize;\n } else {\n length = itemIndex;\n }\n \n for (let i = 0; i < length; i ++)\n {\n offset += this.#sizes[i]!;\n }\n\n return offset;\n }\n\n offsetToItem(offset: number): [itemIndex: number, startOffset: number] {\n let startOffset = 0;\n for (const [i,size] of this.#sizes.entries()) {\n if (startOffset + size > offset) {\n return [i, startOffset];\n }\n startOffset += size;\n }\n\n const itemIndex = Math.floor((offset - startOffset) / this.#defaultItemSize);\n startOffset += itemIndex * this.#defaultItemSize;\n\n const length = this.#sizes.length;\n return [itemIndex+length, startOffset];\n }\n\n #defaultItemSize: number;\n #sizes: number[];\n}\n","import type { ItemOffsetMapping } from \"./ItemOffsetMapping\";\nimport { FixedSizeItemOffsetMapping } from \"./FixedSizeItemOffsetMapping\";\nimport { Result, err, ok } from \"./Result\";\n\n/** Possible spreadsheet error values\n * \n * Includes those that can be returned by `ERROR.TYPE` and additional values\n * introduced by more recent versions of Excel.\n*/\nexport type CellErrorValue = '#NULL!' | \n '#DIV/0!' |\n '#VALUE!' |\n '#REF!' |\n '#NAME?' |\n '#NUM!' |\n '#N/A' |\n '#GETTING_DATA' |\n '#SPILL!' |\n '#UNKNOWN!' |\n '#FIELD!' |\n '#CALC!';\n\n/** Type that represents an error value stored in a cell\n * \n * Defined as a discriminated union so that additional cell value types\n * can be added in future.\n */\nexport interface CellError {\n /** Discriminated union tag */\n type: 'CellError',\n\n /** {@link CellErrorValue | Error Value} */\n value: CellErrorValue;\n};\n\n/** Possible types for a cell value \n * \n * The native JavaScript types string, number and boolean represent the *Text*, *Number* and *Logical*\n * spreadsheet data types. {@link CellError} represents an *Error Value*.\n * \n * Undefined is used to represent a cell with no defined value. Null represents a cell that has been\n * explicitly marked as empty. \n*/\nexport type CellValue = string | number | boolean | null | undefined | CellError;\n\n/** Type that represents an error when validating data to be stored in a cell */\nexport interface ValidationError {\n /** Discriminated union tag */\n type: 'ValidationError',\n\n /** End user message describing the problem */\n message: string,\n};\n\n/** Convenience method that creates a {@link ValidationError} */\nexport function validationError(message: string): ValidationError {\n return { type: 'ValidationError', message };\n}\n\n/** Type that represents an error when storing data in a cell */\nexport interface StorageError {\n /** Discriminated union tag */\n type: 'StorageError',\n\n /** End user message describing the problem */\n message: string,\n\n /** HTTP style status code\n * \n * Describes the type of problem encountered. Expected to be a 4XX or 5XX code.\n */\n statusCode?: number | undefined,\n};\n\n/** Convenience method that creates a {@link StorageError} */\nexport function storageError(message: string, statusCode?: number): StorageError {\n return { type: 'StorageError', message, statusCode };\n}\n\n/** Types of error that can be returned by {@link SpreadsheetData} methods */\nexport type SpreadsheetDataError = ValidationError | StorageError;\n\n/**\n * Interface used to access the data in a spreadsheet\n * \n * The data exposed through the interface may change over time outside of any changes made through the interface. The caller\n * can use the {@link subscribe} method to be notified when the data changes. When reading data, the caller must first request\n * a snapshot using {@link getSnapshot}. All values returned by gettors are relative to a specified snapshot. The values will be\n * consistent with each other as long as the same snapshot is used.\n * \n * @typeParam Snapshot - Type of snapshot. Implementations are free to use whatever type makes sense for them.\n */\nexport interface SpreadsheetData<Snapshot> {\n /** Subscribe to data changes */\n subscribe(onDataChange: () => void): () => void,\n\n /** Return a snapshot to use when accessing values at a consistent point in time */\n getSnapshot(): Snapshot,\n\n /** Number of rows in the spreadsheet */\n getRowCount(snapshot: Snapshot): number,\n\n /** {@link ItemOffsetMapping} which describes sizes and offsets to start of rows */\n getRowItemOffsetMapping(snapshot: Snapshot): ItemOffsetMapping,\n\n /** Number of columns in the spreadsheet */\n getColumnCount(snapshot: Snapshot): number,\n\n /** {@link ItemOffsetMapping} which describes sizes and offsets to start of columns */\n getColumnItemOffsetMapping(snapshot: Snapshot): ItemOffsetMapping,\n\n /** Value of specified cell using 0-based row and column indexes */\n getCellValue(snapshot: Snapshot, row: number, column: number): CellValue;\n\n /** Format of specified cell using 0-based row and column indexes */\n getCellFormat(snapshot: Snapshot, row: number, column: number): string | undefined;\n\n /** Set value and format of specified cell\n * \n * @returns `Ok` if the change was successfully applied\n */\n setCellValueAndFormat(row: number, column: number, value: CellValue, format: string | undefined): Result<void,SpreadsheetDataError>\n\n /** Check whether value and format are valid to set for specified cell\n * \n * @returns `Ok` if the value and format are valid\n */\n isValidCellValueAndFormat(row: number, column: number, value: CellValue, format: string | undefined): Result<void,ValidationError>\n}\n\nconst rowItemOffsetMapping = new FixedSizeItemOffsetMapping(30);\nconst columnItemOffsetMapping = new FixedSizeItemOffsetMapping(100);\n\nexport class EmptySpreadsheetData implements SpreadsheetData<number> {\n subscribe(_onDataChange: () => void) { return () => {}; }\n getSnapshot() { return 0; }\n \n getRowCount(_snapshot: number) { return 0; }\n getRowItemOffsetMapping(_snapshot: number): ItemOffsetMapping { return rowItemOffsetMapping; }\n getColumnCount(_snapshot: number) { return 0; }\n getColumnItemOffsetMapping(_snapshot: number): ItemOffsetMapping { return columnItemOffsetMapping; }\n getCellValue(_snapshot: number, _row: number, _column: number): CellValue { return null; }\n getCellFormat(_snapshot: number, _row: number, _column: number): string|undefined { return undefined; }\n setCellValueAndFormat(_row: number, _column: number, _value: CellValue, _format: string | undefined): Result<void,SpreadsheetDataError> \n { return err(storageError(\"Not implemented\", 501)); }\n isValidCellValueAndFormat(_row: number, _column: number, _value: CellValue, _format: string | undefined): Result<void,ValidationError> \n { return ok(); }\n}\n\n","/** Classic Spreadsheet reference to Column (e.g \"A\") */\nexport type ColRef = string;\n\n/** Classic Spreadsheet reference to Cell (e.g. \"A1\"), Row (e.g. \"1\") or Column (e.g \"A\") */\nexport type RowColRef = string;\n\n/** Equivalent to {@link RowColRef} as coordinate pair. \"A1\" has coords [0,0], \"1\" is [0,undefined] and \"A\" is [undefined,0] */\nexport type RowColCoords = [row: number|undefined, col: number|undefined];\n\n/** Converts a {@link ColRef} to the 0-based index of the column */\nexport function colRefToIndex(col: ColRef): number {\n let n = 0;\n for (let i = 0; i < col.length; i ++) {\n n = col.charCodeAt(i) - 64 + n * 26;\n }\n return n-1;\n}\n\n/** Converts a 0-based column index to a {@link ColRef} */\nexport function indexToColRef(index: number): ColRef {\n let ret = \"\";\n index ++;\n while (index > 0) {\n index --;\n const remainder = index % 26;\n index = Math.floor(index / 26);\n ret = String.fromCharCode(65+remainder) + ret;\n }\n return ret;\n}\n\n/** Splits a RowColRef into a 0-based row index and a {@link ColRef} */\nexport function splitRowColRef(ref: RowColRef): [row: number|undefined, col: ColRef|undefined] {\n const re = /^([A-Z]*)(\\d*)$/;\n const found = ref.match(re);\n if (!found)\n return [undefined,undefined];\n\n const col = found[1];\n const row = found[2] ? parseInt(found[2]) : 0;\n return [(row>0) ? row-1 : undefined, col ? col : undefined];\n}\n\n/** Converts a {@link RowColRef} to {@link RowColCoords} */\nexport function rowColRefToCoords(ref: RowColRef): RowColCoords {\n const [row,col] = splitRowColRef(ref);\n return [row, col ? colRefToIndex(col) : undefined];\n}\n\n/** Converts {@link RowColCoords} to a {@link RowColRef} */\nexport function rowColCoordsToRef(row: number|undefined, col: number|undefined): RowColRef {\n if (row !== undefined) {\n if (col !== undefined) {\n return indexToColRef(col) + (row+1);\n } else {\n return (row+1).toString();\n }\n } else {\n if (col !== undefined) {\n return indexToColRef(col);\n } else {\n return \"\";\n }\n }\n}"],"names":["neverthrow_ok","neverthrow_err"],"mappings":";;AA0EM,SAAU,EAAE,CAAe,KAAQ,EAAA;AACvC,IAAA,OAAOA,IAAa,CAAM,KAAK,CAAC;AAClC;AA0CM,SAAU,GAAG,CAAyB,GAAM,EAAA;AAChD,IAAA,OAAOC,KAAc,CAAM,GAAG,CAAC;AACjC;;ACtHA;;AAEG;MACU,0BAA0B,CAAA;AACrC;;AAEG;AACH,IAAA,WAAA,CAAa,QAAgB,EAAA;AAC3B,QAAA,IAAI,CAAC,cAAc,GAAG,QAAQ;;AAGhC,IAAA,QAAQ,CAAC,UAAkB,EAAA;QACzB,OAAO,IAAI,CAAC,cAAc;;AAG5B,IAAA,UAAU,CAAC,SAAiB,EAAA;AAC1B,QAAA,OAAO,SAAS,GAAG,IAAI,CAAC,cAAc;;AAGxC,IAAA,YAAY,CAAC,MAAc,EAAA;AACzB,QAAA,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,cAAc,CAAC;AAC1D,QAAA,MAAM,WAAW,GAAG,SAAS,GAAG,IAAI,CAAC,cAAc;AAEnD,QAAA,OAAO,CAAC,SAAS,EAAE,WAAW,CAAC;;AAGjC,IAAA,cAAc;AACf;;AC3BD;;AAEG;MACU,6BAA6B,CAAA;AACxC;;;AAGG;IACH,WAAa,CAAA,eAAuB,EAAE,KAAe,EAAA;AACnD,QAAA,IAAI,CAAC,gBAAgB,GAAG,eAAe;AACvC,QAAA,IAAI,CAAC,MAAM,GAAG,KAAK;;AAGrB,IAAA,QAAQ,CAAC,SAAiB,EAAA;QACxB,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,CAAE,GAAG,IAAI,CAAC,gBAAgB;;AAG3F,IAAA,UAAU,CAAC,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;AACgB,SAAA,iBAAiB,CAAC,GAAqB,EAAE,GAAqB,EAAA;AAC5E,IAAA,IAAI,GAAG,KAAK,SAAS,EAAE;AACrB,QAAA,IAAI,GAAG,KAAK,SAAS,EAAE;YACrB,OAAO,aAAa,CAAC,GAAG,CAAC,IAAI,GAAG,GAAC,CAAC,CAAC;;aAC9B;YACL,OAAO,CAAC,GAAG,GAAC,CAAC,EAAE,QAAQ,EAAE;;;SAEtB;AACL,QAAA,IAAI,GAAG,KAAK,SAAS,EAAE;AACrB,YAAA,OAAO,aAAa,CAAC,GAAG,CAAC;;aACpB;AACL,YAAA,OAAO,EAAE;;;AAGf;;;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@candidstartup/infinisheet-types",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.10.0",
|
|
5
5
|
"description": "Common types for the InfiniSheet packages",
|
|
6
6
|
"author": "Tim Wiegand <tim.wiegand@thecandidstartup.org>",
|
|
7
7
|
"license": "BSD-3-Clause",
|
|
@@ -49,5 +49,8 @@
|
|
|
49
49
|
"test": "vitest"
|
|
50
50
|
},
|
|
51
51
|
"main": "index.js",
|
|
52
|
-
"
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"neverthrow": "^8.2.0"
|
|
54
|
+
},
|
|
55
|
+
"gitHead": "948f593793c217bd5b49aea712d3d700702ca120"
|
|
53
56
|
}
|