microsoft-graph 2.34.1 → 2.36.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/.vscode/settings.json +8 -1
- package/dist/cjs/errors/BadRequestError.d.ts +9 -0
- package/dist/cjs/errors/BadRequestError.d.ts.map +1 -0
- package/dist/cjs/errors/BadRequestError.js +14 -0
- package/dist/cjs/errors/BandwidthLimitExceededError.d.ts +9 -0
- package/dist/cjs/errors/BandwidthLimitExceededError.d.ts.map +1 -0
- package/dist/cjs/errors/BandwidthLimitExceededError.js +14 -0
- package/dist/cjs/errors/ConflictError.d.ts +10 -0
- package/dist/cjs/errors/ConflictError.d.ts.map +1 -0
- package/dist/cjs/errors/ConflictError.js +15 -0
- package/dist/cjs/errors/ForbiddenError.d.ts +11 -0
- package/dist/cjs/errors/ForbiddenError.d.ts.map +1 -0
- package/dist/cjs/errors/ForbiddenError.js +16 -0
- package/dist/cjs/errors/GatewayTimeoutError.d.ts +9 -0
- package/dist/cjs/errors/GatewayTimeoutError.d.ts.map +1 -0
- package/dist/cjs/errors/GatewayTimeoutError.js +14 -0
- package/dist/cjs/errors/GoneError.d.ts +9 -0
- package/dist/cjs/errors/GoneError.d.ts.map +1 -0
- package/dist/cjs/errors/GoneError.js +14 -0
- package/dist/cjs/errors/InsufficientStorageError.d.ts +9 -0
- package/dist/cjs/errors/InsufficientStorageError.d.ts.map +1 -0
- package/dist/cjs/errors/InsufficientStorageError.js +14 -0
- package/dist/cjs/errors/InternalServerError.d.ts +9 -0
- package/dist/cjs/errors/InternalServerError.d.ts.map +1 -0
- package/dist/cjs/errors/InternalServerError.js +14 -0
- package/dist/cjs/errors/LengthRequiredError.d.ts +9 -0
- package/dist/cjs/errors/LengthRequiredError.d.ts.map +1 -0
- package/dist/cjs/errors/LengthRequiredError.js +14 -0
- package/dist/cjs/errors/LockedError.d.ts +9 -0
- package/dist/cjs/errors/LockedError.d.ts.map +1 -0
- package/dist/cjs/errors/LockedError.js +14 -0
- package/dist/cjs/errors/MethodNotAllowedError.d.ts +9 -0
- package/dist/cjs/errors/MethodNotAllowedError.d.ts.map +1 -0
- package/dist/cjs/errors/MethodNotAllowedError.js +14 -0
- package/dist/cjs/errors/NotAcceptableError.d.ts +9 -0
- package/dist/cjs/errors/NotAcceptableError.d.ts.map +1 -0
- package/dist/cjs/errors/NotAcceptableError.js +14 -0
- package/dist/cjs/errors/PaymentRequiredError.d.ts +9 -0
- package/dist/cjs/errors/PaymentRequiredError.d.ts.map +1 -0
- package/dist/cjs/errors/PaymentRequiredError.js +14 -0
- package/dist/cjs/errors/PreconditionFailedError.d.ts +9 -0
- package/dist/cjs/errors/PreconditionFailedError.d.ts.map +1 -0
- package/dist/cjs/errors/PreconditionFailedError.js +14 -0
- package/dist/cjs/errors/RequestEntityTooLargeError.d.ts +9 -0
- package/dist/cjs/errors/RequestEntityTooLargeError.d.ts.map +1 -0
- package/dist/cjs/errors/RequestEntityTooLargeError.js +14 -0
- package/dist/cjs/errors/RequestFailedError.d.ts +1 -2
- package/dist/cjs/errors/RequestFailedError.d.ts.map +1 -1
- package/dist/cjs/errors/RequestFailedError.js +1 -8
- package/dist/cjs/errors/RequestedRangeNotSatisfiableError.d.ts +9 -0
- package/dist/cjs/errors/RequestedRangeNotSatisfiableError.d.ts.map +1 -0
- package/dist/cjs/errors/RequestedRangeNotSatisfiableError.js +14 -0
- package/dist/cjs/errors/ServiceUnavailableError.d.ts +9 -0
- package/dist/cjs/errors/ServiceUnavailableError.d.ts.map +1 -0
- package/dist/cjs/errors/ServiceUnavailableError.js +14 -0
- package/dist/cjs/errors/TooManyRequestsError.d.ts +9 -0
- package/dist/cjs/errors/TooManyRequestsError.d.ts.map +1 -0
- package/dist/cjs/errors/TooManyRequestsError.js +14 -0
- package/dist/cjs/errors/UnauthorizedError.d.ts +9 -0
- package/dist/cjs/errors/UnauthorizedError.d.ts.map +1 -0
- package/dist/cjs/errors/UnauthorizedError.js +14 -0
- package/dist/cjs/errors/UnprocessableEntityError.d.ts +9 -0
- package/dist/cjs/errors/UnprocessableEntityError.d.ts.map +1 -0
- package/dist/cjs/errors/UnprocessableEntityError.js +14 -0
- package/dist/cjs/errors/UnsupportedMediaTypeError.d.ts +9 -0
- package/dist/cjs/errors/UnsupportedMediaTypeError.d.ts.map +1 -0
- package/dist/cjs/errors/UnsupportedMediaTypeError.js +14 -0
- package/dist/cjs/operations/driveItem/getDriveItemByPath.d.ts.map +1 -1
- package/dist/cjs/operations/driveItem/getDriveItemByPath.js +7 -0
- package/dist/cjs/operations/driveItem/getDriveItemContent.js +1 -1
- package/dist/cjs/operations/driveItem/streamDriveItemContent.d.ts.map +1 -1
- package/dist/cjs/operations/driveItem/streamDriveItemContent.js +4 -0
- package/dist/cjs/services/drive.d.ts +0 -2
- package/dist/cjs/services/drive.d.ts.map +1 -1
- package/dist/cjs/services/drive.js +3 -8
- package/dist/cjs/services/httpStatus.d.ts +130 -3
- package/dist/cjs/services/httpStatus.d.ts.map +1 -1
- package/dist/cjs/services/httpStatus.js +206 -6
- package/dist/cjs/services/objectMapping.d.ts +100 -0
- package/dist/cjs/services/objectMapping.d.ts.map +1 -0
- package/dist/cjs/services/objectMapping.js +143 -0
- package/dist/cjs/services/operationInvoker.d.ts +20 -3
- package/dist/cjs/services/operationInvoker.d.ts.map +1 -1
- package/dist/cjs/services/operationInvoker.js +192 -57
- package/dist/cjs/tasks/insertWorkbookRangeRow.d.ts +2 -2
- package/dist/cjs/tasks/insertWorkbookRangeRow.js +2 -2
- package/dist/cjs/tasks/insertWorkbookRangeRows.d.ts +3 -3
- package/dist/cjs/tasks/insertWorkbookRangeRows.js +3 -3
- package/dist/cjs/tasks/iterateWorkbookRangeRows.d.ts +1 -1
- package/dist/cjs/tasks/iterateWorkbookRangeRows.js +1 -1
- package/dist/cjs/tasks/readWorkbookRangeFirstRow.d.ts +2 -2
- package/dist/cjs/tasks/readWorkbookRangeFirstRow.js +2 -2
- package/dist/cjs/tasks/readWorkbookRangeRows.d.ts +2 -2
- package/dist/cjs/tasks/readWorkbookRangeRows.js +2 -2
- package/dist/cjs/tasks/updateWorkbookRangeFirstRow.d.ts +3 -3
- package/dist/cjs/tasks/updateWorkbookRangeFirstRow.js +3 -3
- package/dist/cjs/tasks/updateWorkbookRangeRows.d.ts +15 -6
- package/dist/cjs/tasks/updateWorkbookRangeRows.d.ts.map +1 -1
- package/dist/cjs/tasks/updateWorkbookRangeRows.js +16 -7
- package/dist/esm/errors/BadRequestError.d.ts +9 -0
- package/dist/esm/errors/BadRequestError.d.ts.map +1 -0
- package/dist/esm/errors/BadRequestError.js +11 -0
- package/dist/esm/errors/BandwidthLimitExceededError.d.ts +9 -0
- package/dist/esm/errors/BandwidthLimitExceededError.d.ts.map +1 -0
- package/dist/esm/errors/BandwidthLimitExceededError.js +11 -0
- package/dist/esm/errors/ConflictError.d.ts +10 -0
- package/dist/esm/errors/ConflictError.d.ts.map +1 -0
- package/dist/esm/errors/ConflictError.js +12 -0
- package/dist/esm/errors/ForbiddenError.d.ts +11 -0
- package/dist/esm/errors/ForbiddenError.d.ts.map +1 -0
- package/dist/esm/errors/ForbiddenError.js +13 -0
- package/dist/esm/errors/GatewayTimeoutError.d.ts +9 -0
- package/dist/esm/errors/GatewayTimeoutError.d.ts.map +1 -0
- package/dist/esm/errors/GatewayTimeoutError.js +11 -0
- package/dist/esm/errors/GoneError.d.ts +9 -0
- package/dist/esm/errors/GoneError.d.ts.map +1 -0
- package/dist/esm/errors/GoneError.js +11 -0
- package/dist/esm/errors/InsufficientStorageError.d.ts +9 -0
- package/dist/esm/errors/InsufficientStorageError.d.ts.map +1 -0
- package/dist/esm/errors/InsufficientStorageError.js +11 -0
- package/dist/esm/errors/InternalServerError.d.ts +9 -0
- package/dist/esm/errors/InternalServerError.d.ts.map +1 -0
- package/dist/esm/errors/InternalServerError.js +11 -0
- package/dist/esm/errors/LengthRequiredError.d.ts +9 -0
- package/dist/esm/errors/LengthRequiredError.d.ts.map +1 -0
- package/dist/esm/errors/LengthRequiredError.js +11 -0
- package/dist/esm/errors/LockedError.d.ts +9 -0
- package/dist/esm/errors/LockedError.d.ts.map +1 -0
- package/dist/esm/errors/LockedError.js +11 -0
- package/dist/esm/errors/MethodNotAllowedError.d.ts +9 -0
- package/dist/esm/errors/MethodNotAllowedError.d.ts.map +1 -0
- package/dist/esm/errors/MethodNotAllowedError.js +11 -0
- package/dist/esm/errors/NotAcceptableError.d.ts +9 -0
- package/dist/esm/errors/NotAcceptableError.d.ts.map +1 -0
- package/dist/esm/errors/NotAcceptableError.js +11 -0
- package/dist/esm/errors/PaymentRequiredError.d.ts +9 -0
- package/dist/esm/errors/PaymentRequiredError.d.ts.map +1 -0
- package/dist/esm/errors/PaymentRequiredError.js +11 -0
- package/dist/esm/errors/PreconditionFailedError.d.ts +9 -0
- package/dist/esm/errors/PreconditionFailedError.d.ts.map +1 -0
- package/dist/esm/errors/PreconditionFailedError.js +11 -0
- package/dist/esm/errors/RequestEntityTooLargeError.d.ts +9 -0
- package/dist/esm/errors/RequestEntityTooLargeError.d.ts.map +1 -0
- package/dist/esm/errors/RequestEntityTooLargeError.js +11 -0
- package/dist/esm/errors/RequestFailedError.d.ts +1 -2
- package/dist/esm/errors/RequestFailedError.d.ts.map +1 -1
- package/dist/esm/errors/RequestFailedError.js +1 -8
- package/dist/esm/errors/RequestedRangeNotSatisfiableError.d.ts +9 -0
- package/dist/esm/errors/RequestedRangeNotSatisfiableError.d.ts.map +1 -0
- package/dist/esm/errors/RequestedRangeNotSatisfiableError.js +11 -0
- package/dist/esm/errors/ServiceUnavailableError.d.ts +9 -0
- package/dist/esm/errors/ServiceUnavailableError.d.ts.map +1 -0
- package/dist/esm/errors/ServiceUnavailableError.js +11 -0
- package/dist/esm/errors/TooManyRequestsError.d.ts +9 -0
- package/dist/esm/errors/TooManyRequestsError.d.ts.map +1 -0
- package/dist/esm/errors/TooManyRequestsError.js +11 -0
- package/dist/esm/errors/UnauthorizedError.d.ts +9 -0
- package/dist/esm/errors/UnauthorizedError.d.ts.map +1 -0
- package/dist/esm/errors/UnauthorizedError.js +11 -0
- package/dist/esm/errors/UnprocessableEntityError.d.ts +9 -0
- package/dist/esm/errors/UnprocessableEntityError.d.ts.map +1 -0
- package/dist/esm/errors/UnprocessableEntityError.js +11 -0
- package/dist/esm/errors/UnsupportedMediaTypeError.d.ts +9 -0
- package/dist/esm/errors/UnsupportedMediaTypeError.d.ts.map +1 -0
- package/dist/esm/errors/UnsupportedMediaTypeError.js +11 -0
- package/dist/esm/operations/driveItem/getDriveItemByPath.d.ts.map +1 -1
- package/dist/esm/operations/driveItem/getDriveItemByPath.js +4 -0
- package/dist/esm/operations/driveItem/getDriveItemContent.js +2 -2
- package/dist/esm/operations/driveItem/streamDriveItemContent.d.ts.map +1 -1
- package/dist/esm/operations/driveItem/streamDriveItemContent.js +5 -1
- package/dist/esm/services/drive.d.ts +0 -2
- package/dist/esm/services/drive.d.ts.map +1 -1
- package/dist/esm/services/drive.js +4 -9
- package/dist/esm/services/httpStatus.d.ts +130 -3
- package/dist/esm/services/httpStatus.d.ts.map +1 -1
- package/dist/esm/services/httpStatus.js +182 -3
- package/dist/esm/services/objectMapping.d.ts +100 -0
- package/dist/esm/services/objectMapping.d.ts.map +1 -0
- package/dist/esm/services/objectMapping.js +132 -0
- package/dist/esm/services/operationInvoker.d.ts +20 -3
- package/dist/esm/services/operationInvoker.d.ts.map +1 -1
- package/dist/esm/services/operationInvoker.js +192 -58
- package/dist/esm/tasks/insertWorkbookRangeRow.d.ts +2 -2
- package/dist/esm/tasks/insertWorkbookRangeRow.js +2 -2
- package/dist/esm/tasks/insertWorkbookRangeRows.d.ts +3 -3
- package/dist/esm/tasks/insertWorkbookRangeRows.js +3 -3
- package/dist/esm/tasks/iterateWorkbookRangeRows.d.ts +1 -1
- package/dist/esm/tasks/iterateWorkbookRangeRows.js +1 -1
- package/dist/esm/tasks/readWorkbookRangeFirstRow.d.ts +2 -2
- package/dist/esm/tasks/readWorkbookRangeFirstRow.js +2 -2
- package/dist/esm/tasks/readWorkbookRangeRows.d.ts +2 -2
- package/dist/esm/tasks/readWorkbookRangeRows.js +2 -2
- package/dist/esm/tasks/updateWorkbookRangeFirstRow.d.ts +3 -3
- package/dist/esm/tasks/updateWorkbookRangeFirstRow.js +3 -3
- package/dist/esm/tasks/updateWorkbookRangeRows.d.ts +15 -6
- package/dist/esm/tasks/updateWorkbookRangeRows.d.ts.map +1 -1
- package/dist/esm/tasks/updateWorkbookRangeRows.js +16 -7
- package/docs/api/BadRequestError.md +191 -0
- package/docs/api/BandwidthLimitExceededError.md +191 -0
- package/docs/api/ConflictError.md +195 -0
- package/docs/api/ForbiddenError.md +193 -0
- package/docs/api/GatewayTimeoutError.md +191 -0
- package/docs/api/GoneError.md +191 -0
- package/docs/api/InsufficientStorageError.md +191 -0
- package/docs/api/InternalServerError.md +191 -0
- package/docs/api/LengthRequiredError.md +191 -0
- package/docs/api/LockedError.md +191 -0
- package/docs/api/MethodNotAllowedError.md +191 -0
- package/docs/api/NotAcceptableError.md +191 -0
- package/docs/api/PaymentRequiredError.md +191 -0
- package/docs/api/PreconditionFailedError.md +191 -0
- package/docs/api/README.md +30 -10
- package/docs/api/RequestEntityTooLargeError.md +191 -0
- package/docs/api/RequestFailedError.md +1 -19
- package/docs/api/RequestedRangeNotSatisfiableError.md +191 -0
- package/docs/api/ServiceUnavailableError.md +191 -0
- package/docs/api/TooManyRequestsError.md +191 -0
- package/docs/api/UnauthorizedError.md +191 -0
- package/docs/api/UnprocessableEntityError.md +191 -0
- package/docs/api/UnsupportedMediaTypeError.md +191 -0
- package/docs/api/drive.md +20 -0
- package/docs/api/getDriveItemByPath.md +1 -1
- package/docs/api/httpStatus.md +475 -12
- package/docs/api/{insertRow.md → insertWorkbookRangeRow.md} +3 -3
- package/docs/api/{insertRows.md → insertWorkbookRangeRows.md} +5 -5
- package/docs/api/{iterateRows.md → iterateWorkbookRangeRows.md} +2 -2
- package/docs/api/objectMapping.md +225 -0
- package/docs/api/operationInvoker.md +50 -27
- package/docs/api/{readFirstRow.md → readWorkbookRangeFirstRow.md} +3 -3
- package/docs/api/{readRows.md → readWorkbookRangeRows.md} +4 -4
- package/docs/api/streamDriveItemContent.md +1 -1
- package/docs/api/{updateFirstRow.md → updateWorkbookRangeFirstRow.md} +4 -4
- package/docs/api/{updateRows.md → updateWorkbookRangeRows.md} +19 -10
- package/docs/api/writeWorkbookRows.md +1 -1
- package/package.json +551 -51
- package/dist/cjs/models/DataSource.d.ts +0 -49
- package/dist/cjs/models/DataSource.d.ts.map +0 -1
- package/dist/cjs/models/DataSource.js +0 -8
- package/dist/cjs/services/dataSource.d.ts +0 -69
- package/dist/cjs/services/dataSource.d.ts.map +0 -1
- package/dist/cjs/services/dataSource.js +0 -193
- package/dist/esm/models/DataSource.d.ts +0 -49
- package/dist/esm/models/DataSource.d.ts.map +0 -1
- package/dist/esm/models/DataSource.js +0 -7
- package/dist/esm/services/dataSource.d.ts +0 -69
- package/dist/esm/services/dataSource.d.ts.map +0 -1
- package/dist/esm/services/dataSource.js +0 -182
- package/docs/api/DataSource-1.md +0 -191
- package/docs/api/dataSource.md +0 -204
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tooling for easily creating, updating, and deleting items in a worksheet or range.
|
|
3
|
-
* @module DataSource
|
|
4
|
-
* @category Models
|
|
5
|
-
* @experimental
|
|
6
|
-
*/
|
|
7
|
-
import type { Cell, CellValue } from "./Cell.ts";
|
|
8
|
-
import type { ColumnName } from "./Column.ts";
|
|
9
|
-
import type { RowNumber, RowOffset } from "./Row.ts";
|
|
10
|
-
import type { WorkbookRangeRef } from "./WorkbookRange.ts";
|
|
11
|
-
/**
|
|
12
|
-
* Defines a data source for a worksheet or range.
|
|
13
|
-
* @template T Type of the record, extending RecordBase.
|
|
14
|
-
*/
|
|
15
|
-
export type DataSource<T extends RecordBase> = {
|
|
16
|
-
bodyRef: WorkbookRangeRef;
|
|
17
|
-
bodyOffset: RowOffset;
|
|
18
|
-
head: ColumnName[];
|
|
19
|
-
coding: {
|
|
20
|
-
decode: RowDecoder<T>;
|
|
21
|
-
encode: RowEncoder<T> | null;
|
|
22
|
-
};
|
|
23
|
-
} & AsyncIterable<Item<T>>;
|
|
24
|
-
/**
|
|
25
|
-
* Method to decode row into a record.
|
|
26
|
-
*/
|
|
27
|
-
export type RowDecoder<T extends RecordBase> = (row: DataSourceRow) => T;
|
|
28
|
-
/**
|
|
29
|
-
* Method to encode a record into a row.
|
|
30
|
-
*/
|
|
31
|
-
export type RowEncoder<T extends RecordBase> = (record: T) => DataSourceRow;
|
|
32
|
-
/**
|
|
33
|
-
* Item's position within a data source.
|
|
34
|
-
*/
|
|
35
|
-
export type ItemIndex = number & {
|
|
36
|
-
__brand: "ItemIndex";
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* Item within a data source.
|
|
40
|
-
*/
|
|
41
|
-
export type Item<T extends RecordBase> = {
|
|
42
|
-
index: ItemIndex;
|
|
43
|
-
rowNumber: RowNumber;
|
|
44
|
-
record: T;
|
|
45
|
-
};
|
|
46
|
-
export type RecordBase = Record<string, CellValue>;
|
|
47
|
-
export type DataSourceRow = Record<ColumnName, Partial<Cell>>;
|
|
48
|
-
export type RangeOperationCallback = (rangeRef: WorkbookRangeRef) => Promise<void>;
|
|
49
|
-
//# sourceMappingURL=DataSource.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DataSource.d.ts","sourceRoot":"","sources":["../../../src/models/DataSource.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3D;;;GAGG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,UAAU,IAAI;IAC9C,OAAO,EAAE,gBAAgB,CAAC;IAC1B,UAAU,EAAE,SAAS,CAAC;IACtB,IAAI,EAAE,UAAU,EAAE,CAAC;IACnB,MAAM,EAAE;QACP,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;QACtB,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;KAC7B,CAAC;CACF,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAE3B;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,UAAU,IAAI,CAAC,GAAG,EAAE,aAAa,KAAK,CAAC,CAAC;AAEzE;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,UAAU,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,aAAa,CAAC;AAE5E;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG;IAChC,OAAO,EAAE,WAAW,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,IAAI,CAAC,CAAC,SAAS,UAAU,IAAI;IACxC,KAAK,EAAE,SAAS,CAAC;IACjB,SAAS,EAAE,SAAS,CAAC;IACrB,MAAM,EAAE,CAAC,CAAC;CACV,CAAC;AAGF,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AACnD,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AAC9D,MAAM,MAAM,sBAAsB,GAAG,CAAC,QAAQ,EAAE,gBAAgB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tooling for easily creating, updating, and deleting items in a worksheet or range.
|
|
3
|
-
* @module dataSource
|
|
4
|
-
* @category Services
|
|
5
|
-
* @experimental
|
|
6
|
-
*/
|
|
7
|
-
import type { DataSource, Item, ItemIndex, RecordBase, RowDecoder, RowEncoder } from "../models/DataSource.ts";
|
|
8
|
-
import type { WorkbookRangeRef } from "../models/WorkbookRange.ts";
|
|
9
|
-
/**
|
|
10
|
-
* Define a datasource from an entire worksheet.
|
|
11
|
-
* @template T Type of the record, extending RecordBase.
|
|
12
|
-
* @param worksheetRef Workbook range reference to define the data source on.
|
|
13
|
-
* @param decode Function to decode a row into a record.
|
|
14
|
-
* @param encode Function to encode a record into a row. Optional.
|
|
15
|
-
* @returns The initialized data source.
|
|
16
|
-
* @experimental
|
|
17
|
-
*/
|
|
18
|
-
export declare function dataSourceFromWorksheet<T extends RecordBase>(worksheetRef: WorkbookRangeRef, decode: RowDecoder<T>, encode?: RowEncoder<T> | null): Promise<DataSource<T>>;
|
|
19
|
-
/**
|
|
20
|
-
* Defines a data source from a given range.
|
|
21
|
-
* @template T Type of the record, extending RecordBase.
|
|
22
|
-
* @param rangeRef Workbook range reference to define the data source on.
|
|
23
|
-
* @param decode Function to decode a row into a record.
|
|
24
|
-
* @param encode Function to encode a record into a row. Optional.
|
|
25
|
-
* @returns The initialized data source.
|
|
26
|
-
* @experimental
|
|
27
|
-
*/
|
|
28
|
-
export declare function dataSourceFromRange<T extends RecordBase>(rangeRef: WorkbookRangeRef, decode: RowDecoder<T>, encode?: RowEncoder<T> | null): Promise<DataSource<T>>;
|
|
29
|
-
/**
|
|
30
|
-
* Reads all items from the data source.
|
|
31
|
-
* @template T Type of the record, extending RecordBase.
|
|
32
|
-
* @param source Data source to read from.
|
|
33
|
-
* @returns Array of all items in the data source.
|
|
34
|
-
* @deprecated Iterate on the source directly using `for await (const item of source)`.
|
|
35
|
-
*/
|
|
36
|
-
export declare function listItems<T extends RecordBase>(source: DataSource<T>): AsyncIterable<Item<T>>;
|
|
37
|
-
/**
|
|
38
|
-
* Creates a new item in the data source.
|
|
39
|
-
* @template T Type of the record, extending RecordBase.
|
|
40
|
-
* @param source Data source to insert into. Must be initialized.
|
|
41
|
-
* @param record Record to insert.
|
|
42
|
-
* @param after Index after which to insert the new item. If null, inserts at the end. If -1 inserts at top.
|
|
43
|
-
* @returns Newly created item, including its index, row number, and record.
|
|
44
|
-
* @throws {InvalidOperationError} If the data source is not initialized.
|
|
45
|
-
* @throws {InvalidArgumentError} If the 'after' index is out of range.
|
|
46
|
-
* @experimental
|
|
47
|
-
*/
|
|
48
|
-
export declare function createItem<T extends RecordBase>(source: DataSource<T>, record: T, after?: ItemIndex | null): Promise<Item<T>>;
|
|
49
|
-
/**
|
|
50
|
-
* Updates an item in the data source at the specified index.
|
|
51
|
-
* @template T Type of the record, extending RecordBase.
|
|
52
|
-
* @param source Data source to update. Must be initialized.
|
|
53
|
-
* @param index Index of the item to update.
|
|
54
|
-
* @param record New record to write at the specified index.
|
|
55
|
-
* @throws {InvalidOperationError} If the data source is not initialized.
|
|
56
|
-
* @throws {InvalidArgumentError} If the index is out of range.
|
|
57
|
-
* @experimental
|
|
58
|
-
*/
|
|
59
|
-
export declare function updateItem<T extends RecordBase>(source: DataSource<T>, index: ItemIndex, record: T): Promise<void>;
|
|
60
|
-
/**
|
|
61
|
-
* Deletes an item from the data source at the specified index.
|
|
62
|
-
* @template T Type of the record, extending RecordBase.
|
|
63
|
-
* @param source Data source to delete from. Must be initialized.
|
|
64
|
-
* @param index Index of the item to delete.
|
|
65
|
-
* @throws {InvalidOperationError} If the data source is not initialized.
|
|
66
|
-
* @experimental
|
|
67
|
-
*/
|
|
68
|
-
export declare function deleteItem<T extends RecordBase>(source: DataSource<T>, index: ItemIndex): Promise<void>;
|
|
69
|
-
//# sourceMappingURL=dataSource.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dataSource.d.ts","sourceRoot":"","sources":["../../../src/services/dataSource.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,KAAK,EAAE,UAAU,EAAiB,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE9H,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAWnE;;;;;;;;GAQG;AACH,wBAAsB,uBAAuB,CAAC,CAAC,SAAS,UAAU,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,MAAM,GAAE,UAAU,CAAC,CAAC,CAAC,GAAG,IAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAGtL;AACD;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,MAAM,GAAE,UAAU,CAAC,CAAC,CAAC,GAAG,IAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAqC9K;AAED;;;;;;GAMG;AACH,wBAAuB,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAIpG;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAAC,CAAC,SAAS,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,GAAE,SAAS,GAAG,IAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAgBzI;AAED;;;;;;;;;GASG;AACH,wBAAsB,UAAU,CAAC,CAAC,SAAS,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CASxH;AAED;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAAC,CAAC,SAAS,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAI7G"}
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Tooling for easily creating, updating, and deleting items in a worksheet or range.
|
|
4
|
-
* @module dataSource
|
|
5
|
-
* @category Services
|
|
6
|
-
* @experimental
|
|
7
|
-
*/
|
|
8
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.dataSourceFromWorksheet = dataSourceFromWorksheet;
|
|
13
|
-
exports.dataSourceFromRange = dataSourceFromRange;
|
|
14
|
-
exports.listItems = listItems;
|
|
15
|
-
exports.createItem = createItem;
|
|
16
|
-
exports.updateItem = updateItem;
|
|
17
|
-
exports.deleteItem = deleteItem;
|
|
18
|
-
const InvalidOperationError_ts_1 = __importDefault(require("../errors/InvalidOperationError.js"));
|
|
19
|
-
const ProtocolError_ts_1 = __importDefault(require("../errors/ProtocolError.js"));
|
|
20
|
-
const deleteWorkbookRange_ts_1 = __importDefault(require("../operations/workbookRange/deleteWorkbookRange.js"));
|
|
21
|
-
const getWorkbookWorksheetRange_ts_1 = __importDefault(require("../operations/workbookRange/getWorkbookWorksheetRange.js"));
|
|
22
|
-
const insertWorkbookCells_ts_1 = __importDefault(require("../operations/workbookRange/insertWorkbookCells.js"));
|
|
23
|
-
const updateWorkbookRange_ts_1 = __importDefault(require("../operations/workbookRange/updateWorkbookRange.js"));
|
|
24
|
-
const getWorkbookWorksheetUsedRangeRef_ts_1 = __importDefault(require("../operations/workbookWorksheet/getWorkbookWorksheetUsedRangeRef.js"));
|
|
25
|
-
const readWorkbookRows_ts_1 = __importDefault(require("../tasks/readWorkbookRows.js"));
|
|
26
|
-
const addressManipulation_ts_1 = require("./addressManipulation.js");
|
|
27
|
-
const cartesianAddress_ts_1 = require("./cartesianAddress.js");
|
|
28
|
-
const cell_ts_1 = require("./cell.js");
|
|
29
|
-
/**
|
|
30
|
-
* Define a datasource from an entire worksheet.
|
|
31
|
-
* @template T Type of the record, extending RecordBase.
|
|
32
|
-
* @param worksheetRef Workbook range reference to define the data source on.
|
|
33
|
-
* @param decode Function to decode a row into a record.
|
|
34
|
-
* @param encode Function to encode a record into a row. Optional.
|
|
35
|
-
* @returns The initialized data source.
|
|
36
|
-
* @experimental
|
|
37
|
-
*/
|
|
38
|
-
async function dataSourceFromWorksheet(worksheetRef, decode, encode = null) {
|
|
39
|
-
const rangeRef = await (0, getWorkbookWorksheetUsedRangeRef_ts_1.default)(worksheetRef);
|
|
40
|
-
return dataSourceFromRange(rangeRef, decode, encode);
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Defines a data source from a given range.
|
|
44
|
-
* @template T Type of the record, extending RecordBase.
|
|
45
|
-
* @param rangeRef Workbook range reference to define the data source on.
|
|
46
|
-
* @param decode Function to decode a row into a record.
|
|
47
|
-
* @param encode Function to encode a record into a row. Optional.
|
|
48
|
-
* @returns The initialized data source.
|
|
49
|
-
* @experimental
|
|
50
|
-
*/
|
|
51
|
-
async function dataSourceFromRange(rangeRef, decode, encode = null) {
|
|
52
|
-
if ((0, addressManipulation_ts_1.countAddressRows)(rangeRef.address) < 1) {
|
|
53
|
-
throw new InvalidOperationError_ts_1.default("Cannot create a data source from an empty range. It must at least contain a header row.");
|
|
54
|
-
}
|
|
55
|
-
const headRef = (0, addressManipulation_ts_1.subRange)(rangeRef, 0, 1);
|
|
56
|
-
const bodyRef = (0, addressManipulation_ts_1.subRange)(rangeRef, 1);
|
|
57
|
-
const head = await getHead(headRef);
|
|
58
|
-
const { ay: bodyOffset } = (0, cartesianAddress_ts_1.addressToCartesian)(bodyRef.address);
|
|
59
|
-
const source = {
|
|
60
|
-
bodyRef,
|
|
61
|
-
bodyOffset,
|
|
62
|
-
coding: {
|
|
63
|
-
decode,
|
|
64
|
-
encode,
|
|
65
|
-
},
|
|
66
|
-
head,
|
|
67
|
-
async *[Symbol.asyncIterator]() {
|
|
68
|
-
let index = 0;
|
|
69
|
-
for await (const row of (0, readWorkbookRows_ts_1.default)(source.bodyRef)) {
|
|
70
|
-
const record = rowToRecord(row, source);
|
|
71
|
-
const rowNumber = indexToRowNumber(source.bodyOffset, index);
|
|
72
|
-
yield {
|
|
73
|
-
index,
|
|
74
|
-
rowNumber,
|
|
75
|
-
record,
|
|
76
|
-
};
|
|
77
|
-
index++;
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
return source;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Reads all items from the data source.
|
|
85
|
-
* @template T Type of the record, extending RecordBase.
|
|
86
|
-
* @param source Data source to read from.
|
|
87
|
-
* @returns Array of all items in the data source.
|
|
88
|
-
* @deprecated Iterate on the source directly using `for await (const item of source)`.
|
|
89
|
-
*/
|
|
90
|
-
async function* listItems(source) {
|
|
91
|
-
for await (const item of source) {
|
|
92
|
-
yield item;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Creates a new item in the data source.
|
|
97
|
-
* @template T Type of the record, extending RecordBase.
|
|
98
|
-
* @param source Data source to insert into. Must be initialized.
|
|
99
|
-
* @param record Record to insert.
|
|
100
|
-
* @param after Index after which to insert the new item. If null, inserts at the end. If -1 inserts at top.
|
|
101
|
-
* @returns Newly created item, including its index, row number, and record.
|
|
102
|
-
* @throws {InvalidOperationError} If the data source is not initialized.
|
|
103
|
-
* @throws {InvalidArgumentError} If the 'after' index is out of range.
|
|
104
|
-
* @experimental
|
|
105
|
-
*/
|
|
106
|
-
async function createItem(source, record, after = null) {
|
|
107
|
-
const count = (0, addressManipulation_ts_1.countAddressRows)(source.bodyRef.address);
|
|
108
|
-
const index = (after === null ? count : after + 1);
|
|
109
|
-
const rowNumber = indexToRowNumber(source.bodyOffset, index);
|
|
110
|
-
await (0, insertWorkbookCells_ts_1.default)((0, addressManipulation_ts_1.superRange)(source.bodyRef, index, 1), "Down");
|
|
111
|
-
source.bodyRef = (0, addressManipulation_ts_1.superRange)(source.bodyRef, 0, count + 1);
|
|
112
|
-
await updateItem(source, index, record);
|
|
113
|
-
return {
|
|
114
|
-
index,
|
|
115
|
-
rowNumber,
|
|
116
|
-
record,
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Updates an item in the data source at the specified index.
|
|
121
|
-
* @template T Type of the record, extending RecordBase.
|
|
122
|
-
* @param source Data source to update. Must be initialized.
|
|
123
|
-
* @param index Index of the item to update.
|
|
124
|
-
* @param record New record to write at the specified index.
|
|
125
|
-
* @throws {InvalidOperationError} If the data source is not initialized.
|
|
126
|
-
* @throws {InvalidArgumentError} If the index is out of range.
|
|
127
|
-
* @experimental
|
|
128
|
-
*/
|
|
129
|
-
async function updateItem(source, index, record) {
|
|
130
|
-
const row = recordToRow(record, source);
|
|
131
|
-
const rowRef = (0, addressManipulation_ts_1.subRange)(source.bodyRef, index, 1);
|
|
132
|
-
await (0, updateWorkbookRange_ts_1.default)(rowRef, {
|
|
133
|
-
values: [row.map((x) => x.value)],
|
|
134
|
-
text: [row.map((x) => x.text)],
|
|
135
|
-
numberFormat: [row.map((x) => x.format)],
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Deletes an item from the data source at the specified index.
|
|
140
|
-
* @template T Type of the record, extending RecordBase.
|
|
141
|
-
* @param source Data source to delete from. Must be initialized.
|
|
142
|
-
* @param index Index of the item to delete.
|
|
143
|
-
* @throws {InvalidOperationError} If the data source is not initialized.
|
|
144
|
-
* @experimental
|
|
145
|
-
*/
|
|
146
|
-
async function deleteItem(source, index) {
|
|
147
|
-
const rowRef = (0, addressManipulation_ts_1.subRange)(source.bodyRef, index, 1);
|
|
148
|
-
await (0, deleteWorkbookRange_ts_1.default)(rowRef, "Up");
|
|
149
|
-
source.bodyRef = (0, addressManipulation_ts_1.subRange)(source.bodyRef, 0, -1);
|
|
150
|
-
}
|
|
151
|
-
function rowToRecord(row, source) {
|
|
152
|
-
const sourceRow = source.head.reduce((acc, heading, columnIndex) => {
|
|
153
|
-
const cell = row[columnIndex];
|
|
154
|
-
if (!cell) {
|
|
155
|
-
throw new ProtocolError_ts_1.default(`Cell for '${heading}' is undefined`);
|
|
156
|
-
}
|
|
157
|
-
acc[heading] = cell;
|
|
158
|
-
return acc;
|
|
159
|
-
}, {});
|
|
160
|
-
const record = source.coding.decode(sourceRow);
|
|
161
|
-
return record;
|
|
162
|
-
}
|
|
163
|
-
function recordToRow(record, source) {
|
|
164
|
-
if (!source.coding.encode) {
|
|
165
|
-
throw new InvalidOperationError_ts_1.default("Data source does not have an encoder defined. Add an encoder for reading.");
|
|
166
|
-
}
|
|
167
|
-
const sourceRow = source.coding.encode(record);
|
|
168
|
-
const row = source.head.map((heading) => {
|
|
169
|
-
const cell = sourceRow[heading];
|
|
170
|
-
if (cell === undefined) {
|
|
171
|
-
throw new Error(`Encoder produced undefined value for '${heading}'.`); // TODO: Make more specific error
|
|
172
|
-
}
|
|
173
|
-
return {
|
|
174
|
-
value: cell.value ?? "",
|
|
175
|
-
text: cell.text ?? (cell.value ?? "").toString(),
|
|
176
|
-
format: cell.format ?? cell_ts_1.generalCellFormat,
|
|
177
|
-
merge: {},
|
|
178
|
-
alignment: {},
|
|
179
|
-
borders: {},
|
|
180
|
-
fill: {},
|
|
181
|
-
font: {},
|
|
182
|
-
};
|
|
183
|
-
});
|
|
184
|
-
return row;
|
|
185
|
-
}
|
|
186
|
-
function indexToRowNumber(bodyOffset, index) {
|
|
187
|
-
return (bodyOffset + index + 1); // +1 to convert to 1-based index
|
|
188
|
-
}
|
|
189
|
-
async function getHead(headRef) {
|
|
190
|
-
const headRange = await (0, getWorkbookWorksheetRange_ts_1.default)(headRef);
|
|
191
|
-
const head = headRange.text[0].map((x) => x);
|
|
192
|
-
return head;
|
|
193
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tooling for easily creating, updating, and deleting items in a worksheet or range.
|
|
3
|
-
* @module DataSource
|
|
4
|
-
* @category Models
|
|
5
|
-
* @experimental
|
|
6
|
-
*/
|
|
7
|
-
import type { Cell, CellValue } from "./Cell.ts";
|
|
8
|
-
import type { ColumnName } from "./Column.ts";
|
|
9
|
-
import type { RowNumber, RowOffset } from "./Row.ts";
|
|
10
|
-
import type { WorkbookRangeRef } from "./WorkbookRange.ts";
|
|
11
|
-
/**
|
|
12
|
-
* Defines a data source for a worksheet or range.
|
|
13
|
-
* @template T Type of the record, extending RecordBase.
|
|
14
|
-
*/
|
|
15
|
-
export type DataSource<T extends RecordBase> = {
|
|
16
|
-
bodyRef: WorkbookRangeRef;
|
|
17
|
-
bodyOffset: RowOffset;
|
|
18
|
-
head: ColumnName[];
|
|
19
|
-
coding: {
|
|
20
|
-
decode: RowDecoder<T>;
|
|
21
|
-
encode: RowEncoder<T> | null;
|
|
22
|
-
};
|
|
23
|
-
} & AsyncIterable<Item<T>>;
|
|
24
|
-
/**
|
|
25
|
-
* Method to decode row into a record.
|
|
26
|
-
*/
|
|
27
|
-
export type RowDecoder<T extends RecordBase> = (row: DataSourceRow) => T;
|
|
28
|
-
/**
|
|
29
|
-
* Method to encode a record into a row.
|
|
30
|
-
*/
|
|
31
|
-
export type RowEncoder<T extends RecordBase> = (record: T) => DataSourceRow;
|
|
32
|
-
/**
|
|
33
|
-
* Item's position within a data source.
|
|
34
|
-
*/
|
|
35
|
-
export type ItemIndex = number & {
|
|
36
|
-
__brand: "ItemIndex";
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* Item within a data source.
|
|
40
|
-
*/
|
|
41
|
-
export type Item<T extends RecordBase> = {
|
|
42
|
-
index: ItemIndex;
|
|
43
|
-
rowNumber: RowNumber;
|
|
44
|
-
record: T;
|
|
45
|
-
};
|
|
46
|
-
export type RecordBase = Record<string, CellValue>;
|
|
47
|
-
export type DataSourceRow = Record<ColumnName, Partial<Cell>>;
|
|
48
|
-
export type RangeOperationCallback = (rangeRef: WorkbookRangeRef) => Promise<void>;
|
|
49
|
-
//# sourceMappingURL=DataSource.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DataSource.d.ts","sourceRoot":"","sources":["../../../src/models/DataSource.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3D;;;GAGG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,UAAU,IAAI;IAC9C,OAAO,EAAE,gBAAgB,CAAC;IAC1B,UAAU,EAAE,SAAS,CAAC;IACtB,IAAI,EAAE,UAAU,EAAE,CAAC;IACnB,MAAM,EAAE;QACP,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;QACtB,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;KAC7B,CAAC;CACF,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAE3B;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,UAAU,IAAI,CAAC,GAAG,EAAE,aAAa,KAAK,CAAC,CAAC;AAEzE;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,UAAU,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,aAAa,CAAC;AAE5E;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG;IAChC,OAAO,EAAE,WAAW,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,IAAI,CAAC,CAAC,SAAS,UAAU,IAAI;IACxC,KAAK,EAAE,SAAS,CAAC;IACjB,SAAS,EAAE,SAAS,CAAC;IACrB,MAAM,EAAE,CAAC,CAAC;CACV,CAAC;AAGF,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AACnD,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AAC9D,MAAM,MAAM,sBAAsB,GAAG,CAAC,QAAQ,EAAE,gBAAgB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tooling for easily creating, updating, and deleting items in a worksheet or range.
|
|
3
|
-
* @module dataSource
|
|
4
|
-
* @category Services
|
|
5
|
-
* @experimental
|
|
6
|
-
*/
|
|
7
|
-
import type { DataSource, Item, ItemIndex, RecordBase, RowDecoder, RowEncoder } from "../models/DataSource.ts";
|
|
8
|
-
import type { WorkbookRangeRef } from "../models/WorkbookRange.ts";
|
|
9
|
-
/**
|
|
10
|
-
* Define a datasource from an entire worksheet.
|
|
11
|
-
* @template T Type of the record, extending RecordBase.
|
|
12
|
-
* @param worksheetRef Workbook range reference to define the data source on.
|
|
13
|
-
* @param decode Function to decode a row into a record.
|
|
14
|
-
* @param encode Function to encode a record into a row. Optional.
|
|
15
|
-
* @returns The initialized data source.
|
|
16
|
-
* @experimental
|
|
17
|
-
*/
|
|
18
|
-
export declare function dataSourceFromWorksheet<T extends RecordBase>(worksheetRef: WorkbookRangeRef, decode: RowDecoder<T>, encode?: RowEncoder<T> | null): Promise<DataSource<T>>;
|
|
19
|
-
/**
|
|
20
|
-
* Defines a data source from a given range.
|
|
21
|
-
* @template T Type of the record, extending RecordBase.
|
|
22
|
-
* @param rangeRef Workbook range reference to define the data source on.
|
|
23
|
-
* @param decode Function to decode a row into a record.
|
|
24
|
-
* @param encode Function to encode a record into a row. Optional.
|
|
25
|
-
* @returns The initialized data source.
|
|
26
|
-
* @experimental
|
|
27
|
-
*/
|
|
28
|
-
export declare function dataSourceFromRange<T extends RecordBase>(rangeRef: WorkbookRangeRef, decode: RowDecoder<T>, encode?: RowEncoder<T> | null): Promise<DataSource<T>>;
|
|
29
|
-
/**
|
|
30
|
-
* Reads all items from the data source.
|
|
31
|
-
* @template T Type of the record, extending RecordBase.
|
|
32
|
-
* @param source Data source to read from.
|
|
33
|
-
* @returns Array of all items in the data source.
|
|
34
|
-
* @deprecated Iterate on the source directly using `for await (const item of source)`.
|
|
35
|
-
*/
|
|
36
|
-
export declare function listItems<T extends RecordBase>(source: DataSource<T>): AsyncIterable<Item<T>>;
|
|
37
|
-
/**
|
|
38
|
-
* Creates a new item in the data source.
|
|
39
|
-
* @template T Type of the record, extending RecordBase.
|
|
40
|
-
* @param source Data source to insert into. Must be initialized.
|
|
41
|
-
* @param record Record to insert.
|
|
42
|
-
* @param after Index after which to insert the new item. If null, inserts at the end. If -1 inserts at top.
|
|
43
|
-
* @returns Newly created item, including its index, row number, and record.
|
|
44
|
-
* @throws {InvalidOperationError} If the data source is not initialized.
|
|
45
|
-
* @throws {InvalidArgumentError} If the 'after' index is out of range.
|
|
46
|
-
* @experimental
|
|
47
|
-
*/
|
|
48
|
-
export declare function createItem<T extends RecordBase>(source: DataSource<T>, record: T, after?: ItemIndex | null): Promise<Item<T>>;
|
|
49
|
-
/**
|
|
50
|
-
* Updates an item in the data source at the specified index.
|
|
51
|
-
* @template T Type of the record, extending RecordBase.
|
|
52
|
-
* @param source Data source to update. Must be initialized.
|
|
53
|
-
* @param index Index of the item to update.
|
|
54
|
-
* @param record New record to write at the specified index.
|
|
55
|
-
* @throws {InvalidOperationError} If the data source is not initialized.
|
|
56
|
-
* @throws {InvalidArgumentError} If the index is out of range.
|
|
57
|
-
* @experimental
|
|
58
|
-
*/
|
|
59
|
-
export declare function updateItem<T extends RecordBase>(source: DataSource<T>, index: ItemIndex, record: T): Promise<void>;
|
|
60
|
-
/**
|
|
61
|
-
* Deletes an item from the data source at the specified index.
|
|
62
|
-
* @template T Type of the record, extending RecordBase.
|
|
63
|
-
* @param source Data source to delete from. Must be initialized.
|
|
64
|
-
* @param index Index of the item to delete.
|
|
65
|
-
* @throws {InvalidOperationError} If the data source is not initialized.
|
|
66
|
-
* @experimental
|
|
67
|
-
*/
|
|
68
|
-
export declare function deleteItem<T extends RecordBase>(source: DataSource<T>, index: ItemIndex): Promise<void>;
|
|
69
|
-
//# sourceMappingURL=dataSource.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dataSource.d.ts","sourceRoot":"","sources":["../../../src/services/dataSource.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,KAAK,EAAE,UAAU,EAAiB,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE9H,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAWnE;;;;;;;;GAQG;AACH,wBAAsB,uBAAuB,CAAC,CAAC,SAAS,UAAU,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,MAAM,GAAE,UAAU,CAAC,CAAC,CAAC,GAAG,IAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAGtL;AACD;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,MAAM,GAAE,UAAU,CAAC,CAAC,CAAC,GAAG,IAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAqC9K;AAED;;;;;;GAMG;AACH,wBAAuB,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAIpG;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAAC,CAAC,SAAS,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,GAAE,SAAS,GAAG,IAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAgBzI;AAED;;;;;;;;;GASG;AACH,wBAAsB,UAAU,CAAC,CAAC,SAAS,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CASxH;AAED;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAAC,CAAC,SAAS,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAI7G"}
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tooling for easily creating, updating, and deleting items in a worksheet or range.
|
|
3
|
-
* @module dataSource
|
|
4
|
-
* @category Services
|
|
5
|
-
* @experimental
|
|
6
|
-
*/
|
|
7
|
-
import InvalidOperationError from "../errors/InvalidOperationError.js";
|
|
8
|
-
import ProtocolError from "../errors/ProtocolError.js";
|
|
9
|
-
import deleteWorkbookRange from "../operations/workbookRange/deleteWorkbookRange.js";
|
|
10
|
-
import getWorkbookWorksheetRange from "../operations/workbookRange/getWorkbookWorksheetRange.js";
|
|
11
|
-
import insertWorkbookCells from "../operations/workbookRange/insertWorkbookCells.js";
|
|
12
|
-
import updateWorkbookRange from "../operations/workbookRange/updateWorkbookRange.js";
|
|
13
|
-
import getWorkbookWorksheetUsedRangeRef from "../operations/workbookWorksheet/getWorkbookWorksheetUsedRangeRef.js";
|
|
14
|
-
import readWorkbookRows from "../tasks/readWorkbookRows.js";
|
|
15
|
-
import { countAddressRows, subRange, superRange } from "./addressManipulation.js";
|
|
16
|
-
import { addressToCartesian } from "./cartesianAddress.js";
|
|
17
|
-
import { generalCellFormat } from "./cell.js";
|
|
18
|
-
/**
|
|
19
|
-
* Define a datasource from an entire worksheet.
|
|
20
|
-
* @template T Type of the record, extending RecordBase.
|
|
21
|
-
* @param worksheetRef Workbook range reference to define the data source on.
|
|
22
|
-
* @param decode Function to decode a row into a record.
|
|
23
|
-
* @param encode Function to encode a record into a row. Optional.
|
|
24
|
-
* @returns The initialized data source.
|
|
25
|
-
* @experimental
|
|
26
|
-
*/
|
|
27
|
-
export async function dataSourceFromWorksheet(worksheetRef, decode, encode = null) {
|
|
28
|
-
const rangeRef = await getWorkbookWorksheetUsedRangeRef(worksheetRef);
|
|
29
|
-
return dataSourceFromRange(rangeRef, decode, encode);
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Defines a data source from a given range.
|
|
33
|
-
* @template T Type of the record, extending RecordBase.
|
|
34
|
-
* @param rangeRef Workbook range reference to define the data source on.
|
|
35
|
-
* @param decode Function to decode a row into a record.
|
|
36
|
-
* @param encode Function to encode a record into a row. Optional.
|
|
37
|
-
* @returns The initialized data source.
|
|
38
|
-
* @experimental
|
|
39
|
-
*/
|
|
40
|
-
export async function dataSourceFromRange(rangeRef, decode, encode = null) {
|
|
41
|
-
if (countAddressRows(rangeRef.address) < 1) {
|
|
42
|
-
throw new InvalidOperationError("Cannot create a data source from an empty range. It must at least contain a header row.");
|
|
43
|
-
}
|
|
44
|
-
const headRef = subRange(rangeRef, 0, 1);
|
|
45
|
-
const bodyRef = subRange(rangeRef, 1);
|
|
46
|
-
const head = await getHead(headRef);
|
|
47
|
-
const { ay: bodyOffset } = addressToCartesian(bodyRef.address);
|
|
48
|
-
const source = {
|
|
49
|
-
bodyRef,
|
|
50
|
-
bodyOffset,
|
|
51
|
-
coding: {
|
|
52
|
-
decode,
|
|
53
|
-
encode,
|
|
54
|
-
},
|
|
55
|
-
head,
|
|
56
|
-
async *[Symbol.asyncIterator]() {
|
|
57
|
-
let index = 0;
|
|
58
|
-
for await (const row of readWorkbookRows(source.bodyRef)) {
|
|
59
|
-
const record = rowToRecord(row, source);
|
|
60
|
-
const rowNumber = indexToRowNumber(source.bodyOffset, index);
|
|
61
|
-
yield {
|
|
62
|
-
index,
|
|
63
|
-
rowNumber,
|
|
64
|
-
record,
|
|
65
|
-
};
|
|
66
|
-
index++;
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
return source;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Reads all items from the data source.
|
|
74
|
-
* @template T Type of the record, extending RecordBase.
|
|
75
|
-
* @param source Data source to read from.
|
|
76
|
-
* @returns Array of all items in the data source.
|
|
77
|
-
* @deprecated Iterate on the source directly using `for await (const item of source)`.
|
|
78
|
-
*/
|
|
79
|
-
export async function* listItems(source) {
|
|
80
|
-
for await (const item of source) {
|
|
81
|
-
yield item;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Creates a new item in the data source.
|
|
86
|
-
* @template T Type of the record, extending RecordBase.
|
|
87
|
-
* @param source Data source to insert into. Must be initialized.
|
|
88
|
-
* @param record Record to insert.
|
|
89
|
-
* @param after Index after which to insert the new item. If null, inserts at the end. If -1 inserts at top.
|
|
90
|
-
* @returns Newly created item, including its index, row number, and record.
|
|
91
|
-
* @throws {InvalidOperationError} If the data source is not initialized.
|
|
92
|
-
* @throws {InvalidArgumentError} If the 'after' index is out of range.
|
|
93
|
-
* @experimental
|
|
94
|
-
*/
|
|
95
|
-
export async function createItem(source, record, after = null) {
|
|
96
|
-
const count = countAddressRows(source.bodyRef.address);
|
|
97
|
-
const index = (after === null ? count : after + 1);
|
|
98
|
-
const rowNumber = indexToRowNumber(source.bodyOffset, index);
|
|
99
|
-
await insertWorkbookCells(superRange(source.bodyRef, index, 1), "Down");
|
|
100
|
-
source.bodyRef = superRange(source.bodyRef, 0, count + 1);
|
|
101
|
-
await updateItem(source, index, record);
|
|
102
|
-
return {
|
|
103
|
-
index,
|
|
104
|
-
rowNumber,
|
|
105
|
-
record,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Updates an item in the data source at the specified index.
|
|
110
|
-
* @template T Type of the record, extending RecordBase.
|
|
111
|
-
* @param source Data source to update. Must be initialized.
|
|
112
|
-
* @param index Index of the item to update.
|
|
113
|
-
* @param record New record to write at the specified index.
|
|
114
|
-
* @throws {InvalidOperationError} If the data source is not initialized.
|
|
115
|
-
* @throws {InvalidArgumentError} If the index is out of range.
|
|
116
|
-
* @experimental
|
|
117
|
-
*/
|
|
118
|
-
export async function updateItem(source, index, record) {
|
|
119
|
-
const row = recordToRow(record, source);
|
|
120
|
-
const rowRef = subRange(source.bodyRef, index, 1);
|
|
121
|
-
await updateWorkbookRange(rowRef, {
|
|
122
|
-
values: [row.map((x) => x.value)],
|
|
123
|
-
text: [row.map((x) => x.text)],
|
|
124
|
-
numberFormat: [row.map((x) => x.format)],
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Deletes an item from the data source at the specified index.
|
|
129
|
-
* @template T Type of the record, extending RecordBase.
|
|
130
|
-
* @param source Data source to delete from. Must be initialized.
|
|
131
|
-
* @param index Index of the item to delete.
|
|
132
|
-
* @throws {InvalidOperationError} If the data source is not initialized.
|
|
133
|
-
* @experimental
|
|
134
|
-
*/
|
|
135
|
-
export async function deleteItem(source, index) {
|
|
136
|
-
const rowRef = subRange(source.bodyRef, index, 1);
|
|
137
|
-
await deleteWorkbookRange(rowRef, "Up");
|
|
138
|
-
source.bodyRef = subRange(source.bodyRef, 0, -1);
|
|
139
|
-
}
|
|
140
|
-
function rowToRecord(row, source) {
|
|
141
|
-
const sourceRow = source.head.reduce((acc, heading, columnIndex) => {
|
|
142
|
-
const cell = row[columnIndex];
|
|
143
|
-
if (!cell) {
|
|
144
|
-
throw new ProtocolError(`Cell for '${heading}' is undefined`);
|
|
145
|
-
}
|
|
146
|
-
acc[heading] = cell;
|
|
147
|
-
return acc;
|
|
148
|
-
}, {});
|
|
149
|
-
const record = source.coding.decode(sourceRow);
|
|
150
|
-
return record;
|
|
151
|
-
}
|
|
152
|
-
function recordToRow(record, source) {
|
|
153
|
-
if (!source.coding.encode) {
|
|
154
|
-
throw new InvalidOperationError("Data source does not have an encoder defined. Add an encoder for reading.");
|
|
155
|
-
}
|
|
156
|
-
const sourceRow = source.coding.encode(record);
|
|
157
|
-
const row = source.head.map((heading) => {
|
|
158
|
-
const cell = sourceRow[heading];
|
|
159
|
-
if (cell === undefined) {
|
|
160
|
-
throw new Error(`Encoder produced undefined value for '${heading}'.`); // TODO: Make more specific error
|
|
161
|
-
}
|
|
162
|
-
return {
|
|
163
|
-
value: cell.value ?? "",
|
|
164
|
-
text: cell.text ?? (cell.value ?? "").toString(),
|
|
165
|
-
format: cell.format ?? generalCellFormat,
|
|
166
|
-
merge: {},
|
|
167
|
-
alignment: {},
|
|
168
|
-
borders: {},
|
|
169
|
-
fill: {},
|
|
170
|
-
font: {},
|
|
171
|
-
};
|
|
172
|
-
});
|
|
173
|
-
return row;
|
|
174
|
-
}
|
|
175
|
-
function indexToRowNumber(bodyOffset, index) {
|
|
176
|
-
return (bodyOffset + index + 1); // +1 to convert to 1-based index
|
|
177
|
-
}
|
|
178
|
-
async function getHead(headRef) {
|
|
179
|
-
const headRange = await getWorkbookWorksheetRange(headRef);
|
|
180
|
-
const head = headRange.text[0].map((x) => x);
|
|
181
|
-
return head;
|
|
182
|
-
}
|