@serve.zone/interfaces 27.3.0 → 27.4.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.
@@ -740,14 +740,14 @@ const finalize = <T>(
740
740
  };
741
741
 
742
742
  const encodeNormalized = (valueArg: unknown, pathArg: string): Uint8Array => (
743
- new Uint8Array(Buffer.from(canonicalize(valueArg, pathArg), 'utf8'))
743
+ Buffer.from(canonicalize(valueArg, pathArg), 'utf8')
744
744
  );
745
745
 
746
746
  const frame = (domainArg: string, payloadArg: Uint8Array): Uint8Array => {
747
747
  const domain = Buffer.from(domainArg, 'utf8');
748
748
  const output = new Uint8Array(domain.byteLength + payloadArg.byteLength);
749
749
  output.set(domain, 0);
750
- output.set(new Uint8Array(payloadArg), domain.byteLength);
750
+ output.set(payloadArg, domain.byteLength);
751
751
  return output;
752
752
  };
753
753
 
@@ -3901,8 +3901,8 @@ const assertProductionAuthorizationArtifacts = (
3901
3901
  !== digestCloudlyLegacyDeploymentSettlementRequestBundle(requestBundleArg)
3902
3902
  || authorizationArg.scratchReceiptSha256
3903
3903
  !== digestCloudlyLegacyDeploymentSettlementScratchReceipt(scratchReceiptArg)
3904
- || productionMetadataArg.issuedAt < scratchReceiptArg.completedAt
3905
- || authorizationArg.requestedAt < scratchReceiptArg.completedAt
3904
+ || productionMetadataArg.issuedAt <= scratchReceiptArg.completedAt
3905
+ || authorizationArg.requestedAt <= scratchReceiptArg.completedAt
3906
3906
  || authorizationArg.requestedAt < productionMetadataArg.issuedAt
3907
3907
  || authorizationArg.approvedAt < authorizationArg.requestedAt) {
3908
3908
  fail('CROSS_FIELD_MISMATCH', 'productionExecutionAuthorization.sourceProof');
@@ -6128,8 +6128,8 @@ export const normalizeCloudlyLegacyDeploymentSettlementStdioRequest = (
6128
6128
  const approvedAt = readInteger(input.approvedAt, `${payloadPath}.approvedAt`, requestedAt);
6129
6129
  assertAuthorityTimestamp(requestedAt, metadata.productionMetadata, `${payloadPath}.requestedAt`);
6130
6130
  assertAuthorityTimestamp(approvedAt, metadata.productionMetadata, `${payloadPath}.approvedAt`);
6131
- if (metadata.productionMetadata.issuedAt < scratchReceipt.completedAt
6132
- || requestedAt < scratchReceipt.completedAt) {
6131
+ if (metadata.productionMetadata.issuedAt <= scratchReceipt.completedAt
6132
+ || requestedAt <= scratchReceipt.completedAt) {
6133
6133
  fail('CROSS_FIELD_MISMATCH', `${payloadPath}.requestedAt`);
6134
6134
  }
6135
6135
  payload = {
@@ -6538,11 +6538,15 @@ const encodeStdioFrame = (
6538
6538
  pathArg: string,
6539
6539
  ): Uint8Array => {
6540
6540
  const payload = encodeNormalized(valueArg, pathArg);
6541
- if (payload.byteLength + 1 > maximumBytesArg) fail('LIMIT_EXCEEDED', pathArg);
6542
- const output = new Uint8Array(payload.byteLength + 1);
6543
- output.set(payload);
6544
- output[payload.byteLength] = 0x0a;
6545
- return output;
6541
+ try {
6542
+ if (payload.byteLength + 1 > maximumBytesArg) fail('LIMIT_EXCEEDED', pathArg);
6543
+ const output = new Uint8Array(payload.byteLength + 1);
6544
+ output.set(payload);
6545
+ output[payload.byteLength] = 0x0a;
6546
+ return output;
6547
+ } finally {
6548
+ payload.fill(0);
6549
+ }
6546
6550
  };
6547
6551
 
6548
6552
  export const encodeCloudlyLegacyDeploymentSettlementStdioRequestFrame = (
@@ -6576,24 +6580,31 @@ const decodeStdioFrame = <T>(
6576
6580
  fail('INVALID_DATA', pathArg);
6577
6581
  }
6578
6582
  const payloadBytes = new Uint8Array(frameArg.subarray(0, -1));
6579
- let text: string;
6583
+ let canonicalFrame: Uint8Array | undefined;
6580
6584
  try {
6581
- text = new TextDecoder('utf-8', { fatal: true }).decode(payloadBytes);
6582
- } catch {
6583
- return fail('INVALID_DATA', pathArg);
6584
- }
6585
- let value: unknown;
6586
- try {
6587
- value = JSON.parse(text) as unknown;
6588
- } catch {
6589
- return fail('INVALID_DATA', pathArg);
6590
- }
6591
- const normalized = normalizeArg(value);
6592
- const canonicalFrame = encodeArg(normalized);
6593
- if (!Buffer.from(canonicalFrame).equals(Buffer.from(frameArg))) {
6594
- fail('INVALID_DATA', pathArg);
6585
+ let text: string;
6586
+ try {
6587
+ text = new TextDecoder('utf-8', { fatal: true }).decode(payloadBytes);
6588
+ } catch {
6589
+ return fail('INVALID_DATA', pathArg);
6590
+ }
6591
+ let value: unknown;
6592
+ try {
6593
+ value = JSON.parse(text) as unknown;
6594
+ } catch {
6595
+ return fail('INVALID_DATA', pathArg);
6596
+ }
6597
+ const normalized = normalizeArg(value);
6598
+ canonicalFrame = encodeArg(normalized);
6599
+ if (canonicalFrame.byteLength !== frameArg.byteLength
6600
+ || canonicalFrame.some((byteArg, indexArg) => byteArg !== frameArg[indexArg])) {
6601
+ fail('INVALID_DATA', pathArg);
6602
+ }
6603
+ return normalized;
6604
+ } finally {
6605
+ payloadBytes.fill(0);
6606
+ canonicalFrame?.fill(0);
6595
6607
  }
6596
- return normalized;
6597
6608
  };
6598
6609
 
6599
6610
  export const decodeCloudlyLegacyDeploymentSettlementStdioRequestFrame = (
@@ -0,0 +1,323 @@
1
+ import { deepFreezeValue } from './private/canonicaljson.js';
2
+ import type {
3
+ ICorestoreDatabaseBackupReceipt,
4
+ } from './runtime.corestore.js';
5
+ import type {
6
+ ICorestoreDatabaseExportPackageCompletionV1,
7
+ ICorestoreDatabaseExportPackageReleaseCompletionV1,
8
+ ICorestoreDatabaseExportPackageReleaseRequestV1,
9
+ ICorestoreDatabaseExportPackageReleaseResponseV1,
10
+ ICorestoreDatabaseExportPackageRequestV1,
11
+ ICorestoreDatabaseExportPackageResponseV1,
12
+ } from './runtime.corestore.databaseexportpackage.js';
13
+
14
+ interface ICorestoreDatabaseExportPackageGoldenArtifact<TValue> {
15
+ input: TValue;
16
+ canonical: string;
17
+ byteLength: number;
18
+ sha256: string;
19
+ }
20
+
21
+ interface ICorestoreDatabaseExportPackageGoldenVectorsV1 {
22
+ version: 1;
23
+ request: ICorestoreDatabaseExportPackageGoldenArtifact<
24
+ ICorestoreDatabaseExportPackageRequestV1
25
+ >;
26
+ receipt: ICorestoreDatabaseExportPackageGoldenArtifact<ICorestoreDatabaseBackupReceipt>;
27
+ completion: ICorestoreDatabaseExportPackageGoldenArtifact<
28
+ ICorestoreDatabaseExportPackageCompletionV1
29
+ >;
30
+ response: ICorestoreDatabaseExportPackageGoldenArtifact<
31
+ ICorestoreDatabaseExportPackageResponseV1
32
+ >;
33
+ replayResponse: ICorestoreDatabaseExportPackageGoldenArtifact<
34
+ ICorestoreDatabaseExportPackageResponseV1
35
+ >;
36
+ releaseRequest: ICorestoreDatabaseExportPackageGoldenArtifact<
37
+ ICorestoreDatabaseExportPackageReleaseRequestV1
38
+ >;
39
+ releaseCompletion: ICorestoreDatabaseExportPackageGoldenArtifact<
40
+ ICorestoreDatabaseExportPackageReleaseCompletionV1
41
+ >;
42
+ releaseResponse: ICorestoreDatabaseExportPackageGoldenArtifact<
43
+ ICorestoreDatabaseExportPackageReleaseResponseV1
44
+ >;
45
+ replayReleaseResponse: ICorestoreDatabaseExportPackageGoldenArtifact<
46
+ ICorestoreDatabaseExportPackageReleaseResponseV1
47
+ >;
48
+ }
49
+
50
+ const allocation = {
51
+ purpose: 'scratch-rehearsal' as const,
52
+ rehearsalId: 'offline-rehearsal-1',
53
+ allocationId: '3'.repeat(64),
54
+ generation: 2,
55
+ bindingSha256: '4'.repeat(64),
56
+ receiptSha256: '5'.repeat(64),
57
+ };
58
+
59
+ const request: ICorestoreDatabaseExportPackageRequestV1 = {
60
+ schemaVersion: 1,
61
+ kind: 'corestore-database-export-package-request',
62
+ packageAttemptId: 'offline-package-attempt-1',
63
+ packageBackupId: 'package-cloudly-offline-1',
64
+ input: {
65
+ format: 'smartdb.database.export.v1',
66
+ databaseName: 'cloudly',
67
+ byteLength: 4249,
68
+ sha256: '9321522806fa2957c169940990a4bb7072cec52fa65243eb5b4b570f9dbe9677',
69
+ lineFeedTerminator: 'single-lf',
70
+ },
71
+ approvedSourceBackup: {
72
+ backupId: 'backup-cloudly-approved-1',
73
+ sourceServiceId: 'service-cloudly',
74
+ snapshotId: 'snapshot-cloudly-approved-1',
75
+ backupReceiptSha256:
76
+ '1111111111111111111111111111111111111111111111111111111111111111',
77
+ },
78
+ completeOutputReceiptSha256:
79
+ '47eea07082fa86f8bac5af82397321cffc55924f4487866a7b147d9c256e39f5',
80
+ allocationExpectation: {
81
+ expectation: 'exact',
82
+ allocation,
83
+ },
84
+ };
85
+
86
+ const receipt: ICorestoreDatabaseBackupReceipt = {
87
+ schemaVersion: 1,
88
+ format: 'corestore.database.backup.v1',
89
+ backupId: request.packageBackupId,
90
+ sourceServiceId: 'service-cloudly',
91
+ createdAt: 1_700_000_201_000,
92
+ snapshot: {
93
+ capability: 'database',
94
+ resourceName: 'cloudly',
95
+ snapshotId: 'snapshot-packaged-cloudly-1',
96
+ snapshotName: request.packageBackupId,
97
+ originalSize: request.input.byteLength,
98
+ storedSize: 2048,
99
+ createdAt: 1_700_000_201_000,
100
+ tags: {
101
+ corestore: 'resource',
102
+ serviceId: 'service-cloudly',
103
+ serviceName: 'cloudly',
104
+ capability: 'database',
105
+ resourceName: 'cloudly',
106
+ snapshotName: request.packageBackupId,
107
+ backupId: request.packageBackupId,
108
+ },
109
+ databaseName: 'cloudly',
110
+ databaseAllocation: allocation,
111
+ },
112
+ closure: {
113
+ formatVersion: 1,
114
+ snapshotIds: ['snapshot-packaged-cloudly-1'],
115
+ objectCount: 2,
116
+ packCount: 1,
117
+ chunkCount: 3,
118
+ payloadBytes: request.input.byteLength,
119
+ archiveBytes: 2048,
120
+ sha256: '7'.repeat(64),
121
+ },
122
+ };
123
+
124
+ const completion: ICorestoreDatabaseExportPackageCompletionV1 = {
125
+ schemaVersion: 1,
126
+ kind: 'corestore-database-export-package-completion',
127
+ packageAttemptId: request.packageAttemptId,
128
+ requestSha256: 'd9e63a397c066aaaec2904d20c1a12240e0a1a902ab388cdff2cebde6c9e1cec',
129
+ completedAt: 1_700_000_201_000,
130
+ receipt,
131
+ receiptSha256: '081fc6e6cca7ab6c25a4583a6689821a01f1807942ac0259ba3394b8f34ef580',
132
+ closureByteLength: receipt.closure.archiveBytes,
133
+ closureSha256: receipt.closure.sha256,
134
+ };
135
+
136
+ const response: ICorestoreDatabaseExportPackageResponseV1 = {
137
+ schemaVersion: 1,
138
+ kind: 'corestore-database-export-package-response',
139
+ completion,
140
+ replayed: false,
141
+ };
142
+
143
+ const replayResponse: ICorestoreDatabaseExportPackageResponseV1 = {
144
+ ...response,
145
+ replayed: true,
146
+ };
147
+
148
+ const releaseRequest: ICorestoreDatabaseExportPackageReleaseRequestV1 = {
149
+ schemaVersion: 1,
150
+ kind: 'corestore-database-export-package-release-request',
151
+ packageAttemptId: request.packageAttemptId,
152
+ requestSha256: completion.requestSha256,
153
+ completionSha256: 'e771f6f674bc6b00295a38b191aa43cd731e2811f149d54d1fd6b7f14fbc81ce',
154
+ callerFsyncedClosureByteLength: completion.closureByteLength,
155
+ callerFsyncedClosureSha256: completion.closureSha256,
156
+ callerFsyncedReceiptByteLength: 1203,
157
+ callerFsyncedReceiptSha256: completion.receiptSha256,
158
+ callerFsyncedAt: 1_700_000_201_001,
159
+ };
160
+
161
+ const releaseCompletion: ICorestoreDatabaseExportPackageReleaseCompletionV1 = {
162
+ schemaVersion: 1,
163
+ kind: 'corestore-database-export-package-release-completion',
164
+ packageAttemptId: request.packageAttemptId,
165
+ requestSha256: completion.requestSha256,
166
+ completionSha256: releaseRequest.completionSha256,
167
+ releaseRequestSha256:
168
+ '4dc5b3a803aa1e56fdeb74d45ccfa123781c6162a300333c31a85006d9a2d460',
169
+ releasedAt: 1_700_000_201_002,
170
+ };
171
+
172
+ const releaseResponse: ICorestoreDatabaseExportPackageReleaseResponseV1 = {
173
+ schemaVersion: 1,
174
+ kind: 'corestore-database-export-package-release-response',
175
+ release: releaseCompletion,
176
+ replayed: false,
177
+ };
178
+
179
+ const replayReleaseResponse: ICorestoreDatabaseExportPackageReleaseResponseV1 = {
180
+ ...releaseResponse,
181
+ replayed: true,
182
+ };
183
+
184
+ const allocationCanonical =
185
+ '{"allocationId":"3333333333333333333333333333333333333333333333333333333333333333",'
186
+ + '"bindingSha256":"4444444444444444444444444444444444444444444444444444444444444444",'
187
+ + '"generation":2,"purpose":"scratch-rehearsal",'
188
+ + '"receiptSha256":"5555555555555555555555555555555555555555555555555555555555555555",'
189
+ + '"rehearsalId":"offline-rehearsal-1"}';
190
+
191
+ const requestCanonical =
192
+ `{"allocationExpectation":{"allocation":${allocationCanonical},"expectation":"exact"},`
193
+ + '"approvedSourceBackup":{"backupId":"backup-cloudly-approved-1",'
194
+ + '"backupReceiptSha256":"1111111111111111111111111111111111111111111111111111111111111111",'
195
+ + '"snapshotId":"snapshot-cloudly-approved-1","sourceServiceId":"service-cloudly"},'
196
+ + '"completeOutputReceiptSha256":"47eea07082fa86f8bac5af82397321cffc55924f4487866a7b147d9c256e39f5",'
197
+ + '"input":{"byteLength":4249,"databaseName":"cloudly",'
198
+ + '"format":"smartdb.database.export.v1","lineFeedTerminator":"single-lf",'
199
+ + '"sha256":"9321522806fa2957c169940990a4bb7072cec52fa65243eb5b4b570f9dbe9677"},'
200
+ + '"kind":"corestore-database-export-package-request",'
201
+ + '"packageAttemptId":"offline-package-attempt-1",'
202
+ + '"packageBackupId":"package-cloudly-offline-1","schemaVersion":1}';
203
+
204
+ const receiptCanonical =
205
+ '{"backupId":"package-cloudly-offline-1","closure":{"archiveBytes":2048,'
206
+ + '"chunkCount":3,"formatVersion":1,"objectCount":2,"packCount":1,"payloadBytes":4249,'
207
+ + '"sha256":"7777777777777777777777777777777777777777777777777777777777777777",'
208
+ + '"snapshotIds":["snapshot-packaged-cloudly-1"]},"createdAt":1700000201000,'
209
+ + '"format":"corestore.database.backup.v1","schemaVersion":1,'
210
+ + '"snapshot":{"capability":"database","createdAt":1700000201000,'
211
+ + `"databaseAllocation":${allocationCanonical},`
212
+ + '"databaseName":"cloudly","originalSize":4249,"resourceName":"cloudly",'
213
+ + '"snapshotId":"snapshot-packaged-cloudly-1",'
214
+ + '"snapshotName":"package-cloudly-offline-1","storedSize":2048,'
215
+ + '"tags":{"backupId":"package-cloudly-offline-1","capability":"database",'
216
+ + '"corestore":"resource","resourceName":"cloudly","serviceId":"service-cloudly",'
217
+ + '"serviceName":"cloudly","snapshotName":"package-cloudly-offline-1"}},'
218
+ + '"sourceServiceId":"service-cloudly"}';
219
+
220
+ const completionCanonical =
221
+ '{"closureByteLength":2048,'
222
+ + '"closureSha256":"7777777777777777777777777777777777777777777777777777777777777777",'
223
+ + '"completedAt":1700000201000,"kind":"corestore-database-export-package-completion",'
224
+ + '"packageAttemptId":"offline-package-attempt-1",'
225
+ + `"receipt":${receiptCanonical},`
226
+ + '"receiptSha256":"081fc6e6cca7ab6c25a4583a6689821a01f1807942ac0259ba3394b8f34ef580",'
227
+ + '"requestSha256":"d9e63a397c066aaaec2904d20c1a12240e0a1a902ab388cdff2cebde6c9e1cec",'
228
+ + '"schemaVersion":1}';
229
+
230
+ const responseCanonical =
231
+ `{"completion":${completionCanonical},`
232
+ + '"kind":"corestore-database-export-package-response","replayed":false,"schemaVersion":1}';
233
+
234
+ const replayResponseCanonical =
235
+ `{"completion":${completionCanonical},`
236
+ + '"kind":"corestore-database-export-package-response","replayed":true,"schemaVersion":1}';
237
+
238
+ const releaseRequestCanonical =
239
+ '{"callerFsyncedAt":1700000201001,"callerFsyncedClosureByteLength":2048,'
240
+ + '"callerFsyncedClosureSha256":"7777777777777777777777777777777777777777777777777777777777777777",'
241
+ + '"callerFsyncedReceiptByteLength":1203,'
242
+ + '"callerFsyncedReceiptSha256":"081fc6e6cca7ab6c25a4583a6689821a01f1807942ac0259ba3394b8f34ef580",'
243
+ + '"completionSha256":"e771f6f674bc6b00295a38b191aa43cd731e2811f149d54d1fd6b7f14fbc81ce",'
244
+ + '"kind":"corestore-database-export-package-release-request",'
245
+ + '"packageAttemptId":"offline-package-attempt-1",'
246
+ + '"requestSha256":"d9e63a397c066aaaec2904d20c1a12240e0a1a902ab388cdff2cebde6c9e1cec",'
247
+ + '"schemaVersion":1}';
248
+
249
+ const releaseCompletionCanonical =
250
+ '{"completionSha256":"e771f6f674bc6b00295a38b191aa43cd731e2811f149d54d1fd6b7f14fbc81ce",'
251
+ + '"kind":"corestore-database-export-package-release-completion",'
252
+ + '"packageAttemptId":"offline-package-attempt-1",'
253
+ + '"releaseRequestSha256":"4dc5b3a803aa1e56fdeb74d45ccfa123781c6162a300333c31a85006d9a2d460",'
254
+ + '"releasedAt":1700000201002,'
255
+ + '"requestSha256":"d9e63a397c066aaaec2904d20c1a12240e0a1a902ab388cdff2cebde6c9e1cec",'
256
+ + '"schemaVersion":1}';
257
+
258
+ const releaseResponseCanonical =
259
+ '{"kind":"corestore-database-export-package-release-response",'
260
+ + `"release":${releaseCompletionCanonical},"replayed":false,"schemaVersion":1}`;
261
+
262
+ const replayReleaseResponseCanonical =
263
+ '{"kind":"corestore-database-export-package-release-response",'
264
+ + `"release":${releaseCompletionCanonical},"replayed":true,"schemaVersion":1}`;
265
+
266
+ export const corestoreDatabaseExportPackageGoldenVectors:
267
+ Readonly<ICorestoreDatabaseExportPackageGoldenVectorsV1> = deepFreezeValue({
268
+ version: 1,
269
+ request: {
270
+ input: request,
271
+ canonical: requestCanonical,
272
+ byteLength: 1084,
273
+ sha256: 'd9e63a397c066aaaec2904d20c1a12240e0a1a902ab388cdff2cebde6c9e1cec',
274
+ },
275
+ receipt: {
276
+ input: receipt,
277
+ canonical: receiptCanonical,
278
+ byteLength: 1203,
279
+ sha256: '081fc6e6cca7ab6c25a4583a6689821a01f1807942ac0259ba3394b8f34ef580',
280
+ },
281
+ completion: {
282
+ input: completion,
283
+ canonical: completionCanonical,
284
+ byteLength: 1636,
285
+ sha256: 'e771f6f674bc6b00295a38b191aa43cd731e2811f149d54d1fd6b7f14fbc81ce',
286
+ },
287
+ response: {
288
+ input: response,
289
+ canonical: responseCanonical,
290
+ byteLength: 1738,
291
+ sha256: 'b119c4c7b8747ac4ebadf8858be4cde362cf99be66d30a537148a3dcb25171c1',
292
+ },
293
+ replayResponse: {
294
+ input: replayResponse,
295
+ canonical: replayResponseCanonical,
296
+ byteLength: 1737,
297
+ sha256: '3666c3ff9e9da23617c810dc86f27787909b487fd836045c50250c566379ddd2',
298
+ },
299
+ releaseRequest: {
300
+ input: releaseRequest,
301
+ canonical: releaseRequestCanonical,
302
+ byteLength: 594,
303
+ sha256: '4dc5b3a803aa1e56fdeb74d45ccfa123781c6162a300333c31a85006d9a2d460',
304
+ },
305
+ releaseCompletion: {
306
+ input: releaseCompletion,
307
+ canonical: releaseCompletionCanonical,
308
+ byteLength: 414,
309
+ sha256: '7a06c6a571586a94c363880b68aa59d144ba75a3bfaeb6137725183c5b99a19c',
310
+ },
311
+ releaseResponse: {
312
+ input: releaseResponse,
313
+ canonical: releaseResponseCanonical,
314
+ byteLength: 521,
315
+ sha256: '1529914cb60ac561f09bfcc5d0a123d4e676515789ec3859b3e2e84ef6c19afc',
316
+ },
317
+ replayReleaseResponse: {
318
+ input: replayReleaseResponse,
319
+ canonical: replayReleaseResponseCanonical,
320
+ byteLength: 520,
321
+ sha256: 'fa4413657a3ee9f77ca4d1852a6627faa0282712113a07cf6a57e7dd3d0266e9',
322
+ },
323
+ });