@hot-updater/test-utils 1.2.0-rc.58 → 1.2.0-rc.59

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.d.mts CHANGED
@@ -605,4 +605,33 @@ declare const RELEASE_CATALOG_STORAGE_FIXTURES: Readonly<Record<string, string>>
605
605
  /** Storage boundary shared by provider and separately spawned server tests. */
606
606
  declare const createReleaseCatalogTestStorage: () => StorageAdapter;
607
607
  //#endregion
608
- export { AdminApiTestClient, AggregateBatchingSuiteOptions, ContentionOptions, ContentionReport, DatabaseAdapterConformanceContext, DatabaseAdapterConformanceOptions, DatabasePluginTestSuite, type DatabaseTestLifecycle, DatabaseTestSuiteOptions, HttpTestClient, HttpTestHandlers, HttpTestRequest, HttpTestRequestInit, HttpTestServer, type Insights11TestApi, LATER_RELEASE_CATALOG_FIELD, MeasuredDatabase, MeasuredDatabaseOptions, MeasuredDatabaseStorage, MemoryKeyValueStoreOptions, PluginTestHarnessOptions, RELEASE_CATALOG_DOWNLOAD_HASH, RELEASE_CATALOG_MANIFEST_URIS, RELEASE_CATALOG_STORAGE_FIXTURES, ReadBudgetAdapterContext, ReadBudgetSuiteOptions, ReleaseLabelEngineSuiteOptions, RowsExamined, SqlExecutorLike, SqlQuery, SqlStatementLike, StorageAdapterTestSuiteOptions, conformanceCounters, conformanceExpiring, conformanceItems, createAdminApiTestClient, createBundleEventRowFixture, createBundleFixture, createBundlePatchRowFixture, createBundleRowFixture, createChannelRowFixture, createHandlerHttpTestClient, createHttpTestClient, createMeasuredDatabase, createMemoryKeyValueStore, createPluginTestHarness, createReleaseCatalogTestStorage, createReleaseRowFixture, expectInsightsIndex, insights11TestPlugin, insightsTestSuite, jsonRequest, mysqlRowsExamined, postgresRowsExamined, releaseCatalogArtifact, releaseCatalogArtifactFiles, releaseCatalogDownloadUrl, runContentionHarness, setupAggregateBatchingTestSuite, setupBundleMethodsTestSuite, setupCoreAdminTestSuite, setupDatabaseAdapterConformanceSuite, setupDatabaseTestSuite, setupInsightsHttpTestSuite, setupInsightsModelTestSuite, setupReadBudgetTestSuite, setupReleaseCatalogTestSuite, setupReleaseLabelEngineTestSuite, setupReleaseLabelTestSuite, setupSemverSatisfiesTestSuite, setupStorageAdapterTestSuite, startHttpTestServer, storeBundles, toDeployBundle, withAdapterLatency, writeCatalogFromLaterRelease };
608
+ //#region src/capacityCappedStore.d.ts
609
+ interface CapacityCappedStoreOptions {
610
+ /** The write units the store admits a second, as DynamoDB's `MaxWriteRequestUnits`. */
611
+ readonly unitsPerSecond: number;
612
+ /** Virtual time an admitted write takes; 300 ms by default. */
613
+ readonly writeMs?: number;
614
+ /**
615
+ * Virtual time a throttled write takes before the store reports it: the
616
+ * client's own throttling retries; 3 s by default.
617
+ */
618
+ readonly throttledMs?: number;
619
+ }
620
+ /**
621
+ * `store` behind a strict write-capacity cap: a token bucket refilled at
622
+ * `unitsPerSecond` on a virtual clock, holding one second of units, with
623
+ * writes priced as DynamoDB prices transactional ones. A write that costs
624
+ * more than the bucket holds is refused as DynamoDB's store reports a
625
+ * throttle, `{ ok: false, retry: true }`, so one costing more than a second
626
+ * of capacity is never admitted. DynamoDB with
627
+ * `OnDemandThroughput.MaxWriteRequestUnits` is looser, since it admits such a
628
+ * write from burst capacity when it has some and refuses by time window
629
+ * otherwise; the strict cap makes a transaction too large for the cap fail
630
+ * every time instead of by chance. Reads and `deleteConsumed` are not capped.
631
+ */
632
+ declare const createCapacityCappedStore: (store: KeyValueStore, { unitsPerSecond, writeMs, throttledMs }: CapacityCappedStoreOptions) => KeyValueStore & {
633
+ /** Writes refused for capacity so far. */
634
+ readonly throttles: () => number;
635
+ };
636
+ //#endregion
637
+ export { AdminApiTestClient, AggregateBatchingSuiteOptions, CapacityCappedStoreOptions, ContentionOptions, ContentionReport, DatabaseAdapterConformanceContext, DatabaseAdapterConformanceOptions, DatabasePluginTestSuite, type DatabaseTestLifecycle, DatabaseTestSuiteOptions, HttpTestClient, HttpTestHandlers, HttpTestRequest, HttpTestRequestInit, HttpTestServer, type Insights11TestApi, LATER_RELEASE_CATALOG_FIELD, MeasuredDatabase, MeasuredDatabaseOptions, MeasuredDatabaseStorage, MemoryKeyValueStoreOptions, PluginTestHarnessOptions, RELEASE_CATALOG_DOWNLOAD_HASH, RELEASE_CATALOG_MANIFEST_URIS, RELEASE_CATALOG_STORAGE_FIXTURES, ReadBudgetAdapterContext, ReadBudgetSuiteOptions, ReleaseLabelEngineSuiteOptions, RowsExamined, SqlExecutorLike, SqlQuery, SqlStatementLike, StorageAdapterTestSuiteOptions, conformanceCounters, conformanceExpiring, conformanceItems, createAdminApiTestClient, createBundleEventRowFixture, createBundleFixture, createBundlePatchRowFixture, createBundleRowFixture, createCapacityCappedStore, createChannelRowFixture, createHandlerHttpTestClient, createHttpTestClient, createMeasuredDatabase, createMemoryKeyValueStore, createPluginTestHarness, createReleaseCatalogTestStorage, createReleaseRowFixture, expectInsightsIndex, insights11TestPlugin, insightsTestSuite, jsonRequest, mysqlRowsExamined, postgresRowsExamined, releaseCatalogArtifact, releaseCatalogArtifactFiles, releaseCatalogDownloadUrl, runContentionHarness, setupAggregateBatchingTestSuite, setupBundleMethodsTestSuite, setupCoreAdminTestSuite, setupDatabaseAdapterConformanceSuite, setupDatabaseTestSuite, setupInsightsHttpTestSuite, setupInsightsModelTestSuite, setupReadBudgetTestSuite, setupReleaseCatalogTestSuite, setupReleaseLabelEngineTestSuite, setupReleaseLabelTestSuite, setupSemverSatisfiesTestSuite, setupStorageAdapterTestSuite, startHttpTestServer, storeBundles, toDeployBundle, withAdapterLatency, writeCatalogFromLaterRelease };
package/dist/index.mjs CHANGED
@@ -7562,4 +7562,61 @@ async function startHttpTestServer(handlers) {
7562
7562
  };
