@xapi-js/core 1.5.0 → 1.6.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/dist/index.cjs CHANGED
@@ -1152,7 +1152,12 @@ function encodeRoot(schema, value) {
1152
1152
  const rows = value.datasets[datasetId];
1153
1153
  for (const row of rows) {
1154
1154
  const rowIndex = dataset.newRow();
1155
+ dataset.rows[rowIndex].type = row.$rowType;
1155
1156
  for (const id of Object.keys(datasetSchema.columns)) dataset.setColumn(rowIndex, id, row[id]);
1157
+ if (row.$orgRow) dataset.rows[rowIndex].orgRow = Object.entries(row.$orgRow).map(([id, value]) => ({
1158
+ id,
1159
+ value
1160
+ }));
1156
1161
  }
1157
1162
  root.addDataset(dataset);
1158
1163
  }
@@ -1175,6 +1180,8 @@ function decodeRoot(schema, root) {
1175
1180
  datasets[datasetId] = dataset.getRows().map((row) => {
1176
1181
  const value = { ...constants };
1177
1182
  for (const column of row.cols) if (column.id in datasetSchema.columns) value[column.id] = column.value;
1183
+ if (row.type) value.$rowType = row.type;
1184
+ if (row.orgRow) value.$orgRow = Object.fromEntries(row.orgRow.map((column) => [column.id, column.value]));
1178
1185
  return value;
1179
1186
  });
1180
1187
  }
@@ -1184,6 +1191,130 @@ function decodeRoot(schema, root) {
1184
1191
  };
1185
1192
  }
1186
1193
  //#endregion
