@camstack/types 1.2.367 → 1.2.369

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.
@@ -94,6 +94,7 @@ import type { addonSettingsCapability } from '../capabilities/addon-settings.cap
94
94
  import type { audioAnalyzerCapability } from '../capabilities/audio-analyzer.cap.js';
95
95
  import type { deviceAdoptionCapability } from '../capabilities/device-adoption.cap.js';
96
96
  import type { deviceExportCapability } from '../capabilities/device-export.cap.js';
97
+ import type { deviceHistoryCapability } from '../capabilities/device-history.cap.js';
97
98
  import type { deviceManagerCapability } from '../capabilities/device-manager.cap.js';
98
99
  import type { deviceStateCapability } from '../capabilities/device-state.cap.js';
99
100
  import type { faceGalleryCapability } from '../capabilities/face-gallery.cap.js';
@@ -293,6 +294,7 @@ export interface DeviceProxy {
293
294
  readonly audioAnalyzer: Pick<InferDeviceProxyCap<typeof audioAnalyzerCapability>, 'detachDevice'>;
294
295
  readonly deviceAdoption: Pick<InferDeviceProxyCap<typeof deviceAdoptionCapability>, 'getStatus'>;
295
296
  readonly deviceExport: Pick<InferDeviceProxyCap<typeof deviceExportCapability>, 'getDeviceSettingsContribution' | 'getDeviceLiveContribution' | 'applyDeviceSettingsPatch'>;
297
+ readonly deviceHistory: Pick<InferDeviceProxyCap<typeof deviceHistoryCapability>, 'listSeries' | 'query' | 'getDeviceEnabled' | 'setDeviceEnabled'>;
296
298
  readonly deviceManager: Pick<InferDeviceProxyCap<typeof deviceManagerCapability>, 'loadConfig' | 'loadRuntimeState' | 'loadMeta' | 'setName' | 'setLocation' | 'setType' | 'setIntegrationId' | 'setLinkDeviceId' | 'setPrimaryChildEntityId' | 'setChildLayout' | 'setDisplay' | 'getWireableFields' | 'setRole' | 'applyInitialMeta' | 'setMetadata' | 'setDisabled' | 'getDevice' | 'getLinkedDevices' | 'getStreamSources' | 'getConfigSchema' | 'getSettingsSchema' | 'updateConfig' | 'enable' | 'disable' | 'remove' | 'getStreamProfileMap' | 'setStreamProfileMap' | 'probeStreams' | 'getBindings' | 'setWrapperActive' | 'getWrapperActivation' | 'getDeviceSettingsAggregate' | 'getDeviceLiveInfoAggregate' | 'getDeviceAggregate' | 'runDeviceAction' | 'updateDeviceField' | 'updateDeviceFieldsBatch' | 'testField' | 'getDeviceStatusAggregate'>;
297
299
  readonly deviceState: Pick<InferDeviceProxyCap<typeof deviceStateCapability>, 'getSnapshot' | 'getCapSlice' | 'setCapSlice' | 'claimFields' | 'patchOwnedFields' | 'releaseClaim' | 'getNativeCapSlice'>;
298
300
  readonly faceGallery: Pick<InferDeviceProxyCap<typeof faceGalleryCapability>, 'listRecentFaces' | 'getFaceByTrack'>;
@@ -6,7 +6,7 @@
6
6
  * scope+access check inside `protectedProcedure` (see
7
7
  * `server/backend/src/api/trpc/trpc.middleware.ts`).
8
8
  *
9
- * Coverage: 1321 method paths across 172 capabilities.
9
+ * Coverage: 1332 method paths across 173 capabilities.
10
10
  */
11
11
  import type { CapabilityMethodAccess } from '../capabilities/capability-definition.js';
12
12
  export interface MethodAccessRecord {
@@ -6,8 +6,8 @@
6
6
  * system-scope cap that takes a deviceId was previously never device-filtered
7
7
  * — see the generator header).
8
8
  *
9
- * Coverage: 520 methods carry a device reference, of which
10
- * 165 are on SYSTEM-scope caps.
9
+ * Coverage: 524 methods carry a device reference, of which
10
+ * 169 are on SYSTEM-scope caps.
11
11
  *
12
12
  * Top-level fields, number arrays, and one-level arrays of objects carrying
13
13
  * a numeric device field (targets[].deviceId) are all mapped; the matcher
@@ -16,6 +16,7 @@ import type { decoderCapability } from '../capabilities/decoder.cap.js';
16
16
  import type { deviceAdoptionCapability } from '../capabilities/device-adoption.cap.js';
17
17
  import type { deviceCredentialsCapability } from '../capabilities/device-credentials.cap.js';
18
18
  import type { deviceExportCapability } from '../capabilities/device-export.cap.js';
19
+ import type { deviceHistoryCapability } from '../capabilities/device-history.cap.js';
19
20
  import type { deviceManagerCapability } from '../capabilities/device-manager.cap.js';
20
21
  import type { deviceProviderCapability } from '../capabilities/device-provider.cap.js';
21
22
  import type { deviceStateCapability } from '../capabilities/device-state.cap.js';
@@ -76,6 +77,7 @@ export interface SystemProxy {
76
77
  readonly deviceAdoption: Pick<InferProvider<typeof deviceAdoptionCapability>, 'listCandidateFilters' | 'listCandidates' | 'getCandidate' | 'refresh' | 'adopt' | 'release' | 'resync'>;
77
78
  readonly deviceCredentials: Pick<InferProvider<typeof deviceCredentialsCapability>, 'listDeviceCredentials' | 'startEnrollment' | 'revokeDeviceCredential' | 'getDeviceCertificateSettings' | 'setDeviceCertificateSettings' | 'deleteDeviceCredential' | 'getDeviceCaStatus' | 'renameDeviceCredential'>;
78
79
  readonly deviceExport: Pick<InferProvider<typeof deviceExportCapability>, 'getStatus' | 'listSupportedDeviceKinds' | 'listExposedDevices' | 'exposeDevice' | 'unexposeDevice'>;
80
+ readonly deviceHistory: Pick<InferProvider<typeof deviceHistoryCapability>, 'listNodeSeries' | 'queryNode' | 'declareSeries' | 'record' | 'recordBuckets' | 'getStatus'>;
79
81
  readonly deviceManager: Pick<InferProvider<typeof deviceManagerCapability>, 'allocateDeviceId' | 'migrateDevice' | 'registerDevice' | 'removeDevice' | 'persistConfig' | 'getRoleDisplayDefaults' | 'setRoleDisplayDefaults' | 'listLocations' | 'addLocation' | 'removeLocation' | 'renameLocation' | 'listLocationIcons' | 'setLocationIcon' | 'listLocationDescriptions' | 'setLocationDescription' | 'listSiteZones' | 'setSiteZone' | 'removeSiteZone' | 'renameSiteZone' | 'setLocationZone' | 'listPersistedByAddon' | 'listAll' | 'getChildren' | 'getChildrenBatch' | 'getLinkedDevicesBatch' | 'removeByIntegration' | 'getBindingsBatch' | 'getAllBindings' | 'listDeviceIdsByCaps' | 'listWrappersForCap' | 'listBindableCapsForDeviceType' | 'discoverDevices' | 'adoptDevice' | 'getCreationSchema' | 'createDevice' | 'testCreationField' | 'adoptionListCandidateFilters' | 'adoptionListCandidates' | 'adoptionRefresh' | 'adoptionAdopt' | 'adoptionRelease' | 'adoptionStartJob' | 'adoptionListJobs' | 'adoptionCancelJob' | 'adoptionResync' | 'discoveryProviders' | 'discoverAllProviders' | 'discoverProvider' | 'providerCreationType' | 'providerDiscoveryParamsSchema' | 'getDeviceStatusAggregateBatch'>;
80
82
  readonly deviceProvider: Pick<InferProvider<typeof deviceProviderCapability>, 'start' | 'stop' | 'getStatus' | 'getDevices' | 'reloadDevice' | 'supportsDiscovery' | 'discoverDevices' | 'getDiscoveryParamsSchema' | 'getManualCreationType' | 'adoptDiscoveredDevice' | 'supportsManualCreation' | 'getChildCreationSchema' | 'createDevice' | 'testCreationField'>;
81
83
  readonly deviceState: Pick<InferProvider<typeof deviceStateCapability>, 'getAllSnapshots' | 'listClaims'>;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Producer-side five-minute bucket accumulator (D850, plan §5.4).
3
+ *
4
+ * PURE: no I/O, no timers, the clock is a parameter. It lives in
5
+ * `@camstack/types` because it is bundled with every addon — an addon cannot
6
+ * import another addon, and an import from `@camstack/system` breaks on an
7
+ * older server. A producer that samples faster than `record` allows (once per
8
+ * 10 s per series) aggregates here and sends CLOSED buckets with
9
+ * `deviceHistory.recordBuckets`.
10
+ *
11
+ * The caller owns delivery: `takeClosed` hands buckets over, and a bucket the
12
+ * caller could not deliver goes back through `requeue`, which keeps at most
13
+ * {@link MAX_REQUEUED_BUCKETS_PER_SERIES} per series (one hour) and RETURNS what
14
+ * it had to drop so the caller can say so, with a `deviceId` tag (D58, D391).
15
+ */
16
+ import type { DeviceHistorySubject } from '../capabilities/device-history.cap.js';
17
+ /** Width of a bucket the history store accepts. */
18
+ export declare const HISTORY_BUCKET_MS: number;
19
+ /** One hour of failed deliveries per series is retried; older buckets are dropped. */
20
+ export declare const MAX_REQUEUED_BUCKETS_PER_SERIES = 12;
21
+ /** A closed bucket, shaped exactly like one `recordBuckets` entry. */
22
+ export interface ClosedHistoryBucket {
23
+ readonly key: string;
24
+ readonly subject: DeviceHistorySubject;
25
+ readonly scope: string;
26
+ readonly bucketStart: number;
27
+ readonly samples: number;
28
+ readonly sum: number;
29
+ readonly min: number;
30
+ readonly max: number;
31
+ readonly last: number | null;
32
+ readonly lastTs: number | null;
33
+ }
34
+ export declare function bucketStartOf(at: number): number;
35
+ export declare class BucketAccumulator {
36
+ private readonly open;
37
+ private readonly requeued;
38
+ /** Add one observation. A non-finite value or timestamp is ignored (never counted as 0). */
39
+ note(key: string, subject: DeviceHistorySubject, scope: string, value: number, at: number): void;
40
+ /**
41
+ * Buckets whose window ended at or before `now`, oldest first, requeued ones
42
+ * included. They leave the accumulator: delivery is the caller's.
43
+ */
44
+ takeClosed(now: number): readonly ClosedHistoryBucket[];
45
+ /**
46
+ * Put undelivered buckets back for the next `takeClosed`. Keeps the newest
47
+ * {@link MAX_REQUEUED_BUCKETS_PER_SERIES} per series and returns the buckets
48
+ * it dropped (empty when none).
49
+ */
50
+ requeue(buckets: readonly ClosedHistoryBucket[]): readonly ClosedHistoryBucket[];
51
+ /** Buckets currently held (open plus requeued) — for a gauge in the producer's own status. */
52
+ pendingBucketCount(): number;
53
+ }
package/dist/index.d.ts CHANGED
@@ -240,6 +240,7 @@ export { METHOD_DEVICE_SELECTORS, SYSTEM_SCOPE_DEVICE_METHODS, } from './generat
240
240
  export { CAP_PROVIDER_KIND_MAP, getCapsByProviderKind, PROVIDER_KIND_CAP_NAMES, } from './generated/provider-kind-map.js';
241
241
  export type { RuntimeStatePolicy } from './generated/runtime-state-durability.js';
242
242
  export { isRestoredCap, RESTORED_CAP_NAMES, RUNTIME_STATE_POLICY, runtimeStatePolicyFor, } from './generated/runtime-state-durability.js';
243
+ export { BucketAccumulator, bucketStartOf, type ClosedHistoryBucket, HISTORY_BUCKET_MS, MAX_REQUEUED_BUCKETS_PER_SERIES, } from './history/bucket-accumulator.js';
243
244
  export { HISTORY_CATALOG, HISTORY_NONE_CAPS, historyFieldsFor, } from './generated/history-catalog.js';
244
245
  export type { ScopePresetId, ScopePresetSpec } from './generated/scope-presets.js';
245
246
  export { SCOPE_PRESETS } from './generated/scope-presets.js';