7563
7563
  }
7564
7564
  //#endregion
7565
- export { LATER_RELEASE_CATALOG_FIELD, RELEASE_CATALOG_DOWNLOAD_HASH, RELEASE_CATALOG_MANIFEST_URIS, RELEASE_CATALOG_STORAGE_FIXTURES, conformanceCounters, conformanceExpiring, conformanceItems, createAdminApiTestClient, createBundleEventRowFixture, createBundleFixture, createBundlePatchRowFixture, createBundleRowFixture, createChannelRowFixture, createHandlerHttpTestClient, createHttpTestClient, createMeasuredDatabase, createMemoryKeyValueStore, createPluginTestHarness, createReleaseCatalogTestStorage, createReleaseRowFixture, expectInsightsIndex, insights11TestPlugin, insightsTestSuite, jsonRequest, mysqlRowsExamined, postgresRowsExamined, releaseCatalogArtifact, releaseCatalogArtifactFiles, releaseCatalogDownloadUrl, runContentionHarness, setupAggregateBatchingTestSuite, setupBundleMethodsTestSuite, setupCoreAdminTestSuite, setupDatabaseAdapterConformanceSuite, setupDatabaseTestSuite, setupInsightsHttpTestSuite, setupInsightsModelTestSuite, setupReadBudgetTestSuite, setupReleaseCatalogTestSuite, setupReleaseLabelEngineTestSuite, setupReleaseLabelTestSuite, setupSemverSatisfiesTestSuite, setupStorageAdapterTestSuite, startHttpTestServer, storeBundles, toDeployBundle, withAdapterLatency, writeCatalogFromLaterRelease };
7565
+ //#region src/capacityCappedStore.ts
7566
+ /**
7567
+ * DynamoDB's price of one op in `TransactWriteItems`: 2 write units per
7568
+ * started KB of the item.
7569
+ */
7570
+ const unitsOf = (op) => {
7571
+ const item = op.type === "put" ? op.value : op.type === "add" ? {
7572
+ ...op.init,
7573
+ ...op.by
7574
+ } : {};
7575
+ const bytes = new TextEncoder().encode(JSON.stringify([
7576
+ op.key.pk,
7577
+ op.key.sk,
7578
+ item
7579
+ ])).length;
7580
+ return 2 * Math.max(1, Math.ceil(bytes / 1024));
7581
+ };
7582
+ /**
7583
+ * `store` behind a strict write-capacity cap: a token bucket refilled at
7584
+ * `unitsPerSecond` on a virtual clock, holding one second of units, with
7585
+ * writes priced as DynamoDB prices transactional ones. A write that costs
7586
+ * more than the bucket holds is refused as DynamoDB's store reports a
7587
+ * throttle, `{ ok: false, retry: true }`, so one costing more than a second
7588
+ * of capacity is never admitted. DynamoDB with
7589
+ * `OnDemandThroughput.MaxWriteRequestUnits` is looser, since it admits such a
7590
+ * write from burst capacity when it has some and refuses by time window
7591
+ * otherwise; the strict cap makes a transaction too large for the cap fail
7592
+ * every time instead of by chance. Reads and `deleteConsumed` are not capped.
7593
+ */
7594
+ const createCapacityCappedStore = (store, { unitsPerSecond, writeMs = 300, throttledMs = 3e3 }) => {
7595
+ let clock = 0;
7596
+ let filledAt = 0;
7597
+ let units = unitsPerSecond;
7598
+ let throttles = 0;
7599
+ return {
7600
+ ...store,
7601
+ throttles: () => throttles,
7602
+ async write(ops) {
7603
+ units = Math.min(unitsPerSecond, units + (clock - filledAt) / 1e3 * unitsPerSecond);
7604
+ filledAt = clock;
7605
+ const cost = ops.reduce((sum, op) => sum + unitsOf(op), 0);
7606
+ if (cost > units) {
7607
+ throttles += 1;
7608
+ clock += throttledMs;
7609
+ return {
7610
+ ok: false,
7611
+ retry: true
7612
+ };
7613
+ }
7614
+ const result = await store.write(ops);
7615
+ units -= cost;
7616
+ clock += writeMs;
7617
+ return result;
7618
+ }
7619
+ };
7620
+ };
7621
+ //#endregion
7622
+ export { LATER_RELEASE_CATALOG_FIELD, RELEASE_CATALOG_DOWNLOAD_HASH, RELEASE_CATALOG_MANIFEST_URIS, RELEASE_CATALOG_STORAGE_FIXTURES, conformanceCounters, conformanceExpiring, conformanceItems, createAdminApiTestClient, createBundleEventRowFixture, createBundleFixture, createBundlePatchRowFixture, createBundleRowFixture, createCapacityCappedStore, createChannelRowFixture, createHandlerHttpTestClient, createHttpTestClient, createMeasuredDatabase, createMemoryKeyValueStore, createPluginTestHarness, createReleaseCatalogTestStorage, createReleaseRowFixture, expectInsightsIndex, insights11TestPlugin, insightsTestSuite, jsonRequest, mysqlRowsExamined, postgresRowsExamined, releaseCatalogArtifact, releaseCatalogArtifactFiles, releaseCatalogDownloadUrl, runContentionHarness, setupAggregateBatchingTestSuite, setupBundleMethodsTestSuite, setupCoreAdminTestSuite, setupDatabaseAdapterConformanceSuite, setupDatabaseTestSuite, setupInsightsHttpTestSuite, setupInsightsModelTestSuite, setupReadBudgetTestSuite, setupReleaseCatalogTestSuite, setupReleaseLabelEngineTestSuite, setupReleaseLabelTestSuite, setupSemverSatisfiesTestSuite, setupStorageAdapterTestSuite, startHttpTestServer, storeBundles, toDeployBundle, withAdapterLatency, writeCatalogFromLaterRelease };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hot-updater/test-utils",
3
- "version": "1.2.0-rc.58",
3
+ "version": "1.2.0-rc.59",
4
4
  "type": "module",
