@x12i/memorix-retrieval 1.1.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.
- package/README.md +124 -0
- package/catalox-seeds/inputs/entity-descriptors/assets.json +296 -0
- package/catalox-seeds/inputs/entity-descriptors/variabilities-groups.json +312 -0
- package/catalox-seeds/inputs/entity-descriptors/vulnerabilities.json +419 -0
- package/catalox-seeds/inputs/item-descriptors/asset-detail-item.json +85 -0
- package/catalox-seeds/inputs/item-descriptors/variabilities-group-detail-item.json +87 -0
- package/catalox-seeds/inputs/item-descriptors/vulnerability-detail-item.json +106 -0
- package/catalox-seeds/inputs/list-descriptors/assets-main-list.json +46 -0
- package/catalox-seeds/inputs/list-descriptors/critical-vulnerabilities-list.json +44 -0
- package/catalox-seeds/inputs/list-descriptors/variabilities-groups-main-list.json +43 -0
- package/catalox-seeds/inputs/list-descriptors/vulnerabilities-main-list.json +47 -0
- package/catalox-seeds/inputs/manifest.json +44 -0
- package/catalox-seeds/inputs/memorix-catalog-ids.json +8 -0
- package/catalox-seeds/inputs/memorix-descriptors.bundle.json +1502 -0
- package/catalox-seeds/inputs/memorix-entity-descriptors.catalog.json +1029 -0
- package/catalox-seeds/inputs/memorix-entity-descriptors.items.json +1026 -0
- package/catalox-seeds/inputs/memorix-item-descriptors.catalog.json +283 -0
- package/catalox-seeds/inputs/memorix-item-descriptors.items.json +280 -0
- package/catalox-seeds/inputs/memorix-list-descriptors.catalog.json +185 -0
- package/catalox-seeds/inputs/memorix-list-descriptors.items.json +182 -0
- package/catalox-seeds/inputs/scope.json +4 -0
- package/catalox-seeds/memorix-retrieval-descriptors.manifest.json +1844 -0
- package/dist/client/catalox-like.d.ts +16 -0
- package/dist/client/catalox-like.d.ts.map +1 -0
- package/dist/client/catalox-like.js +2 -0
- package/dist/client/catalox-like.js.map +1 -0
- package/dist/client/create-client.d.ts +3 -0
- package/dist/client/create-client.d.ts.map +1 -0
- package/dist/client/create-client.js +50 -0
- package/dist/client/create-client.js.map +1 -0
- package/dist/client/create-from-env.d.ts +3 -0
- package/dist/client/create-from-env.d.ts.map +1 -0
- package/dist/client/create-from-env.js +10 -0
- package/dist/client/create-from-env.js.map +1 -0
- package/dist/client/types.d.ts +109 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +2 -0
- package/dist/client/types.js.map +1 -0
- package/dist/client/xronox-like.d.ts +18 -0
- package/dist/client/xronox-like.d.ts.map +1 -0
- package/dist/client/xronox-like.js +2 -0
- package/dist/client/xronox-like.js.map +1 -0
- package/dist/content/fetch-content-object.d.ts +16 -0
- package/dist/content/fetch-content-object.d.ts.map +1 -0
- package/dist/content/fetch-content-object.js +54 -0
- package/dist/content/fetch-content-object.js.map +1 -0
- package/dist/content/map-content-errors.d.ts +5 -0
- package/dist/content/map-content-errors.d.ts.map +1 -0
- package/dist/content/map-content-errors.js +39 -0
- package/dist/content/map-content-errors.js.map +1 -0
- package/dist/content/memorix-content-object.d.ts +21 -0
- package/dist/content/memorix-content-object.d.ts.map +1 -0
- package/dist/content/memorix-content-object.js +54 -0
- package/dist/content/memorix-content-object.js.map +1 -0
- package/dist/content/resolve-content-config.d.ts +19 -0
- package/dist/content/resolve-content-config.d.ts.map +1 -0
- package/dist/content/resolve-content-config.js +37 -0
- package/dist/content/resolve-content-config.js.map +1 -0
- package/dist/data/collection-name.d.ts +4 -0
- package/dist/data/collection-name.d.ts.map +1 -0
- package/dist/data/collection-name.js +23 -0
- package/dist/data/collection-name.js.map +1 -0
- package/dist/data/identity.d.ts +36 -0
- package/dist/data/identity.d.ts.map +1 -0
- package/dist/data/identity.js +68 -0
- package/dist/data/identity.js.map +1 -0
- package/dist/data/memorix-read.d.ts +17 -0
- package/dist/data/memorix-read.d.ts.map +1 -0
- package/dist/data/memorix-read.js +55 -0
- package/dist/data/memorix-read.js.map +1 -0
- package/dist/data/multi-match.d.ts +16 -0
- package/dist/data/multi-match.d.ts.map +1 -0
- package/dist/data/multi-match.js +65 -0
- package/dist/data/multi-match.js.map +1 -0
- package/dist/data/path.d.ts +3 -0
- package/dist/data/path.d.ts.map +1 -0
- package/dist/data/path.js +23 -0
- package/dist/data/path.js.map +1 -0
- package/dist/data/xronox-read.d.ts +13 -0
- package/dist/data/xronox-read.d.ts.map +1 -0
- package/dist/data/xronox-read.js +34 -0
- package/dist/data/xronox-read.js.map +1 -0
- package/dist/descriptors/catalog-ids.d.ts +5 -0
- package/dist/descriptors/catalog-ids.d.ts.map +1 -0
- package/dist/descriptors/catalog-ids.js +5 -0
- package/dist/descriptors/catalog-ids.js.map +1 -0
- package/dist/descriptors/descriptor-types.d.ts +187 -0
- package/dist/descriptors/descriptor-types.d.ts.map +1 -0
- package/dist/descriptors/descriptor-types.js +2 -0
- package/dist/descriptors/descriptor-types.js.map +1 -0
- package/dist/descriptors/load-entity-descriptor.d.ts +4 -0
- package/dist/descriptors/load-entity-descriptor.d.ts.map +1 -0
- package/dist/descriptors/load-entity-descriptor.js +15 -0
- package/dist/descriptors/load-entity-descriptor.js.map +1 -0
- package/dist/descriptors/load-item-descriptor.d.ts +4 -0
- package/dist/descriptors/load-item-descriptor.d.ts.map +1 -0
- package/dist/descriptors/load-item-descriptor.js +15 -0
- package/dist/descriptors/load-item-descriptor.js.map +1 -0
- package/dist/descriptors/load-list-descriptor.d.ts +4 -0
- package/dist/descriptors/load-list-descriptor.d.ts.map +1 -0
- package/dist/descriptors/load-list-descriptor.js +15 -0
- package/dist/descriptors/load-list-descriptor.js.map +1 -0
- package/dist/descriptors/validate-descriptor.d.ts +7 -0
- package/dist/descriptors/validate-descriptor.d.ts.map +1 -0
- package/dist/descriptors/validate-descriptor.js +80 -0
- package/dist/descriptors/validate-descriptor.js.map +1 -0
- package/dist/errors/errors.d.ts +6 -0
- package/dist/errors/errors.d.ts.map +1 -0
- package/dist/errors/errors.js +12 -0
- package/dist/errors/errors.js.map +1 -0
- package/dist/errors/issues.d.ts +14 -0
- package/dist/errors/issues.d.ts.map +1 -0
- package/dist/errors/issues.js +7 -0
- package/dist/errors/issues.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/mongo/connection.d.ts +3 -0
- package/dist/mongo/connection.d.ts.map +1 -0
- package/dist/mongo/connection.js +8 -0
- package/dist/mongo/connection.js.map +1 -0
- package/dist/mongo/env.d.ts +6 -0
- package/dist/mongo/env.d.ts.map +1 -0
- package/dist/mongo/env.js +33 -0
- package/dist/mongo/env.js.map +1 -0
- package/dist/mongo/read-collection.d.ts +14 -0
- package/dist/mongo/read-collection.d.ts.map +1 -0
- package/dist/mongo/read-collection.js +45 -0
- package/dist/mongo/read-collection.js.map +1 -0
- package/dist/mongo/resolve-db.d.ts +6 -0
- package/dist/mongo/resolve-db.d.ts.map +1 -0
- package/dist/mongo/resolve-db.js +9 -0
- package/dist/mongo/resolve-db.js.map +1 -0
- package/dist/mongo/types.d.ts +2 -0
- package/dist/mongo/types.d.ts.map +1 -0
- package/dist/mongo/types.js +2 -0
- package/dist/mongo/types.js.map +1 -0
- package/dist/relations/fetch-relation.d.ts +5 -0
- package/dist/relations/fetch-relation.d.ts.map +1 -0
- package/dist/relations/fetch-relation.js +57 -0
- package/dist/relations/fetch-relation.js.map +1 -0
- package/dist/relations/resolve-relations.d.ts +6 -0
- package/dist/relations/resolve-relations.d.ts.map +1 -0
- package/dist/relations/resolve-relations.js +20 -0
- package/dist/relations/resolve-relations.js.map +1 -0
- package/dist/retrieval/batch-fetch.d.ts +11 -0
- package/dist/retrieval/batch-fetch.d.ts.map +1 -0
- package/dist/retrieval/batch-fetch.js +80 -0
- package/dist/retrieval/batch-fetch.js.map +1 -0
- package/dist/retrieval/compose-item.d.ts +11 -0
- package/dist/retrieval/compose-item.d.ts.map +1 -0
- package/dist/retrieval/compose-item.js +18 -0
- package/dist/retrieval/compose-item.js.map +1 -0
- package/dist/retrieval/compose-row.d.ts +4 -0
- package/dist/retrieval/compose-row.d.ts.map +1 -0
- package/dist/retrieval/compose-row.js +14 -0
- package/dist/retrieval/compose-row.js.map +1 -0
- package/dist/retrieval/fetch-item.d.ts +3 -0
- package/dist/retrieval/fetch-item.d.ts.map +1 -0
- package/dist/retrieval/fetch-item.js +107 -0
- package/dist/retrieval/fetch-item.js.map +1 -0
- package/dist/retrieval/fetch-list.d.ts +3 -0
- package/dist/retrieval/fetch-list.d.ts.map +1 -0
- package/dist/retrieval/fetch-list.js +148 -0
- package/dist/retrieval/fetch-list.js.map +1 -0
- package/dist/retrieval/resolve-fields.d.ts +10 -0
- package/dist/retrieval/resolve-fields.d.ts.map +1 -0
- package/dist/retrieval/resolve-fields.js +52 -0
- package/dist/retrieval/resolve-fields.js.map +1 -0
- package/dist/retrieval/resolve-filters.d.ts +3 -0
- package/dist/retrieval/resolve-filters.d.ts.map +1 -0
- package/dist/retrieval/resolve-filters.js +57 -0
- package/dist/retrieval/resolve-filters.js.map +1 -0
- package/dist/retrieval/resolve-pagination-driver.d.ts +6 -0
- package/dist/retrieval/resolve-pagination-driver.d.ts.map +1 -0
- package/dist/retrieval/resolve-pagination-driver.js +22 -0
- package/dist/retrieval/resolve-pagination-driver.js.map +1 -0
- package/dist/retrieval/resolve-property-source.d.ts +10 -0
- package/dist/retrieval/resolve-property-source.d.ts.map +1 -0
- package/dist/retrieval/resolve-property-source.js +48 -0
- package/dist/retrieval/resolve-property-source.js.map +1 -0
- package/dist/retrieval/resolve-sort.d.ts +14 -0
- package/dist/retrieval/resolve-sort.d.ts.map +1 -0
- package/dist/retrieval/resolve-sort.js +28 -0
- package/dist/retrieval/resolve-sort.js.map +1 -0
- package/dist/tests/collection-env.test.d.ts +2 -0
- package/dist/tests/collection-env.test.d.ts.map +1 -0
- package/dist/tests/collection-env.test.js +44 -0
- package/dist/tests/collection-env.test.js.map +1 -0
- package/dist/tests/content-object.test.d.ts +2 -0
- package/dist/tests/content-object.test.d.ts.map +1 -0
- package/dist/tests/content-object.test.js +39 -0
- package/dist/tests/content-object.test.js.map +1 -0
- package/dist/tests/descriptor-validation.test.d.ts +2 -0
- package/dist/tests/descriptor-validation.test.d.ts.map +1 -0
- package/dist/tests/descriptor-validation.test.js +25 -0
- package/dist/tests/descriptor-validation.test.js.map +1 -0
- package/dist/tests/env.test.d.ts +2 -0
- package/dist/tests/env.test.d.ts.map +1 -0
- package/dist/tests/env.test.js +17 -0
- package/dist/tests/env.test.js.map +1 -0
- package/dist/tests/fetch-item.test.d.ts +2 -0
- package/dist/tests/fetch-item.test.d.ts.map +1 -0
- package/dist/tests/fetch-item.test.js +86 -0
- package/dist/tests/fetch-item.test.js.map +1 -0
- package/dist/tests/fetch-list.test.d.ts +2 -0
- package/dist/tests/fetch-list.test.d.ts.map +1 -0
- package/dist/tests/fetch-list.test.js +85 -0
- package/dist/tests/fetch-list.test.js.map +1 -0
- package/dist/tests/fixtures.d.ts +5 -0
- package/dist/tests/fixtures.d.ts.map +1 -0
- package/dist/tests/fixtures.js +137 -0
- package/dist/tests/fixtures.js.map +1 -0
- package/dist/tests/identity.test.d.ts +2 -0
- package/dist/tests/identity.test.d.ts.map +1 -0
- package/dist/tests/identity.test.js +32 -0
- package/dist/tests/identity.test.js.map +1 -0
- package/dist/tests/multi-match.test.d.ts +2 -0
- package/dist/tests/multi-match.test.d.ts.map +1 -0
- package/dist/tests/multi-match.test.js +31 -0
- package/dist/tests/multi-match.test.js.map +1 -0
- package/dist/tests/read-collection.test.d.ts +2 -0
- package/dist/tests/read-collection.test.d.ts.map +1 -0
- package/dist/tests/read-collection.test.js +19 -0
- package/dist/tests/read-collection.test.js.map +1 -0
- package/dist/tests/relations.test.d.ts +2 -0
- package/dist/tests/relations.test.d.ts.map +1 -0
- package/dist/tests/relations.test.js +77 -0
- package/dist/tests/relations.test.js.map +1 -0
- package/docs/MEMORIX-DATABASE-CONVENTIONS.md +325 -0
- package/package.json +52 -0
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
# Memorix Database Conventions
|
|
2
|
+
|
|
3
|
+
This document defines the shared MongoDB naming and layout conventions for Memorix. All services, pipelines, and tools in the x12i ecosystem should follow these rules so entity data, event data, and source enrichment stay consistent across peers.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Memorix uses **three logical database roles**:
|
|
8
|
+
|
|
9
|
+
| Role | Purpose | Default database name |
|
|
10
|
+
|------|---------|------------------------|
|
|
11
|
+
| **Entities** | Canonical entity records (vulnerabilities, assets, groups, …) | `memorix-entities` |
|
|
12
|
+
| **Events** | Event records derived from or linked to entities | `memorix-events` |
|
|
13
|
+
| **Source** | Upstream operational / enrichment data used to extend Memorix records | *(environment-specific)* |
|
|
14
|
+
|
|
15
|
+
All three may live on the **same MongoDB cluster** (single `MONGO_URI`). They are separated by **database name**, not by connection string.
|
|
16
|
+
|
|
17
|
+
### Simple mode (default)
|
|
18
|
+
|
|
19
|
+
Most peers only need:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
MONGO_URI=mongodb://localhost:27017
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Packages resolve `memorix-entities`, `memorix-events`, collection names, and entity vs event routing internally. Override with `MEMORIX_ENTITIES_DB`, `MEMORIX_EVENTS_DB`, or per-type collection env vars only when required.
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
29
|
+
│ MongoDB cluster │
|
|
30
|
+
│ ┌──────────────────┐ ┌──────────────────┐ │
|
|
31
|
+
│ │ memorix-entities │ │ memorix-events │ ← Memorix │
|
|
32
|
+
│ │ vulnerabilities │ │ vulnerability- │ targets │
|
|
33
|
+
│ │ assets │ │ events │ │
|
|
34
|
+
│ └────────▲─────────┘ └────────▲─────────┘ │
|
|
35
|
+
│ │ │ │
|
|
36
|
+
│ └───────────┬───────────┘ │
|
|
37
|
+
│ │ join / enrich │
|
|
38
|
+
│ ┌────────▼─────────┐ │
|
|
39
|
+
│ │ source-db │ ← source databases │
|
|
40
|
+
│ │ *-information │ │
|
|
41
|
+
│ └──────────────────┘ │
|
|
42
|
+
└─────────────────────────────────────────────────────────────┘
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Target types
|
|
46
|
+
|
|
47
|
+
Every Memorix record belongs to exactly one **target**:
|
|
48
|
+
|
|
49
|
+
| Target | Database | Typical use |
|
|
50
|
+
|--------|----------|-------------|
|
|
51
|
+
| `entity` | `memorix-entities` | Stable domain objects (vulnerability, asset, group, …) |
|
|
52
|
+
| `event` | `memorix-events` | Occurrences, detections, or timeline entries |
|
|
53
|
+
|
|
54
|
+
Tools must declare which target they read or write. Do not mix entity and event documents in the same collection.
|
|
55
|
+
|
|
56
|
+
## Environment variables
|
|
57
|
+
|
|
58
|
+
### Connection
|
|
59
|
+
|
|
60
|
+
| Variable | Aliases | Required | Description |
|
|
61
|
+
|----------|---------|----------|-------------|
|
|
62
|
+
| `MONGO_URI` | `MONGO_CONNECTION_STRING` | Yes | MongoDB connection string for the cluster |
|
|
63
|
+
|
|
64
|
+
### Memorix target databases
|
|
65
|
+
|
|
66
|
+
Resolution order matters: **first non-empty value wins**.
|
|
67
|
+
|
|
68
|
+
#### Entity database (`target: entity`)
|
|
69
|
+
|
|
70
|
+
| Priority | Variable |
|
|
71
|
+
|----------|----------|
|
|
72
|
+
| 1 | `MEMORIX_ENTITIES_DB` |
|
|
73
|
+
| 2 | `MEMORIX_DB_ENTITIES` |
|
|
74
|
+
| 3 | `memorix_entities_db` |
|
|
75
|
+
| 4 | `MEMORIX_DB` *(legacy fallback)* |
|
|
76
|
+
| 5 | **Default:** `memorix-entities` |
|
|
77
|
+
|
|
78
|
+
#### Event database (`target: event`)
|
|
79
|
+
|
|
80
|
+
| Priority | Variable |
|
|
81
|
+
|----------|----------|
|
|
82
|
+
| 1 | `MEMORIX_EVENTS_DB` |
|
|
83
|
+
| 2 | `MEMORIX_DB_EVENTS` |
|
|
84
|
+
| 3 | `memorix_events_db` |
|
|
85
|
+
| 4 | `MEMORIX_DB` *(legacy fallback)* |
|
|
86
|
+
| 5 | **Default:** `memorix-events` |
|
|
87
|
+
|
|
88
|
+
> **Peer rule:** Prefer `MEMORIX_ENTITIES_DB` and `MEMORIX_EVENTS_DB`. Treat `MEMORIX_DB` as a legacy single-database override only.
|
|
89
|
+
|
|
90
|
+
### Source databases
|
|
91
|
+
|
|
92
|
+
Source databases hold upstream data that Memorix tools use to **fill in or extend** entity/event `data` fields. They are never the write target for completion pipelines.
|
|
93
|
+
|
|
94
|
+
| Priority | Variable | Description |
|
|
95
|
+
|----------|----------|-------------|
|
|
96
|
+
| 1 | `MEMORIX_SOURCE_DB` | Preferred default source database name |
|
|
97
|
+
| 2 | `SOURCE_DATABASE_NAME` | Alternative default |
|
|
98
|
+
| 3 | `SOURCEDATABASENAME` / `sourceDatabaseName` / `source_database_name` | Legacy aliases |
|
|
99
|
+
|
|
100
|
+
Per-job overrides are allowed via mapping config or application code. When using JSON mappings with `@x12i/env-tokens`, reference env vars as `"databaseName": "{{ENV.sourceDatabaseName}}"`.
|
|
101
|
+
|
|
102
|
+
### Collection overrides (per entity type)
|
|
103
|
+
|
|
104
|
+
Normalize `entityType` by replacing `-` with `_` and uppercasing.
|
|
105
|
+
|
|
106
|
+
| Target | Env key pattern | Example (`entityType: vulnerability`) |
|
|
107
|
+
|--------|-----------------|----------------------------------------|
|
|
108
|
+
| `entity` | `MEMORIX_ENTITIES_COLLECTION_<ENTITY_TYPE>` | `MEMORIX_ENTITIES_COLLECTION_VULNERABILITY` |
|
|
109
|
+
| `event` | `MEMORIX_EVENTS_COLLECTION_<ENTITY_TYPE>` | `MEMORIX_EVENTS_COLLECTION_VULNERABILITY` |
|
|
110
|
+
|
|
111
|
+
## Collection naming
|
|
112
|
+
|
|
113
|
+
### Memorix entity collections (`memorix-entities`)
|
|
114
|
+
|
|
115
|
+
Use **plural, kebab-case** collection names that describe the entity domain.
|
|
116
|
+
|
|
117
|
+
| `entityType` | Recommended collection | Accepted fallbacks |
|
|
118
|
+
|--------------|------------------------|--------------------|
|
|
119
|
+
| `vulnerability` | `vulnerabilities` | `vulnerability` |
|
|
120
|
+
| `variabilities-group` | `vulnerability-groups` | `vulnerabilities-groups`, `variabilities-groups` |
|
|
121
|
+
| `assets` | `assets` | — |
|
|
122
|
+
|
|
123
|
+
**Default heuristic** when nothing else is configured:
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
<entityType> → e.g. vulnerability
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Prefer explicit names in config over heuristics.
|
|
130
|
+
|
|
131
|
+
### Memorix event collections (`memorix-events`)
|
|
132
|
+
|
|
133
|
+
Use `<domain>-events` or `<domain>s-events`.
|
|
134
|
+
|
|
135
|
+
| `entityType` | Recommended collection | Accepted fallbacks |
|
|
136
|
+
|--------------|------------------------|--------------------|
|
|
137
|
+
| `vulnerability` | `vulnerability-events` | `vulnerabilities-events` |
|
|
138
|
+
| `assets` | `asset-events` | `assets-events` |
|
|
139
|
+
|
|
140
|
+
**Default heuristic:**
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
<entityType>-events → e.g. vulnerability-events
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Source collections
|
|
147
|
+
|
|
148
|
+
Source collections typically use an **`-information`** suffix to distinguish them from Memorix canonical stores:
|
|
149
|
+
|
|
150
|
+
| Source collection | Feeds entity type | Notes |
|
|
151
|
+
|-------------------|-------------------|-------|
|
|
152
|
+
| `vulnerabilities-information` | `vulnerability` | Raw / enriched vulnerability facts |
|
|
153
|
+
| `vulnerability-groups-information` | `variabilities-group` | Group-level enrichment |
|
|
154
|
+
| `assets-information` | `assets` | Asset metadata |
|
|
155
|
+
|
|
156
|
+
**Peer rule:** Source collection names are referenced in `targetSelector.sourceCollection` on Memorix records and in completion mappings. Keep these strings stable — they are the join key for mapping selection.
|
|
157
|
+
|
|
158
|
+
## Collection name resolution order
|
|
159
|
+
|
|
160
|
+
When a tool needs to pick a Memorix collection, resolve in this order:
|
|
161
|
+
|
|
162
|
+
1. Explicit override (CLI flag, API option, or code parameter)
|
|
163
|
+
2. Mapping / config field `targetCollection`
|
|
164
|
+
3. Environment variable (`MEMORIX_ENTITIES_COLLECTION_*` or `MEMORIX_EVENTS_COLLECTION_*`)
|
|
165
|
+
4. `targetCollectionCandidates` from mapping config
|
|
166
|
+
5. Built-in defaults for known `entityType` values (see tables above)
|
|
167
|
+
6. Heuristic default (`<entityType>` or `<entityType>-events`)
|
|
168
|
+
7. Verify the collection exists in the target database; fail clearly if not
|
|
169
|
+
|
|
170
|
+
All peers should implement the same precedence so local, CI, and production behave identically given the same env.
|
|
171
|
+
|
|
172
|
+
## Document shape
|
|
173
|
+
|
|
174
|
+
### Memorix entity / event document
|
|
175
|
+
|
|
176
|
+
Documents in `memorix-entities` and `memorix-events` share this layout:
|
|
177
|
+
|
|
178
|
+
```json
|
|
179
|
+
{
|
|
180
|
+
"_id": "<ObjectId>",
|
|
181
|
+
"recordId": "<optional stable id>",
|
|
182
|
+
"entityId": "<for entity records>",
|
|
183
|
+
"eventId": "<for event records>",
|
|
184
|
+
"capturedAt": "<ISO-8601 timestamp>",
|
|
185
|
+
"data": {
|
|
186
|
+
"... domain fields ..."
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
| Field | Entity | Event | Notes |
|
|
192
|
+
|-------|--------|-------|-------|
|
|
193
|
+
| `_id` | Required | Required | MongoDB primary key |
|
|
194
|
+
| `recordId` | Recommended | Recommended | Logical id; falls back to `_id` string |
|
|
195
|
+
| `entityId` | Required* | Optional | Join key for entity completion |
|
|
196
|
+
| `eventId` | — | Required* | Join key for event completion |
|
|
197
|
+
| `data` | Required | Required | Payload; completion writes here |
|
|
198
|
+
| `modifiedAt` | Optional | Optional | Set by writers on update (ISO-8601) |
|
|
199
|
+
|
|
200
|
+
\*Required for completion pipelines that match on these paths.
|
|
201
|
+
|
|
202
|
+
Legacy field `snapshotId` is still read as a fallback for `recordId` but **must not** be written by new code.
|
|
203
|
+
|
|
204
|
+
### Provenance (logical, not always stored)
|
|
205
|
+
|
|
206
|
+
Completion and ingestion tools track provenance in memory using:
|
|
207
|
+
|
|
208
|
+
| Field | Description |
|
|
209
|
+
|-------|-------------|
|
|
210
|
+
| `sourceCollection` | Which source collection this record was enriched from |
|
|
211
|
+
| `sourceDatabase` | Source database name |
|
|
212
|
+
| `sourceId` | Id in the source system |
|
|
213
|
+
| `idField` | Which id field was used when the record was created |
|
|
214
|
+
|
|
215
|
+
These align with `targetSelector` in completion mappings.
|
|
216
|
+
|
|
217
|
+
### Source document
|
|
218
|
+
|
|
219
|
+
Source documents are ordinary MongoDB documents in the source database. There is no required Memorix envelope — tools match on configured paths (e.g. `vulnerabilityId`, `ip_address`).
|
|
220
|
+
|
|
221
|
+
Do **not** write completion results back to source collections unless a separate, explicit pipeline owns that source.
|
|
222
|
+
|
|
223
|
+
## Entity types
|
|
224
|
+
|
|
225
|
+
`entityType` is a **kebab-case** string identifying the domain object:
|
|
226
|
+
|
|
227
|
+
```
|
|
228
|
+
vulnerability
|
|
229
|
+
variabilities-group
|
|
230
|
+
assets
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Rules:
|
|
234
|
+
|
|
235
|
+
- Use lowercase letters and hyphens only.
|
|
236
|
+
- One `entityType` maps to one primary entity collection and optionally one event collection.
|
|
237
|
+
- Env vars and config keys derive from `entityType` by replacing `-` with `_` and uppercasing.
|
|
238
|
+
|
|
239
|
+
## Completion mapping conventions
|
|
240
|
+
|
|
241
|
+
Tools that enrich Memorix from source data (e.g. `@x12i/memorix-completion`) use JSON mappings with these conventions:
|
|
242
|
+
|
|
243
|
+
```json
|
|
244
|
+
{
|
|
245
|
+
"name": "complete-vulnerability-entity-missing-data",
|
|
246
|
+
"entityType": "vulnerability",
|
|
247
|
+
"target": "entity",
|
|
248
|
+
"targetCollection": "vulnerabilities",
|
|
249
|
+
"targetSelector": {
|
|
250
|
+
"sourceCollection": "vulnerabilities-information",
|
|
251
|
+
"idField": "vulnerabilityId"
|
|
252
|
+
},
|
|
253
|
+
"source": {
|
|
254
|
+
"databaseName": "{{ENV.sourceDatabaseName}}",
|
|
255
|
+
"collection": "vulnerabilities-information"
|
|
256
|
+
},
|
|
257
|
+
"match": {
|
|
258
|
+
"targetPath": "entityId",
|
|
259
|
+
"sourcePath": "vulnerabilityId"
|
|
260
|
+
},
|
|
261
|
+
"writeRoot": "data",
|
|
262
|
+
"fields": [
|
|
263
|
+
{ "sourcePath": "enrichment", "targetPath": "enrichment" }
|
|
264
|
+
]
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
| Field | Convention |
|
|
269
|
+
|-------|------------|
|
|
270
|
+
| `target` | `"entity"` or `"event"` — selects Memorix database |
|
|
271
|
+
| `targetCollection` | Explicit Memorix collection (recommended) |
|
|
272
|
+
| `targetSelector.sourceCollection` | Must match record's source lineage |
|
|
273
|
+
| `source.databaseName` | Source DB; use `{{ENV.*}}` for env-driven deploys |
|
|
274
|
+
| `source.collection` | Source collection to read from |
|
|
275
|
+
| `match.targetPath` | Path on Memorix record (usually `entityId` or `eventId`) |
|
|
276
|
+
| `match.sourcePath` | Path on source document |
|
|
277
|
+
| `writeRoot` | Always `"data"` — never overwrite envelope fields via completion |
|
|
278
|
+
|
|
279
|
+
Default completion mode: **fill missing fields only** (`onlyFillMissing: true`, `overwriteExisting: false`).
|
|
280
|
+
|
|
281
|
+
## `.env` example
|
|
282
|
+
|
|
283
|
+
```bash
|
|
284
|
+
# Cluster
|
|
285
|
+
MONGO_URI=mongodb://localhost:27017
|
|
286
|
+
|
|
287
|
+
# Memorix targets (defaults shown — omit to use defaults)
|
|
288
|
+
MEMORIX_ENTITIES_DB=memorix-entities
|
|
289
|
+
MEMORIX_EVENTS_DB=memorix-events
|
|
290
|
+
|
|
291
|
+
# Source database for enrichment pipelines
|
|
292
|
+
MEMORIX_SOURCE_DB=poc-data-mapping
|
|
293
|
+
# or: SOURCE_DATABASE_NAME=poc-data-mapping
|
|
294
|
+
|
|
295
|
+
# Optional per-type collection overrides
|
|
296
|
+
MEMORIX_ENTITIES_COLLECTION_VULNERABILITY=vulnerabilities
|
|
297
|
+
MEMORIX_EVENTS_COLLECTION_VULNERABILITY=vulnerability-events
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
## Checklist for new peers
|
|
301
|
+
|
|
302
|
+
When building a new service or tool that touches Memorix:
|
|
303
|
+
|
|
304
|
+
- [ ] Connect with `MONGO_URI` / `MONGO_CONNECTION_STRING`
|
|
305
|
+
- [ ] Select database via `target`: `entity` → `memorix-entities`, `event` → `memorix-events`
|
|
306
|
+
- [ ] Respect env precedence documented above
|
|
307
|
+
- [ ] Use recommended collection names or set explicit env overrides
|
|
308
|
+
- [ ] Store domain payload under `data`
|
|
309
|
+
- [ ] Read enrichment from source databases; write only to Memorix target databases
|
|
310
|
+
- [ ] Use stable `sourceCollection` strings for mapping / provenance
|
|
311
|
+
- [ ] Use kebab-case `entityType` values consistently
|
|
312
|
+
- [ ] Fail with a clear error when a collection cannot be resolved
|
|
313
|
+
|
|
314
|
+
## Reference implementation
|
|
315
|
+
|
|
316
|
+
Shared env resolution is mirrored across peers:
|
|
317
|
+
|
|
318
|
+
| Concern | Module |
|
|
319
|
+
|---------|--------|
|
|
320
|
+
| Database name from env | `@x12i/memorix-completion` / `@x12i/memorix-retrieval` → `src/mongo/env.ts` → `resolveMemorixDbName`, `resolveDefaultSourceDbName` |
|
|
321
|
+
| Completion collection resolution | `@x12i/memorix-completion` → `src/mongo/resolve-collection.ts` → `resolveTargetCollectionName` |
|
|
322
|
+
| Retrieval collection resolution | `@x12i/memorix-retrieval` → `src/data/collection-name.ts` → `resolveMemorixCollectionName` (descriptor + env override + prefix/postfix heuristic) |
|
|
323
|
+
| Record document shape | `@x12i/memorix-completion` → `src/types.ts` → `MemorixRecord`, `CompletionMapping` |
|
|
324
|
+
|
|
325
|
+
If this document and a package disagree, **update this document and the package together** — they are intended to stay in sync.
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@x12i/memorix-retrieval",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Descriptor-driven Memorix retrieval layer for lists, items, and content objects",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"catalox-seeds",
|
|
17
|
+
"docs"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc",
|
|
21
|
+
"test": "vitest run",
|
|
22
|
+
"catalox:seed:build": "node scripts/build-seed-manifest.mjs",
|
|
23
|
+
"catalox:seed:memorix-retrieval:validate": "npm run catalox:seed:build && catalox seed validate --file catalox-seeds/memorix-retrieval-descriptors.manifest.json",
|
|
24
|
+
"catalox:seed:memorix-retrieval:apply": "npm run catalox:seed:build && node scripts/apply-seed-manifest.mjs",
|
|
25
|
+
"mongo:check-collections": "node scripts/check-mongo-collections.mjs",
|
|
26
|
+
"smoke:retrieval": "npm run build && node scripts/smoke-retrieval.mjs"
|
|
27
|
+
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=18.0.0"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@x12i/catalox": "^4.1.2",
|
|
33
|
+
"@x12i/helpers": "^1.7.0",
|
|
34
|
+
"mongodb": "^6.21.0"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@x12i/xronox": ">=3.7.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependenciesMeta": {
|
|
40
|
+
"@x12i/xronox": {
|
|
41
|
+
"optional": true
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/node": "^20.14.0",
|
|
46
|
+
"typescript": "^5.6.0",
|
|
47
|
+
"vitest": "^2.1.0"
|
|
48
|
+
},
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
}
|
|
52
|
+
}
|