minions-sdk 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/LICENSE +21 -0
- package/dist/evolution/index.d.ts +21 -0
- package/dist/evolution/index.d.ts.map +1 -0
- package/dist/evolution/index.js +86 -0
- package/dist/evolution/index.js.map +1 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/lifecycle/index.d.ts +58 -0
- package/dist/lifecycle/index.d.ts.map +1 -0
- package/dist/lifecycle/index.js +157 -0
- package/dist/lifecycle/index.js.map +1 -0
- package/dist/registry/index.d.ts +43 -0
- package/dist/registry/index.d.ts.map +1 -0
- package/dist/registry/index.js +74 -0
- package/dist/registry/index.js.map +1 -0
- package/dist/relations/index.d.ts +62 -0
- package/dist/relations/index.d.ts.map +1 -0
- package/dist/relations/index.js +120 -0
- package/dist/relations/index.js.map +1 -0
- package/dist/schemas/index.d.ts +28 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +167 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/types/index.d.ts +196 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils.d.ts +14 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +26 -0
- package/dist/utils.js.map +1 -0
- package/dist/validation/index.d.ts +21 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/index.js +173 -0
- package/dist/validation/index.js.map +1 -0
- package/package.json +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Minions Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module minions-sdk/evolution
|
|
3
|
+
* Schema evolution utilities — migrate minions when their type schema changes.
|
|
4
|
+
*/
|
|
5
|
+
import type { Minion, FieldDefinition } from '../types/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* Migrate a minion from an old schema to a new schema.
|
|
8
|
+
*
|
|
9
|
+
* Rules:
|
|
10
|
+
* - Fields added in new schema: get default value or remain absent
|
|
11
|
+
* - Fields removed from schema: values move to `_legacy`
|
|
12
|
+
* - Fields whose type changed: if value doesn't match new type, move to `_legacy`
|
|
13
|
+
* - Fields made required: if missing, minion is flagged (via validation)
|
|
14
|
+
*
|
|
15
|
+
* @param minion - The minion to migrate
|
|
16
|
+
* @param oldSchema - The previous field definitions
|
|
17
|
+
* @param newSchema - The new field definitions
|
|
18
|
+
* @returns The migrated minion
|
|
19
|
+
*/
|
|
20
|
+
export declare function migrateMinion(minion: Minion, oldSchema: FieldDefinition[], newSchema: FieldDefinition[]): Minion;
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/evolution/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGjE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,eAAe,EAAE,EAC5B,SAAS,EAAE,eAAe,EAAE,GAC3B,MAAM,CAwCR"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module minions-sdk/evolution
|
|
3
|
+
* Schema evolution utilities — migrate minions when their type schema changes.
|
|
4
|
+
*/
|
|
5
|
+
import { now } from '../utils.js';
|
|
6
|
+
/**
|
|
7
|
+
* Migrate a minion from an old schema to a new schema.
|
|
8
|
+
*
|
|
9
|
+
* Rules:
|
|
10
|
+
* - Fields added in new schema: get default value or remain absent
|
|
11
|
+
* - Fields removed from schema: values move to `_legacy`
|
|
12
|
+
* - Fields whose type changed: if value doesn't match new type, move to `_legacy`
|
|
13
|
+
* - Fields made required: if missing, minion is flagged (via validation)
|
|
14
|
+
*
|
|
15
|
+
* @param minion - The minion to migrate
|
|
16
|
+
* @param oldSchema - The previous field definitions
|
|
17
|
+
* @param newSchema - The new field definitions
|
|
18
|
+
* @returns The migrated minion
|
|
19
|
+
*/
|
|
20
|
+
export function migrateMinion(minion, oldSchema, newSchema) {
|
|
21
|
+
const newFieldNames = new Set(newSchema.map((f) => f.name));
|
|
22
|
+
const newFieldMap = new Map(newSchema.map((f) => [f.name, f]));
|
|
23
|
+
const oldFieldMap = new Map(oldSchema.map((f) => [f.name, f]));
|
|
24
|
+
const migratedFields = {};
|
|
25
|
+
const legacy = { ...(minion._legacy ?? {}) };
|
|
26
|
+
// Process existing field values
|
|
27
|
+
for (const [key, value] of Object.entries(minion.fields)) {
|
|
28
|
+
if (!newFieldNames.has(key)) {
|
|
29
|
+
// Field removed — move to legacy
|
|
30
|
+
legacy[key] = value;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
const newDef = newFieldMap.get(key);
|
|
34
|
+
const oldDef = oldFieldMap.get(key);
|
|
35
|
+
if (oldDef && oldDef.type !== newDef.type && !isCompatibleValue(value, newDef.type)) {
|
|
36
|
+
// Type changed and value incompatible — move to legacy
|
|
37
|
+
legacy[key] = value;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
// Field still exists with compatible value — keep it
|
|
41
|
+
migratedFields[key] = value;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Apply defaults for newly added fields
|
|
46
|
+
for (const fieldDef of newSchema) {
|
|
47
|
+
if (migratedFields[fieldDef.name] === undefined && fieldDef.defaultValue !== undefined) {
|
|
48
|
+
migratedFields[fieldDef.name] = fieldDef.defaultValue;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
...minion,
|
|
53
|
+
fields: migratedFields,
|
|
54
|
+
_legacy: Object.keys(legacy).length > 0 ? legacy : undefined,
|
|
55
|
+
updatedAt: now(),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Basic check if a value is compatible with a target field type.
|
|
60
|
+
*/
|
|
61
|
+
function isCompatibleValue(value, targetType) {
|
|
62
|
+
if (value === null || value === undefined)
|
|
63
|
+
return true;
|
|
64
|
+
switch (targetType) {
|
|
65
|
+
case 'string':
|
|
66
|
+
case 'textarea':
|
|
67
|
+
case 'url':
|
|
68
|
+
case 'email':
|
|
69
|
+
case 'date':
|
|
70
|
+
case 'select':
|
|
71
|
+
return typeof value === 'string';
|
|
72
|
+
case 'number':
|
|
73
|
+
return typeof value === 'number';
|
|
74
|
+
case 'boolean':
|
|
75
|
+
return typeof value === 'boolean';
|
|
76
|
+
case 'tags':
|
|
77
|
+
case 'multi-select':
|
|
78
|
+
case 'array':
|
|
79
|
+
return Array.isArray(value);
|
|
80
|
+
case 'json':
|
|
81
|
+
return true; // JSON accepts anything
|
|
82
|
+
default:
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/evolution/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,aAAa,CAC3B,MAAc,EACd,SAA4B,EAC5B,SAA4B;IAE5B,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAC5D,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/D,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAE/D,MAAM,cAAc,GAA4B,EAAE,CAAC;IACnD,MAAM,MAAM,GAA4B,EAAE,GAAG,CAAC,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,CAAC;IAEtE,gCAAgC;IAChC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,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AAK,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IAEvD,QAAQ,UAAU,EAAE,CAAC;QACnB,KAAK,QAAQ,CAAC;QACd,KAAK,UAAU,CAAC;QAChB,KAAK,KAAK,CAAC;QACX,KAAK,OAAO,CAAC;QACb,KAAK,MAAM,CAAC;QACZ,KAAK,QAAQ;YACX,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;QACnC,KAAK,QAAQ;YACX,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;QACnC,KAAK,SAAS;YACZ,OAAO,OAAO,KAAK,KAAK,SAAS,CAAC;QACpC,KAAK,MAAM,CAAC;QACZ,KAAK,cAAc,CAAC;QACpB,KAAK,OAAO;YACV,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC9B,KAAK,MAAM;YACT,OAAO,IAAI,CAAC,CAAC,wBAAwB;QACvC;YACE,OAAO,IAAI,CAAC;IAChB,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module minions-sdk
|
|
3
|
+
* Framework-agnostic core library for the Minions structured object system.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* import { TypeRegistry, createMinion, RelationGraph } from 'minions-sdk';
|
|
8
|
+
*
|
|
9
|
+
* const registry = new TypeRegistry();
|
|
10
|
+
* const agentType = registry.getBySlug('agent')!;
|
|
11
|
+
*
|
|
12
|
+
* const { minion, validation } = createMinion({
|
|
13
|
+
* title: 'Research Assistant',
|
|
14
|
+
* fields: {
|
|
15
|
+
* role: 'researcher',
|
|
16
|
+
* model: 'gpt-4',
|
|
17
|
+
* systemPrompt: 'You are a research assistant.',
|
|
18
|
+
* tools: ['web-search', 'summarize'],
|
|
19
|
+
* },
|
|
20
|
+
* }, agentType);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export type { FieldType, FieldValidation, FieldDefinition, RelationType, MinionStatus, MinionPriority, Minion, MinionType, Relation, CreateMinionInput, UpdateMinionInput, CreateRelationInput, ExecutionResult, Executable, ValidationError, ValidationResult, } from './types/index.js';
|
|
24
|
+
export { validateField, validateFields } from './validation/index.js';
|
|
25
|
+
export { noteType, linkType, fileType, contactType, agentType, teamType, thoughtType, promptTemplateType, testCaseType, taskType, builtinTypes, } from './schemas/index.js';
|
|
26
|
+
export { TypeRegistry } from './registry/index.js';
|
|
27
|
+
export { RelationGraph } from './relations/index.js';
|
|
28
|
+
export { createMinion, updateMinion, softDelete, hardDelete, restoreMinion, applyDefaults } from './lifecycle/index.js';
|
|
29
|
+
export { migrateMinion } from './evolution/index.js';
|
|
30
|
+
export { generateId, now } from './utils.js';
|
|
31
|
+
/**
|
|
32
|
+
* Current specification version.
|
|
33
|
+
* This MUST match the `version` field in package.json.
|
|
34
|
+
* Drift is caught by the spec version test in src/__tests__/index.test.ts.
|
|
35
|
+
*/
|
|
36
|
+
export declare const SPEC_VERSION: string;
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,YAAY,EACV,SAAS,EACT,eAAe,EACf,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,MAAM,EACN,UAAU,EACV,QAAQ,EACR,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,UAAU,EACV,eAAe,EACf,gBAAgB,GACjB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAGtE,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,SAAS,EACT,QAAQ,EACR,WAAW,EACX,kBAAkB,EAClB,YAAY,EACZ,QAAQ,EACR,YAAY,GACb,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGrD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGxH,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGrD,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAE7C;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,MAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module minions-sdk
|
|
3
|
+
* Framework-agnostic core library for the Minions structured object system.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* import { TypeRegistry, createMinion, RelationGraph } from 'minions-sdk';
|
|
8
|
+
*
|
|
9
|
+
* const registry = new TypeRegistry();
|
|
10
|
+
* const agentType = registry.getBySlug('agent')!;
|
|
11
|
+
*
|
|
12
|
+
* const { minion, validation } = createMinion({
|
|
13
|
+
* title: 'Research Assistant',
|
|
14
|
+
* fields: {
|
|
15
|
+
* role: 'researcher',
|
|
16
|
+
* model: 'gpt-4',
|
|
17
|
+
* systemPrompt: 'You are a research assistant.',
|
|
18
|
+
* tools: ['web-search', 'summarize'],
|
|
19
|
+
* },
|
|
20
|
+
* }, agentType);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
// ─── Validation ──────────────────────────────────────────────────────────────
|
|
24
|
+
export { validateField, validateFields } from './validation/index.js';
|
|
25
|
+
// ─── Schemas ─────────────────────────────────────────────────────────────────
|
|
26
|
+
export { noteType, linkType, fileType, contactType, agentType, teamType, thoughtType, promptTemplateType, testCaseType, taskType, builtinTypes, } from './schemas/index.js';
|
|
27
|
+
// ─── Registry ────────────────────────────────────────────────────────────────
|
|
28
|
+
export { TypeRegistry } from './registry/index.js';
|
|
29
|
+
// ─── Relations ───────────────────────────────────────────────────────────────
|
|
30
|
+
export { RelationGraph } from './relations/index.js';
|
|
31
|
+
// ─── Lifecycle ───────────────────────────────────────────────────────────────
|
|
32
|
+
export { createMinion, updateMinion, softDelete, hardDelete, restoreMinion, applyDefaults } from './lifecycle/index.js';
|
|
33
|
+
// ─── Evolution ───────────────────────────────────────────────────────────────
|
|
34
|
+
export { migrateMinion } from './evolution/index.js';
|
|
35
|
+
// ─── Utilities ───────────────────────────────────────────────────────────────
|
|
36
|
+
export { generateId, now } from './utils.js';
|
|
37
|
+
/**
|
|
38
|
+
* Current specification version.
|
|
39
|
+
* This MUST match the `version` field in package.json.
|
|
40
|
+
* Drift is caught by the spec version test in src/__tests__/index.test.ts.
|
|
41
|
+
*/
|
|
42
|
+
export const SPEC_VERSION = '0.1.0';
|
|
43
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAsBH,gFAAgF;AAChF,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEtE,gFAAgF;AAChF,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,SAAS,EACT,QAAQ,EACR,WAAW,EACX,kBAAkB,EAClB,YAAY,EACZ,QAAQ,EACR,YAAY,GACb,MAAM,oBAAoB,CAAC;AAE5B,gFAAgF;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,gFAAgF;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,gFAAgF;AAChF,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAExH,gFAAgF;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,gFAAgF;AAChF,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAE7C;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAW,OAAO,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module minions-sdk/lifecycle
|
|
3
|
+
* Minion lifecycle utilities — create, update, soft delete, hard delete, restore.
|
|
4
|
+
*/
|
|
5
|
+
import type { Minion, CreateMinionInput, UpdateMinionInput, MinionType, ValidationResult } from '../types/index.js';
|
|
6
|
+
import type { RelationGraph } from '../relations/index.js';
|
|
7
|
+
/**
|
|
8
|
+
* Create a new Minion instance from input, generating id and timestamps.
|
|
9
|
+
* Validates fields against the provided MinionType schema.
|
|
10
|
+
* @param input - The creation input
|
|
11
|
+
* @param type - The MinionType to validate against
|
|
12
|
+
* @returns An object with the created minion and any validation result
|
|
13
|
+
*/
|
|
14
|
+
export declare function createMinion(input: CreateMinionInput, type: MinionType): {
|
|
15
|
+
minion: Minion;
|
|
16
|
+
validation: ValidationResult;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Update an existing Minion with new values.
|
|
20
|
+
* Validates updated fields against the provided MinionType schema.
|
|
21
|
+
* @param minion - The existing minion
|
|
22
|
+
* @param input - The update input
|
|
23
|
+
* @param type - The MinionType to validate against
|
|
24
|
+
* @returns An object with the updated minion and any validation result
|
|
25
|
+
*/
|
|
26
|
+
export declare function updateMinion(minion: Minion, input: UpdateMinionInput, type: MinionType): {
|
|
27
|
+
minion: Minion;
|
|
28
|
+
validation: ValidationResult;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Soft-delete a minion by setting deletedAt/deletedBy.
|
|
32
|
+
* @param minion - The minion to soft-delete
|
|
33
|
+
* @param deletedBy - Optional identifier of who deleted it
|
|
34
|
+
* @returns The soft-deleted minion
|
|
35
|
+
*/
|
|
36
|
+
export declare function softDelete(minion: Minion, deletedBy?: string): Minion;
|
|
37
|
+
/**
|
|
38
|
+
* Hard-delete a minion by removing all of its relations from the graph.
|
|
39
|
+
*
|
|
40
|
+
* **Important:** This function only cleans up the relation graph. The caller
|
|
41
|
+
* is responsible for removing the minion object itself from whatever storage
|
|
42
|
+
* layer is in use (array, database, etc.).
|
|
43
|
+
*
|
|
44
|
+
* @param minion - The minion to hard-delete
|
|
45
|
+
* @param graph - The RelationGraph to clean up
|
|
46
|
+
*/
|
|
47
|
+
export declare function hardDelete(minion: Minion, graph: RelationGraph): void;
|
|
48
|
+
/**
|
|
49
|
+
* Restore a soft-deleted minion.
|
|
50
|
+
* @param minion - The soft-deleted minion
|
|
51
|
+
* @returns The restored minion
|
|
52
|
+
*/
|
|
53
|
+
export declare function restoreMinion(minion: Minion): Minion;
|
|
54
|
+
/**
|
|
55
|
+
* Apply default values from the schema to a fields object.
|
|
56
|
+
*/
|
|
57
|
+
export declare function applyDefaults(fields: Record<string, unknown>, type: MinionType): Record<string, unknown>;
|
|
58
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lifecycle/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,MAAM,EACN,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,EACV,gBAAgB,EACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAmD3D;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,iBAAiB,EACxB,IAAI,EAAE,UAAU,GACf;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,gBAAgB,CAAA;CAAE,CAyBlD;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,iBAAiB,EACxB,IAAI,EAAE,UAAU,GACf;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,gBAAgB,CAAA;CAAE,CAsBlD;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAQrE;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,IAAI,CAErE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAOpD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,IAAI,EAAE,UAAU,GACf,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAQzB"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module minions-sdk/lifecycle
|
|
3
|
+
* Minion lifecycle utilities — create, update, soft delete, hard delete, restore.
|
|
4
|
+
*/
|
|
5
|
+
import { validateFields } from '../validation/index.js';
|
|
6
|
+
import { generateId, now } from '../utils.js';
|
|
7
|
+
/** Field types whose values are included in searchable text. */
|
|
8
|
+
const SEARCHABLE_FIELD_TYPES = new Set([
|
|
9
|
+
'string',
|
|
10
|
+
'textarea',
|
|
11
|
+
'url',
|
|
12
|
+
'email',
|
|
13
|
+
'tags',
|
|
14
|
+
'select',
|
|
15
|
+
]);
|
|
16
|
+
/**
|
|
17
|
+
* Compute a lowercased full-text search string from a minion's title and
|
|
18
|
+
* string-like field values.
|
|
19
|
+
*/
|
|
20
|
+
function computeSearchableText(minion, type) {
|
|
21
|
+
const parts = [minion.title];
|
|
22
|
+
if (minion.description) {
|
|
23
|
+
parts.push(minion.description);
|
|
24
|
+
}
|
|
25
|
+
for (const fieldDef of type.schema) {
|
|
26
|
+
if (!SEARCHABLE_FIELD_TYPES.has(fieldDef.type))
|
|
27
|
+
continue;
|
|
28
|
+
const value = minion.fields[fieldDef.name];
|
|
29
|
+
if (value === undefined || value === null)
|
|
30
|
+
continue;
|
|
31
|
+
if (fieldDef.type === 'tags' && Array.isArray(value)) {
|
|
32
|
+
parts.push(value.join(' '));
|
|
33
|
+
}
|
|
34
|
+
else if (typeof value === 'string') {
|
|
35
|
+
parts.push(value);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return parts.join(' ').toLowerCase();
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Strip entries whose value is `undefined` from a fields object.
|
|
42
|
+
*/
|
|
43
|
+
function stripUndefined(fields) {
|
|
44
|
+
return Object.fromEntries(Object.entries(fields).filter(([, v]) => v !== undefined));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Create a new Minion instance from input, generating id and timestamps.
|
|
48
|
+
* Validates fields against the provided MinionType schema.
|
|
49
|
+
* @param input - The creation input
|
|
50
|
+
* @param type - The MinionType to validate against
|
|
51
|
+
* @returns An object with the created minion and any validation result
|
|
52
|
+
*/
|
|
53
|
+
export function createMinion(input, type) {
|
|
54
|
+
const fields = applyDefaults(input.fields ?? {}, type);
|
|
55
|
+
const validation = validateFields(fields, type.schema);
|
|
56
|
+
const timestamp = now();
|
|
57
|
+
const minion = {
|
|
58
|
+
id: generateId(),
|
|
59
|
+
title: input.title,
|
|
60
|
+
minionTypeId: type.id,
|
|
61
|
+
fields,
|
|
62
|
+
createdAt: timestamp,
|
|
63
|
+
updatedAt: timestamp,
|
|
64
|
+
tags: input.tags,
|
|
65
|
+
status: input.status ?? 'active',
|
|
66
|
+
priority: input.priority,
|
|
67
|
+
description: input.description,
|
|
68
|
+
dueDate: input.dueDate,
|
|
69
|
+
categoryId: input.categoryId,
|
|
70
|
+
folderId: input.folderId,
|
|
71
|
+
createdBy: input.createdBy,
|
|
72
|
+
};
|
|
73
|
+
minion.searchableText = computeSearchableText(minion, type);
|
|
74
|
+
return { minion, validation };
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Update an existing Minion with new values.
|
|
78
|
+
* Validates updated fields against the provided MinionType schema.
|
|
79
|
+
* @param minion - The existing minion
|
|
80
|
+
* @param input - The update input
|
|
81
|
+
* @param type - The MinionType to validate against
|
|
82
|
+
* @returns An object with the updated minion and any validation result
|
|
83
|
+
*/
|
|
84
|
+
export function updateMinion(minion, input, type) {
|
|
85
|
+
const fields = stripUndefined({ ...minion.fields, ...(input.fields ?? {}) });
|
|
86
|
+
const validation = validateFields(fields, type.schema);
|
|
87
|
+
const updated = {
|
|
88
|
+
...minion,
|
|
89
|
+
title: input.title ?? minion.title,
|
|
90
|
+
fields,
|
|
91
|
+
tags: input.tags ?? minion.tags,
|
|
92
|
+
status: input.status ?? minion.status,
|
|
93
|
+
priority: input.priority ?? minion.priority,
|
|
94
|
+
description: input.description ?? minion.description,
|
|
95
|
+
dueDate: input.dueDate ?? minion.dueDate,
|
|
96
|
+
categoryId: input.categoryId ?? minion.categoryId,
|
|
97
|
+
folderId: input.folderId ?? minion.folderId,
|
|
98
|
+
updatedAt: now(),
|
|
99
|
+
updatedBy: input.updatedBy,
|
|
100
|
+
};
|
|
101
|
+
updated.searchableText = computeSearchableText(updated, type);
|
|
102
|
+
return { minion: updated, validation };
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Soft-delete a minion by setting deletedAt/deletedBy.
|
|
106
|
+
* @param minion - The minion to soft-delete
|
|
107
|
+
* @param deletedBy - Optional identifier of who deleted it
|
|
108
|
+
* @returns The soft-deleted minion
|
|
109
|
+
*/
|
|
110
|
+
export function softDelete(minion, deletedBy) {
|
|
111
|
+
const ts = now();
|
|
112
|
+
return {
|
|
113
|
+
...minion,
|
|
114
|
+
deletedAt: ts,
|
|
115
|
+
deletedBy: deletedBy ?? null,
|
|
116
|
+
updatedAt: ts,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Hard-delete a minion by removing all of its relations from the graph.
|
|
121
|
+
*
|
|
122
|
+
* **Important:** This function only cleans up the relation graph. The caller
|
|
123
|
+
* is responsible for removing the minion object itself from whatever storage
|
|
124
|
+
* layer is in use (array, database, etc.).
|
|
125
|
+
*
|
|
126
|
+
* @param minion - The minion to hard-delete
|
|
127
|
+
* @param graph - The RelationGraph to clean up
|
|
128
|
+
*/
|
|
129
|
+
export function hardDelete(minion, graph) {
|
|
130
|
+
graph.removeByMinionId(minion.id);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Restore a soft-deleted minion.
|
|
134
|
+
* @param minion - The soft-deleted minion
|
|
135
|
+
* @returns The restored minion
|
|
136
|
+
*/
|
|
137
|
+
export function restoreMinion(minion) {
|
|
138
|
+
return {
|
|
139
|
+
...minion,
|
|
140
|
+
deletedAt: null,
|
|
141
|
+
deletedBy: null,
|
|
142
|
+
updatedAt: now(),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Apply default values from the schema to a fields object.
|
|
147
|
+
*/
|
|
148
|
+
export function applyDefaults(fields, type) {
|
|
149
|
+
const result = { ...fields };
|
|
150
|
+
for (const fieldDef of type.schema) {
|
|
151
|
+
if (result[fieldDef.name] === undefined && fieldDef.defaultValue !== undefined) {
|
|
152
|
+
result[fieldDef.name] = fieldDef.defaultValue;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lifecycle/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAE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UAAU,aAAa,CAAC,MAAc;IAC1C,OAAO;QACL,GAAG,MAAM;QACT,SAAS,EAAE,IAAI;QACf,SAAS,EAAE,IAAI;QACf,SAAS,EAAE,GAAG,EAAE;KACjB,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAC3B,MAA+B,EAC/B,IAAgB;IAEhB,MAAM,MAAM,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC;IAC7B,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QACnC,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,SAAS,IAAI,QAAQ,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;YAC/E,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,YAAY,CAAC;QAChD,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module minions-sdk/registry
|
|
3
|
+
* MinionType registry — register, retrieve, and validate types.
|
|
4
|
+
*/
|
|
5
|
+
import type { MinionType } from '../types/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* An in-memory registry for MinionTypes.
|
|
8
|
+
* Pre-loaded with all built-in system types.
|
|
9
|
+
*/
|
|
10
|
+
export declare class TypeRegistry {
|
|
11
|
+
private types;
|
|
12
|
+
private slugIndex;
|
|
13
|
+
constructor(loadBuiltins?: boolean);
|
|
14
|
+
/**
|
|
15
|
+
* Register a MinionType in the registry.
|
|
16
|
+
* @throws Error if a type with the same id or slug already exists.
|
|
17
|
+
*/
|
|
18
|
+
register(type: MinionType): void;
|
|
19
|
+
/**
|
|
20
|
+
* Get a type by its ID.
|
|
21
|
+
* @returns The MinionType or undefined if not found.
|
|
22
|
+
*/
|
|
23
|
+
getById(id: string): MinionType | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Get a type by its slug.
|
|
26
|
+
* @returns The MinionType or undefined if not found.
|
|
27
|
+
*/
|
|
28
|
+
getBySlug(slug: string): MinionType | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* List all registered types.
|
|
31
|
+
*/
|
|
32
|
+
list(): MinionType[];
|
|
33
|
+
/**
|
|
34
|
+
* Check if a type exists by ID.
|
|
35
|
+
*/
|
|
36
|
+
has(id: string): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Remove a type from the registry.
|
|
39
|
+
* @returns true if the type was removed.
|
|
40
|
+
*/
|
|
41
|
+
remove(id: string): boolean;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/registry/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGpD;;;GAGG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,KAAK,CAAsC;IACnD,OAAO,CAAC,SAAS,CAAkC;gBAEvC,YAAY,UAAO;IAQ/B;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI;IAWhC;;;OAGG;IACH,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAI3C;;;OAGG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAK/C;;OAEG;IACH,IAAI,IAAI,UAAU,EAAE;IAIpB;;OAEG;IACH,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAIxB;;;OAGG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;CAO5B"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module minions-sdk/registry
|
|
3
|
+
* MinionType registry — register, retrieve, and validate types.
|
|
4
|
+
*/
|
|
5
|
+
import { builtinTypes } from '../schemas/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* An in-memory registry for MinionTypes.
|
|
8
|
+
* Pre-loaded with all built-in system types.
|
|
9
|
+
*/
|
|
10
|
+
export class TypeRegistry {
|
|
11
|
+
types = new Map();
|
|
12
|
+
slugIndex = new Map();
|
|
13
|
+
constructor(loadBuiltins = true) {
|
|
14
|
+
if (loadBuiltins) {
|
|
15
|
+
for (const t of builtinTypes) {
|
|
16
|
+
this.register(t);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Register a MinionType in the registry.
|
|
22
|
+
* @throws Error if a type with the same id or slug already exists.
|
|
23
|
+
*/
|
|
24
|
+
register(type) {
|
|
25
|
+
if (this.types.has(type.id)) {
|
|
26
|
+
throw new Error(`Type with id "${type.id}" is already registered`);
|
|
27
|
+
}
|
|
28
|
+
if (this.slugIndex.has(type.slug)) {
|
|
29
|
+
throw new Error(`Type with slug "${type.slug}" is already registered`);
|
|
30
|
+
}
|
|
31
|
+
this.types.set(type.id, type);
|
|
32
|
+
this.slugIndex.set(type.slug, type.id);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get a type by its ID.
|
|
36
|
+
* @returns The MinionType or undefined if not found.
|
|
37
|
+
*/
|
|
38
|
+
getById(id) {
|
|
39
|
+
return this.types.get(id);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get a type by its slug.
|
|
43
|
+
* @returns The MinionType or undefined if not found.
|
|
44
|
+
*/
|
|
45
|
+
getBySlug(slug) {
|
|
46
|
+
const id = this.slugIndex.get(slug);
|
|
47
|
+
return id ? this.types.get(id) : undefined;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* List all registered types.
|
|
51
|
+
*/
|
|
52
|
+
list() {
|
|
53
|
+
return Array.from(this.types.values());
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Check if a type exists by ID.
|
|
57
|
+
*/
|
|
58
|
+
has(id) {
|
|
59
|
+
return this.types.has(id);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Remove a type from the registry.
|
|
63
|
+
* @returns true if the type was removed.
|
|
64
|
+
*/
|
|
65
|
+
remove(id) {
|
|
66
|
+
const type = this.types.get(id);
|
|
67
|
+
if (!type)
|
|
68
|
+
return false;
|
|
69
|
+
this.types.delete(id);
|
|
70
|
+
this.slugIndex.delete(type.slug);
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/registry/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD;;;GAGG;AACH,MAAM,OAAO,YAAY;IACf,KAAK,GAA4B,IAAI,GAAG,EAAE,CAAC;IAC3C,SAAS,GAAwB,IAAI,GAAG,EAAE,CAAC;IAEnD,YAAY,YAAY,GAAG,IAAI;QAC7B,IAAI,YAAY,EAAE,CAAC;YACjB,KAAK,MAAM,CAAC,IAAI,YAAY,EAAE,CAAC;gBAC7B,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;YACnB,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,QAAQ,CAAC,IAAgB;QACvB,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,iBAAiB,IAAI,CAAC,EAAE,yBAAyB,CAAC,CAAC;QACrE,CAAC;QACD,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAClC,MAAM,IAAI,KAAK,CAAC,mBAAmB,IAAI,CAAC,IAAI,yBAAyB,CAAC,CAAC;QACzE,CAAC;QACD,IAAI,CAAC,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+
import type { Relation, RelationType, CreateRelationInput } from '../types/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* In-memory relation graph manager.
|
|
8
|
+
* Provides utilities to add, remove, query, and traverse relations.
|
|
9
|
+
*/
|
|
10
|
+
export declare class RelationGraph {
|
|
11
|
+
private relations;
|
|
12
|
+
/**
|
|
13
|
+
* Add a relation to the graph.
|
|
14
|
+
* @returns The created Relation.
|
|
15
|
+
*/
|
|
16
|
+
add(input: CreateRelationInput): Relation;
|
|
17
|
+
/**
|
|
18
|
+
* Remove a relation by ID.
|
|
19
|
+
* @returns true if the relation was removed.
|
|
20
|
+
*/
|
|
21
|
+
remove(id: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Remove all relations involving a given minion (as source or target).
|
|
24
|
+
* @returns Number of relations removed.
|
|
25
|
+
*/
|
|
26
|
+
removeByMinionId(minionId: string): number;
|
|
27
|
+
/**
|
|
28
|
+
* Get a relation by ID.
|
|
29
|
+
*/
|
|
30
|
+
get(id: string): Relation | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Get all relations.
|
|
33
|
+
*/
|
|
34
|
+
list(): Relation[];
|
|
35
|
+
/**
|
|
36
|
+
* Get all relations where the given minion is the source.
|
|
37
|
+
*/
|
|
38
|
+
getFromSource(sourceId: string, type?: RelationType): Relation[];
|
|
39
|
+
/**
|
|
40
|
+
* Get all relations where the given minion is the target.
|
|
41
|
+
*/
|
|
42
|
+
getToTarget(targetId: string, type?: RelationType): Relation[];
|
|
43
|
+
/**
|
|
44
|
+
* Get children of a minion (targets of parent_of relations from this minion).
|
|
45
|
+
*/
|
|
46
|
+
getChildren(parentId: string): string[];
|
|
47
|
+
/**
|
|
48
|
+
* Get parents of a minion (sources of parent_of relations to this minion).
|
|
49
|
+
*/
|
|
50
|
+
getParents(childId: string): string[];
|
|
51
|
+
/**
|
|
52
|
+
* Get the full tree of descendants from a root minion using parent_of relations.
|
|
53
|
+
* Returns a flat array of all descendant IDs (depth-first).
|
|
54
|
+
*/
|
|
55
|
+
getTree(rootId: string): string[];
|
|
56
|
+
/**
|
|
57
|
+
* Get all minions connected to the given minion (regardless of direction or type).
|
|
58
|
+
* Returns a flat array of connected minion IDs.
|
|
59
|
+
*/
|
|
60
|
+
getNetwork(minionId: string): string[];
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/relations/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAGrF;;;GAGG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,SAAS,CAAoC;IAErD;;;OAGG;IACH,GAAG,CAAC,KAAK,EAAE,mBAAmB,GAAG,QAAQ;IAczC;;;OAGG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAI3B;;;OAGG;IACH,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAW1C;;OAEG;IACH,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS;IAIrC;;OAEG;IACH,IAAI,IAAI,QAAQ,EAAE;IAIlB;;OAEG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY,GAAG,QAAQ,EAAE;IAMhE;;OAEG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY,GAAG,QAAQ,EAAE;IAM9D;;OAEG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE;IAIvC;;OAEG;IACH,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;IAIrC;;;OAGG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE;IAiBjC;;;OAGG;IACH,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE;CAQvC"}
|