5
5
  "description": "Test utilities for Hot Updater packages",
6
6
  "sideEffects": false,
@@ -50,10 +50,10 @@
50
50
  "mysql2": "*",
51
51
  "pg": "*",
52
52
  "vitest": "^4.0.0",
53
- "@hot-updater/plugin-insights": "^1.2.0-rc.58",
54
- "@hot-updater/protocol": "^1.2.0-rc.58",
55
- "@hot-updater/server": "^1.2.0-rc.58",
56
- "@hot-updater/plugin-core": "^1.2.0-rc.58"
53
+ "@hot-updater/plugin-insights": "^1.2.0-rc.59",
54
+ "@hot-updater/protocol": "^1.2.0-rc.59",
55
+ "@hot-updater/plugin-core": "^1.2.0-rc.59",
56
+ "@hot-updater/server": "^1.2.0-rc.59"
57
57
  },
58
58
  "peerDependenciesMeta": {
59
59
  "@electric-sql/pglite": {
@@ -84,10 +84,10 @@
84
84
  "typescript": "npm:@typescript/typescript6@6.0.2",
85
85
  "vitest": "4.1.4",
86
86
  "workspace-tools": "^0.42.3",
87
- "@hot-updater/plugin-insights": "1.2.0-rc.58",
88
- "@hot-updater/protocol": "1.2.0-rc.58",
89
- "@hot-updater/plugin-core": "1.2.0-rc.58",
90
- "@hot-updater/server": "1.2.0-rc.58"
87
+ "@hot-updater/plugin-insights": "1.2.0-rc.59",
88
+ "@hot-updater/protocol": "1.2.0-rc.59",
89
+ "@hot-updater/plugin-core": "1.2.0-rc.59",
90
+ "@hot-updater/server": "1.2.0-rc.59"
91
91
  },
92
92
  "inlinedDependencies": {
93
93
  "@clack/core": "1.4.3",