@helyx/bot 0.4.9 → 0.4.13

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.
@@ -0,0 +1,5 @@
1
+ import { PlatformNumericWriteBehindService, type NumericWriteBehindRegistration } from "@helyx/platform";
2
+ import { type ModuleDefinition } from "@helyx/sdk";
3
+ export declare function numericWriteBehindRegistrations(modules: readonly ModuleDefinition[]): readonly NumericWriteBehindRegistration[];
4
+ export declare function createLocalNumericWriteBehind(services: ReadonlyMap<string, unknown>, modules: readonly ModuleDefinition[]): PlatformNumericWriteBehindService;
5
+ //# sourceMappingURL=numeric-write-behind.d.ts.map
@@ -0,0 +1,37 @@
1
+ import { PlatformNumericWriteBehindService, } from "@helyx/platform";
2
+ import { HELYX_SERVICE_NAMES, } from "@helyx/sdk";
3
+ export function numericWriteBehindRegistrations(modules) {
4
+ const registrations = [];
5
+ for (const module of modules) {
6
+ for (const [collection, definition] of Object.entries(module.records ?? {})) {
7
+ if ((definition.incrementableFields?.length ?? 0) === 0)
8
+ continue;
9
+ const uniqueBy = definition.uniqueKeys?.find((key) => key.length > 0 &&
10
+ key.every((field) => definition.fields[field] !== undefined &&
11
+ definition.fields[field].optional !== true));
12
+ const select = definition.readableFields?.filter((field) => {
13
+ const type = definition.fields[field]?.type;
14
+ return type === "number" || type === "date";
15
+ });
16
+ if (!uniqueBy?.length || !select?.length)
17
+ throw new Error(`Numeric write-behind collection requires a non-optional unique key and readable numeric result fields: ${module.manifest.id}/${collection}`);
18
+ registrations.push({
19
+ moduleId: module.manifest.id,
20
+ collection,
21
+ uniqueBy,
22
+ select,
23
+ });
24
+ }
25
+ }
26
+ return registrations;
27
+ }
28
+ export function createLocalNumericWriteBehind(services, modules) {
29
+ const writer = services.get(HELYX_SERVICE_NAMES.records);
30
+ if (!writer)
31
+ throw new Error("Numeric write-behind requires the module record service");
32
+ return new PlatformNumericWriteBehindService({
33
+ writer,
34
+ registrations: numericWriteBehindRegistrations(modules),
35
+ });
36
+ }
37
+ //# sourceMappingURL=numeric-write-behind.js.map