h1v3 0.7.2 → 0.7.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "h1v3",
3
- "version": "0.7.2",
3
+ "version": "0.7.3",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "author": "",
@@ -1,4 +1,4 @@
1
- import { EVENT_STORE_META } from "../event-store/configuration.js";
1
+ import { EVENT_STORE_META } from "../configuration/configure-eventStore.js";
2
2
  import { eventStore as eventStoreModular } from "../../dist/browser/client/event-store.js";
3
3
 
4
4
  function adaptDatabase(db) {
@@ -1,6 +1,7 @@
1
1
  import { EVENTS } from "../../dist/browser/client/event-store.js";
2
- import { updateProjections } from "./projections.js";
3
- import { refPathToTriggerPath } from "../paths.js";
2
+ import { refPathToTriggerPath } from "./paths.js";
3
+ import { updateProjections } from "../event-store/projections.js";
4
+
4
5
 
5
6
  export const EVENT_STORE_META = Symbol("Event store configuration metadata");
6
7
 
@@ -34,11 +35,4 @@ export function configureEventStore({ ref, projections, ...rest }, { onValueWrit
34
35
  );
35
36
 
36
37
  }
37
-
38
- configureEventStore.inject = ({ onValueWritten, observe, paths, region, instance }) =>
39
-
40
- (eventStoreFactory, ...args) =>
41
-
42
- configureEventStore(eventStoreFactory(paths, ...args), { onValueWritten, observe, region, instance });
43
-
44
-
38
+ configureEventStore.inject = ({ onValueWritten, observe, paths, region, instance }) => (eventStoreFactory, ...args) => configureEventStore(eventStoreFactory(paths, ...args), { onValueWritten, observe, region, instance });
@@ -0,0 +1,48 @@
1
+ import { loadConfigurationFromModule } from "./load-configuration.js";
2
+
3
+ function buildConfigDigest(module, paths) {
4
+
5
+
6
+ const refConfigMap = loadConfigurationFromModule(module)
7
+ .flatMap(x => x.map(y => y[1]))
8
+ .reduce((index, config) => ({ ...index, [config.ref]: config }), {});
9
+
10
+ function patchForPath(map) {
11
+
12
+ const ret = {
13
+ ...map
14
+ };
15
+ const mappedConfig = refConfigMap[map.path];
16
+ for (const [x, y] of Object.entries(ret).filter(([_, v]) => typeof v === "object")) {
17
+
18
+ ret[x] = patchForPath(y);
19
+
20
+ }
21
+ if (mappedConfig && (mappedConfig.read || mappedConfig.write)) {
22
+
23
+ ret.projections = mappedConfig.projections;
24
+ ret.eventTypes = mappedConfig.eventTypes;
25
+
26
+ }
27
+ return ret;
28
+
29
+ }
30
+
31
+ return patchForPath(paths);
32
+
33
+ }
34
+ const publicFor1Day = "public, max-age=86400";
35
+
36
+ export function configureMetadataEndpoint({ module, paths, onRequest, region, cacheControl = publicFor1Day }) {
37
+
38
+ const digest = buildConfigDigest(module, paths);
39
+ return onRequest(
40
+ { region },
41
+ async (_, res) => {
42
+
43
+ res.header("Cache-Control", cacheControl).send(digest);
44
+
45
+ }
46
+ );
47
+
48
+ }
@@ -1,72 +1,8 @@
1
- import { loadConfigurationFromModule } from "./load-configuration.js";
2
1
  import { refPathToTriggerPath } from "./paths.js";
3
- import { all, assertNewDataDoesNotHave, assertNewDataHasString, any, assertNewDataHasNumber, assertNewDataHasOneOf, assertNewDataHasLowercaseHexCharacters, assertNewDataFieldDoesNotMatch } from "./rules.js";
2
+ import { all, assertNewDataHasString, assertNewDataHasOneOf, assertNewDataHasLowercaseHexCharacters, assertNewDataFieldDoesNotMatch, assertNewDataDoesNotHave, any, assertNewDataHasNumber } from "./rules.js";
4
3
 
5
- export const RAW_STORE_META = Symbol("Raw database metadata");
6
-
7
- export function configureConfigStore(paths, _onValueWritten, _observe) {
8
-
9
- if (!paths?.config?.path) throw new Error("Missing: paths.config.path");
10
- return {
11
- [RAW_STORE_META]: {
12
- raw: true,
13
- ref: paths.config.path,
14
- read: true,
15
- write: false
16
- }
17
- };
18
-
19
- }
20
-
21
- function buildConfigDigest(module, paths) {
22
-
23
-
24
- const refConfigMap =
25
- loadConfigurationFromModule(module)
26
- .flatMap(x => x.map(y => y[1]))
27
- .reduce((index, config) => ({ ...index, [config.ref]: config }), {});
28
-
29
- function patchForPath(map) {
30
-
31
- const ret = {
32
- ...map
33
- };
34
- const mappedConfig = refConfigMap[map.path];
35
- for (const [x, y] of Object.entries(ret).filter(([_, v]) => typeof v === "object")) {
36
-
37
- ret[x] = patchForPath(y);
38
-
39
- }
40
- if (mappedConfig && (mappedConfig.read || mappedConfig.write)) {
41
-
42
- ret.projections = mappedConfig.projections;
43
- ret.eventTypes = mappedConfig.eventTypes;
44
-
45
- }
46
- return ret;
47
-
48
- }
49
-
50
- return patchForPath(paths);
51
-
52
- }
53
-
54
- const publicFor1Day = "public, max-age=86400";
55
-
56
- export function configureMetadataEndpoint({ module, paths, onRequest, region, cacheControl = publicFor1Day }) {
57
-
58
- const digest = buildConfigDigest(module, paths);
59
- return onRequest(
60
- { region },
61
- async (_, res) => {
62
-
63
- res.header("Cache-Control", cacheControl).send(digest);
64
-
65
- }
66
- );
67
-
68
- }
69
4
 
5
+ export const RAW_STORE_META = Symbol("Raw database metadata");
70
6
  const googleLogLevels = ["DEBUG", "INFO", "NOTICE", "WARNING", "ERROR", "CRITICAL", "ALERT", "EMERGENCY"];
71
7
 
72
8
  function decideSeverity(newData) {
@@ -75,7 +11,6 @@ function decideSeverity(newData) {
75
11
  return googleLogLevels.includes(text) ? text : "INFO";
76
12
 
77
13
  }
78
-
79
14
  /*
80
15
 
81
16
  message, severity, // required
@@ -95,7 +30,7 @@ function handleO11yEventWritten(observe, e) {
95
30
  const timestamp = now.toISOString();
96
31
  const message = newData?.message || "Missing log message";
97
32
 
98
- const { traceId, spanId, ...rest } = newData
33
+ const { traceId, spanId, ...rest } = newData;
99
34
  const logData = { ...rest, time_server_ms };
100
35
 
101
36
  observe({
@@ -107,7 +42,6 @@ function handleO11yEventWritten(observe, e) {
107
42
  timestamp,
108
43
 
109
44
  logData
110
-
111
45
  });
112
46
  after.ref.update({ time_server_ms });
113
47
 
@@ -115,7 +49,7 @@ function handleO11yEventWritten(observe, e) {
115
49
 
116
50
  }
117
51
 
118
- export function configureLoggingStore({ paths, onValueWritten, observe, region, instance }) {
52
+ export function configureO11yStore({ paths, onValueWritten, observe, region, instance }) {
119
53
 
120
54
  if (!paths) throw new Error("Missing paths");
121
55
  if (!onValueWritten) throw new Error("Missing onValueWritten");
@@ -170,4 +104,3 @@ export function configureLoggingStore({ paths, onValueWritten, observe, region,
170
104
  );
171
105
 
172
106
  }
173
-
@@ -1,7 +1,7 @@
1
1
  import { resolve } from "path";
2
2
  import { pathToFileURL } from "url";
3
- import { EVENT_STORE_META } from "./event-store/configuration.js";
4
- import { RAW_STORE_META } from "./configuration.js";
3
+ import { EVENT_STORE_META } from "./configure-eventStore.js";
4
+ import { RAW_STORE_META } from "./configure-o11y-store.js";
5
5
 
6
6
  export async function loadConfiguration(argv) {
7
7
 
@@ -1,4 +1,4 @@
1
- import { PROJECTIONS } from "../dist/browser/client/event-store.js";
1
+ import { PROJECTIONS } from "../../dist/browser/client/event-store.js";
2
2
 
3
3
  export const any = (...args) =>
4
4
 
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  import { listEventStores } from "./commands/list-event-stores.js";
4
4
  import { generateRules } from "./commands/generate-rules.js";
package/src/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  export { PROJECTIONS, EVENTS } from "../dist/browser/client/event-store.js";
2
2
 
3
- export * from "./event-store/configuration.js";
4
-
5
- export * from "./configuration.js";
3
+ export * from "./configuration/configure-eventStore.js";
4
+ export * from "./configuration/configure-metadata-endpoint.js";
5
+ export * from "./configuration/configure-o11y-store.js";
6
6
 
7
7
  export const passThroughView = {
8
8
  "?": (view, e, key) => {
@@ -24,7 +24,7 @@ export * as userTeams from "./membership/user-teams/store.js";
24
24
 
25
25
  export * as userInvites from "./membership/userInvites/store.js";
26
26
 
27
- export * as rules from "./rules.js";
27
+ export * as rules from "./configuration/rules.js";
28
28
 
29
29
  export function explodePathVars(expr) {
30
30
 
@@ -34,5 +34,3 @@ export function explodePathVars(expr) {
34
34
  }
35
35
 
36
36
  export * as o11y from "./observability/index.js";
37
-
38
- export { loadConfigurationFromModule } from "./load-configuration.js";
@@ -1,4 +1,4 @@
1
- import { assertIsMyTeam } from "../../rules.js";
1
+ import { assertIsMyTeam } from "../../configuration/rules.js";
2
2
  import { eventTypes } from "./events.js";
3
3
  import current from "./projections/current.js";
4
4
  import { verifyStorePaths } from "./verify-store-paths.js";
@@ -13,7 +13,7 @@ import {
13
13
  any,
14
14
  all,
15
15
  assertEventIsOfType
16
- } from "../../rules.js";
16
+ } from "../../configuration/rules.js";
17
17
  import { verifyStorePaths } from "../team-details/verify-store-paths.js";
18
18
 
19
19
  export function store(paths) {
@@ -1,4 +1,4 @@
1
- import { assertUserIsMe } from "../../rules.js";
1
+ import { assertUserIsMe } from "../../configuration/rules.js";
2
2
  import { verifyStorePaths } from "../team-details/verify-store-paths.js";
3
3
  import { eventTypes } from "./events.js";
4
4
  import current from "./projections/current.js";
@@ -1,4 +1,4 @@
1
- import { assertUserIsMe } from "../../rules.js";
1
+ import { assertUserIsMe } from "../../configuration/rules.js";
2
2
  import { verifyStorePaths } from "../team-details/verify-store-paths.js";
3
3
  import { eventTypes } from "./events.js";
4
4
  import current from "./projections/current.js";
@@ -2,7 +2,7 @@ import { eventTypes, ACCEPTED_INVITATION, REJECTED_INVITATION } from "./events.j
2
2
  import pending from "./projections/pending.js";
3
3
  import { PROJECTIONS } from "../../index.js";
4
4
  import { verifyStorePaths } from "../team-details/verify-store-paths.js";
5
- import { all, any, assertEventIsOfType, assertDataFieldIsMyVerifiedEmail, assertMyVerifiedEmail, not, assertNewDataHas } from "../../rules.js";
5
+ import { all, any, assertEventIsOfType, assertDataFieldIsMyVerifiedEmail, assertMyVerifiedEmail, not, assertNewDataHas } from "../../configuration/rules.js";
6
6
 
7
7
  const assertAcceptedOrRejectedEvent = assertEventIsOfType(
8
8
  ACCEPTED_INVITATION,
File without changes