1194
+ //#region src/codec.ts
1195
+ const rowTypes = {
1196
+ N: void 0,
1197
+ I: "insert",
1198
+ U: "update",
1199
+ D: "delete",
1200
+ O: void 0
1201
+ };
1202
+ function sizeOf(size, type) {
1203
+ if (size !== void 0) return Number(size);
1204
+ return type === "STRING" ? 255 : 0;
1205
+ }
1206
+ function jsonValue(value, type) {
1207
+ if (value === null || value === void 0) return void 0;
1208
+ if (type === "DATE" || type === "DATETIME" || type === "TIME") return typeof value === "string" ? convertToColumnType(value, type) : value;
1209
+ if (type === "BLOB" && typeof value === "string") return convertToColumnType(value, type);
1210
+ return value;
1211
+ }
1212
+ function jsonWireValue(value, type) {
1213
+ if (value === void 0) return void 0;
1214
+ if (value instanceof Date) return dateToString(value, type);
1215
+ if (value instanceof Uint8Array) return uint8ArrayToBase64(value);
1216
+ return value;
1217
+ }
1218
+ function columnsToObject(columns) {
1219
+ return Object.fromEntries(columns.map((column) => [column.id, column.value]));
1220
+ }
1221
+ function readRow(dataset, row) {
1222
+ const rowType = rowTypes[row._RowType_ ?? "N"];
1223
+ if (row._RowType_ === "O") {
1224
+ const previous = dataset.rows[dataset.rows.length - 1];
1225
+ if (previous?.type !== "update") return;
1226
+ previous.orgRow = dataset.getColumns().filter((column) => Object.prototype.hasOwnProperty.call(row, column.id)).map((column) => ({
1227
+ id: column.id,
1228
+ value: jsonValue(row[column.id], column.type)
1229
+ }));
1230
+ return;
1231
+ }
1232
+ const index = dataset.newRow();
1233
+ dataset.rows[index].type = rowType;
1234
+ for (const column of dataset.getColumns()) if (Object.prototype.hasOwnProperty.call(row, column.id)) dataset.rows[index].cols.push({
1235
+ id: column.id,
1236
+ value: jsonValue(row[column.id], column.type)
1237
+ });
1238
+ }
1239
+ function readJson(value) {
1240
+ const root = new XapiRoot();
1241
+ for (const parameter of value.Parameters ?? []) root.addParameter({
1242
+ id: parameter.id,
1243
+ type: parameter.type,
1244
+ value: jsonValue(parameter.value, parameter.type)
1245
+ });
1246
+ for (const source of value.Datasets ?? []) {
1247
+ const dataset = new Dataset(source.id);
1248
+ for (const column of source.ColumnInfo.ConstColumn ?? []) {
1249
+ const type = column.type ?? "STRING";
1250
+ dataset.addConstColumn({
1251
+ id: column.id,
1252
+ type,
1253
+ size: sizeOf(column.size, type),
1254
+ value: jsonValue(column.value, type)
1255
+ });
1256
+ }
1257
+ for (const column of source.ColumnInfo.Column) {
1258
+ const type = column.type ?? "STRING";
1259
+ dataset.addColumn({
1260
+ id: column.id,
1261
+ type,
1262
+ size: sizeOf(column.size, type)
1263
+ });
1264
+ }
1265
+ for (const row of source.Rows) readRow(dataset, row);
1266
+ root.addDataset(dataset);
1267
+ }
1268
+ return root;
1269
+ }
1270
+ function writeJson(root) {
1271
+ return {
1272
+ version: "1.0",
1273
+ ...root.parameterSize() ? { Parameters: root.getParameters().map((parameter) => ({
1274
+ id: parameter.id,
1275
+ ...parameter.type ? { type: parameter.type } : {},
1276
+ ...parameter.value !== void 0 ? { value: jsonWireValue(parameter.value, parameter.type ?? "STRING") } : {}
1277
+ })) } : {},
1278
+ ...root.datasetSize() ? { Datasets: root.getDatasets().map((dataset) => ({
1279
+ id: dataset.id,
1280
+ ColumnInfo: {
1281
+ ...dataset.constColumnSize() ? { ConstColumn: dataset.getConstColumns().map((column) => ({
1282
+ id: column.id,
1283
+ type: column.type,
1284
+ size: column.size,
1285
+ value: jsonWireValue(column.value, column.type)
1286
+ })) } : {},
1287
+ Column: dataset.getColumns().map((column) => ({
1288
+ id: column.id,
1289
+ type: column.type,
1290
+ size: column.size
1291
+ }))
1292
+ },
1293
+ Rows: dataset.getRows().flatMap((row) => {
1294
+ const current = {
1295
+ _RowType_: row.type === "insert" ? "I" : row.type === "update" ? "U" : row.type === "delete" ? "D" : "N",
1296
+ ...columnsToObject(row.cols)
1297
+ };
1298
+ if (!row.orgRow) return [current];
1299
+ return [current, {
1300
+ _RowType_: "O",
1301
+ ...columnsToObject(row.orgRow)
1302
+ }];
1303
+ })
1304
+ })) } : {}
1305
+ };
1306
+ }
1307
+ const nexacroJsonCodec = {
1308
+ serialize: writeJson,
1309
+ deserialize: readJson
1310
+ };
1311
+ function parseJson(value) {
1312
+ return nexacroJsonCodec.deserialize(JSON.parse(value));
1313
+ }
1314
+ function writeJsonString(root) {
1315
+ return JSON.stringify(nexacroJsonCodec.serialize(root));
1316
+ }
1317
+ //#endregion
1187
1318
  exports.ColumnTypeError = ColumnTypeError;
1188
1319
  exports.Dataset = Dataset;
1189
1320
  exports.InvalidXmlError = InvalidXmlError;
@@ -1209,11 +1340,14 @@ exports.escapeXml = escapeXml;
1209
1340
  exports.initXapi = initXapi;
1210
1341
  exports.isXapiRoot = isXapiRoot;
1211
1342
  exports.makeParseEntities = makeParseEntities;
1343
+ exports.nexacroJsonCodec = nexacroJsonCodec;
1212
1344
  exports.parse = parse;
1345
+ exports.parseJson = parseJson;
1213
1346
  exports.parseXml = parseXml;
1214
1347
  exports.rowType = rowType;
1215
1348
  exports.stringToDate = stringToDate;
1216
1349
  exports.stringToReadableStream = stringToReadableStream;
1217
1350
  exports.uint8ArrayToBase64 = uint8ArrayToBase64;
1218
1351
  exports.write = write;
