@mastra/factory 0.0.0 → 0.1.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/LICENSE.md +30 -0
- package/dist/auth.d.ts +181 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +370 -0
- package/dist/auth.js.map +1 -0
- package/dist/capabilities/connection.d.ts +9 -0
- package/dist/capabilities/connection.d.ts.map +1 -0
- package/dist/capabilities/connection.js +1 -0
- package/dist/capabilities/connection.js.map +1 -0
- package/dist/capabilities/intake.d.ts +93 -0
- package/dist/capabilities/intake.d.ts.map +1 -0
- package/dist/capabilities/intake.js +1 -0
- package/dist/capabilities/intake.js.map +1 -0
- package/dist/capabilities/version-control.d.ts +239 -0
- package/dist/capabilities/version-control.d.ts.map +1 -0
- package/dist/capabilities/version-control.js +1 -0
- package/dist/capabilities/version-control.js.map +1 -0
- package/dist/factory.d.ts +145 -0
- package/dist/factory.d.ts.map +1 -0
- package/dist/factory.js +38245 -0
- package/dist/factory.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38245 -0
- package/dist/index.js.map +1 -0
- package/dist/integrations/base.d.ts +197 -0
- package/dist/integrations/base.d.ts.map +1 -0
- package/dist/integrations/base.js +1 -0
- package/dist/integrations/base.js.map +1 -0
- package/dist/integrations/github/config.d.ts +60 -0
- package/dist/integrations/github/config.d.ts.map +1 -0
- package/dist/integrations/github/config.js +28 -0
- package/dist/integrations/github/config.js.map +1 -0
- package/dist/integrations/github/factory-session.d.ts +12 -0
- package/dist/integrations/github/factory-session.d.ts.map +1 -0
- package/dist/integrations/github/factory-session.js +41 -0
- package/dist/integrations/github/factory-session.js.map +1 -0
- package/dist/integrations/github/integration.d.ts +191 -0
- package/dist/integrations/github/integration.d.ts.map +1 -0
- package/dist/integrations/github/integration.js +3001 -0
- package/dist/integrations/github/integration.js.map +1 -0
- package/dist/integrations/github/issue-triage.d.ts +27 -0
- package/dist/integrations/github/issue-triage.d.ts.map +1 -0
- package/dist/integrations/github/issue-triage.js +82 -0
- package/dist/integrations/github/issue-triage.js.map +1 -0
- package/dist/integrations/github/project-lock.d.ts +78 -0
- package/dist/integrations/github/project-lock.d.ts.map +1 -0
- package/dist/integrations/github/project-lock.js +70 -0
- package/dist/integrations/github/project-lock.js.map +1 -0
- package/dist/integrations/github/provenance.d.ts +27 -0
- package/dist/integrations/github/provenance.d.ts.map +1 -0
- package/dist/integrations/github/provenance.js +104 -0
- package/dist/integrations/github/provenance.js.map +1 -0
- package/dist/integrations/github/routes.d.ts +72 -0
- package/dist/integrations/github/routes.d.ts.map +1 -0
- package/dist/integrations/github/routes.js +1834 -0
- package/dist/integrations/github/routes.js.map +1 -0
- package/dist/integrations/github/sandbox.d.ts +268 -0
- package/dist/integrations/github/sandbox.d.ts.map +1 -0
- package/dist/integrations/github/sandbox.js +381 -0
- package/dist/integrations/github/sandbox.js.map +1 -0
- package/dist/integrations/github/session-subscriptions.d.ts +23 -0
- package/dist/integrations/github/session-subscriptions.d.ts.map +1 -0
- package/dist/integrations/github/session-subscriptions.js +190 -0
- package/dist/integrations/github/session-subscriptions.js.map +1 -0
- package/dist/integrations/github/subscriptions.d.ts +54 -0
- package/dist/integrations/github/subscriptions.d.ts.map +1 -0
- package/dist/integrations/github/subscriptions.js +70 -0
- package/dist/integrations/github/subscriptions.js.map +1 -0
- package/dist/integrations/github/webhook.d.ts +87 -0
- package/dist/integrations/github/webhook.d.ts.map +1 -0
- package/dist/integrations/github/webhook.js +381 -0
- package/dist/integrations/github/webhook.js.map +1 -0
- package/dist/integrations/linear/agent-tools.d.ts +34 -0
- package/dist/integrations/linear/agent-tools.d.ts.map +1 -0
- package/dist/integrations/linear/agent-tools.js +108 -0
- package/dist/integrations/linear/agent-tools.js.map +1 -0
- package/dist/integrations/linear/integration.d.ts +233 -0
- package/dist/integrations/linear/integration.d.ts.map +1 -0
- package/dist/integrations/linear/integration.js +962 -0
- package/dist/integrations/linear/integration.js.map +1 -0
- package/dist/integrations/linear/routes.d.ts +61 -0
- package/dist/integrations/linear/routes.d.ts.map +1 -0
- package/dist/integrations/linear/routes.js +242 -0
- package/dist/integrations/linear/routes.js.map +1 -0
- package/dist/integrations/linear/storage.d.ts +65 -0
- package/dist/integrations/linear/storage.d.ts.map +1 -0
- package/dist/integrations/linear/storage.js +1 -0
- package/dist/integrations/linear/storage.js.map +1 -0
- package/dist/integrations/platform/api-client.d.ts +24 -0
- package/dist/integrations/platform/api-client.d.ts.map +1 -0
- package/dist/integrations/platform/api-client.js +153 -0
- package/dist/integrations/platform/api-client.js.map +1 -0
- package/dist/integrations/platform/github/event-worker.d.ts +44 -0
- package/dist/integrations/platform/github/event-worker.d.ts.map +1 -0
- package/dist/integrations/platform/github/event-worker.js +585 -0
- package/dist/integrations/platform/github/event-worker.js.map +1 -0
- package/dist/integrations/platform/github/integration.d.ts +36 -0
- package/dist/integrations/platform/github/integration.d.ts.map +1 -0
- package/dist/integrations/platform/github/integration.js +3253 -0
- package/dist/integrations/platform/github/integration.js.map +1 -0
- package/dist/integrations/platform/linear/integration.d.ts +46 -0
- package/dist/integrations/platform/linear/integration.d.ts.map +1 -0
- package/dist/integrations/platform/linear/integration.js +891 -0
- package/dist/integrations/platform/linear/integration.js.map +1 -0
- package/dist/integrations/workos/integration.d.ts +39 -0
- package/dist/integrations/workos/integration.d.ts.map +1 -0
- package/dist/integrations/workos/integration.js +96 -0
- package/dist/integrations/workos/integration.js.map +1 -0
- package/dist/routes/config.d.ts +220 -0
- package/dist/routes/config.d.ts.map +1 -0
- package/dist/routes/config.js +770 -0
- package/dist/routes/config.js.map +1 -0
- package/dist/routes/fs.d.ts +105 -0
- package/dist/routes/fs.d.ts.map +1 -0
- package/dist/routes/fs.js +294 -0
- package/dist/routes/fs.js.map +1 -0
- package/dist/routes/intake.d.ts +23 -0
- package/dist/routes/intake.d.ts.map +1 -0
- package/dist/routes/intake.js +179 -0
- package/dist/routes/intake.js.map +1 -0
- package/dist/routes/oauth.d.ts +43 -0
- package/dist/routes/oauth.d.ts.map +1 -0
- package/dist/routes/oauth.js +25058 -0
- package/dist/routes/oauth.js.map +1 -0
- package/dist/routes/projects.d.ts +19 -0
- package/dist/routes/projects.d.ts.map +1 -0
- package/dist/routes/projects.js +395 -0
- package/dist/routes/projects.js.map +1 -0
- package/dist/routes/provider-credentials.d.ts +81 -0
- package/dist/routes/provider-credentials.d.ts.map +1 -0
- package/dist/routes/provider-credentials.js +68 -0
- package/dist/routes/provider-credentials.js.map +1 -0
- package/dist/routes/route.d.ts +48 -0
- package/dist/routes/route.d.ts.map +1 -0
- package/dist/routes/route.js +11 -0
- package/dist/routes/route.js.map +1 -0
- package/dist/routes/skills.d.ts +30 -0
- package/dist/routes/skills.d.ts.map +1 -0
- package/dist/routes/skills.js +181 -0
- package/dist/routes/skills.js.map +1 -0
- package/dist/routes/surface.d.ts +83 -0
- package/dist/routes/surface.d.ts.map +1 -0
- package/dist/routes/surface.js +28519 -0
- package/dist/routes/surface.js.map +1 -0
- package/dist/routes/tenant-credentials.d.ts +74 -0
- package/dist/routes/tenant-credentials.d.ts.map +1 -0
- package/dist/routes/tenant-credentials.js +181 -0
- package/dist/routes/tenant-credentials.js.map +1 -0
- package/dist/routes/work-items.d.ts +40 -0
- package/dist/routes/work-items.d.ts.map +1 -0
- package/dist/routes/work-items.js +902 -0
- package/dist/routes/work-items.js.map +1 -0
- package/dist/rules/binding-context.d.ts +5 -0
- package/dist/rules/binding-context.d.ts.map +1 -0
- package/dist/rules/binding-context.js +40 -0
- package/dist/rules/binding-context.js.map +1 -0
- package/dist/rules/defaults.d.ts +9 -0
- package/dist/rules/defaults.d.ts.map +1 -0
- package/dist/rules/defaults.js +334 -0
- package/dist/rules/defaults.js.map +1 -0
- package/dist/rules/dispatcher.d.ts +40 -0
- package/dist/rules/dispatcher.d.ts.map +1 -0
- package/dist/rules/dispatcher.js +695 -0
- package/dist/rules/dispatcher.js.map +1 -0
- package/dist/rules/github-service.d.ts +29 -0
- package/dist/rules/github-service.d.ts.map +1 -0
- package/dist/rules/github-service.js +474 -0
- package/dist/rules/github-service.js.map +1 -0
- package/dist/rules/index.d.ts +7 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +583 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/rules/linear-service.d.ts +27 -0
- package/dist/rules/linear-service.d.ts.map +1 -0
- package/dist/rules/linear-service.js +343 -0
- package/dist/rules/linear-service.js.map +1 -0
- package/dist/rules/processor.d.ts +54 -0
- package/dist/rules/processor.d.ts.map +1 -0
- package/dist/rules/processor.js +629 -0
- package/dist/rules/processor.js.map +1 -0
- package/dist/rules/resolve.d.ts +17 -0
- package/dist/rules/resolve.d.ts.map +1 -0
- package/dist/rules/resolve.js +27 -0
- package/dist/rules/resolve.js.map +1 -0
- package/dist/rules/start-coordinator.d.ts +58 -0
- package/dist/rules/start-coordinator.d.ts.map +1 -0
- package/dist/rules/start-coordinator.js +136 -0
- package/dist/rules/start-coordinator.js.map +1 -0
- package/dist/rules/tools.d.ts +10 -0
- package/dist/rules/tools.d.ts.map +1 -0
- package/dist/rules/tools.js +93 -0
- package/dist/rules/tools.js.map +1 -0
- package/dist/rules/transition-service.d.ts +32 -0
- package/dist/rules/transition-service.d.ts.map +1 -0
- package/dist/rules/transition-service.js +474 -0
- package/dist/rules/transition-service.js.map +1 -0
- package/dist/rules/types.d.ts +225 -0
- package/dist/rules/types.d.ts.map +1 -0
- package/dist/rules/types.js +33 -0
- package/dist/rules/types.js.map +1 -0
- package/dist/rules/validation.d.ts +11 -0
- package/dist/rules/validation.d.ts.map +1 -0
- package/dist/rules/validation.js +310 -0
- package/dist/rules/validation.js.map +1 -0
- package/dist/sandbox/fleet.d.ts +208 -0
- package/dist/sandbox/fleet.d.ts.map +1 -0
- package/dist/sandbox/fleet.js +259 -0
- package/dist/sandbox/fleet.js.map +1 -0
- package/dist/sandbox/reattach.d.ts +3 -0
- package/dist/sandbox/reattach.d.ts.map +1 -0
- package/dist/sandbox/reattach.js +9 -0
- package/dist/sandbox/reattach.js.map +1 -0
- package/dist/server-error.d.ts +12 -0
- package/dist/server-error.d.ts.map +1 -0
- package/dist/server-error.js +20 -0
- package/dist/server-error.js.map +1 -0
- package/dist/skills/service.d.ts +48 -0
- package/dist/skills/service.d.ts.map +1 -0
- package/dist/skills/service.js +45 -0
- package/dist/skills/service.js.map +1 -0
- package/dist/spa-static.d.ts +34 -0
- package/dist/spa-static.d.ts.map +1 -0
- package/dist/spa-static.js +73 -0
- package/dist/spa-static.js.map +1 -0
- package/dist/state-signing.d.ts +48 -0
- package/dist/state-signing.d.ts.map +1 -0
- package/dist/state-signing.js +48 -0
- package/dist/state-signing.js.map +1 -0
- package/dist/storage/domains/audit/agent-audit.d.ts +27 -0
- package/dist/storage/domains/audit/agent-audit.d.ts.map +1 -0
- package/dist/storage/domains/audit/agent-audit.js +65 -0
- package/dist/storage/domains/audit/agent-audit.js.map +1 -0
- package/dist/storage/domains/audit/base.d.ts +140 -0
- package/dist/storage/domains/audit/base.d.ts.map +1 -0
- package/dist/storage/domains/audit/base.js +127 -0
- package/dist/storage/domains/audit/base.js.map +1 -0
- package/dist/storage/domains/audit/domain.d.ts +69 -0
- package/dist/storage/domains/audit/domain.d.ts.map +1 -0
- package/dist/storage/domains/audit/domain.js +165 -0
- package/dist/storage/domains/audit/domain.js.map +1 -0
- package/dist/storage/domains/credentials/base.d.ts +134 -0
- package/dist/storage/domains/credentials/base.d.ts.map +1 -0
- package/dist/storage/domains/credentials/base.js +257 -0
- package/dist/storage/domains/credentials/base.js.map +1 -0
- package/dist/storage/domains/intake/base.d.ts +38 -0
- package/dist/storage/domains/intake/base.d.ts.map +1 -0
- package/dist/storage/domains/intake/base.js +62 -0
- package/dist/storage/domains/intake/base.js.map +1 -0
- package/dist/storage/domains/integrations/base.d.ts +126 -0
- package/dist/storage/domains/integrations/base.d.ts.map +1 -0
- package/dist/storage/domains/integrations/base.js +252 -0
- package/dist/storage/domains/integrations/base.js.map +1 -0
- package/dist/storage/domains/model-packs/base.d.ts +49 -0
- package/dist/storage/domains/model-packs/base.d.ts.map +1 -0
- package/dist/storage/domains/model-packs/base.js +95 -0
- package/dist/storage/domains/model-packs/base.js.map +1 -0
- package/dist/storage/domains/projects/base.d.ts +55 -0
- package/dist/storage/domains/projects/base.d.ts.map +1 -0
- package/dist/storage/domains/projects/base.js +99 -0
- package/dist/storage/domains/projects/base.js.map +1 -0
- package/dist/storage/domains/queue-health/base.d.ts +52 -0
- package/dist/storage/domains/queue-health/base.d.ts.map +1 -0
- package/dist/storage/domains/queue-health/base.js +87 -0
- package/dist/storage/domains/queue-health/base.js.map +1 -0
- package/dist/storage/domains/source-control/base.d.ts +288 -0
- package/dist/storage/domains/source-control/base.d.ts.map +1 -0
- package/dist/storage/domains/source-control/base.js +722 -0
- package/dist/storage/domains/source-control/base.js.map +1 -0
- package/dist/storage/domains/source-control/inmemory.d.ts +158 -0
- package/dist/storage/domains/source-control/inmemory.d.ts.map +1 -0
- package/dist/storage/domains/source-control/inmemory.js +348 -0
- package/dist/storage/domains/source-control/inmemory.js.map +1 -0
- package/dist/storage/domains/work-items/base.d.ts +412 -0
- package/dist/storage/domains/work-items/base.d.ts.map +1 -0
- package/dist/storage/domains/work-items/base.js +1174 -0
- package/dist/storage/domains/work-items/base.js.map +1 -0
- package/dist/storage/domains/work-items/metrics.d.ts +101 -0
- package/dist/storage/domains/work-items/metrics.d.ts.map +1 -0
- package/dist/storage/domains/work-items/metrics.js +203 -0
- package/dist/storage/domains/work-items/metrics.js.map +1 -0
- package/dist/workspace.d.ts +20 -0
- package/dist/workspace.d.ts.map +1 -0
- package/dist/workspace.js +364 -0
- package/dist/workspace.js.map +1 -0
- package/package.json +19 -19
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-user intake selections for every configured intake integration.
|
|
3
|
+
*
|
|
4
|
+
* Integration ids are dynamic. Each integration contributes provider-neutral
|
|
5
|
+
* sources through `FactoryIntegration.intake`; this domain only persists which
|
|
6
|
+
* source ids the user selected.
|
|
7
|
+
*/
|
|
8
|
+
import { FactoryStorageDomain } from '@mastra/core/storage';
|
|
9
|
+
import type { CollectionSchema } from '@mastra/core/storage';
|
|
10
|
+
export interface IntakeSelection {
|
|
11
|
+
enabled: boolean;
|
|
12
|
+
/** Provider-owned source ids; `null` means nothing is selected. */
|
|
13
|
+
sourceIds: string[] | null;
|
|
14
|
+
}
|
|
15
|
+
export type IntakeConfig = Record<string, IntakeSelection>;
|
|
16
|
+
export declare const DEFAULT_INTAKE_CONFIG: IntakeConfig;
|
|
17
|
+
export declare const INTAKE_SETTINGS_SCHEMA: CollectionSchema;
|
|
18
|
+
export declare class IntakeStorage extends FactoryStorageDomain {
|
|
19
|
+
#private;
|
|
20
|
+
constructor();
|
|
21
|
+
init(): Promise<void>;
|
|
22
|
+
dangerouslyClearAll(): Promise<void>;
|
|
23
|
+
getConfig({ orgId, userId, integrationIds, }: {
|
|
24
|
+
orgId: string;
|
|
25
|
+
userId: string;
|
|
26
|
+
/**
|
|
27
|
+
* When provided, the result contains exactly these integration ids, with
|
|
28
|
+
* unset integrations defaulting to `{ enabled: true, sourceIds: null }`.
|
|
29
|
+
*/
|
|
30
|
+
integrationIds?: string[];
|
|
31
|
+
}): Promise<IntakeConfig>;
|
|
32
|
+
saveConfig({ orgId, userId, config }: {
|
|
33
|
+
orgId: string;
|
|
34
|
+
userId: string;
|
|
35
|
+
config: IntakeConfig;
|
|
36
|
+
}): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/intake/base.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,oBAAoB,EAAwB,MAAM,sBAAsB,CAAC;AAClF,OAAO,KAAK,EAAE,gBAAgB,EAAqB,MAAM,sBAAsB,CAAC;AAEhF,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,mEAAmE;IACnE,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;CAC5B;AAED,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;AAE3D,eAAO,MAAM,qBAAqB,EAAE,YAAiB,CAAC;AAEtD,eAAO,MAAM,sBAAsB,EAAE,gBAWpC,CAAC;AAEF,qBAAa,aAAc,SAAQ,oBAAoB;;;IAK/C,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrB,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAQpC,SAAS,CAAC,EACd,KAAK,EACL,MAAM,EACN,cAAc,GACf,EAAE;QACD,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf;;;WAGG;QACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;KAC3B,GAAG,OAAO,CAAC,YAAY,CAAC;IAYnB,UAAU,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,YAAY,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAYpH"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// src/storage/domains/intake/base.ts
|
|
2
|
+
import { FactoryStorageDomain, UniqueViolationError } from "@mastra/core/storage";
|
|
3
|
+
var DEFAULT_INTAKE_CONFIG = {};
|
|
4
|
+
var INTAKE_SETTINGS_SCHEMA = {
|
|
5
|
+
name: "intake_settings",
|
|
6
|
+
columns: {
|
|
7
|
+
id: { type: "uuid-pk" },
|
|
8
|
+
org_id: { type: "text" },
|
|
9
|
+
user_id: { type: "text" },
|
|
10
|
+
config: { type: "json" },
|
|
11
|
+
created_at: { type: "timestamp" },
|
|
12
|
+
updated_at: { type: "timestamp" }
|
|
13
|
+
},
|
|
14
|
+
uniqueIndexes: [{ name: "intake_settings_org_user_unique", columns: ["org_id", "user_id"] }]
|
|
15
|
+
};
|
|
16
|
+
var IntakeStorage = class extends FactoryStorageDomain {
|
|
17
|
+
constructor() {
|
|
18
|
+
super("intake");
|
|
19
|
+
}
|
|
20
|
+
async init() {
|
|
21
|
+
await this.ensureCollections([INTAKE_SETTINGS_SCHEMA]);
|
|
22
|
+
}
|
|
23
|
+
async dangerouslyClearAll() {
|
|
24
|
+
await this.ops.deleteMany("intake_settings", {});
|
|
25
|
+
}
|
|
26
|
+
get #db() {
|
|
27
|
+
return this.ops;
|
|
28
|
+
}
|
|
29
|
+
async getConfig({
|
|
30
|
+
orgId,
|
|
31
|
+
userId,
|
|
32
|
+
integrationIds
|
|
33
|
+
}) {
|
|
34
|
+
const row = await this.#db.findOne("intake_settings", {
|
|
35
|
+
org_id: orgId,
|
|
36
|
+
user_id: userId
|
|
37
|
+
});
|
|
38
|
+
const saved = structuredClone(row?.config ?? DEFAULT_INTAKE_CONFIG);
|
|
39
|
+
if (!integrationIds) return saved;
|
|
40
|
+
return Object.fromEntries(
|
|
41
|
+
integrationIds.map((integrationId) => [integrationId, saved[integrationId] ?? { enabled: true, sourceIds: null }])
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
async saveConfig({ orgId, userId, config }) {
|
|
45
|
+
const now = /* @__PURE__ */ new Date();
|
|
46
|
+
const where = { org_id: orgId, user_id: userId };
|
|
47
|
+
const updated = await this.#db.updateMany("intake_settings", where, { config, updated_at: now });
|
|
48
|
+
if (updated > 0) return;
|
|
49
|
+
try {
|
|
50
|
+
await this.#db.insertOne("intake_settings", { ...where, config, created_at: now, updated_at: now });
|
|
51
|
+
} catch (error) {
|
|
52
|
+
if (!(error instanceof UniqueViolationError)) throw error;
|
|
53
|
+
await this.#db.updateMany("intake_settings", where, { config, updated_at: now });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
export {
|
|
58
|
+
DEFAULT_INTAKE_CONFIG,
|
|
59
|
+
INTAKE_SETTINGS_SCHEMA,
|
|
60
|
+
IntakeStorage
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/storage/domains/intake/base.ts"],"sourcesContent":["/**\n * Per-user intake selections for every configured intake integration.\n *\n * Integration ids are dynamic. Each integration contributes provider-neutral\n * sources through `FactoryIntegration.intake`; this domain only persists which\n * source ids the user selected.\n */\n\nimport { FactoryStorageDomain, UniqueViolationError } from '@mastra/core/storage';\nimport type { CollectionSchema, FactoryStorageOps } from '@mastra/core/storage';\n\nexport interface IntakeSelection {\n enabled: boolean;\n /** Provider-owned source ids; `null` means nothing is selected. */\n sourceIds: string[] | null;\n}\n\nexport type IntakeConfig = Record<string, IntakeSelection>;\n\nexport const DEFAULT_INTAKE_CONFIG: IntakeConfig = {};\n\nexport const INTAKE_SETTINGS_SCHEMA: CollectionSchema = {\n name: 'intake_settings',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n user_id: { type: 'text' },\n config: { type: 'json' },\n created_at: { type: 'timestamp' },\n updated_at: { type: 'timestamp' },\n },\n uniqueIndexes: [{ name: 'intake_settings_org_user_unique', columns: ['org_id', 'user_id'] }],\n};\n\nexport class IntakeStorage extends FactoryStorageDomain {\n constructor() {\n super('intake');\n }\n\n async init(): Promise<void> {\n await this.ensureCollections([INTAKE_SETTINGS_SCHEMA]);\n }\n\n async dangerouslyClearAll(): Promise<void> {\n await this.ops.deleteMany('intake_settings', {});\n }\n\n get #db(): FactoryStorageOps {\n return this.ops;\n }\n\n async getConfig({\n orgId,\n userId,\n integrationIds,\n }: {\n orgId: string;\n userId: string;\n /**\n * When provided, the result contains exactly these integration ids, with\n * unset integrations defaulting to `{ enabled: true, sourceIds: null }`.\n */\n integrationIds?: string[];\n }): Promise<IntakeConfig> {\n const row = await this.#db.findOne<{ config: IntakeConfig }>('intake_settings', {\n org_id: orgId,\n user_id: userId,\n });\n const saved = structuredClone(row?.config ?? DEFAULT_INTAKE_CONFIG);\n if (!integrationIds) return saved;\n return Object.fromEntries(\n integrationIds.map(integrationId => [integrationId, saved[integrationId] ?? { enabled: true, sourceIds: null }]),\n );\n }\n\n async saveConfig({ orgId, userId, config }: { orgId: string; userId: string; config: IntakeConfig }): Promise<void> {\n const now = new Date();\n const where = { org_id: orgId, user_id: userId };\n const updated = await this.#db.updateMany('intake_settings', where, { config, updated_at: now });\n if (updated > 0) return;\n try {\n await this.#db.insertOne('intake_settings', { ...where, config, created_at: now, updated_at: now });\n } catch (error) {\n if (!(error instanceof UniqueViolationError)) throw error;\n await this.#db.updateMany('intake_settings', where, { config, updated_at: now });\n }\n }\n}\n"],"mappings":";AAQA,SAAS,sBAAsB,4BAA4B;AAWpD,IAAM,wBAAsC,CAAC;AAE7C,IAAM,yBAA2C;AAAA,EACtD,MAAM;AAAA,EACN,SAAS;AAAA,IACP,IAAI,EAAE,MAAM,UAAU;AAAA,IACtB,QAAQ,EAAE,MAAM,OAAO;AAAA,IACvB,SAAS,EAAE,MAAM,OAAO;AAAA,IACxB,QAAQ,EAAE,MAAM,OAAO;AAAA,IACvB,YAAY,EAAE,MAAM,YAAY;AAAA,IAChC,YAAY,EAAE,MAAM,YAAY;AAAA,EAClC;AAAA,EACA,eAAe,CAAC,EAAE,MAAM,mCAAmC,SAAS,CAAC,UAAU,SAAS,EAAE,CAAC;AAC7F;AAEO,IAAM,gBAAN,cAA4B,qBAAqB;AAAA,EACtD,cAAc;AACZ,UAAM,QAAQ;AAAA,EAChB;AAAA,EAEA,MAAM,OAAsB;AAC1B,UAAM,KAAK,kBAAkB,CAAC,sBAAsB,CAAC;AAAA,EACvD;AAAA,EAEA,MAAM,sBAAqC;AACzC,UAAM,KAAK,IAAI,WAAW,mBAAmB,CAAC,CAAC;AAAA,EACjD;AAAA,EAEA,IAAI,MAAyB;AAC3B,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAM,UAAU;AAAA,IACd;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAQ0B;AACxB,UAAM,MAAM,MAAM,KAAK,IAAI,QAAkC,mBAAmB;AAAA,MAC9E,QAAQ;AAAA,MACR,SAAS;AAAA,IACX,CAAC;AACD,UAAM,QAAQ,gBAAgB,KAAK,UAAU,qBAAqB;AAClE,QAAI,CAAC,eAAgB,QAAO;AAC5B,WAAO,OAAO;AAAA,MACZ,eAAe,IAAI,mBAAiB,CAAC,eAAe,MAAM,aAAa,KAAK,EAAE,SAAS,MAAM,WAAW,KAAK,CAAC,CAAC;AAAA,IACjH;AAAA,EACF;AAAA,EAEA,MAAM,WAAW,EAAE,OAAO,QAAQ,OAAO,GAA2E;AAClH,UAAM,MAAM,oBAAI,KAAK;AACrB,UAAM,QAAQ,EAAE,QAAQ,OAAO,SAAS,OAAO;AAC/C,UAAM,UAAU,MAAM,KAAK,IAAI,WAAW,mBAAmB,OAAO,EAAE,QAAQ,YAAY,IAAI,CAAC;AAC/F,QAAI,UAAU,EAAG;AACjB,QAAI;AACF,YAAM,KAAK,IAAI,UAAU,mBAAmB,EAAE,GAAG,OAAO,QAAQ,YAAY,KAAK,YAAY,IAAI,CAAC;AAAA,IACpG,SAAS,OAAO;AACd,UAAI,EAAE,iBAAiB,sBAAuB,OAAM;AACpD,YAAM,KAAK,IAAI,WAAW,mBAAmB,OAAO,EAAE,QAAQ,YAAY,IAAI,CAAC;AAAA,IACjF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic integration storage — the default persistence surface for
|
|
3
|
+
* `FactoryIntegration`s.
|
|
4
|
+
*
|
|
5
|
+
* Most integrations persist the same three shapes: an org-owned OAuth
|
|
6
|
+
* **connection**, **subscriptions** binding external objects to
|
|
7
|
+
* sessions/threads, and per-`(org, user)` **settings**. This built-in domain
|
|
8
|
+
* stores all three in shared collections keyed by `integration_id`, so an
|
|
9
|
+
* integration author writes zero schema, zero DDL, and zero queries — and
|
|
10
|
+
* org scoping is enforced by construction through the pre-scoped handle
|
|
11
|
+
* returned by {@link IntegrationStorage.forIntegration}.
|
|
12
|
+
*
|
|
13
|
+
* Source-control integrations additionally use the shared, provider-scoped
|
|
14
|
+
* source-control domain for installations, projects, worktrees, and sandboxes.
|
|
15
|
+
*
|
|
16
|
+
* Payloads (`data` / `config`) are JSON documents typed per-integration via
|
|
17
|
+
* the handle's generics. JSON round-trips exactly what JSON can represent:
|
|
18
|
+
* store timestamps inside payloads as epoch millis or ISO strings, not
|
|
19
|
+
* `Date`s.
|
|
20
|
+
*/
|
|
21
|
+
import { FactoryStorageDomain } from '@mastra/core/storage';
|
|
22
|
+
import type { CollectionSchema } from '@mastra/core/storage';
|
|
23
|
+
export declare const INTEGRATION_CONNECTIONS_SCHEMA: CollectionSchema;
|
|
24
|
+
export declare const INTEGRATION_SUBSCRIPTIONS_SCHEMA: CollectionSchema;
|
|
25
|
+
export declare const INTEGRATION_SETTINGS_SCHEMA: CollectionSchema;
|
|
26
|
+
/** An integration's org-owned connection (typically the OAuth grant). */
|
|
27
|
+
export interface IntegrationConnection<TData> {
|
|
28
|
+
id: string;
|
|
29
|
+
orgId: string;
|
|
30
|
+
/** Who connected it (audit only). */
|
|
31
|
+
userId: string | null;
|
|
32
|
+
data: TData;
|
|
33
|
+
metadata: Record<string, unknown>;
|
|
34
|
+
createdAt: Date;
|
|
35
|
+
updatedAt: Date;
|
|
36
|
+
}
|
|
37
|
+
/** A subscription binding an external object to a session/thread. */
|
|
38
|
+
export interface IntegrationSubscription<TData> {
|
|
39
|
+
id: string;
|
|
40
|
+
orgId: string;
|
|
41
|
+
targetKey: string;
|
|
42
|
+
sessionId: string | null;
|
|
43
|
+
resourceId: string | null;
|
|
44
|
+
threadId: string | null;
|
|
45
|
+
sessionScope: string | null;
|
|
46
|
+
status: string;
|
|
47
|
+
data: TData;
|
|
48
|
+
createdAt: Date;
|
|
49
|
+
updatedAt: Date;
|
|
50
|
+
}
|
|
51
|
+
export type CreateIntegrationSubscriptionInput<TData> = {
|
|
52
|
+
orgId: string;
|
|
53
|
+
targetKey: string;
|
|
54
|
+
sessionId?: string | null;
|
|
55
|
+
resourceId?: string | null;
|
|
56
|
+
threadId?: string | null;
|
|
57
|
+
sessionScope?: string | null;
|
|
58
|
+
/** Defaults to `'active'`. */
|
|
59
|
+
status?: string;
|
|
60
|
+
} & ({} extends TData ? {
|
|
61
|
+
data?: TData;
|
|
62
|
+
} : {
|
|
63
|
+
data: TData;
|
|
64
|
+
});
|
|
65
|
+
/**
|
|
66
|
+
* Typed query surface pre-scoped to one `integration_id`. Every read and
|
|
67
|
+
* write is automatically filtered/stamped with the integration id, so an
|
|
68
|
+
* integration cannot reach another integration's rows.
|
|
69
|
+
*/
|
|
70
|
+
export interface IntegrationStorageHandle<TConnection = Record<string, unknown>, TSettings = Record<string, unknown>, TSubscription = Record<string, unknown>> {
|
|
71
|
+
readonly integrationId: string;
|
|
72
|
+
connections: {
|
|
73
|
+
/** The org's connection, or `null` when not connected. */
|
|
74
|
+
get(orgId: string): Promise<IntegrationConnection<TConnection> | null>;
|
|
75
|
+
/** Insert or replace the org's connection (one per org; `created_at` preserved on update). */
|
|
76
|
+
upsert(orgId: string, input: {
|
|
77
|
+
userId?: string | null;
|
|
78
|
+
data: TConnection;
|
|
79
|
+
metadata?: Record<string, unknown>;
|
|
80
|
+
}): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Atomic read-modify-write of the connection's `data` payload (token
|
|
83
|
+
* rotation etc.). Returns the updated connection, or `null` when the org
|
|
84
|
+
* has no connection.
|
|
85
|
+
*/
|
|
86
|
+
update(orgId: string, fn: (data: TConnection) => TConnection): Promise<IntegrationConnection<TConnection> | null>;
|
|
87
|
+
/** Remove the org's connection. Returns whether a row was deleted. */
|
|
88
|
+
delete(orgId: string): Promise<boolean>;
|
|
89
|
+
};
|
|
90
|
+
subscriptions: {
|
|
91
|
+
create(input: CreateIntegrationSubscriptionInput<TSubscription>): Promise<IntegrationSubscription<TSubscription>>;
|
|
92
|
+
/** All subscriptions for an external object (webhook fan-out), optionally filtered by status. */
|
|
93
|
+
listByTarget(targetKey: string, opts?: {
|
|
94
|
+
status?: string;
|
|
95
|
+
}): Promise<IntegrationSubscription<TSubscription>[]>;
|
|
96
|
+
listBySession(sessionId: string): Promise<IntegrationSubscription<TSubscription>[]>;
|
|
97
|
+
listByThread(resourceId: string, threadId: string): Promise<IntegrationSubscription<TSubscription>[]>;
|
|
98
|
+
updateStatus(id: string, status: string): Promise<void>;
|
|
99
|
+
delete(id: string): Promise<boolean>;
|
|
100
|
+
/** Targeted cleanup, always org-scoped. Returns the number of rows deleted. */
|
|
101
|
+
deleteWhere(where: {
|
|
102
|
+
orgId: string;
|
|
103
|
+
targetKey?: string;
|
|
104
|
+
sessionId?: string;
|
|
105
|
+
}): Promise<number>;
|
|
106
|
+
};
|
|
107
|
+
settings: {
|
|
108
|
+
/** The `(org, user)` config, or `null` when never saved. */
|
|
109
|
+
get(orgId: string, userId: string): Promise<TSettings | null>;
|
|
110
|
+
/** Upsert the `(org, user)` config (`created_at` preserved on update). */
|
|
111
|
+
save(orgId: string, userId: string, config: TSettings): Promise<void>;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The built-in generic integration domain, written once against the
|
|
116
|
+
* `FactoryStorageOps` surface — works on any `FactoryStorage` backend.
|
|
117
|
+
*/
|
|
118
|
+
export declare class IntegrationStorage extends FactoryStorageDomain {
|
|
119
|
+
#private;
|
|
120
|
+
constructor();
|
|
121
|
+
init(): Promise<void>;
|
|
122
|
+
dangerouslyClearAll(): Promise<void>;
|
|
123
|
+
/** A typed handle pre-scoped to `integrationId`. */
|
|
124
|
+
forIntegration<TConnection = Record<string, unknown>, TSettings = Record<string, unknown>, TSubscription = Record<string, unknown>>(integrationId: string): IntegrationStorageHandle<TConnection, TSettings, TSubscription>;
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/integrations/base.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,oBAAoB,EAAwB,MAAM,sBAAsB,CAAC;AAClF,OAAO,KAAK,EAAE,gBAAgB,EAAqB,MAAM,sBAAsB,CAAC;AAEhF,eAAO,MAAM,8BAA8B,EAAE,gBAc5C,CAAC;AAEF,eAAO,MAAM,gCAAgC,EAAE,gBAqB9C,CAAC;AAEF,eAAO,MAAM,2BAA2B,EAAE,gBAczC,CAAC;AAEF,yEAAyE;AACzE,MAAM,WAAW,qBAAqB,CAAC,KAAK;IAC1C,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,qCAAqC;IACrC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,IAAI,EAAE,KAAK,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,qEAAqE;AACrE,MAAM,WAAW,uBAAuB,CAAC,KAAK;IAC5C,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,KAAK,CAAC;IACZ,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,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C;QAC9D,0EAA0E;QAC1E,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;KACvE,CAAC;CACH;AA4BD;;;GAGG;AACH,qBAAa,kBAAmB,SAAQ,oBAAoB;;;IAKpD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAQrB,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAU1C,oDAAoD;IACpD,cAAc,CACZ,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrC,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACvC,aAAa,EAAE,MAAM,GAAG,wBAAwB,CAAC,WAAW,EAAE,SAAS,EAAE,aAAa,CAAC;CAmL1F"}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
// src/storage/domains/integrations/base.ts
|
|
2
|
+
import { FactoryStorageDomain, UniqueViolationError } from "@mastra/core/storage";
|
|
3
|
+
var INTEGRATION_CONNECTIONS_SCHEMA = {
|
|
4
|
+
name: "integration_connections",
|
|
5
|
+
columns: {
|
|
6
|
+
id: { type: "uuid-pk" },
|
|
7
|
+
integration_id: { type: "text" },
|
|
8
|
+
org_id: { type: "text" },
|
|
9
|
+
/** Who connected it (audit only — never scopes reads). */
|
|
10
|
+
user_id: { type: "text", nullable: true },
|
|
11
|
+
data: { type: "json" },
|
|
12
|
+
metadata: { type: "json" },
|
|
13
|
+
created_at: { type: "timestamp" },
|
|
14
|
+
updated_at: { type: "timestamp" }
|
|
15
|
+
},
|
|
16
|
+
uniqueIndexes: [{ name: "integration_connections_integration_org_unique", columns: ["integration_id", "org_id"] }]
|
|
17
|
+
};
|
|
18
|
+
var INTEGRATION_SUBSCRIPTIONS_SCHEMA = {
|
|
19
|
+
name: "integration_subscriptions",
|
|
20
|
+
columns: {
|
|
21
|
+
id: { type: "uuid-pk" },
|
|
22
|
+
integration_id: { type: "text" },
|
|
23
|
+
org_id: { type: "text" },
|
|
24
|
+
/** Canonical external-object key the integration derives (e.g. `pr:{installation}:{repo}:{number}`). */
|
|
25
|
+
target_key: { type: "text" },
|
|
26
|
+
session_id: { type: "text", nullable: true },
|
|
27
|
+
resource_id: { type: "text", nullable: true },
|
|
28
|
+
thread_id: { type: "text", nullable: true },
|
|
29
|
+
session_scope: { type: "text", nullable: true },
|
|
30
|
+
status: { type: "text" },
|
|
31
|
+
data: { type: "json" },
|
|
32
|
+
created_at: { type: "timestamp" },
|
|
33
|
+
updated_at: { type: "timestamp" }
|
|
34
|
+
},
|
|
35
|
+
indexes: [
|
|
36
|
+
{ name: "integration_subscriptions_target_idx", columns: ["integration_id", "target_key"] },
|
|
37
|
+
{ name: "integration_subscriptions_org_idx", columns: ["integration_id", "org_id"] }
|
|
38
|
+
]
|
|
39
|
+
};
|
|
40
|
+
var INTEGRATION_SETTINGS_SCHEMA = {
|
|
41
|
+
name: "integration_settings",
|
|
42
|
+
columns: {
|
|
43
|
+
id: { type: "uuid-pk" },
|
|
44
|
+
integration_id: { type: "text" },
|
|
45
|
+
org_id: { type: "text" },
|
|
46
|
+
user_id: { type: "text" },
|
|
47
|
+
config: { type: "json" },
|
|
48
|
+
created_at: { type: "timestamp" },
|
|
49
|
+
updated_at: { type: "timestamp" }
|
|
50
|
+
},
|
|
51
|
+
uniqueIndexes: [
|
|
52
|
+
{ name: "integration_settings_integration_org_user_unique", columns: ["integration_id", "org_id", "user_id"] }
|
|
53
|
+
]
|
|
54
|
+
};
|
|
55
|
+
var IntegrationStorage = class extends FactoryStorageDomain {
|
|
56
|
+
constructor() {
|
|
57
|
+
super("integrations");
|
|
58
|
+
}
|
|
59
|
+
async init() {
|
|
60
|
+
await this.ensureCollections([
|
|
61
|
+
INTEGRATION_CONNECTIONS_SCHEMA,
|
|
62
|
+
INTEGRATION_SUBSCRIPTIONS_SCHEMA,
|
|
63
|
+
INTEGRATION_SETTINGS_SCHEMA
|
|
64
|
+
]);
|
|
65
|
+
}
|
|
66
|
+
async dangerouslyClearAll() {
|
|
67
|
+
await this.ops.deleteMany("integration_subscriptions", {});
|
|
68
|
+
await this.ops.deleteMany("integration_settings", {});
|
|
69
|
+
await this.ops.deleteMany("integration_connections", {});
|
|
70
|
+
}
|
|
71
|
+
get #db() {
|
|
72
|
+
return this.ops;
|
|
73
|
+
}
|
|
74
|
+
/** A typed handle pre-scoped to `integrationId`. */
|
|
75
|
+
forIntegration(integrationId) {
|
|
76
|
+
if (!integrationId) throw new Error("[IntegrationStorage] integrationId is required.");
|
|
77
|
+
const db = () => this.#db;
|
|
78
|
+
const scoped = { integration_id: integrationId };
|
|
79
|
+
const mapConnection = (row) => ({
|
|
80
|
+
id: row.id,
|
|
81
|
+
orgId: row.org_id,
|
|
82
|
+
userId: row.user_id,
|
|
83
|
+
data: row.data,
|
|
84
|
+
metadata: row.metadata ?? {},
|
|
85
|
+
createdAt: row.created_at,
|
|
86
|
+
updatedAt: row.updated_at
|
|
87
|
+
});
|
|
88
|
+
const mapSubscription = (row) => ({
|
|
89
|
+
id: row.id,
|
|
90
|
+
orgId: row.org_id,
|
|
91
|
+
targetKey: row.target_key,
|
|
92
|
+
sessionId: row.session_id,
|
|
93
|
+
resourceId: row.resource_id,
|
|
94
|
+
threadId: row.thread_id,
|
|
95
|
+
sessionScope: row.session_scope,
|
|
96
|
+
status: row.status,
|
|
97
|
+
data: row.data,
|
|
98
|
+
createdAt: row.created_at,
|
|
99
|
+
updatedAt: row.updated_at
|
|
100
|
+
});
|
|
101
|
+
return {
|
|
102
|
+
integrationId,
|
|
103
|
+
connections: {
|
|
104
|
+
get: async (orgId) => {
|
|
105
|
+
const row = await db().findOne("integration_connections", { ...scoped, org_id: orgId });
|
|
106
|
+
return row ? mapConnection(row) : null;
|
|
107
|
+
},
|
|
108
|
+
upsert: async (orgId, input) => {
|
|
109
|
+
const where = { ...scoped, org_id: orgId };
|
|
110
|
+
const update = async () => db().updateMany("integration_connections", where, {
|
|
111
|
+
user_id: input.userId ?? null,
|
|
112
|
+
data: input.data,
|
|
113
|
+
metadata: input.metadata ?? {},
|
|
114
|
+
updated_at: /* @__PURE__ */ new Date()
|
|
115
|
+
});
|
|
116
|
+
let lastError;
|
|
117
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
118
|
+
if (await update() > 0) return;
|
|
119
|
+
const now = /* @__PURE__ */ new Date();
|
|
120
|
+
try {
|
|
121
|
+
await db().insertOne("integration_connections", {
|
|
122
|
+
...where,
|
|
123
|
+
user_id: input.userId ?? null,
|
|
124
|
+
data: input.data,
|
|
125
|
+
metadata: input.metadata ?? {},
|
|
126
|
+
created_at: now,
|
|
127
|
+
updated_at: now
|
|
128
|
+
});
|
|
129
|
+
return;
|
|
130
|
+
} catch (error) {
|
|
131
|
+
if (!(error instanceof UniqueViolationError)) throw error;
|
|
132
|
+
lastError = error;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
throw lastError;
|
|
136
|
+
},
|
|
137
|
+
update: async (orgId, fn) => {
|
|
138
|
+
const row = await db().updateAtomic(
|
|
139
|
+
"integration_connections",
|
|
140
|
+
{ ...scoped, org_id: orgId },
|
|
141
|
+
(current) => ({ data: fn(current.data), updated_at: /* @__PURE__ */ new Date() })
|
|
142
|
+
);
|
|
143
|
+
return row ? mapConnection(row) : null;
|
|
144
|
+
},
|
|
145
|
+
delete: async (orgId) => {
|
|
146
|
+
const deleted = await db().deleteMany("integration_connections", { ...scoped, org_id: orgId });
|
|
147
|
+
return deleted > 0;
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
subscriptions: {
|
|
151
|
+
create: async (input) => {
|
|
152
|
+
const now = /* @__PURE__ */ new Date();
|
|
153
|
+
const row = await db().insertOne("integration_subscriptions", {
|
|
154
|
+
...scoped,
|
|
155
|
+
org_id: input.orgId,
|
|
156
|
+
target_key: input.targetKey,
|
|
157
|
+
session_id: input.sessionId ?? null,
|
|
158
|
+
resource_id: input.resourceId ?? null,
|
|
159
|
+
thread_id: input.threadId ?? null,
|
|
160
|
+
session_scope: input.sessionScope ?? null,
|
|
161
|
+
status: input.status ?? "active",
|
|
162
|
+
data: input.data ?? {},
|
|
163
|
+
created_at: now,
|
|
164
|
+
updated_at: now
|
|
165
|
+
});
|
|
166
|
+
return mapSubscription(row);
|
|
167
|
+
},
|
|
168
|
+
listByTarget: async (targetKey, opts) => {
|
|
169
|
+
const rows = await db().findMany(
|
|
170
|
+
"integration_subscriptions",
|
|
171
|
+
{ ...scoped, target_key: targetKey, ...opts?.status !== void 0 ? { status: opts.status } : {} },
|
|
172
|
+
{ orderBy: [["created_at", "asc"]] }
|
|
173
|
+
);
|
|
174
|
+
return rows.map(mapSubscription);
|
|
175
|
+
},
|
|
176
|
+
listBySession: async (sessionId) => {
|
|
177
|
+
const rows = await db().findMany(
|
|
178
|
+
"integration_subscriptions",
|
|
179
|
+
{ ...scoped, session_id: sessionId },
|
|
180
|
+
{ orderBy: [["created_at", "asc"]] }
|
|
181
|
+
);
|
|
182
|
+
return rows.map(mapSubscription);
|
|
183
|
+
},
|
|
184
|
+
listByThread: async (resourceId, threadId) => {
|
|
185
|
+
const rows = await db().findMany(
|
|
186
|
+
"integration_subscriptions",
|
|
187
|
+
{ ...scoped, resource_id: resourceId, thread_id: threadId },
|
|
188
|
+
{ orderBy: [["created_at", "asc"]] }
|
|
189
|
+
);
|
|
190
|
+
return rows.map(mapSubscription);
|
|
191
|
+
},
|
|
192
|
+
updateStatus: async (id, status) => {
|
|
193
|
+
await db().updateMany("integration_subscriptions", { ...scoped, id }, { status, updated_at: /* @__PURE__ */ new Date() });
|
|
194
|
+
},
|
|
195
|
+
delete: async (id) => {
|
|
196
|
+
const deleted = await db().deleteMany("integration_subscriptions", { ...scoped, id });
|
|
197
|
+
return deleted > 0;
|
|
198
|
+
},
|
|
199
|
+
deleteWhere: async (where) => {
|
|
200
|
+
return db().deleteMany("integration_subscriptions", {
|
|
201
|
+
...scoped,
|
|
202
|
+
org_id: where.orgId,
|
|
203
|
+
...where.targetKey !== void 0 ? { target_key: where.targetKey } : {},
|
|
204
|
+
...where.sessionId !== void 0 ? { session_id: where.sessionId } : {}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
settings: {
|
|
209
|
+
get: async (orgId, userId) => {
|
|
210
|
+
const row = await db().findOne("integration_settings", {
|
|
211
|
+
...scoped,
|
|
212
|
+
org_id: orgId,
|
|
213
|
+
user_id: userId
|
|
214
|
+
});
|
|
215
|
+
return row ? structuredClone(row.config) : null;
|
|
216
|
+
},
|
|
217
|
+
save: async (orgId, userId, config) => {
|
|
218
|
+
const where = { ...scoped, org_id: orgId, user_id: userId };
|
|
219
|
+
const update = async () => db().updateMany("integration_settings", where, {
|
|
220
|
+
config,
|
|
221
|
+
updated_at: /* @__PURE__ */ new Date()
|
|
222
|
+
});
|
|
223
|
+
let lastError;
|
|
224
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
225
|
+
if (await update() > 0) return;
|
|
226
|
+
const now = /* @__PURE__ */ new Date();
|
|
227
|
+
try {
|
|
228
|
+
await db().insertOne("integration_settings", {
|
|
229
|
+
...where,
|
|
230
|
+
config,
|
|
231
|
+
created_at: now,
|
|
232
|
+
updated_at: now
|
|
233
|
+
});
|
|
234
|
+
return;
|
|
235
|
+
} catch (error) {
|
|
236
|
+
if (!(error instanceof UniqueViolationError)) throw error;
|
|
237
|
+
lastError = error;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
throw lastError;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
export {
|
|
247
|
+
INTEGRATION_CONNECTIONS_SCHEMA,
|
|
248
|
+
INTEGRATION_SETTINGS_SCHEMA,
|
|
249
|
+
INTEGRATION_SUBSCRIPTIONS_SCHEMA,
|
|
250
|
+
IntegrationStorage
|
|
251
|
+
};
|
|
252
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/storage/domains/integrations/base.ts"],"sourcesContent":["/**\n * Generic integration storage — the default persistence surface for\n * `FactoryIntegration`s.\n *\n * Most integrations persist the same three shapes: an org-owned OAuth\n * **connection**, **subscriptions** binding external objects to\n * sessions/threads, and per-`(org, user)` **settings**. This built-in domain\n * stores all three in shared collections keyed by `integration_id`, so an\n * integration author writes zero schema, zero DDL, and zero queries — and\n * org scoping is enforced by construction through the pre-scoped handle\n * returned by {@link IntegrationStorage.forIntegration}.\n *\n * Source-control integrations additionally use the shared, provider-scoped\n * source-control domain for installations, projects, worktrees, and sandboxes.\n *\n * Payloads (`data` / `config`) are JSON documents typed per-integration via\n * the handle's generics. JSON round-trips exactly what JSON can represent:\n * store timestamps inside payloads as epoch millis or ISO strings, not\n * `Date`s.\n */\n\nimport { FactoryStorageDomain, UniqueViolationError } from '@mastra/core/storage';\nimport type { CollectionSchema, FactoryStorageOps } from '@mastra/core/storage';\n\nexport const INTEGRATION_CONNECTIONS_SCHEMA: CollectionSchema = {\n name: 'integration_connections',\n columns: {\n id: { type: 'uuid-pk' },\n integration_id: { type: 'text' },\n org_id: { type: 'text' },\n /** Who connected it (audit only — never scopes reads). */\n user_id: { type: 'text', nullable: true },\n data: { type: 'json' },\n metadata: { type: 'json' },\n created_at: { type: 'timestamp' },\n updated_at: { type: 'timestamp' },\n },\n uniqueIndexes: [{ name: 'integration_connections_integration_org_unique', columns: ['integration_id', 'org_id'] }],\n};\n\nexport const INTEGRATION_SUBSCRIPTIONS_SCHEMA: CollectionSchema = {\n name: 'integration_subscriptions',\n columns: {\n id: { type: 'uuid-pk' },\n integration_id: { type: 'text' },\n org_id: { type: 'text' },\n /** Canonical external-object key the integration derives (e.g. `pr:{installation}:{repo}:{number}`). */\n target_key: { type: 'text' },\n session_id: { type: 'text', nullable: true },\n resource_id: { type: 'text', nullable: true },\n thread_id: { type: 'text', nullable: true },\n session_scope: { type: 'text', nullable: true },\n status: { type: 'text' },\n data: { type: 'json' },\n created_at: { type: 'timestamp' },\n updated_at: { type: 'timestamp' },\n },\n indexes: [\n { name: 'integration_subscriptions_target_idx', columns: ['integration_id', 'target_key'] },\n { name: 'integration_subscriptions_org_idx', columns: ['integration_id', 'org_id'] },\n ],\n};\n\nexport const INTEGRATION_SETTINGS_SCHEMA: CollectionSchema = {\n name: 'integration_settings',\n columns: {\n id: { type: 'uuid-pk' },\n integration_id: { type: 'text' },\n org_id: { type: 'text' },\n user_id: { type: 'text' },\n config: { type: 'json' },\n created_at: { type: 'timestamp' },\n updated_at: { type: 'timestamp' },\n },\n uniqueIndexes: [\n { name: 'integration_settings_integration_org_user_unique', columns: ['integration_id', 'org_id', 'user_id'] },\n ],\n};\n\n/** An integration's org-owned connection (typically the OAuth grant). */\nexport interface IntegrationConnection<TData> {\n id: string;\n orgId: string;\n /** Who connected it (audit only). */\n userId: string | null;\n data: TData;\n metadata: Record<string, unknown>;\n createdAt: Date;\n updatedAt: Date;\n}\n\n/** A subscription binding an external object to a session/thread. */\nexport interface IntegrationSubscription<TData> {\n id: string;\n orgId: string;\n targetKey: string;\n sessionId: string | null;\n resourceId: string | null;\n threadId: string | null;\n sessionScope: string | null;\n status: string;\n data: TData;\n createdAt: Date;\n updatedAt: Date;\n}\n\nexport type CreateIntegrationSubscriptionInput<TData> = {\n orgId: string;\n targetKey: string;\n sessionId?: string | null;\n resourceId?: string | null;\n threadId?: string | null;\n sessionScope?: string | null;\n /** Defaults to `'active'`. */\n status?: string;\n} & ({} extends TData ? { data?: TData } : { data: TData });\n\n/**\n * Typed query surface pre-scoped to one `integration_id`. Every read and\n * write is automatically filtered/stamped with the integration id, so an\n * integration cannot reach another integration's rows.\n */\nexport interface IntegrationStorageHandle<\n TConnection = Record<string, unknown>,\n TSettings = Record<string, unknown>,\n TSubscription = Record<string, unknown>,\n> {\n readonly integrationId: string;\n connections: {\n /** The org's connection, or `null` when not connected. */\n get(orgId: string): Promise<IntegrationConnection<TConnection> | null>;\n /** Insert or replace the org's connection (one per org; `created_at` preserved on update). */\n upsert(\n orgId: string,\n input: { userId?: string | null; data: TConnection; metadata?: Record<string, unknown> },\n ): Promise<void>;\n /**\n * Atomic read-modify-write of the connection's `data` payload (token\n * rotation etc.). Returns the updated connection, or `null` when the org\n * has no connection.\n */\n update(orgId: string, fn: (data: TConnection) => TConnection): Promise<IntegrationConnection<TConnection> | null>;\n /** Remove the org's connection. Returns whether a row was deleted. */\n delete(orgId: string): Promise<boolean>;\n };\n subscriptions: {\n create(input: CreateIntegrationSubscriptionInput<TSubscription>): Promise<IntegrationSubscription<TSubscription>>;\n /** All subscriptions for an external object (webhook fan-out), optionally filtered by status. */\n listByTarget(targetKey: string, opts?: { status?: string }): Promise<IntegrationSubscription<TSubscription>[]>;\n listBySession(sessionId: string): Promise<IntegrationSubscription<TSubscription>[]>;\n listByThread(resourceId: string, threadId: string): Promise<IntegrationSubscription<TSubscription>[]>;\n updateStatus(id: string, status: string): Promise<void>;\n delete(id: string): Promise<boolean>;\n /** Targeted cleanup, always org-scoped. Returns the number of rows deleted. */\n deleteWhere(where: { orgId: string; targetKey?: string; sessionId?: string }): Promise<number>;\n };\n settings: {\n /** The `(org, user)` config, or `null` when never saved. */\n get(orgId: string, userId: string): Promise<TSettings | null>;\n /** Upsert the `(org, user)` config (`created_at` preserved on update). */\n save(orgId: string, userId: string, config: TSettings): Promise<void>;\n };\n}\n\ninterface ConnectionRow extends Record<string, unknown> {\n id: string;\n integration_id: string;\n org_id: string;\n user_id: string | null;\n data: unknown;\n metadata: Record<string, unknown>;\n created_at: Date;\n updated_at: Date;\n}\n\ninterface SubscriptionRow extends Record<string, unknown> {\n id: string;\n integration_id: string;\n org_id: string;\n target_key: string;\n session_id: string | null;\n resource_id: string | null;\n thread_id: string | null;\n session_scope: string | null;\n status: string;\n data: unknown;\n created_at: Date;\n updated_at: Date;\n}\n\n/**\n * The built-in generic integration domain, written once against the\n * `FactoryStorageOps` surface — works on any `FactoryStorage` backend.\n */\nexport class IntegrationStorage extends FactoryStorageDomain {\n constructor() {\n super('integrations');\n }\n\n async init(): Promise<void> {\n await this.ensureCollections([\n INTEGRATION_CONNECTIONS_SCHEMA,\n INTEGRATION_SUBSCRIPTIONS_SCHEMA,\n INTEGRATION_SETTINGS_SCHEMA,\n ]);\n }\n\n async dangerouslyClearAll(): Promise<void> {\n await this.ops.deleteMany('integration_subscriptions', {});\n await this.ops.deleteMany('integration_settings', {});\n await this.ops.deleteMany('integration_connections', {});\n }\n\n get #db(): FactoryStorageOps {\n return this.ops;\n }\n\n /** A typed handle pre-scoped to `integrationId`. */\n forIntegration<\n TConnection = Record<string, unknown>,\n TSettings = Record<string, unknown>,\n TSubscription = Record<string, unknown>,\n >(integrationId: string): IntegrationStorageHandle<TConnection, TSettings, TSubscription> {\n if (!integrationId) throw new Error('[IntegrationStorage] integrationId is required.');\n const db = () => this.#db;\n const scoped = { integration_id: integrationId };\n\n const mapConnection = (row: ConnectionRow): IntegrationConnection<TConnection> => ({\n id: row.id,\n orgId: row.org_id,\n userId: row.user_id,\n data: row.data as TConnection,\n metadata: row.metadata ?? {},\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n });\n\n const mapSubscription = (row: SubscriptionRow): IntegrationSubscription<TSubscription> => ({\n id: row.id,\n orgId: row.org_id,\n targetKey: row.target_key,\n sessionId: row.session_id,\n resourceId: row.resource_id,\n threadId: row.thread_id,\n sessionScope: row.session_scope,\n status: row.status,\n data: row.data as TSubscription,\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n });\n\n return {\n integrationId,\n connections: {\n get: async orgId => {\n const row = await db().findOne<ConnectionRow>('integration_connections', { ...scoped, org_id: orgId });\n return row ? mapConnection(row) : null;\n },\n upsert: async (orgId, input) => {\n const where = { ...scoped, org_id: orgId };\n const update = async () =>\n db().updateMany('integration_connections', where, {\n user_id: input.userId ?? null,\n data: input.data,\n metadata: input.metadata ?? {},\n updated_at: new Date(),\n });\n\n let lastError: unknown;\n for (let attempt = 0; attempt < 2; attempt++) {\n if ((await update()) > 0) return;\n\n const now = new Date();\n try {\n await db().insertOne<ConnectionRow>('integration_connections', {\n ...where,\n user_id: input.userId ?? null,\n data: input.data,\n metadata: input.metadata ?? {},\n created_at: now,\n updated_at: now,\n });\n return;\n } catch (error) {\n if (!(error instanceof UniqueViolationError)) throw error;\n lastError = error;\n }\n }\n throw lastError;\n },\n update: async (orgId, fn) => {\n const row = await db().updateAtomic<ConnectionRow>(\n 'integration_connections',\n { ...scoped, org_id: orgId },\n current => ({ data: fn(current.data as TConnection), updated_at: new Date() }),\n );\n return row ? mapConnection(row) : null;\n },\n delete: async orgId => {\n const deleted = await db().deleteMany('integration_connections', { ...scoped, org_id: orgId });\n return deleted > 0;\n },\n },\n subscriptions: {\n create: async input => {\n const now = new Date();\n const row = await db().insertOne<SubscriptionRow>('integration_subscriptions', {\n ...scoped,\n org_id: input.orgId,\n target_key: input.targetKey,\n session_id: input.sessionId ?? null,\n resource_id: input.resourceId ?? null,\n thread_id: input.threadId ?? null,\n session_scope: input.sessionScope ?? null,\n status: input.status ?? 'active',\n data: input.data ?? {},\n created_at: now,\n updated_at: now,\n });\n return mapSubscription(row);\n },\n listByTarget: async (targetKey, opts) => {\n const rows = await db().findMany<SubscriptionRow>(\n 'integration_subscriptions',\n { ...scoped, target_key: targetKey, ...(opts?.status !== undefined ? { status: opts.status } : {}) },\n { orderBy: [['created_at', 'asc']] },\n );\n return rows.map(mapSubscription);\n },\n listBySession: async sessionId => {\n const rows = await db().findMany<SubscriptionRow>(\n 'integration_subscriptions',\n { ...scoped, session_id: sessionId },\n { orderBy: [['created_at', 'asc']] },\n );\n return rows.map(mapSubscription);\n },\n listByThread: async (resourceId, threadId) => {\n const rows = await db().findMany<SubscriptionRow>(\n 'integration_subscriptions',\n { ...scoped, resource_id: resourceId, thread_id: threadId },\n { orderBy: [['created_at', 'asc']] },\n );\n return rows.map(mapSubscription);\n },\n updateStatus: async (id, status) => {\n await db().updateMany('integration_subscriptions', { ...scoped, id }, { status, updated_at: new Date() });\n },\n delete: async id => {\n const deleted = await db().deleteMany('integration_subscriptions', { ...scoped, id });\n return deleted > 0;\n },\n deleteWhere: async where => {\n return db().deleteMany('integration_subscriptions', {\n ...scoped,\n org_id: where.orgId,\n ...(where.targetKey !== undefined ? { target_key: where.targetKey } : {}),\n ...(where.sessionId !== undefined ? { session_id: where.sessionId } : {}),\n });\n },\n },\n settings: {\n get: async (orgId, userId) => {\n const row = await db().findOne<{ config: TSettings }>('integration_settings', {\n ...scoped,\n org_id: orgId,\n user_id: userId,\n });\n return row ? structuredClone(row.config) : null;\n },\n save: async (orgId, userId, config) => {\n const where = { ...scoped, org_id: orgId, user_id: userId };\n const update = async () =>\n db().updateMany('integration_settings', where, {\n config,\n updated_at: new Date(),\n });\n\n let lastError: unknown;\n for (let attempt = 0; attempt < 2; attempt++) {\n if ((await update()) > 0) return;\n\n const now = new Date();\n try {\n await db().insertOne('integration_settings', {\n ...where,\n config,\n created_at: now,\n updated_at: now,\n });\n return;\n } catch (error) {\n if (!(error instanceof UniqueViolationError)) throw error;\n lastError = error;\n }\n }\n throw lastError;\n },\n },\n };\n }\n}\n"],"mappings":";AAqBA,SAAS,sBAAsB,4BAA4B;AAGpD,IAAM,iCAAmD;AAAA,EAC9D,MAAM;AAAA,EACN,SAAS;AAAA,IACP,IAAI,EAAE,MAAM,UAAU;AAAA,IACtB,gBAAgB,EAAE,MAAM,OAAO;AAAA,IAC/B,QAAQ,EAAE,MAAM,OAAO;AAAA;AAAA,IAEvB,SAAS,EAAE,MAAM,QAAQ,UAAU,KAAK;AAAA,IACxC,MAAM,EAAE,MAAM,OAAO;AAAA,IACrB,UAAU,EAAE,MAAM,OAAO;AAAA,IACzB,YAAY,EAAE,MAAM,YAAY;AAAA,IAChC,YAAY,EAAE,MAAM,YAAY;AAAA,EAClC;AAAA,EACA,eAAe,CAAC,EAAE,MAAM,kDA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C,gBAAK,MAAM,OAAO,IAAK,EAAG;AAE1B,kBAAM,MAAM,oBAAI,KAAK;AACrB,gBAAI;AACF,oBAAM,GAAG,EAAE,UAAU,wBAAwB;AAAA,gBAC3C,GAAG;AAAA,gBACH;AAAA,gBACA,YAAY;AAAA,gBACZ,YAAY;AAAA,cACd,CAAC;AACD;AAAA,YACF,SAAS,OAAO;AACd,kBAAI,EAAE,iBAAiB,sBAAuB,OAAM;AACpD,0BAAY;AAAA,YACd;AAAA,UACF;AACA,gBAAM;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { FactoryStorageDomain } from '@mastra/core/storage';
|
|
2
|
+
import type { CollectionSchema } from '@mastra/core/storage';
|
|
3
|
+
/** A saved custom model pack: one model per mode (build / plan / fast). */
|
|
4
|
+
export interface ModelPackRecord {
|
|
5
|
+
id: string;
|
|
6
|
+
orgId: string;
|
|
7
|
+
createdBy: string;
|
|
8
|
+
name: string;
|
|
9
|
+
models: {
|
|
10
|
+
build: string;
|
|
11
|
+
plan: string;
|
|
12
|
+
fast: string;
|
|
13
|
+
};
|
|
14
|
+
createdAt: Date;
|
|
15
|
+
updatedAt: Date;
|
|
16
|
+
}
|
|
17
|
+
export interface UpsertModelPackInput {
|
|
18
|
+
name: string;
|
|
19
|
+
models: {
|
|
20
|
+
build: string;
|
|
21
|
+
plan: string;
|
|
22
|
+
fast: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export declare const MODEL_PACKS_SCHEMA: CollectionSchema;
|
|
26
|
+
export declare class ModelPacksStorage extends FactoryStorageDomain {
|
|
27
|
+
#private;
|
|
28
|
+
constructor();
|
|
29
|
+
init(): Promise<void>;
|
|
30
|
+
dangerouslyClearAll(): Promise<void>;
|
|
31
|
+
/** Create or replace a pack by `(orgId, name)` — mirrors the settings.json upsert semantics. */
|
|
32
|
+
upsert({ orgId, userId, input, }: {
|
|
33
|
+
orgId: string;
|
|
34
|
+
userId: string;
|
|
35
|
+
input: UpsertModelPackInput;
|
|
36
|
+
}): Promise<ModelPackRecord>;
|
|
37
|
+
list({ orgId }: {
|
|
38
|
+
orgId: string;
|
|
39
|
+
}): Promise<ModelPackRecord[]>;
|
|
40
|
+
get({ orgId, id }: {
|
|
41
|
+
orgId: string;
|
|
42
|
+
id: string;
|
|
43
|
+
}): Promise<ModelPackRecord | null>;
|
|
44
|
+
delete({ orgId, id }: {
|
|
45
|
+
orgId: string;
|
|
46
|
+
id: string;
|
|
47
|
+
}): Promise<boolean>;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/model-packs/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAqB,MAAM,sBAAsB,CAAC;AAEhF,2EAA2E;AAC3E,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACtD,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CACvD;AAED,eAAO,MAAM,kBAAkB,EAAE,gBAchC,CAAC;AA0BF,qBAAa,iBAAkB,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