@affino/datagrid-worker 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/postMessageTransport.d.ts +31 -0
- package/dist/postMessageTransport.d.ts.map +1 -0
- package/dist/postMessageTransport.js +81 -0
- package/dist/protocol.d.ts +43 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +134 -0
- package/dist/workerHost.d.ts +13 -0
- package/dist/workerHost.d.ts.map +1 -0
- package/dist/workerHost.js +58 -0
- package/dist/workerOwnedRowModel.d.ts +41 -0
- package/dist/workerOwnedRowModel.d.ts.map +1 -0
- package/dist/workerOwnedRowModel.js +893 -0
- package/dist/workerOwnedRowModelHost.d.ts +13 -0
- package/dist/workerOwnedRowModelHost.d.ts.map +1 -0
- package/dist/workerOwnedRowModelHost.js +127 -0
- package/dist/workerOwnedRowModelProtocol.d.ts +99 -0
- package/dist/workerOwnedRowModelProtocol.d.ts.map +1 -0
- package/dist/workerOwnedRowModelProtocol.js +70 -0
- package/package.json +45 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type CreateClientRowModelOptions, type DataGridRowNodeInput } from "@affino/datagrid-core";
|
|
2
|
+
import type { DataGridWorkerMessageSource, DataGridWorkerMessageTarget } from "./postMessageTransport.js";
|
|
3
|
+
export interface CreateDataGridWorkerOwnedRowModelHostOptions<T = unknown> extends Omit<CreateClientRowModelOptions<T>, "rows"> {
|
|
4
|
+
rows?: readonly DataGridRowNodeInput<T>[];
|
|
5
|
+
source: DataGridWorkerMessageSource;
|
|
6
|
+
target: DataGridWorkerMessageTarget;
|
|
7
|
+
channel?: string | null;
|
|
8
|
+
}
|
|
9
|
+
export interface DataGridWorkerOwnedRowModelHost {
|
|
10
|
+
dispose: () => void;
|
|
11
|
+
}
|
|
12
|
+
export declare function createDataGridWorkerOwnedRowModelHost<T = unknown>(options: CreateDataGridWorkerOwnedRowModelHostOptions<T>): DataGridWorkerOwnedRowModelHost;
|
|
13
|
+
//# sourceMappingURL=workerOwnedRowModelHost.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workerOwnedRowModelHost.d.ts","sourceRoot":"","sources":["../src/workerOwnedRowModelHost.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,2BAA2B,EAChC,KAAK,oBAAoB,EAC1B,MAAM,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAEV,2BAA2B,EAC3B,2BAA2B,EAC5B,MAAM,2BAA2B,CAAA;AASlC,MAAM,WAAW,4CAA4C,CAAC,CAAC,GAAG,OAAO,CACvE,SAAQ,IAAI,CAAC,2BAA2B,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC;IACpD,IAAI,CAAC,EAAE,SAAS,oBAAoB,CAAC,CAAC,CAAC,EAAE,CAAA;IACzC,MAAM,EAAE,2BAA2B,CAAA;IACnC,MAAM,EAAE,2BAA2B,CAAA;IACnC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACxB;AAED,MAAM,WAAW,+BAA+B;IAC9C,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB;AA6ED,wBAAgB,qCAAqC,CAAC,CAAC,GAAG,OAAO,EAC/D,OAAO,EAAE,4CAA4C,CAAC,CAAC,CAAC,GACvD,+BAA+B,CAmEjC"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { createClientRowModel, } from "@affino/datagrid-core";
|
|
2
|
+
import { DATAGRID_WORKER_ROW_MODEL_PAYLOAD_SCHEMA_VERSION, createDataGridWorkerRowModelUpdateMessage, isDataGridWorkerRowModelCommandMessage, } from "./workerOwnedRowModelProtocol.js";
|
|
3
|
+
function executeCommand(model, command) {
|
|
4
|
+
var _a, _b;
|
|
5
|
+
switch (command.type) {
|
|
6
|
+
case "sync":
|
|
7
|
+
return;
|
|
8
|
+
case "set-rows": {
|
|
9
|
+
const setRows = model.setRows;
|
|
10
|
+
setRows === null || setRows === void 0 ? void 0 : setRows(command.rows);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
case "patch-rows": {
|
|
14
|
+
model.patchRows(command.updates, command.options);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
case "set-viewport-range":
|
|
18
|
+
model.setViewportRange(command.range);
|
|
19
|
+
return;
|
|
20
|
+
case "set-pagination":
|
|
21
|
+
model.setPagination(command.pagination);
|
|
22
|
+
return;
|
|
23
|
+
case "set-page-size":
|
|
24
|
+
model.setPageSize(command.pageSize);
|
|
25
|
+
return;
|
|
26
|
+
case "set-current-page":
|
|
27
|
+
model.setCurrentPage(command.page);
|
|
28
|
+
return;
|
|
29
|
+
case "set-sort-model":
|
|
30
|
+
model.setSortModel(command.sortModel);
|
|
31
|
+
return;
|
|
32
|
+
case "set-filter-model":
|
|
33
|
+
model.setFilterModel(command.filterModel);
|
|
34
|
+
return;
|
|
35
|
+
case "set-sort-and-filter-model":
|
|
36
|
+
(_a = model.setSortAndFilterModel) === null || _a === void 0 ? void 0 : _a.call(model, command.input);
|
|
37
|
+
return;
|
|
38
|
+
case "set-group-by":
|
|
39
|
+
model.setGroupBy(command.groupBy);
|
|
40
|
+
return;
|
|
41
|
+
case "set-pivot-model":
|
|
42
|
+
model.setPivotModel(command.pivotModel);
|
|
43
|
+
return;
|
|
44
|
+
case "set-aggregation-model":
|
|
45
|
+
model.setAggregationModel(command.aggregationModel);
|
|
46
|
+
return;
|
|
47
|
+
case "set-group-expansion":
|
|
48
|
+
model.setGroupExpansion(command.expansion);
|
|
49
|
+
return;
|
|
50
|
+
case "register-formula-field":
|
|
51
|
+
(_b = model.registerFormulaField) === null || _b === void 0 ? void 0 : _b.call(model, command.definition);
|
|
52
|
+
return;
|
|
53
|
+
case "toggle-group":
|
|
54
|
+
model.toggleGroup(command.groupKey);
|
|
55
|
+
return;
|
|
56
|
+
case "expand-group":
|
|
57
|
+
model.expandGroup(command.groupKey);
|
|
58
|
+
return;
|
|
59
|
+
case "collapse-group":
|
|
60
|
+
model.collapseGroup(command.groupKey);
|
|
61
|
+
return;
|
|
62
|
+
case "expand-all-groups":
|
|
63
|
+
model.expandAllGroups();
|
|
64
|
+
return;
|
|
65
|
+
case "collapse-all-groups":
|
|
66
|
+
model.collapseAllGroups();
|
|
67
|
+
return;
|
|
68
|
+
case "refresh":
|
|
69
|
+
model.refresh(command.reason);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export function createDataGridWorkerOwnedRowModelHost(options) {
|
|
74
|
+
const { source, target, channel, rows, ...clientRowModelOptions } = options;
|
|
75
|
+
const model = createClientRowModel({
|
|
76
|
+
...clientRowModelOptions,
|
|
77
|
+
rows: rows !== null && rows !== void 0 ? rows : [],
|
|
78
|
+
});
|
|
79
|
+
let disposed = false;
|
|
80
|
+
const emitUpdate = (requestId = 0) => {
|
|
81
|
+
var _a, _b, _c, _d, _e, _f;
|
|
82
|
+
if (disposed) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const snapshot = model.getSnapshot();
|
|
86
|
+
const visibleRange = {
|
|
87
|
+
start: snapshot.viewportRange.start,
|
|
88
|
+
end: snapshot.viewportRange.end,
|
|
89
|
+
};
|
|
90
|
+
const visibleRows = model.getRowsInRange(visibleRange);
|
|
91
|
+
const payload = {
|
|
92
|
+
schemaVersion: DATAGRID_WORKER_ROW_MODEL_PAYLOAD_SCHEMA_VERSION,
|
|
93
|
+
snapshot,
|
|
94
|
+
aggregationModel: model.getAggregationModel(),
|
|
95
|
+
formulaFields: (_b = (_a = model.getFormulaFields) === null || _a === void 0 ? void 0 : _a.call(model)) !== null && _b !== void 0 ? _b : [],
|
|
96
|
+
formulaExecutionPlan: (_d = (_c = model.getFormulaExecutionPlan) === null || _c === void 0 ? void 0 : _c.call(model)) !== null && _d !== void 0 ? _d : null,
|
|
97
|
+
formulaComputeStageDiagnostics: (_f = (_e = model.getFormulaComputeStageDiagnostics) === null || _e === void 0 ? void 0 : _e.call(model)) !== null && _f !== void 0 ? _f : null,
|
|
98
|
+
visibleRows,
|
|
99
|
+
visibleRange,
|
|
100
|
+
};
|
|
101
|
+
const message = createDataGridWorkerRowModelUpdateMessage(requestId, payload, channel);
|
|
102
|
+
target.postMessage(message);
|
|
103
|
+
};
|
|
104
|
+
const onMessage = (event) => {
|
|
105
|
+
if (disposed) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (!isDataGridWorkerRowModelCommandMessage(event.data, channel)) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const commandMessage = event.data;
|
|
112
|
+
executeCommand(model, commandMessage.payload);
|
|
113
|
+
emitUpdate(commandMessage.requestId);
|
|
114
|
+
};
|
|
115
|
+
source.addEventListener("message", onMessage);
|
|
116
|
+
emitUpdate(0);
|
|
117
|
+
return {
|
|
118
|
+
dispose() {
|
|
119
|
+
if (disposed) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
disposed = true;
|
|
123
|
+
source.removeEventListener("message", onMessage);
|
|
124
|
+
model.dispose();
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { DataGridAggregationModel, DataGridClientRowPatch, DataGridClientRowPatchOptions, DataGridFormulaComputeStageDiagnostics, DataGridFormulaFieldSnapshot, DataGridFilterSnapshot, DataGridGroupBySpec, DataGridGroupExpansionSnapshot, DataGridPaginationInput, DataGridPivotSpec, DataGridRowModelRefreshReason, DataGridRowModelSnapshot, DataGridRowNode, DataGridRowNodeInput, DataGridSortAndFilterModelInput, DataGridSortState, DataGridViewportRange } from "@affino/datagrid-core";
|
|
2
|
+
import type { DataGridFormulaExecutionPlanSnapshot, DataGridFormulaFieldDefinition } from "@affino/datagrid-formula-engine";
|
|
3
|
+
export declare const DATAGRID_WORKER_ROW_MODEL_PROTOCOL_VERSION: 1;
|
|
4
|
+
export declare const DATAGRID_WORKER_ROW_MODEL_PAYLOAD_SCHEMA_VERSION: 2;
|
|
5
|
+
export declare const DATAGRID_WORKER_ROW_MODEL_PROTOCOL_CHANNEL = "affino.datagrid.row-model";
|
|
6
|
+
export interface DataGridWorkerRowModelProtocolHeader {
|
|
7
|
+
version: typeof DATAGRID_WORKER_ROW_MODEL_PROTOCOL_VERSION;
|
|
8
|
+
channel: string;
|
|
9
|
+
requestId: number;
|
|
10
|
+
timestamp: number;
|
|
11
|
+
}
|
|
12
|
+
export type DataGridWorkerViewportCoalesceScope = "user" | "prefetch";
|
|
13
|
+
export type DataGridWorkerRowModelCommand<T = unknown> = {
|
|
14
|
+
type: "sync";
|
|
15
|
+
} | {
|
|
16
|
+
type: "set-rows";
|
|
17
|
+
rows: readonly DataGridRowNodeInput<T>[];
|
|
18
|
+
} | {
|
|
19
|
+
type: "patch-rows";
|
|
20
|
+
updates: readonly DataGridClientRowPatch<T>[];
|
|
21
|
+
options?: DataGridClientRowPatchOptions;
|
|
22
|
+
} | {
|
|
23
|
+
type: "set-viewport-range";
|
|
24
|
+
range: DataGridViewportRange;
|
|
25
|
+
coalesceScope?: DataGridWorkerViewportCoalesceScope;
|
|
26
|
+
} | {
|
|
27
|
+
type: "set-pagination";
|
|
28
|
+
pagination: DataGridPaginationInput | null;
|
|
29
|
+
} | {
|
|
30
|
+
type: "set-page-size";
|
|
31
|
+
pageSize: number | null;
|
|
32
|
+
} | {
|
|
33
|
+
type: "set-current-page";
|
|
34
|
+
page: number;
|
|
35
|
+
} | {
|
|
36
|
+
type: "set-sort-model";
|
|
37
|
+
sortModel: readonly DataGridSortState[];
|
|
38
|
+
} | {
|
|
39
|
+
type: "set-filter-model";
|
|
40
|
+
filterModel: DataGridFilterSnapshot | null;
|
|
41
|
+
} | {
|
|
42
|
+
type: "set-sort-and-filter-model";
|
|
43
|
+
input: DataGridSortAndFilterModelInput;
|
|
44
|
+
} | {
|
|
45
|
+
type: "set-group-by";
|
|
46
|
+
groupBy: DataGridGroupBySpec | null;
|
|
47
|
+
} | {
|
|
48
|
+
type: "set-pivot-model";
|
|
49
|
+
pivotModel: DataGridPivotSpec | null;
|
|
50
|
+
} | {
|
|
51
|
+
type: "set-aggregation-model";
|
|
52
|
+
aggregationModel: DataGridAggregationModel<T> | null;
|
|
53
|
+
} | {
|
|
54
|
+
type: "set-group-expansion";
|
|
55
|
+
expansion: DataGridGroupExpansionSnapshot | null;
|
|
56
|
+
} | {
|
|
57
|
+
type: "register-formula-field";
|
|
58
|
+
definition: DataGridFormulaFieldDefinition;
|
|
59
|
+
} | {
|
|
60
|
+
type: "toggle-group";
|
|
61
|
+
groupKey: string;
|
|
62
|
+
} | {
|
|
63
|
+
type: "expand-group";
|
|
64
|
+
groupKey: string;
|
|
65
|
+
} | {
|
|
66
|
+
type: "collapse-group";
|
|
67
|
+
groupKey: string;
|
|
68
|
+
} | {
|
|
69
|
+
type: "expand-all-groups";
|
|
70
|
+
} | {
|
|
71
|
+
type: "collapse-all-groups";
|
|
72
|
+
} | {
|
|
73
|
+
type: "refresh";
|
|
74
|
+
reason?: DataGridRowModelRefreshReason;
|
|
75
|
+
};
|
|
76
|
+
export interface DataGridWorkerRowModelCommandMessage<T = unknown> extends DataGridWorkerRowModelProtocolHeader {
|
|
77
|
+
kind: "row-model-command";
|
|
78
|
+
payload: DataGridWorkerRowModelCommand<T>;
|
|
79
|
+
}
|
|
80
|
+
export interface DataGridWorkerRowModelUpdatePayload<T = unknown> {
|
|
81
|
+
schemaVersion?: number;
|
|
82
|
+
snapshot: DataGridRowModelSnapshot<T>;
|
|
83
|
+
aggregationModel: DataGridAggregationModel<T> | null;
|
|
84
|
+
formulaFields?: readonly DataGridFormulaFieldSnapshot[];
|
|
85
|
+
formulaExecutionPlan?: DataGridFormulaExecutionPlanSnapshot | null;
|
|
86
|
+
formulaComputeStageDiagnostics?: DataGridFormulaComputeStageDiagnostics | null;
|
|
87
|
+
visibleRows: readonly DataGridRowNode<T>[];
|
|
88
|
+
visibleRange: DataGridViewportRange;
|
|
89
|
+
}
|
|
90
|
+
export interface DataGridWorkerRowModelUpdateMessage<T = unknown> extends DataGridWorkerRowModelProtocolHeader {
|
|
91
|
+
kind: "row-model-update";
|
|
92
|
+
payload: DataGridWorkerRowModelUpdatePayload<T>;
|
|
93
|
+
}
|
|
94
|
+
export type DataGridWorkerRowModelProtocolMessage<T = unknown> = DataGridWorkerRowModelCommandMessage<T> | DataGridWorkerRowModelUpdateMessage<T>;
|
|
95
|
+
export declare function createDataGridWorkerRowModelCommandMessage<T = unknown>(requestId: number, payload: DataGridWorkerRowModelCommand<T>, channel?: string | null): DataGridWorkerRowModelCommandMessage<T>;
|
|
96
|
+
export declare function createDataGridWorkerRowModelUpdateMessage<T = unknown>(requestId: number, payload: DataGridWorkerRowModelUpdatePayload<T>, channel?: string | null): DataGridWorkerRowModelUpdateMessage<T>;
|
|
97
|
+
export declare function isDataGridWorkerRowModelCommandMessage<T = unknown>(value: unknown, channel?: string | null): value is DataGridWorkerRowModelCommandMessage<T>;
|
|
98
|
+
export declare function isDataGridWorkerRowModelUpdateMessage<T = unknown>(value: unknown, channel?: string | null): value is DataGridWorkerRowModelUpdateMessage<T>;
|
|
99
|
+
//# sourceMappingURL=workerOwnedRowModelProtocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workerOwnedRowModelProtocol.d.ts","sourceRoot":"","sources":["../src/workerOwnedRowModelProtocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,sBAAsB,EACtB,6BAA6B,EAC7B,sCAAsC,EACtC,4BAA4B,EAC5B,sBAAsB,EACtB,mBAAmB,EACnB,8BAA8B,EAC9B,uBAAuB,EACvB,iBAAiB,EACjB,6BAA6B,EAC7B,wBAAwB,EACxB,eAAe,EACf,oBAAoB,EACpB,+BAA+B,EAC/B,iBAAiB,EACjB,qBAAqB,EACtB,MAAM,uBAAuB,CAAA;AA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CAAC,CAWlD;AAED,wBAAgB,qCAAqC,CAAC,CAAC,GAAG,OAAO,EAC/D,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GACtB,KAAK,IAAI,mCAAmC,CAAC,CAAC,CAAC,CAgBjD"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export const DATAGRID_WORKER_ROW_MODEL_PROTOCOL_VERSION = 1;
|
|
2
|
+
export const DATAGRID_WORKER_ROW_MODEL_PAYLOAD_SCHEMA_VERSION = 2;
|
|
3
|
+
export const DATAGRID_WORKER_ROW_MODEL_PROTOCOL_CHANNEL = "affino.datagrid.row-model";
|
|
4
|
+
function normalizeChannel(channel) {
|
|
5
|
+
const normalized = channel === null || channel === void 0 ? void 0 : channel.trim();
|
|
6
|
+
return normalized && normalized.length > 0
|
|
7
|
+
? normalized
|
|
8
|
+
: DATAGRID_WORKER_ROW_MODEL_PROTOCOL_CHANNEL;
|
|
9
|
+
}
|
|
10
|
+
function isProtocolHeader(value) {
|
|
11
|
+
if (!value || typeof value !== "object") {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
const candidate = value;
|
|
15
|
+
return (candidate.version === DATAGRID_WORKER_ROW_MODEL_PROTOCOL_VERSION &&
|
|
16
|
+
typeof candidate.channel === "string" &&
|
|
17
|
+
Number.isFinite(candidate.requestId) &&
|
|
18
|
+
Number.isFinite(candidate.timestamp));
|
|
19
|
+
}
|
|
20
|
+
export function createDataGridWorkerRowModelCommandMessage(requestId, payload, channel) {
|
|
21
|
+
return {
|
|
22
|
+
kind: "row-model-command",
|
|
23
|
+
version: DATAGRID_WORKER_ROW_MODEL_PROTOCOL_VERSION,
|
|
24
|
+
channel: normalizeChannel(channel),
|
|
25
|
+
requestId,
|
|
26
|
+
timestamp: Date.now(),
|
|
27
|
+
payload,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export function createDataGridWorkerRowModelUpdateMessage(requestId, payload, channel) {
|
|
31
|
+
const normalizedPayload = (typeof payload.schemaVersion === "number"
|
|
32
|
+
&& Number.isFinite(payload.schemaVersion))
|
|
33
|
+
? payload
|
|
34
|
+
: {
|
|
35
|
+
...payload,
|
|
36
|
+
schemaVersion: DATAGRID_WORKER_ROW_MODEL_PAYLOAD_SCHEMA_VERSION,
|
|
37
|
+
};
|
|
38
|
+
return {
|
|
39
|
+
kind: "row-model-update",
|
|
40
|
+
version: DATAGRID_WORKER_ROW_MODEL_PROTOCOL_VERSION,
|
|
41
|
+
channel: normalizeChannel(channel),
|
|
42
|
+
requestId,
|
|
43
|
+
timestamp: Date.now(),
|
|
44
|
+
payload: normalizedPayload,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export function isDataGridWorkerRowModelCommandMessage(value, channel) {
|
|
48
|
+
if (!isProtocolHeader(value)) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
const candidate = value;
|
|
52
|
+
return (candidate.kind === "row-model-command" &&
|
|
53
|
+
candidate.channel === normalizeChannel(channel) &&
|
|
54
|
+
candidate.payload != null &&
|
|
55
|
+
typeof candidate.payload.type === "string");
|
|
56
|
+
}
|
|
57
|
+
export function isDataGridWorkerRowModelUpdateMessage(value, channel) {
|
|
58
|
+
var _a;
|
|
59
|
+
if (!isProtocolHeader(value)) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
const candidate = value;
|
|
63
|
+
const payloadSchemaVersion = (_a = candidate.payload) === null || _a === void 0 ? void 0 : _a.schemaVersion;
|
|
64
|
+
return (candidate.kind === "row-model-update" &&
|
|
65
|
+
candidate.channel === normalizeChannel(channel) &&
|
|
66
|
+
candidate.payload != null &&
|
|
67
|
+
(payloadSchemaVersion == null
|
|
68
|
+
|| (typeof payloadSchemaVersion === "number" && Number.isFinite(payloadSchemaVersion))) &&
|
|
69
|
+
typeof candidate.payload.snapshot === "object");
|
|
70
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@affino/datagrid-worker",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"author": "Anton Pavlov <a.pavlov@affino.dev>",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "Worker transport protocol and postMessage bridge for Affino DataGrid compute runtime",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"main": "dist/index.js",
|
|
14
|
+
"types": "dist/index.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@affino/datagrid-core": "0.3.3",
|
|
21
|
+
"@affino/datagrid-formula-engine": "0.1.1"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/affinio/affinio.git",
|
|
26
|
+
"directory": "packages/datagrid-worker"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/affinio/affinio/tree/main/packages/datagrid-worker#readme",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"keywords": [
|
|
31
|
+
"datagrid",
|
|
32
|
+
"worker",
|
|
33
|
+
"postmessage",
|
|
34
|
+
"runtime",
|
|
35
|
+
"transport"
|
|
36
|
+
],
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/affinio/affinio/issues"
|
|
39
|
+
},
|
|
40
|
+
"module": "dist/index.js",
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "pnpm --filter @affino/datagrid-formula-engine build && tsc -p tsconfig.json",
|
|
43
|
+
"test": "vitest run --config vitest.config.ts"
|
|
44
|
+
}
|
|
45
|
+
}
|