1352
+ exports.writeJsonString = writeJsonString;
1219
1353
  exports.xapi = xapi;
package/dist/index.d.cts CHANGED
@@ -506,7 +506,15 @@ interface XapiOperation<Request extends XapiRootSchema = XapiRootSchema, Respons
506
506
  type RequiredColumnKeys<Columns extends XapiColumns> = { [Key in keyof Columns]-?: Columns[Key]["optional"] extends true ? never : Key; }[keyof Columns];
507
507
  type OptionalColumnKeys<Columns extends XapiColumns> = { [Key in keyof Columns]-?: Columns[Key]["optional"] extends true ? Key : never; }[keyof Columns];
508
508
  type InferColumns<Columns extends XapiColumns> = { [Key in RequiredColumnKeys<Columns>]: XapiTypeMap[Columns[Key]["type"]]; } & { [Key in OptionalColumnKeys<Columns>]?: XapiTypeMap[Columns[Key]["type"]]; };
509
- type InferDataset<Schema extends XapiDatasetSchema> = InferColumns<Schema["columns"]>[];
509
+ /**
510
+ * A schema row remains assignable from the old plain object shape, while
511
+ * retaining the Nexacro row metadata when an operation needs it.
512
+ */
513
+ type InferDatasetRow<Schema extends XapiDatasetSchema> = InferColumns<Schema["columns"]> & {
514
+ $rowType?: RowType;
515
+ $orgRow?: Partial<InferColumns<Schema["columns"]>>;
516
+ };
517
+ type InferDataset<Schema extends XapiDatasetSchema> = InferDatasetRow<Schema>[];
510
518
  type InferRoot<Schema extends XapiRootSchema> = {
511
519
  parameters: InferColumns<Schema["parameters"]>;
512
520
  datasets: { [Key in keyof Schema["datasets"]]: InferDataset<Schema["datasets"][Key]>; };
@@ -543,4 +551,43 @@ declare const xapi: {
543
551
  declare function encodeRoot<Schema extends XapiRootSchema>(schema: Schema, value: InferRoot<Schema>): XapiRoot;
544
552
  declare function decodeRoot<Schema extends XapiRootSchema>(schema: Schema, root: XapiRoot): InferRoot<Schema>;
545
553
  //#endregion
546
- export { Col, Column, ColumnInfo, ColumnType, ColumnTypeError, ConstColumn, Dataset, InferColumns, InferDataset, InferRoot, InvalidXmlError, NexaVersion, Parameter, RequestOf, ResponseOf, Row, RowType, Rows, StringWritableStream, XapiColumnSchema, XapiColumns, XapiDatasetSchema, XapiDatasets, XapiOperation, XapiOptions, XapiParameters, XapiRoot, XapiRootSchema, XapiTypeMap, XapiValueType, XapiVersion, XmlNode, XmlStringBuilder, XplatformVersion, _unescapeXml, arrayBufferToString, base64ToUint8Array, columnType, convertToColumnType, convertToString, dateToString, decodeRoot, defineDataset, defineOperation, defineRoot, encodeControlChars, encodeRoot, escapeXml, initXapi, isXapiRoot, makeParseEntities, parse, parseXml, rowType, stringToDate, stringToReadableStream, uint8ArrayToBase64, write, xapi };
554
+ //#region src/codec.d.ts
555
+ /** The wire representation used by Nexacro's Dataset JSON format. */
556
+ interface NexacroJsonParameter {
557
+ id: string;
558
+ type?: ColumnType;
559
+ value?: string | number;
560
+ }
561
+ interface NexacroJsonColumn {
562
+ id: string;
563
+ type?: ColumnType;
564
+ size?: number | string;
565
+ value?: string | number;
566
+ }
567
+ interface NexacroJsonRow {
568
+ _RowType_?: "N" | "I" | "U" | "D" | "O";
569
+ [columnId: string]: unknown;
570
+ }
571
+ interface NexacroJsonDataset {
572
+ id: string;
573
+ ColumnInfo: {
574
+ ConstColumn?: NexacroJsonColumn[];
575
+ Column: NexacroJsonColumn[];
576
+ };
577
+ Rows: NexacroJsonRow[];
578
+ }
579
+ interface NexacroJsonRoot {
580
+ version: "1.0";
581
+ Parameters?: NexacroJsonParameter[];
582
+ Datasets?: NexacroJsonDataset[];
583
+ }
584
+ /** A serializer boundary around the X-API internal model. */
585
+ interface XapiCodec<Serialized> {
586
+ serialize(root: XapiRoot): Serialized;
587
+ deserialize(value: Serialized): XapiRoot;
588
+ }
589
+ declare const nexacroJsonCodec: XapiCodec<NexacroJsonRoot>;
590
+ declare function parseJson(value: string): XapiRoot;
591
+ declare function writeJsonString(root: XapiRoot): string;
592
+ //#endregion
593
+ export { Col, Column, ColumnInfo, ColumnType, ColumnTypeError, ConstColumn, Dataset, InferColumns, InferDataset, InferDatasetRow, InferRoot, InvalidXmlError, NexaVersion, NexacroJsonColumn, NexacroJsonDataset, NexacroJsonParameter, NexacroJsonRoot, NexacroJsonRow, Parameter, RequestOf, ResponseOf, Row, RowType, Rows, StringWritableStream, XapiCodec, XapiColumnSchema, XapiColumns, XapiDatasetSchema, XapiDatasets, XapiOperation, XapiOptions, XapiParameters, XapiRoot, XapiRootSchema, XapiTypeMap, XapiValueType, XapiVersion, XmlNode, XmlStringBuilder, XplatformVersion, _unescapeXml, arrayBufferToString, base64ToUint8Array, columnType, convertToColumnType, convertToString, dateToString, decodeRoot, defineDataset, defineOperation, defineRoot, encodeControlChars, encodeRoot, escapeXml, initXapi, isXapiRoot, makeParseEntities, nexacroJsonCodec, parse, parseJson, parseXml, rowType, stringToDate, stringToReadableStream, uint8ArrayToBase64, write, writeJsonString, xapi };
package/dist/index.d.ts CHANGED
@@ -506,7 +506,15 @@ interface XapiOperation<Request extends XapiRootSchema = XapiRootSchema, Respons
506
506
  type RequiredColumnKeys<Columns extends XapiColumns> = { [Key in keyof Columns]-?: Columns[Key]["optional"] extends true ? never : Key; }[keyof Columns];
507
507
  type OptionalColumnKeys<Columns extends XapiColumns> = { [Key in keyof Columns]-?: Columns[Key]["optional"] extends true ? Key : never; }[keyof Columns];
508
508
  type InferColumns<Columns extends XapiColumns> = { [Key in RequiredColumnKeys<Columns>]: XapiTypeMap[Columns[Key]["type"]]; } & { [Key in OptionalColumnKeys<Columns>]?: XapiTypeMap[Columns[Key]["type"]]; };
509
- type InferDataset<Schema extends XapiDatasetSchema> = InferColumns<Schema["columns"]>[];
509
+ /**
510
+ * A schema row remains assignable from the old plain object shape, while
511
+ * retaining the Nexacro row metadata when an operation needs it.
512
+ */
513
+ type InferDatasetRow<Schema extends XapiDatasetSchema> = InferColumns<Schema["columns"]> & {
514
+ $rowType?: RowType;
515
+ $orgRow?: Partial<InferColumns<Schema["columns"]>>;
516
+ };
517
+ type InferDataset<Schema extends XapiDatasetSchema> = InferDatasetRow<Schema>[];
510
518
  type InferRoot<Schema extends XapiRootSchema> = {
511
519
  parameters: InferColumns<Schema["parameters"]>;
512
520
  datasets: { [Key in keyof Schema["datasets"]]: InferDataset<Schema["datasets"][Key]>; };
@@ -543,4 +551,43 @@ declare const xapi: {
543
551
  declare function encodeRoot<Schema extends XapiRootSchema>(schema: Schema, value: InferRoot<Schema>): XapiRoot;
544
552
  declare function decodeRoot<Schema extends XapiRootSchema>(schema: Schema, root: XapiRoot): InferRoot<Schema>;
545
553
  //#endregion
546
- export { Col, Column, ColumnInfo, ColumnType, ColumnTypeError, ConstColumn, Dataset, InferColumns, InferDataset, InferRoot, InvalidXmlError, NexaVersion, Parameter, RequestOf, ResponseOf, Row, RowType, Rows, StringWritableStream, XapiColumnSchema, XapiColumns, XapiDatasetSchema, XapiDatasets, XapiOperation, XapiOptions, XapiParameters, XapiRoot, XapiRootSchema, XapiTypeMap, XapiValueType, XapiVersion, XmlNode, XmlStringBuilder, XplatformVersion, _unescapeXml, arrayBufferToString, base64ToUint8Array, columnType, convertToColumnType, convertToString, dateToString, decodeRoot, defineDataset, defineOperation, defineRoot, encodeControlChars, encodeRoot, escapeXml, initXapi, isXapiRoot, makeParseEntities, parse, parseXml, rowType, stringToDate, stringToReadableStream, uint8ArrayToBase64, write, xapi };
554
+ //#region src/codec.d.ts
555
+ /** The wire representation used by Nexacro's Dataset JSON format. */
556
+ interface NexacroJsonParameter {
557
+ id: string;
558
+ type?: ColumnType;
559
+ value?: string | number;
560
+ }
561
+ interface NexacroJsonColumn {
562
+ id: string;
563
+ type?: ColumnType;
564
+ size?: number | string;
565
+ value?: string | number;
566
+ }
567
+ interface NexacroJsonRow {
568
+ _RowType_?: "N" | "I" | "U" | "D" | "O";
569
+ [columnId: string]: unknown;
570
+ }
571
+ interface NexacroJsonDataset {
572
+ id: string;
573
+ ColumnInfo: {
574
+ ConstColumn?: NexacroJsonColumn[];
575
+ Column: NexacroJsonColumn[];
576
+ };
577
+ Rows: NexacroJsonRow[];
578
+ }
579
+ interface NexacroJsonRoot {
580
+ version: "1.0";
581
+ Parameters?: NexacroJsonParameter[];
582
+ Datasets?: NexacroJsonDataset[];
583
+ }
584
+ /** A serializer boundary around the X-API internal model. */
585
+ interface XapiCodec<Serialized> {
586
+ serialize(root: XapiRoot): Serialized;
587
+ deserialize(value: Serialized): XapiRoot;
588
+ }
589
+ declare const nexacroJsonCodec: XapiCodec<NexacroJsonRoot>;
590
+ declare function parseJson(value: string): XapiRoot;
591
+ declare function writeJsonString(root: XapiRoot): string;
592
+ //#endregion
593
+ export { Col, Column, ColumnInfo, ColumnType, ColumnTypeError, ConstColumn, Dataset, InferColumns, InferDataset, InferDatasetRow, InferRoot, InvalidXmlError, NexaVersion, NexacroJsonColumn, NexacroJsonDataset, NexacroJsonParameter, NexacroJsonRoot, NexacroJsonRow, Parameter, RequestOf, ResponseOf, Row, RowType, Rows, StringWritableStream, XapiCodec, XapiColumnSchema, XapiColumns, XapiDatasetSchema, XapiDatasets, XapiOperation, XapiOptions, XapiParameters, XapiRoot, XapiRootSchema, XapiTypeMap, XapiValueType, XapiVersion, XmlNode, XmlStringBuilder, XplatformVersion, _unescapeXml, arrayBufferToString, base64ToUint8Array, columnType, convertToColumnType, convertToString, dateToString, decodeRoot, defineDataset, defineOperation, defineRoot, encodeControlChars, encodeRoot, escapeXml, initXapi, isXapiRoot, makeParseEntities, nexacroJsonCodec, parse, parseJson, parseXml, rowType, stringToDate, stringToReadableStream, uint8ArrayToBase64, write, writeJsonString, xapi };
package/dist/index.js CHANGED
@@ -1151,7 +1151,12 @@ function encodeRoot(schema, value) {
1151
1151
  const rows = value.datasets[datasetId];
1152
1152
  for (const row of rows) {
1153
1153
  const rowIndex = dataset.newRow();
1154
+ dataset.rows[rowIndex].type = row.$rowType;
1154
1155
  for (const id of Object.keys(datasetSchema.columns)) dataset.setColumn(rowIndex, id, row[id]);
1156
+ if (row.$orgRow) dataset.rows[rowIndex].orgRow = Object.entries(row.$orgRow).map(([id, value]) => ({
1157
+ id,
1158
+ value
1159
+ }));
1155
1160
  }
1156
1161
  root.addDataset(dataset);
1157
1162
  }
@@ -1174,6 +1179,8 @@ function decodeRoot(schema, root) {
1174
1179
  datasets[datasetId] = dataset.getRows().map((row) => {
1175
1180
  const value = { ...constants };
1176
1181
  for (const column of row.cols) if (column.id in datasetSchema.columns) value[column.id] = column.value;
1182
+ if (row.type) value.$rowType = row.type;
1183
+ if (row.orgRow) value.$orgRow = Object.fromEntries(row.orgRow.map((column) => [column.id, column.value]));
1177
1184
  return value;
1178
1185
  });
1179
1186
  }
@@ -1183,4 +1190,128 @@ function decodeRoot(schema, root) {
1183
1190
  };
1184
1191
  }
1185
1192
  //#endregion
1186
- export { ColumnTypeError, Dataset, InvalidXmlError, NexaVersion, StringWritableStream, XapiRoot, XmlStringBuilder, XplatformVersion, _unescapeXml, arrayBufferToString, base64ToUint8Array, columnType, convertToColumnType, convertToString, dateToString, decodeRoot, defineDataset, defineOperation, defineRoot, encodeControlChars, encodeRoot, escapeXml, initXapi, isXapiRoot, makeParseEntities, parse, parseXml, rowType, stringToDate, stringToReadableStream, uint8ArrayToBase64, write, xapi };
1193
+ //#region src/codec.ts
1194
+ const rowTypes = {
1195
+ N: void 0,
1196
+ I: "insert",
1197
+ U: "update",
1198
+ D: "delete",
1199
+ O: void 0
1200
+ };
1201
+ function sizeOf(size, type) {
1202
+ if (size !== void 0) return Number(size);
1203
+ return type === "STRING" ? 255 : 0;
1204
+ }
1205
+ function jsonValue(value, type) {
1206
+ if (value === null || value === void 0) return void 0;
1207
+ if (type === "DATE" || type === "DATETIME" || type === "TIME") return typeof value === "string" ? convertToColumnType(value, type) : value;
1208
+ if (type === "BLOB" && typeof value === "string") return convertToColumnType(value, type);
1209
+ return value;
1210
+ }
1211
+ function jsonWireValue(value, type) {
1212
+ if (value === void 0) return void 0;
1213
+ if (value instanceof Date) return dateToString(value, type);
1214
+ if (value instanceof Uint8Array) return uint8ArrayToBase64(value);
1215
+ return value;
1216
+ }
1217
+ function columnsToObject(columns) {
1218
+ return Object.fromEntries(columns.map((column) => [column.id, column.value]));
1219
+ }
1220
+ function readRow(dataset, row) {
1221
+ const rowType = rowTypes[row._RowType_ ?? "N"];
1222
+ if (row._RowType_ === "O") {
1223
+ const previous = dataset.rows[dataset.rows.length - 1];
1224
+ if (previous?.type !== "update") return;
1225
+ previous.orgRow = dataset.getColumns().filter((column) => Object.prototype.hasOwnProperty.call(row, column.id)).map((column) => ({
1226
+ id: column.id,
1227
+ value: jsonValue(row[column.id], column.type)
1228
+ }));
1229
+ return;
1230
+ }
1231
+ const index = dataset.newRow();
1232
+ dataset.rows[index].type = rowType;
1233
+ for (const column of dataset.getColumns()) if (Object.prototype.hasOwnProperty.call(row, column.id)) dataset.rows[index].cols.push({
1234
+ id: column.id,
1235
+ value: jsonValue(row[column.id], column.type)
1236
+ });
1237
+ }
1238
+ function readJson(value) {
1239
+ const root = new XapiRoot();
1240
+ for (const parameter of value.Parameters ?? []) root.addParameter({
1241
+ id: parameter.id,
1242
+ type: parameter.type,
1243
+ value: jsonValue(parameter.value, parameter.type)
1244
+ });
1245
+ for (const source of value.Datasets ?? []) {
1246
+ const dataset = new Dataset(source.id);
1247
+ for (const column of source.ColumnInfo.ConstColumn ?? []) {
1248
+ const type = column.type ?? "STRING";
1249
+ dataset.addConstColumn({
1250
+ id: column.id,
1251
+ type,
1252
+ size: sizeOf(column.size, type),
1253
+ value: jsonValue(column.value, type)
1254
+ });
1255
+ }
1256
+ for (const column of source.ColumnInfo.Column) {
1257
+ const type = column.type ?? "STRING";
1258
+ dataset.addColumn({
1259
+ id: column.id,
1260
+ type,
1261
+ size: sizeOf(column.size, type)
1262
+ });
1263
+ }
1264
+ for (const row of source.Rows) readRow(dataset, row);
1265
+ root.addDataset(dataset);
1266
+ }
1267
+ return root;
1268
+ }
1269
+ function writeJson(root) {
1270
+ return {
1271
+ version: "1.0",
1272
+ ...root.parameterSize() ? { Parameters: root.getParameters().map((parameter) => ({
1273
+ id: parameter.id,
1274
+ ...parameter.type ? { type: parameter.type } : {},
1275
+ ...parameter.value !== void 0 ? { value: jsonWireValue(parameter.value, parameter.type ?? "STRING") } : {}
1276
+ })) } : {},
1277
+ ...root.datasetSize() ? { Datasets: root.getDatasets().map((dataset) => ({
1278
+ id: dataset.id,
1279
+ ColumnInfo: {
1280
+ ...dataset.constColumnSize() ? { ConstColumn: dataset.getConstColumns().map((column) => ({
1281
+ id: column.id,
1282
+ type: column.type,
1283
+ size: column.size,
1284
+ value: jsonWireValue(column.value, column.type)
1285
+ })) } : {},
1286
+ Column: dataset.getColumns().map((column) => ({
1287
+ id: column.id,
1288
+ type: column.type,
1289
+ size: column.size
1290
+ }))
1291
+ },
1292
+ Rows: dataset.getRows().flatMap((row) => {
1293
+ const current = {
1294
+ _RowType_: row.type === "insert" ? "I" : row.type === "update" ? "U" : row.type === "delete" ? "D" : "N",
1295
+ ...columnsToObject(row.cols)
1296
+ };
1297
+ if (!row.orgRow) return [current];
1298
+ return [current, {
1299
+ _RowType_: "O",
1300
+ ...columnsToObject(row.orgRow)
1301
+ }];
1302
+ })
1303
+ })) } : {}
1304
+ };
1305
+ }
1306
+ const nexacroJsonCodec = {
1307
+ serialize: writeJson,
1308
+ deserialize: readJson
1309
+ };
1310
+ function parseJson(value) {
1311
+ return nexacroJsonCodec.deserialize(JSON.parse(value));
1312
+ }
1313
+ function writeJsonString(root) {
1314
+ return JSON.stringify(nexacroJsonCodec.serialize(root));
1315
+ }
1316
+ //#endregion
1317
+ export { ColumnTypeError, Dataset, InvalidXmlError, NexaVersion, StringWritableStream, XapiRoot, XmlStringBuilder, XplatformVersion, _unescapeXml, arrayBufferToString, base64ToUint8Array, columnType, convertToColumnType, convertToString, dateToString, decodeRoot, defineDataset, defineOperation, defineRoot, encodeControlChars, encodeRoot, escapeXml, initXapi, isXapiRoot, makeParseEntities, nexacroJsonCodec, parse, parseJson, parseXml, rowType, stringToDate, stringToReadableStream, uint8ArrayToBase64, write, writeJsonString, xapi };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xapi-js/core",
3
3
  "type": "module",
4
- "version": "1.5.0",
4
+ "version": "1.6.0",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",