@x12i/memorix-descriptors 0.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 +96 -0
- package/dist/admin/create-admin.d.ts +74 -0
- package/dist/admin/create-admin.d.ts.map +1 -0
- package/dist/admin/create-admin.js +102 -0
- package/dist/admin/create-admin.js.map +1 -0
- package/dist/catalog/ids.d.ts +12 -0
- package/dist/catalog/ids.d.ts.map +1 -0
- package/dist/catalog/ids.js +32 -0
- package/dist/catalog/ids.js.map +1 -0
- package/dist/catalox/client.d.ts +19 -0
- package/dist/catalox/client.d.ts.map +1 -0
- package/dist/catalox/client.js +51 -0
- package/dist/catalox/client.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +191 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/collections/env-bridge.d.ts +3 -0
- package/dist/collections/env-bridge.d.ts.map +1 -0
- package/dist/collections/env-bridge.js +8 -0
- package/dist/collections/env-bridge.js.map +1 -0
- package/dist/collections/resolve.d.ts +20 -0
- package/dist/collections/resolve.d.ts.map +1 -0
- package/dist/collections/resolve.js +49 -0
- package/dist/collections/resolve.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/integrity/graph.d.ts +19 -0
- package/dist/integrity/graph.d.ts.map +1 -0
- package/dist/integrity/graph.js +65 -0
- package/dist/integrity/graph.js.map +1 -0
- package/dist/integrity/validate.d.ts +4 -0
- package/dist/integrity/validate.d.ts.map +1 -0
- package/dist/integrity/validate.js +278 -0
- package/dist/integrity/validate.js.map +1 -0
- package/dist/mutations/common.d.ts +9 -0
- package/dist/mutations/common.d.ts.map +1 -0
- package/dist/mutations/common.js +108 -0
- package/dist/mutations/common.js.map +1 -0
- package/dist/mutations/content-type.d.ts +21 -0
- package/dist/mutations/content-type.d.ts.map +1 -0
- package/dist/mutations/content-type.js +278 -0
- package/dist/mutations/content-type.js.map +1 -0
- package/dist/mutations/entity.d.ts +21 -0
- package/dist/mutations/entity.d.ts.map +1 -0
- package/dist/mutations/entity.js +276 -0
- package/dist/mutations/entity.js.map +1 -0
- package/dist/mutations/item.d.ts +16 -0
- package/dist/mutations/item.d.ts.map +1 -0
- package/dist/mutations/item.js +131 -0
- package/dist/mutations/item.js.map +1 -0
- package/dist/mutations/list.d.ts +16 -0
- package/dist/mutations/list.d.ts.map +1 -0
- package/dist/mutations/list.js +143 -0
- package/dist/mutations/list.js.map +1 -0
- package/dist/mutations/mapping.d.ts +12 -0
- package/dist/mutations/mapping.d.ts.map +1 -0
- package/dist/mutations/mapping.js +104 -0
- package/dist/mutations/mapping.js.map +1 -0
- package/dist/mutations/property.d.ts +18 -0
- package/dist/mutations/property.d.ts.map +1 -0
- package/dist/mutations/property.js +256 -0
- package/dist/mutations/property.js.map +1 -0
- package/dist/mutations/relation.d.ts +31 -0
- package/dist/mutations/relation.d.ts.map +1 -0
- package/dist/mutations/relation.js +195 -0
- package/dist/mutations/relation.js.map +1 -0
- package/dist/reconcile/index.d.ts +29 -0
- package/dist/reconcile/index.d.ts.map +1 -0
- package/dist/reconcile/index.js +58 -0
- package/dist/reconcile/index.js.map +1 -0
- package/dist/seeds/index.d.ts +33 -0
- package/dist/seeds/index.d.ts.map +1 -0
- package/dist/seeds/index.js +186 -0
- package/dist/seeds/index.js.map +1 -0
- package/dist/store/snapshot.d.ts +6 -0
- package/dist/store/snapshot.d.ts.map +1 -0
- package/dist/store/snapshot.js +49 -0
- package/dist/store/snapshot.js.map +1 -0
- package/dist/tests/validation.test.d.ts +2 -0
- package/dist/tests/validation.test.d.ts.map +1 -0
- package/dist/tests/validation.test.js +114 -0
- package/dist/tests/validation.test.js.map +1 -0
- package/dist/types/index.d.ts +151 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/validation/descriptor-validation.d.ts +20 -0
- package/dist/validation/descriptor-validation.d.ts.map +1 -0
- package/dist/validation/descriptor-validation.js +148 -0
- package/dist/validation/descriptor-validation.js.map +1 -0
- package/docs/MEMORIX-CATALOX-CONTRACTS.md +591 -0
- package/docs/MEMORIX-DATABASE-CONVENTIONS.md +338 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# @x12i/memorix-descriptors
|
|
2
|
+
|
|
3
|
+
Write-side control plane for Memorix entity, list, and item descriptors — plus content types, collections, relations, and completion mappings — stored in Catalox and consumed by `@x12i/memorix-retrieval`.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
| Concern | Package |
|
|
8
|
+
|--------|---------|
|
|
9
|
+
| Load descriptors, compose lists/items, graph, inventory | `@x12i/memorix-retrieval` |
|
|
10
|
+
| Create/update/delete descriptors and mappings in Catalox | `@x12i/memorix-descriptors` |
|
|
11
|
+
|
|
12
|
+
This package validates referential integrity across entity ↔ list ↔ item ↔ relation ↔ content type ↔ mapping, supports dry-run on all mutations, and stays compatible with the `catalox-seeds/inputs/` workflow from retrieval.
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @x12i/memorix-descriptors @x12i/catalox @x12i/memorix-retrieval @x12i/xronox
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Bootstrap
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { bindCataloxContext, createCataloxFromEnv } from "@x12i/catalox/firebase";
|
|
24
|
+
import { createMemorixDescriptorAdmin, resolveMemorixAppId } from "@x12i/memorix-descriptors";
|
|
25
|
+
|
|
26
|
+
const { catalox } = createCataloxFromEnv();
|
|
27
|
+
const bound = bindCataloxContext(catalox, {
|
|
28
|
+
appId: resolveMemorixAppId(),
|
|
29
|
+
actor: { type: "service", id: "memorix-descriptors" },
|
|
30
|
+
superAdmin: true,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const admin = createMemorixDescriptorAdmin({ catalox: bound });
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Or from environment (includes optional Xronox for inventory):
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { createMemorixDescriptorAdminFromEnv } from "@x12i/memorix-descriptors";
|
|
40
|
+
|
|
41
|
+
const admin = await createMemorixDescriptorAdminFromEnv();
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Register an entity (atomic default list + item)
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
const result = await admin.registerEntityDescriptor({
|
|
48
|
+
entityName: "impact-stories",
|
|
49
|
+
target: "knowledge",
|
|
50
|
+
collectionPrefix: "impact-stories",
|
|
51
|
+
canonicalContentType: {
|
|
52
|
+
key: "narratives",
|
|
53
|
+
postfix: "narratives",
|
|
54
|
+
collection: "impact-stories-narratives",
|
|
55
|
+
},
|
|
56
|
+
identity: { idField: "knowledgeId" },
|
|
57
|
+
}, { dryRun: true });
|
|
58
|
+
|
|
59
|
+
console.log(result.cataloxWrites, result.integrity);
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## CLI
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
npx memorix-descriptors validate
|
|
66
|
+
npx memorix-descriptors reconcile
|
|
67
|
+
npx memorix-descriptors graph --format mermaid
|
|
68
|
+
npx memorix-descriptors entity register --file ./new-entity.json --dry-run
|
|
69
|
+
npx memorix-descriptors seed export ./catalox-seeds/inputs
|
|
70
|
+
npx memorix-descriptors seed import ./catalox-seeds/inputs --dry-run
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Catalox catalogs
|
|
74
|
+
|
|
75
|
+
| Catalog id | Purpose |
|
|
76
|
+
|-----------|---------|
|
|
77
|
+
| `memorix-entity-descriptors` | Entity schema root |
|
|
78
|
+
| `memorix-list-descriptors` | Tabular views |
|
|
79
|
+
| `memorix-item-descriptors` | Record detail layouts |
|
|
80
|
+
| `memorix-completion-mappings` | Source → Memorix payload maps |
|
|
81
|
+
|
|
82
|
+
## Implementation phases
|
|
83
|
+
|
|
84
|
+
- **Phase 1 (current):** bootstrap, validation, entity/content/property CRUD, seeds, dry-run
|
|
85
|
+
- **Phase 2:** list/item/relation hardening, cascade rules
|
|
86
|
+
- **Phase 3:** mapping catalog + Mongo reconcile
|
|
87
|
+
- **Phase 4:** knowledge target contract bump across ecosystem
|
|
88
|
+
- **Phase 5:** rename/migrate, audit log, CI seed validation
|
|
89
|
+
|
|
90
|
+
## Related packages
|
|
91
|
+
|
|
92
|
+
- `@x12i/memorix-retrieval` — read/composition layer
|
|
93
|
+
- `@x12i/catalox` — descriptor storage
|
|
94
|
+
- `@x12i/memorix-completion` — payload document writes
|
|
95
|
+
|
|
96
|
+
See `docs/MEMORIX-CATALOX-CONTRACTS.md` and `docs/MEMORIX-DATABASE-CONVENTIONS.md` for canonical contracts.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { XronoxLike } from "@x12i/memorix-retrieval";
|
|
2
|
+
import type { CataloxBoundClient } from "../catalox/client.js";
|
|
3
|
+
import type { ContentTypeInput, DescriptorMutationOptions, MemorixCompletionMapping, PropertyInput, RegisterEntityDescriptorInput } from "../types/index.js";
|
|
4
|
+
import { registerEntityDescriptor, removeEntityDescriptor, updateEntityDescriptor } from "../mutations/entity.js";
|
|
5
|
+
import { addContentType, ensureCollection, planCollectionRename, removeContentType, resolveCollection, updateContentType } from "../mutations/content-type.js";
|
|
6
|
+
import { addProperty, removeProperty, updateProperty } from "../mutations/property.js";
|
|
7
|
+
import { createListDescriptor, removeListDescriptor, setEntityDefaultList, updateListDescriptor } from "../mutations/list.js";
|
|
8
|
+
import { createItemDescriptor, removeItemDescriptor, setEntityDefaultItem, updateItemDescriptor } from "../mutations/item.js";
|
|
9
|
+
import { addRelation, removeRelation, updateRelation, type RelationInput } from "../mutations/relation.js";
|
|
10
|
+
import { registerMapping, removeMapping, updateMapping } from "../mutations/mapping.js";
|
|
11
|
+
import { applyDescriptorSeedManifest, importDescriptorSeedInputs, type DescriptorSeedManifest } from "../seeds/index.js";
|
|
12
|
+
import { reconcileDescriptorsWithMongo } from "../reconcile/index.js";
|
|
13
|
+
export type CreateMemorixDescriptorAdminOptions = {
|
|
14
|
+
catalox: CataloxBoundClient;
|
|
15
|
+
xronox?: XronoxLike;
|
|
16
|
+
appId?: string;
|
|
17
|
+
processEnv?: NodeJS.ProcessEnv;
|
|
18
|
+
};
|
|
19
|
+
export type MemorixDescriptorAdmin = {
|
|
20
|
+
readonly appId: string;
|
|
21
|
+
readonly catalox: CataloxBoundClient;
|
|
22
|
+
validateMemorixDescriptors(): Promise<import("../types/index.js").DescriptorIntegrityReport>;
|
|
23
|
+
getDescriptorGraph(): Promise<import("../integrity/graph.js").DescriptorGraph>;
|
|
24
|
+
getDescriptorGraphMermaid(): Promise<string>;
|
|
25
|
+
registerEntityDescriptor(input: RegisterEntityDescriptorInput, options?: DescriptorMutationOptions): ReturnType<typeof registerEntityDescriptor>;
|
|
26
|
+
updateEntityDescriptor(entityName: string, patch: Partial<Record<string, unknown>>, options?: DescriptorMutationOptions): ReturnType<typeof updateEntityDescriptor>;
|
|
27
|
+
removeEntityDescriptor(entityName: string, options?: DescriptorMutationOptions): ReturnType<typeof removeEntityDescriptor>;
|
|
28
|
+
addContentType(entityName: string, input: ContentTypeInput, options?: DescriptorMutationOptions): ReturnType<typeof addContentType>;
|
|
29
|
+
updateContentType(entityName: string, key: string, patch: Partial<ContentTypeInput>, options?: DescriptorMutationOptions): ReturnType<typeof updateContentType>;
|
|
30
|
+
removeContentType(entityName: string, key: string, options?: DescriptorMutationOptions): ReturnType<typeof removeContentType>;
|
|
31
|
+
resolveCollection(entityName: string, contentTypeKey: string): ReturnType<typeof resolveCollection>;
|
|
32
|
+
ensureCollection(entityName: string, contentTypeKey: string, options?: DescriptorMutationOptions): ReturnType<typeof ensureCollection>;
|
|
33
|
+
planCollectionRename(entityName: string, contentTypeKey: string, newCollectionName: string): Promise<ReturnType<typeof planCollectionRename>>;
|
|
34
|
+
addProperty(entityName: string, key: string, property: PropertyInput, options?: DescriptorMutationOptions & {
|
|
35
|
+
addToDefaultList?: boolean;
|
|
36
|
+
addToDefaultItem?: boolean;
|
|
37
|
+
}): ReturnType<typeof addProperty>;
|
|
38
|
+
updateProperty(entityName: string, key: string, patch: Partial<PropertyInput>, options?: DescriptorMutationOptions): ReturnType<typeof updateProperty>;
|
|
39
|
+
removeProperty(entityName: string, key: string, options?: DescriptorMutationOptions): ReturnType<typeof removeProperty>;
|
|
40
|
+
createListDescriptor(input: Record<string, unknown>, options?: DescriptorMutationOptions): ReturnType<typeof createListDescriptor>;
|
|
41
|
+
updateListDescriptor(id: string, patch: Record<string, unknown>, options?: DescriptorMutationOptions): ReturnType<typeof updateListDescriptor>;
|
|
42
|
+
removeListDescriptor(id: string, options?: DescriptorMutationOptions): ReturnType<typeof removeListDescriptor>;
|
|
43
|
+
setEntityDefaultList(entityName: string, listDescriptorId: string, options?: DescriptorMutationOptions): ReturnType<typeof setEntityDefaultList>;
|
|
44
|
+
createItemDescriptor(input: Record<string, unknown>, options?: DescriptorMutationOptions): ReturnType<typeof createItemDescriptor>;
|
|
45
|
+
updateItemDescriptor(id: string, patch: Record<string, unknown>, options?: DescriptorMutationOptions): ReturnType<typeof updateItemDescriptor>;
|
|
46
|
+
removeItemDescriptor(id: string, options?: DescriptorMutationOptions): ReturnType<typeof removeItemDescriptor>;
|
|
47
|
+
setEntityDefaultItem(entityName: string, itemDescriptorId: string, options?: DescriptorMutationOptions): ReturnType<typeof setEntityDefaultItem>;
|
|
48
|
+
addRelation(sourceEntity: string, relationKey: string, descriptor: RelationInput, options?: DescriptorMutationOptions): ReturnType<typeof addRelation>;
|
|
49
|
+
updateRelation(sourceEntity: string, relationKey: string, patch: Partial<RelationInput>, options?: DescriptorMutationOptions): ReturnType<typeof updateRelation>;
|
|
50
|
+
removeRelation(sourceEntity: string, relationKey: string, options?: DescriptorMutationOptions): ReturnType<typeof removeRelation>;
|
|
51
|
+
registerMapping(input: MemorixCompletionMapping, options?: DescriptorMutationOptions): ReturnType<typeof registerMapping>;
|
|
52
|
+
updateMapping(id: string, patch: Partial<MemorixCompletionMapping>, options?: DescriptorMutationOptions): ReturnType<typeof updateMapping>;
|
|
53
|
+
removeMapping(id: string, options?: DescriptorMutationOptions): ReturnType<typeof removeMapping>;
|
|
54
|
+
buildDescriptorSeedManifest(scope?: import("../types/index.js").MemorixSeedScope): Promise<DescriptorSeedManifest>;
|
|
55
|
+
exportDescriptorSeedInputs(dir: string, scope?: import("../types/index.js").MemorixSeedScope): Promise<void>;
|
|
56
|
+
importDescriptorSeedInputs(dir: string, options?: {
|
|
57
|
+
dryRun?: boolean;
|
|
58
|
+
scope?: import("../types/index.js").MemorixSeedScope;
|
|
59
|
+
}): ReturnType<typeof importDescriptorSeedInputs>;
|
|
60
|
+
applyDescriptorSeedManifest(manifest: DescriptorSeedManifest, options?: {
|
|
61
|
+
dryRun?: boolean;
|
|
62
|
+
force?: boolean;
|
|
63
|
+
}): ReturnType<typeof applyDescriptorSeedManifest>;
|
|
64
|
+
reconcileDescriptorsWithMongo(): ReturnType<typeof reconcileDescriptorsWithMongo>;
|
|
65
|
+
loadSnapshot(): Promise<import("../types/index.js").DescriptorSnapshot>;
|
|
66
|
+
};
|
|
67
|
+
export declare function createMemorixDescriptorAdmin(options: CreateMemorixDescriptorAdminOptions): MemorixDescriptorAdmin;
|
|
68
|
+
export type CreateMemorixDescriptorAdminFromEnvOptions = {
|
|
69
|
+
appId?: string;
|
|
70
|
+
processEnv?: NodeJS.ProcessEnv;
|
|
71
|
+
xronox?: XronoxLike;
|
|
72
|
+
};
|
|
73
|
+
export declare function createMemorixDescriptorAdminFromEnv(options?: CreateMemorixDescriptorAdminFromEnvOptions): Promise<MemorixDescriptorAdmin>;
|
|
74
|
+
//# sourceMappingURL=create-admin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-admin.d.ts","sourceRoot":"","sources":["../../src/admin/create-admin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE/D,OAAO,KAAK,EACV,gBAAgB,EAChB,yBAAyB,EACzB,wBAAwB,EACxB,aAAa,EACb,6BAA6B,EAC9B,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,EACvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,WAAW,EACX,cAAc,EACd,cAAc,EACf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,WAAW,EACX,cAAc,EACd,cAAc,EACd,KAAK,aAAa,EACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,eAAe,EACf,aAAa,EACb,aAAa,EACd,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EACL,2BAA2B,EAG3B,0BAA0B,EAC1B,KAAK,sBAAsB,EAC5B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAC;AAGtE,MAAM,MAAM,mCAAmC,GAAG;IAChD,OAAO,EAAE,kBAAkB,CAAC;IAC5B,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAA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,mBAAmB,EAAE,kBAAkB,CAAC,CAAC;CACzE,CAAC;AAEF,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,mCAAmC,GAC3C,sBAAsB,CAsGxB;AAED,MAAM,MAAM,0CAA0C,GAAG;IACvD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IAC/B,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB,CAAC;AAEF,wBAAsB,mCAAmC,CACvD,OAAO,GAAE,0CAA+C,GACvD,OAAO,CAAC,sBAAsB,CAAC,CA2BjC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { resolveMemorixAppId } from "../catalog/ids.js";
|
|
2
|
+
import { loadDescriptorSnapshot } from "../store/snapshot.js";
|
|
3
|
+
import { registerEntityDescriptor, removeEntityDescriptor, updateEntityDescriptor, } from "../mutations/entity.js";
|
|
4
|
+
import { addContentType, ensureCollection, planCollectionRename, removeContentType, resolveCollection, updateContentType, } from "../mutations/content-type.js";
|
|
5
|
+
import { addProperty, removeProperty, updateProperty, } from "../mutations/property.js";
|
|
6
|
+
import { createListDescriptor, removeListDescriptor, setEntityDefaultList, updateListDescriptor, } from "../mutations/list.js";
|
|
7
|
+
import { createItemDescriptor, removeItemDescriptor, setEntityDefaultItem, updateItemDescriptor, } from "../mutations/item.js";
|
|
8
|
+
import { addRelation, removeRelation, updateRelation, } from "../mutations/relation.js";
|
|
9
|
+
import { registerMapping, removeMapping, updateMapping, } from "../mutations/mapping.js";
|
|
10
|
+
import { validateMemorixDescriptors } from "../integrity/validate.js";
|
|
11
|
+
import { buildDescriptorGraph, descriptorGraphToMermaid } from "../integrity/graph.js";
|
|
12
|
+
import { applyDescriptorSeedManifest, buildDescriptorSeedManifest, exportDescriptorSeedInputsFromCatalox, importDescriptorSeedInputs, } from "../seeds/index.js";
|
|
13
|
+
import { reconcileDescriptorsWithMongo } from "../reconcile/index.js";
|
|
14
|
+
import { validateMemorixEntityDescriptor } from "../validation/descriptor-validation.js";
|
|
15
|
+
export function createMemorixDescriptorAdmin(options) {
|
|
16
|
+
const processEnv = options.processEnv ?? process.env;
|
|
17
|
+
const appId = resolveMemorixAppId({ appId: options.appId }, processEnv);
|
|
18
|
+
const catalox = options.catalox;
|
|
19
|
+
const loadSnapshot = () => loadDescriptorSnapshot(catalox);
|
|
20
|
+
const ctx = {
|
|
21
|
+
catalox,
|
|
22
|
+
xronox: options.xronox,
|
|
23
|
+
env: processEnv,
|
|
24
|
+
loadSnapshot,
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
appId,
|
|
28
|
+
catalox,
|
|
29
|
+
loadSnapshot,
|
|
30
|
+
validateMemorixDescriptors: () => validateMemorixDescriptors(loadSnapshot),
|
|
31
|
+
getDescriptorGraph: async () => buildDescriptorGraph(await loadSnapshot()),
|
|
32
|
+
getDescriptorGraphMermaid: async () => descriptorGraphToMermaid(buildDescriptorGraph(await loadSnapshot())),
|
|
33
|
+
registerEntityDescriptor: (input, mutationOptions) => registerEntityDescriptor(ctx, input, mutationOptions),
|
|
34
|
+
updateEntityDescriptor: (entityName, patch, mutationOptions) => updateEntityDescriptor(ctx, entityName, patch, mutationOptions),
|
|
35
|
+
removeEntityDescriptor: (entityName, mutationOptions) => removeEntityDescriptor(ctx, entityName, mutationOptions),
|
|
36
|
+
addContentType: (entityName, input, mutationOptions) => addContentType(ctx, entityName, input, mutationOptions),
|
|
37
|
+
updateContentType: (entityName, key, patch, mutationOptions) => updateContentType(ctx, entityName, key, patch, mutationOptions),
|
|
38
|
+
removeContentType: (entityName, key, mutationOptions) => removeContentType(ctx, entityName, key, mutationOptions),
|
|
39
|
+
resolveCollection: (entityName, contentTypeKey) => resolveCollection(ctx, entityName, contentTypeKey),
|
|
40
|
+
ensureCollection: (entityName, contentTypeKey, mutationOptions) => ensureCollection(ctx, entityName, contentTypeKey, mutationOptions),
|
|
41
|
+
planCollectionRename: (entityName, contentTypeKey, newCollectionName) => {
|
|
42
|
+
return loadSnapshot().then((snapshot) => {
|
|
43
|
+
const entityRaw = snapshot.entityDescriptors[entityName];
|
|
44
|
+
if (!entityRaw) {
|
|
45
|
+
throw new Error(`Entity "${entityName}" not found`);
|
|
46
|
+
}
|
|
47
|
+
const entity = validateMemorixEntityDescriptor(entityRaw);
|
|
48
|
+
return planCollectionRename(entity, contentTypeKey, newCollectionName, processEnv);
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
addProperty: (entityName, key, property, mutationOptions) => addProperty(ctx, entityName, key, property, mutationOptions),
|
|
52
|
+
updateProperty: (entityName, key, patch, mutationOptions) => updateProperty(ctx, entityName, key, patch, mutationOptions),
|
|
53
|
+
removeProperty: (entityName, key, mutationOptions) => removeProperty(ctx, entityName, key, mutationOptions),
|
|
54
|
+
createListDescriptor: (input, mutationOptions) => createListDescriptor(ctx, input, mutationOptions),
|
|
55
|
+
updateListDescriptor: (id, patch, mutationOptions) => updateListDescriptor(ctx, id, patch, mutationOptions),
|
|
56
|
+
removeListDescriptor: (id, mutationOptions) => removeListDescriptor(ctx, id, mutationOptions),
|
|
57
|
+
setEntityDefaultList: (entityName, listDescriptorId, mutationOptions) => setEntityDefaultList(ctx, entityName, listDescriptorId, mutationOptions),
|
|
58
|
+
createItemDescriptor: (input, mutationOptions) => createItemDescriptor(ctx, input, mutationOptions),
|
|
59
|
+
updateItemDescriptor: (id, patch, mutationOptions) => updateItemDescriptor(ctx, id, patch, mutationOptions),
|
|
60
|
+
removeItemDescriptor: (id, mutationOptions) => removeItemDescriptor(ctx, id, mutationOptions),
|
|
61
|
+
setEntityDefaultItem: (entityName, itemDescriptorId, mutationOptions) => setEntityDefaultItem(ctx, entityName, itemDescriptorId, mutationOptions),
|
|
62
|
+
addRelation: (sourceEntity, relationKey, descriptor, mutationOptions) => addRelation(ctx, sourceEntity, relationKey, descriptor, mutationOptions),
|
|
63
|
+
updateRelation: (sourceEntity, relationKey, patch, mutationOptions) => updateRelation(ctx, sourceEntity, relationKey, patch, mutationOptions),
|
|
64
|
+
removeRelation: (sourceEntity, relationKey, mutationOptions) => removeRelation(ctx, sourceEntity, relationKey, mutationOptions),
|
|
65
|
+
registerMapping: (input, mutationOptions) => registerMapping(ctx, input, mutationOptions),
|
|
66
|
+
updateMapping: (id, patch, mutationOptions) => updateMapping(ctx, id, patch, mutationOptions),
|
|
67
|
+
removeMapping: (id, mutationOptions) => removeMapping(ctx, id, mutationOptions),
|
|
68
|
+
buildDescriptorSeedManifest: async (scope) => buildDescriptorSeedManifest(await loadSnapshot(), scope),
|
|
69
|
+
exportDescriptorSeedInputs: (dir, scope) => exportDescriptorSeedInputsFromCatalox(catalox, dir, scope),
|
|
70
|
+
importDescriptorSeedInputs: (dir, importOptions) => importDescriptorSeedInputs(catalox, dir, importOptions),
|
|
71
|
+
applyDescriptorSeedManifest: (manifest, applyOptions) => applyDescriptorSeedManifest(catalox, manifest, applyOptions),
|
|
72
|
+
reconcileDescriptorsWithMongo: () => reconcileDescriptorsWithMongo({ catalox, appId, processEnv }),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
export async function createMemorixDescriptorAdminFromEnv(options = {}) {
|
|
76
|
+
const { createCataloxFromEnv } = await import("@x12i/catalox/firebase");
|
|
77
|
+
const processEnv = options.processEnv ?? process.env;
|
|
78
|
+
const appId = resolveMemorixAppId({ appId: options.appId }, processEnv);
|
|
79
|
+
const { catalox } = createCataloxFromEnv();
|
|
80
|
+
const bound = catalox.withContext({
|
|
81
|
+
appId,
|
|
82
|
+
actor: { type: "service", id: "memorix-descriptors" },
|
|
83
|
+
superAdmin: true,
|
|
84
|
+
});
|
|
85
|
+
let xronox = options.xronox;
|
|
86
|
+
if (!xronox) {
|
|
87
|
+
try {
|
|
88
|
+
const { createMemorixXronoxFromEnv } = await import("@x12i/memorix-retrieval");
|
|
89
|
+
xronox = await createMemorixXronoxFromEnv({ processEnv });
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
xronox = undefined;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return createMemorixDescriptorAdmin({
|
|
96
|
+
catalox: bound,
|
|
97
|
+
xronox,
|
|
98
|
+
appId,
|
|
99
|
+
processEnv,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=create-admin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-admin.js","sourceRoot":"","sources":["../../src/admin/create-admin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAS9D,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,WAAW,EACX,cAAc,EACd,cAAc,GACf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,WAAW,EACX,cAAc,EACd,cAAc,GAEf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,eAAe,EACf,aAAa,EACb,aAAa,GACd,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AACvF,OAAO,EACL,2BAA2B,EAC3B,2BAA2B,EAC3B,qCAAqC,EACrC,0BAA0B,GAE3B,MAAM,mBAAmB,CAAC;AA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AA4B,CAAC;QAClC,OAAO,EAAE,KAAK;QACd,MAAM;QACN,KAAK;QACL,UAAU;KACX,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const MEMORIX_APP_ID = "memorix";
|
|
2
|
+
export declare const MEMORIX_ENTITY_DESCRIPTORS_CATALOG = "memorix-entity-descriptors";
|
|
3
|
+
export declare const MEMORIX_LIST_DESCRIPTORS_CATALOG = "memorix-list-descriptors";
|
|
4
|
+
export declare const MEMORIX_ITEM_DESCRIPTORS_CATALOG = "memorix-item-descriptors";
|
|
5
|
+
export declare const MEMORIX_COMPLETION_MAPPINGS_CATALOG = "memorix-completion-mappings";
|
|
6
|
+
export declare const MEMORIX_DESCRIPTOR_CATALOG_IDS: readonly ["memorix-entity-descriptors", "memorix-list-descriptors", "memorix-item-descriptors", "memorix-completion-mappings"];
|
|
7
|
+
export declare function resolveMemorixAppId(options?: {
|
|
8
|
+
appId?: string;
|
|
9
|
+
}, processEnv?: NodeJS.ProcessEnv): string;
|
|
10
|
+
export declare function defaultIdFieldForTarget(target: import("../types/index.js").MemorixTarget): import("../types/index.js").MemorixIdField;
|
|
11
|
+
export declare function allowedIdFieldsForTarget(target: import("../types/index.js").MemorixTarget): import("../types/index.js").MemorixIdField[];
|
|
12
|
+
//# sourceMappingURL=ids.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../../src/catalog/ids.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,YAAY,CAAC;AAExC,eAAO,MAAM,kCAAkC,+BAA+B,CAAC;AAC/E,eAAO,MAAM,gCAAgC,6BAA6B,CAAC;AAC3E,eAAO,MAAM,gCAAgC,6BAA6B,CAAC;AAC3E,eAAO,MAAM,mCAAmC,gCAAgC,CAAC;AAEjF,eAAO,MAAM,8BAA8B,gIAKjC,CAAC;AAEX,wBAAgB,mBAAmB,CACjC,OAAO,CAAC,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,EAC5B,UAAU,GAAE,MAAM,CAAC,UAAwB,GAC1C,MAAM,CAOR;AAED,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,OAAO,mBAAmB,EAAE,aAAa,GAChD,OAAO,mBAAmB,EAAE,cAAc,CAI5C;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,OAAO,mBAAmB,EAAE,aAAa,GAChD,OAAO,mBAAmB,EAAE,cAAc,EAAE,CAI9C"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export const MEMORIX_APP_ID = "memorix";
|
|
2
|
+
export const MEMORIX_ENTITY_DESCRIPTORS_CATALOG = "memorix-entity-descriptors";
|
|
3
|
+
export const MEMORIX_LIST_DESCRIPTORS_CATALOG = "memorix-list-descriptors";
|
|
4
|
+
export const MEMORIX_ITEM_DESCRIPTORS_CATALOG = "memorix-item-descriptors";
|
|
5
|
+
export const MEMORIX_COMPLETION_MAPPINGS_CATALOG = "memorix-completion-mappings";
|
|
6
|
+
export const MEMORIX_DESCRIPTOR_CATALOG_IDS = [
|
|
7
|
+
MEMORIX_ENTITY_DESCRIPTORS_CATALOG,
|
|
8
|
+
MEMORIX_LIST_DESCRIPTORS_CATALOG,
|
|
9
|
+
MEMORIX_ITEM_DESCRIPTORS_CATALOG,
|
|
10
|
+
MEMORIX_COMPLETION_MAPPINGS_CATALOG,
|
|
11
|
+
];
|
|
12
|
+
export function resolveMemorixAppId(options, processEnv = process.env) {
|
|
13
|
+
return (options?.appId?.trim() ||
|
|
14
|
+
processEnv.CATALOX_APP_ID?.trim() ||
|
|
15
|
+
processEnv.MEMORIX_APP_ID?.trim() ||
|
|
16
|
+
MEMORIX_APP_ID);
|
|
17
|
+
}
|
|
18
|
+
export function defaultIdFieldForTarget(target) {
|
|
19
|
+
if (target === "event")
|
|
20
|
+
return "eventId";
|
|
21
|
+
if (target === "knowledge")
|
|
22
|
+
return "knowledgeId";
|
|
23
|
+
return "entityId";
|
|
24
|
+
}
|
|
25
|
+
export function allowedIdFieldsForTarget(target) {
|
|
26
|
+
if (target === "entity")
|
|
27
|
+
return ["entityId", "eventId"];
|
|
28
|
+
if (target === "event")
|
|
29
|
+
return ["eventId", "entityId"];
|
|
30
|
+
return ["knowledgeId"];
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=ids.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ids.js","sourceRoot":"","sources":["../../src/catalog/ids.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,CAAC;AAExC,MAAM,CAAC,MAAM,kCAAkC,GAAG,4BAA4B,CAAC;AAC/E,MAAM,CAAC,MAAM,gCAAgC,GAAG,0BAA0B,CAAC;AAC3E,MAAM,CAAC,MAAM,gCAAgC,GAAG,0BAA0B,CAAC;AAC3E,MAAM,CAAC,MAAM,mCAAmC,GAAG,6BAA6B,CAAC;AAEjF,MAAM,CAAC,MAAM,8BAA8B,GAAG;IAC5C,kCAAkC;IAClC,gCAAgC;IAChC,gCAAgC;IAChC,mCAAmC;CAC3B,CAAC;AAEX,MAAM,UAAU,mBAAmB,CACjC,OAA4B,EAC5B,aAAgC,OAAO,CAAC,GAAG;IAE3C,OAAO,CACL,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE;QACtB,UAAU,CAAC,cAAc,EAAE,IAAI,EAAE;QACjC,UAAU,CAAC,cAAc,EAAE,IAAI,EAAE;QACjC,cAAc,CACf,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,uBAAuB,CACrC,MAAiD;IAEjD,IAAI,MAAM,KAAK,OAAO;QAAE,OAAO,SAAS,CAAC;IACzC,IAAI,MAAM,KAAK,WAAW;QAAE,OAAO,aAAa,CAAC;IACjD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,wBAAwB,CACtC,MAAiD;IAEjD,IAAI,MAAM,KAAK,QAAQ;QAAE,OAAO,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;IACxD,IAAI,MAAM,KAAK,OAAO;QAAE,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IACvD,OAAO,CAAC,aAAa,CAAC,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CataloxBound } from "@x12i/catalox";
|
|
2
|
+
import type { MemorixSeedScope } from "../types/index.js";
|
|
3
|
+
export type CataloxBoundClient = CataloxBound;
|
|
4
|
+
export type CatalogItemRecord = {
|
|
5
|
+
id: string;
|
|
6
|
+
data: Record<string, unknown>;
|
|
7
|
+
};
|
|
8
|
+
export declare function mergeScopeIntoData(data: Record<string, unknown>, scope?: MemorixSeedScope): Record<string, unknown>;
|
|
9
|
+
export declare function listAllCatalogItems(catalox: CataloxBoundClient, catalogId: string): Promise<CatalogItemRecord[]>;
|
|
10
|
+
export declare function getCatalogItemData(catalox: CataloxBoundClient, catalogId: string, itemId: string): Promise<Record<string, unknown> | null>;
|
|
11
|
+
export declare function upsertCatalogItem(catalox: CataloxBoundClient, catalogId: string, data: Record<string, unknown>, scope?: MemorixSeedScope): Promise<void>;
|
|
12
|
+
export declare function deleteCatalogItem(catalox: CataloxBoundClient, catalogId: string, itemId: string): Promise<void>;
|
|
13
|
+
export declare const CATALOG_BY_KIND: {
|
|
14
|
+
readonly entity: "memorix-entity-descriptors";
|
|
15
|
+
readonly list: "memorix-list-descriptors";
|
|
16
|
+
readonly item: "memorix-item-descriptors";
|
|
17
|
+
readonly mapping: "memorix-completion-mappings";
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/catalox/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAQ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ope) {
|
|
3
|
+
if (!scope)
|
|
4
|
+
return data;
|
|
5
|
+
return { ...data, scope };
|
|
6
|
+
}
|
|
7
|
+
export async function listAllCatalogItems(catalox, catalogId) {
|
|
8
|
+
const items = [];
|
|
9
|
+
let offset = 0;
|
|
10
|
+
const limit = 200;
|
|
11
|
+
for (;;) {
|
|
12
|
+
const page = await catalox.listCatalogItems(catalogId, { limit, offset });
|
|
13
|
+
if (page.listOutcome === "mapping_blocked") {
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
for (const item of page.items) {
|
|
17
|
+
items.push({
|
|
18
|
+
id: String(item.itemId),
|
|
19
|
+
data: (item.data ?? {}),
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (!page.nextCursor && page.items.length < limit) {
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
offset += page.items.length;
|
|
26
|
+
if (page.items.length === 0) {
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return items;
|
|
31
|
+
}
|
|
32
|
+
export async function getCatalogItemData(catalox, catalogId, itemId) {
|
|
33
|
+
const result = await catalox.getCatalogItem(catalogId, itemId);
|
|
34
|
+
if (result.outcome === "not_found" || result.outcome === "mapping_blocked") {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
return (result.item.data ?? {});
|
|
38
|
+
}
|
|
39
|
+
export async function upsertCatalogItem(catalox, catalogId, data, scope) {
|
|
40
|
+
await catalox.upsertNativeCatalogItem(catalogId, mergeScopeIntoData(data, scope));
|
|
41
|
+
}
|
|
42
|
+
export async function deleteCatalogItem(catalox, catalogId, itemId) {
|
|
43
|
+
await catalox.deleteNativeCatalogItem(catalogId, itemId);
|
|
44
|
+
}
|
|
45
|
+
export const CATALOG_BY_KIND = {
|
|
46
|
+
entity: MEMORIX_ENTITY_DESCRIPTORS_CATALOG,
|
|
47
|
+
list: MEMORIX_LIST_DESCRIPTORS_CATALOG,
|
|
48
|
+
item: MEMORIX_ITEM_DESCRIPTORS_CATALOG,
|
|
49
|
+
mapping: MEMORIX_COMPLETION_MAPPINGS_CATALOG,
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/catalox/client.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,mCAAmC,EACnC,kCAAkC,EAClC,gCAAgC,EAChC,gCAAgC,GACjC,MAAM,mBAAmB,CAAC;AAS3B,MAAM,UAAU,kBAAkB,CAChC,IAA6B,EAC7B,KAAwB;IAExB,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IACxB,OAAO,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,CAAC;AAC5B,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,OAA2B,EAC3B,SAAiB;IAEjB,MAAM,KAAK,GAAwB,EAAE,CAAC;IACtC,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,MAAM,KAAK,GAAG,GAAG,CAAC;IAElB,SAAS,CAAC;QACR,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,gBAAgB,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;QAC1E,IAAI,IAAI,CAAC,WAAW,KAAK,iBAAiB,EAAE,CAAC;YAC3C,MAAM;QACR,CAAC;QACD,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC9B,KAAK,CAAC,IAAI,CAAC;gBACT,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;gBACvB,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,CAA4B;aACnD,CAAC,CAAC;QACL,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,KAAK,EAAE,CAAC;YAClD,MAAM;QACR,CAAC;QACD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bin/env node
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { createMemorixDescriptorAdminFromEnv, descriptorGraphToMermaid, } from "../index.js";
|
|
4
|
+
async function main() {
|
|
5
|
+
const [command, ...args] = process.argv.slice(2);
|
|
6
|
+
if (!command || command === "--help" || command === "-h") {
|
|
7
|
+
printHelp();
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const admin = await createMemorixDescriptorAdminFromEnv();
|
|
11
|
+
const dryRun = args.includes("--dry-run");
|
|
12
|
+
const formatIdx = args.indexOf("--format");
|
|
13
|
+
const format = formatIdx >= 0 ? args[formatIdx + 1] : undefined;
|
|
14
|
+
switch (command) {
|
|
15
|
+
case "validate": {
|
|
16
|
+
const report = await admin.validateMemorixDescriptors();
|
|
17
|
+
console.log(JSON.stringify(report, null, 2));
|
|
18
|
+
process.exitCode = report.valid ? 0 : 1;
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
case "reconcile": {
|
|
22
|
+
const result = await admin.reconcileDescriptorsWithMongo();
|
|
23
|
+
console.log(JSON.stringify(result, null, 2));
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
case "graph": {
|
|
27
|
+
const graph = await admin.getDescriptorGraph();
|
|
28
|
+
if (format === "mermaid") {
|
|
29
|
+
console.log(descriptorGraphToMermaid(graph));
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
console.log(JSON.stringify(graph, null, 2));
|
|
33
|
+
}
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
case "entity": {
|
|
37
|
+
await handleEntityCommand(admin, args, dryRun);
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
case "content-type": {
|
|
41
|
+
await handleContentTypeCommand(admin, args, dryRun);
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
case "list": {
|
|
45
|
+
await handleListCommand(admin, args, dryRun);
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
case "item": {
|
|
49
|
+
await handleItemCommand(admin, args, dryRun);
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
case "mapping": {
|
|
53
|
+
await handleMappingCommand(admin, args, dryRun);
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
case "seed": {
|
|
57
|
+
await handleSeedCommand(admin, args, dryRun);
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
default:
|
|
61
|
+
console.error(`Unknown command: ${command}`);
|
|
62
|
+
printHelp();
|
|
63
|
+
process.exitCode = 1;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async function handleEntityCommand(admin, args, dryRun) {
|
|
67
|
+
const [sub, ...rest] = args;
|
|
68
|
+
if (sub === "register") {
|
|
69
|
+
const file = readFlag(rest, "--file");
|
|
70
|
+
if (!file)
|
|
71
|
+
throw new Error("entity register requires --file");
|
|
72
|
+
const input = JSON.parse(await readFile(file, "utf8"));
|
|
73
|
+
const result = await admin.registerEntityDescriptor(input, { dryRun });
|
|
74
|
+
console.log(JSON.stringify(result, null, 2));
|
|
75
|
+
process.exitCode = result.ok ? 0 : 1;
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
throw new Error(`Unknown entity subcommand: ${sub ?? "(none)"}`);
|
|
79
|
+
}
|
|
80
|
+
async function handleContentTypeCommand(admin, args, dryRun) {
|
|
81
|
+
const [sub, entityName, key, ...rest] = args;
|
|
82
|
+
if (sub === "add") {
|
|
83
|
+
const postfix = readFlag(rest, "--postfix") ?? key;
|
|
84
|
+
const result = await admin.addContentType(entityName, { key, postfix }, { dryRun });
|
|
85
|
+
console.log(JSON.stringify(result, null, 2));
|
|
86
|
+
process.exitCode = result.ok ? 0 : 1;
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
throw new Error(`Unknown content-type subcommand: ${sub ?? "(none)"}`);
|
|
90
|
+
}
|
|
91
|
+
async function handleListCommand(admin, args, dryRun) {
|
|
92
|
+
const [sub, ...rest] = args;
|
|
93
|
+
if (sub === "create") {
|
|
94
|
+
const file = readFlag(rest, "--file");
|
|
95
|
+
if (!file)
|
|
96
|
+
throw new Error("list create requires --file");
|
|
97
|
+
const input = JSON.parse(await readFile(file, "utf8"));
|
|
98
|
+
const result = await admin.createListDescriptor(input, { dryRun });
|
|
99
|
+
console.log(JSON.stringify(result, null, 2));
|
|
100
|
+
process.exitCode = result.ok ? 0 : 1;
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (sub === "update") {
|
|
104
|
+
const [id, ...tail] = rest;
|
|
105
|
+
const file = readFlag(tail, "--file");
|
|
106
|
+
if (!id || !file)
|
|
107
|
+
throw new Error("list update requires <id> --file");
|
|
108
|
+
const patch = JSON.parse(await readFile(file, "utf8"));
|
|
109
|
+
const result = await admin.updateListDescriptor(id, patch, { dryRun });
|
|
110
|
+
console.log(JSON.stringify(result, null, 2));
|
|
111
|
+
process.exitCode = result.ok ? 0 : 1;
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
throw new Error(`Unknown list subcommand: ${sub ?? "(none)"}`);
|
|
115
|
+
}
|
|
116
|
+
async function handleItemCommand(admin, args, dryRun) {
|
|
117
|
+
const [sub, ...rest] = args;
|
|
118
|
+
if (sub === "update") {
|
|
119
|
+
const [id, ...tail] = rest;
|
|
120
|
+
const file = readFlag(tail, "--file");
|
|
121
|
+
if (!id || !file)
|
|
122
|
+
throw new Error("item update requires <id> --file");
|
|
123
|
+
const patch = JSON.parse(await readFile(file, "utf8"));
|
|
124
|
+
const result = await admin.updateItemDescriptor(id, patch, { dryRun });
|
|
125
|
+
console.log(JSON.stringify(result, null, 2));
|
|
126
|
+
process.exitCode = result.ok ? 0 : 1;
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
throw new Error(`Unknown item subcommand: ${sub ?? "(none)"}`);
|
|
130
|
+
}
|
|
131
|
+
async function handleMappingCommand(admin, args, dryRun) {
|
|
132
|
+
const [sub, ...rest] = args;
|
|
133
|
+
if (sub === "register") {
|
|
134
|
+
const file = readFlag(rest, "--file");
|
|
135
|
+
if (!file)
|
|
136
|
+
throw new Error("mapping register requires --file");
|
|
137
|
+
const input = JSON.parse(await readFile(file, "utf8"));
|
|
138
|
+
const result = await admin.registerMapping(input, { dryRun });
|
|
139
|
+
console.log(JSON.stringify(result, null, 2));
|
|
140
|
+
process.exitCode = result.ok ? 0 : 1;
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
throw new Error(`Unknown mapping subcommand: ${sub ?? "(none)"}`);
|
|
144
|
+
}
|
|
145
|
+
async function handleSeedCommand(admin, args, dryRun) {
|
|
146
|
+
const [sub, dir] = args;
|
|
147
|
+
if (sub === "export") {
|
|
148
|
+
if (!dir)
|
|
149
|
+
throw new Error("seed export requires <dir>");
|
|
150
|
+
await admin.exportDescriptorSeedInputs(dir);
|
|
151
|
+
console.log(JSON.stringify({ ok: true, dir }, null, 2));
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (sub === "import") {
|
|
155
|
+
if (!dir)
|
|
156
|
+
throw new Error("seed import requires <dir>");
|
|
157
|
+
const result = await admin.importDescriptorSeedInputs(dir, { dryRun });
|
|
158
|
+
console.log(JSON.stringify(result, null, 2));
|
|
159
|
+
process.exitCode = result.ok ? 0 : 1;
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
throw new Error(`Unknown seed subcommand: ${sub ?? "(none)"}`);
|
|
163
|
+
}
|
|
164
|
+
function readFlag(args, flag) {
|
|
165
|
+
const idx = args.indexOf(flag);
|
|
166
|
+
if (idx < 0)
|
|
167
|
+
return undefined;
|
|
168
|
+
return args[idx + 1];
|
|
169
|
+
}
|
|
170
|
+
function printHelp() {
|
|
171
|
+
console.log(`memorix-descriptors — Memorix descriptor management in Catalox
|
|
172
|
+
|
|
173
|
+
Usage:
|
|
174
|
+
memorix-descriptors validate
|
|
175
|
+
memorix-descriptors reconcile
|
|
176
|
+
memorix-descriptors graph [--format mermaid]
|
|
177
|
+
memorix-descriptors entity register --file ./new-entity.json [--dry-run]
|
|
178
|
+
memorix-descriptors content-type add <entity> <key> --postfix <postfix> [--dry-run]
|
|
179
|
+
memorix-descriptors list create --file ./list.json [--dry-run]
|
|
180
|
+
memorix-descriptors list update <id> --file ./patch.json [--dry-run]
|
|
181
|
+
memorix-descriptors item update <id> --file ./patch.json [--dry-run]
|
|
182
|
+
memorix-descriptors mapping register --file ./mapping.json [--dry-run]
|
|
183
|
+
memorix-descriptors seed export ./catalox-seeds/inputs
|
|
184
|
+
memorix-descriptors seed import ./catalox-seeds/inputs [--dry-run]
|
|
185
|
+
`);
|
|
186
|
+
}
|
|
187
|
+
main().catch((err) => {
|
|
188
|
+
console.error(err);
|
|
189
|
+
process.exit(1);
|
|
190
|
+
});
|
|
191
|
+
//# sourceMappingURL=index.js.map
|