@distrohelena/canton-typescript-sdk 1.0.2 → 1.0.3

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.
@@ -240,7 +240,7 @@ class GrpcContractCache {
240
240
  async writeSnapshotAsync(parties, key, activeAtOffset, contracts, creationMetadata, outcome) {
241
241
  const expiresAtEpochMs = effectiveExpiryEpochMs(this.now, this.ttlMs);
242
242
  const snapshot = {
243
- version: 2,
243
+ version: 3,
244
244
  endpointScope: this.endpointScope,
245
245
  parties,
246
246
  activeAtOffset,
@@ -314,7 +314,7 @@ class GrpcContractCache {
314
314
  : {}),
315
315
  };
316
316
  const snapshot = {
317
- version: 2,
317
+ version: 3,
318
318
  endpointScope: this.endpointScope,
319
319
  parties,
320
320
  activeAtOffset: activeAtOffset,
@@ -416,7 +416,7 @@ function asCompatibleSnapshot(value, endpointScope, parties, nowEpochMs, ignoreE
416
416
  const expiresAtEpochMs = candidate.expiresAtEpochMs;
417
417
  const contracts = materializeContractRows(candidate.contracts);
418
418
  const creationMetadata = materializeCreationMetadata(candidate.creationMetadata, contracts);
419
- if (version !== 2
419
+ if (version !== 3
420
420
  || storedEndpointScope !== endpointScope
421
421
  || (rawParties !== undefined && storedParties === undefined)
422
422
  || !sameParties(storedParties, parties)
@@ -144,16 +144,22 @@ function int64(value, name) {
144
144
  }
145
145
  function timestamp(value) {
146
146
  int64(value, "timestamp");
147
- if (BigInt(value) < -62135596800000000n || BigInt(value) > 253402300799999999n) {
147
+ const micros = BigInt(value);
148
+ if (micros < -62135596800000000n || micros > 253402300799999999n) {
148
149
  throw new validation_error_js_1.ValidationError("gRPC query timestamp is outside the Ledger API range");
149
150
  }
150
- return value;
151
+ // Daml-LF JSON encoding, as stored by PQS: sub-second part of length 0, 3, or 6.
152
+ const seconds = micros >= 0n || micros % 1000000n === 0n ? micros / 1000000n : micros / 1000000n - 1n;
153
+ const fraction = micros - seconds * 1000000n;
154
+ const base = new Date(Number(seconds) * 1000).toISOString().slice(0, 19);
155
+ const subSecond = fraction === 0n ? "" : fraction % 1000n === 0n ? `.${(fraction / 1000n).toString().padStart(3, "0")}` : `.${fraction.toString().padStart(6, "0")}`;
156
+ return `${base}${subSecond}Z`;
151
157
  }
152
158
  function date(value) {
153
159
  if (!Number.isInteger(value) || value < MIN_DATE_EPOCH_DAY || value > MAX_DATE_EPOCH_DAY) {
154
160
  throw new validation_error_js_1.ValidationError("gRPC query date is outside the Ledger API range");
155
161
  }
156
- return value;
162
+ return new Date(value * 86_400_000).toISOString().slice(0, 10);
157
163
  }
158
164
  function numeric(value) {
159
165
  if (!/^[+-]?\d{1,38}(?:\.\d{0,37})?$/.test(value)) {
@@ -236,7 +236,7 @@ export class GrpcContractCache {
236
236
  async writeSnapshotAsync(parties, key, activeAtOffset, contracts, creationMetadata, outcome) {
237
237
  const expiresAtEpochMs = effectiveExpiryEpochMs(this.now, this.ttlMs);
238
238
  const snapshot = {
239
- version: 2,
239
+ version: 3,
240
240
  endpointScope: this.endpointScope,
241
241
  parties,
242
242
  activeAtOffset,
@@ -310,7 +310,7 @@ export class GrpcContractCache {
310
310
  : {}),
311
311
  };
312
312
  const snapshot = {
313
- version: 2,
313
+ version: 3,
314
314
  endpointScope: this.endpointScope,
315
315
  parties,
316
316
  activeAtOffset: activeAtOffset,
@@ -411,7 +411,7 @@ function asCompatibleSnapshot(value, endpointScope, parties, nowEpochMs, ignoreE
411
411
  const expiresAtEpochMs = candidate.expiresAtEpochMs;
412
412
  const contracts = materializeContractRows(candidate.contracts);
413
413
  const creationMetadata = materializeCreationMetadata(candidate.creationMetadata, contracts);
414
- if (version !== 2
414
+ if (version !== 3
415
415
  || storedEndpointScope !== endpointScope
416
416
  || (rawParties !== undefined && storedParties === undefined)
417
417
  || !sameParties(storedParties, parties)
@@ -135,16 +135,22 @@ function int64(value, name) {
135
135
  }
136
136
  function timestamp(value) {
137
137
  int64(value, "timestamp");
138
- if (BigInt(value) < -62135596800000000n || BigInt(value) > 253402300799999999n) {
138
+ const micros = BigInt(value);
139
+ if (micros < -62135596800000000n || micros > 253402300799999999n) {
139
140
  throw new ValidationError("gRPC query timestamp is outside the Ledger API range");
140
141
  }
141
- return value;
142
+ // Daml-LF JSON encoding, as stored by PQS: sub-second part of length 0, 3, or 6.
143
+ const seconds = micros >= 0n || micros % 1000000n === 0n ? micros / 1000000n : micros / 1000000n - 1n;
144
+ const fraction = micros - seconds * 1000000n;
145
+ const base = new Date(Number(seconds) * 1000).toISOString().slice(0, 19);
146
+ const subSecond = fraction === 0n ? "" : fraction % 1000n === 0n ? `.${(fraction / 1000n).toString().padStart(3, "0")}` : `.${fraction.toString().padStart(6, "0")}`;
147
+ return `${base}${subSecond}Z`;
142
148
  }
143
149
  function date(value) {
144
150
  if (!Number.isInteger(value) || value < MIN_DATE_EPOCH_DAY || value > MAX_DATE_EPOCH_DAY) {
145
151
  throw new ValidationError("gRPC query date is outside the Ledger API range");
146
152
  }
147
- return value;
153
+ return new Date(value * 86_400_000).toISOString().slice(0, 10);
148
154
  }
149
155
  function numeric(value) {
150
156
  if (!/^[+-]?\d{1,38}(?:\.\d{0,37})?$/.test(value)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@distrohelena/canton-typescript-sdk",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",