@mastra/pg 1.9.3 → 1.9.4-alpha.1
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 +20 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +202 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +203 -5
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/channels/index.d.ts +25 -0
- package/dist/storage/domains/channels/index.d.ts.map +1 -0
- package/dist/storage/domains/workflows/index.d.ts +10 -0
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +2 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @mastra/pg
|
|
2
2
|
|
|
3
|
+
## 1.9.4-alpha.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Added platform channels framework with ChannelProvider interface, ChannelsStorage domain, and ChannelConnectResult discriminated union supporting OAuth, deep link, and immediate connection flows. Channels can be registered on the Mastra instance and expose connect/disconnect/list APIs for platform integrations. ([#15876](https://github.com/mastra-ai/mastra/pull/15876))
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`b2deb29`](https://github.com/mastra-ai/mastra/commit/b2deb29412b300c868655b5840463614fbb7962d), [`66644be`](https://github.com/mastra-ai/mastra/commit/66644beac1aa560f0e417956ff007c89341dc382), [`310b953`](https://github.com/mastra-ai/mastra/commit/310b95345f302dcd5ba3ed862bdc96f059d44122), [`43f0e1d`](https://github.com/mastra-ai/mastra/commit/43f0e1d5d5a74ba6fc746f2ad89ebe0c64777a7d), [`da0b9e2`](https://github.com/mastra-ai/mastra/commit/da0b9e2ba7ecc560213b426d6c097fe63946086e)]:
|
|
10
|
+
- @mastra/core@1.31.0-alpha.3
|
|
11
|
+
|
|
12
|
+
## 1.9.4-alpha.0
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Fixed workflow snapshot sanitization in `@mastra/pg` for strings containing escaped surrogate patterns like `[^\ud800-\udfff]`. This prevents invalid JSON escape sequences that caused PostgreSQL `jsonb` writes to fail with error `22P02`. ([#15923](https://github.com/mastra-ai/mastra/pull/15923))
|
|
17
|
+
|
|
18
|
+
Fixes #15920
|
|
19
|
+
|
|
20
|
+
- Updated dependencies [[`e109607`](https://github.com/mastra-ai/mastra/commit/e10960749251e34d46b480a20648c490fd30381b)]:
|
|
21
|
+
- @mastra/core@1.31.0-alpha.1
|
|
22
|
+
|
|
3
23
|
## 1.9.3
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/dist/docs/SKILL.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -4658,6 +4658,202 @@ var BlobsPG = class extends storage.BlobStore {
|
|
|
4658
4658
|
};
|
|
4659
4659
|
}
|
|
4660
4660
|
};
|
|
4661
|
+
var ChannelsPG = class _ChannelsPG extends storage.ChannelsStorage {
|
|
4662
|
+
#db;
|
|
4663
|
+
#schema;
|
|
4664
|
+
#skipDefaultIndexes;
|
|
4665
|
+
#indexes;
|
|
4666
|
+
static MANAGED_TABLES = [storage.TABLE_CHANNEL_INSTALLATIONS, storage.TABLE_CHANNEL_CONFIG];
|
|
4667
|
+
constructor(config) {
|
|
4668
|
+
super();
|
|
4669
|
+
const { client, schemaName, skipDefaultIndexes, indexes } = resolvePgConfig(config);
|
|
4670
|
+
this.#db = new PgDB({ client, schemaName, skipDefaultIndexes });
|
|
4671
|
+
this.#schema = schemaName || "public";
|
|
4672
|
+
this.#skipDefaultIndexes = skipDefaultIndexes;
|
|
4673
|
+
this.#indexes = indexes?.filter((idx) => _ChannelsPG.MANAGED_TABLES.includes(idx.table));
|
|
4674
|
+
}
|
|
4675
|
+
async init() {
|
|
4676
|
+
await this.#db.createTable({
|
|
4677
|
+
tableName: storage.TABLE_CHANNEL_INSTALLATIONS,
|
|
4678
|
+
schema: storage.TABLE_SCHEMAS[storage.TABLE_CHANNEL_INSTALLATIONS]
|
|
4679
|
+
});
|
|
4680
|
+
await this.#db.createTable({
|
|
4681
|
+
tableName: storage.TABLE_CHANNEL_CONFIG,
|
|
4682
|
+
schema: storage.TABLE_SCHEMAS[storage.TABLE_CHANNEL_CONFIG]
|
|
4683
|
+
});
|
|
4684
|
+
await this.createDefaultIndexes();
|
|
4685
|
+
await this.createCustomIndexes();
|
|
4686
|
+
}
|
|
4687
|
+
static getDefaultIndexDefs(schemaPrefix) {
|
|
4688
|
+
return [
|
|
4689
|
+
{
|
|
4690
|
+
name: `${schemaPrefix}idx_channel_installations_webhook`,
|
|
4691
|
+
table: storage.TABLE_CHANNEL_INSTALLATIONS,
|
|
4692
|
+
columns: ["webhookId"],
|
|
4693
|
+
unique: true
|
|
4694
|
+
},
|
|
4695
|
+
{
|
|
4696
|
+
name: `${schemaPrefix}idx_channel_installations_platform_agent`,
|
|
4697
|
+
table: storage.TABLE_CHANNEL_INSTALLATIONS,
|
|
4698
|
+
columns: ["platform", "agentId"]
|
|
4699
|
+
}
|
|
4700
|
+
];
|
|
4701
|
+
}
|
|
4702
|
+
static getExportDDL(schemaName) {
|
|
4703
|
+
const statements = [];
|
|
4704
|
+
const parsedSchema = schemaName ? utils.parseSqlIdentifier(schemaName, "schema name") : "";
|
|
4705
|
+
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
4706
|
+
for (const tableName of _ChannelsPG.MANAGED_TABLES) {
|
|
4707
|
+
statements.push(
|
|
4708
|
+
generateTableSQL({
|
|
4709
|
+
tableName,
|
|
4710
|
+
schema: storage.TABLE_SCHEMAS[tableName],
|
|
4711
|
+
schemaName,
|
|
4712
|
+
includeAllConstraints: true
|
|
4713
|
+
})
|
|
4714
|
+
);
|
|
4715
|
+
}
|
|
4716
|
+
for (const idx of _ChannelsPG.getDefaultIndexDefs(schemaPrefix)) {
|
|
4717
|
+
statements.push(generateIndexSQL(idx, schemaName));
|
|
4718
|
+
}
|
|
4719
|
+
return statements;
|
|
4720
|
+
}
|
|
4721
|
+
getDefaultIndexDefinitions() {
|
|
4722
|
+
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
4723
|
+
return _ChannelsPG.getDefaultIndexDefs(schemaPrefix);
|
|
4724
|
+
}
|
|
4725
|
+
async createDefaultIndexes() {
|
|
4726
|
+
if (this.#skipDefaultIndexes) return;
|
|
4727
|
+
for (const indexDef of this.getDefaultIndexDefinitions()) {
|
|
4728
|
+
try {
|
|
4729
|
+
await this.#db.createIndex(indexDef);
|
|
4730
|
+
} catch (error) {
|
|
4731
|
+
this.logger?.warn?.(`Failed to create index ${indexDef.name}:`, error);
|
|
4732
|
+
}
|
|
4733
|
+
}
|
|
4734
|
+
}
|
|
4735
|
+
async createCustomIndexes() {
|
|
4736
|
+
if (!this.#indexes || this.#indexes.length === 0) return;
|
|
4737
|
+
for (const indexDef of this.#indexes) {
|
|
4738
|
+
try {
|
|
4739
|
+
await this.#db.createIndex(indexDef);
|
|
4740
|
+
} catch (error) {
|
|
4741
|
+
this.logger?.warn?.(`Failed to create custom index ${indexDef.name}:`, error);
|
|
4742
|
+
}
|
|
4743
|
+
}
|
|
4744
|
+
}
|
|
4745
|
+
async dangerouslyClearAll() {
|
|
4746
|
+
await this.#db.clearTable({ tableName: storage.TABLE_CHANNEL_INSTALLATIONS });
|
|
4747
|
+
await this.#db.clearTable({ tableName: storage.TABLE_CHANNEL_CONFIG });
|
|
4748
|
+
}
|
|
4749
|
+
async saveInstallation(installation) {
|
|
4750
|
+
const schemaName = getSchemaName2(this.#schema);
|
|
4751
|
+
const tableName = getTableName2({ indexName: storage.TABLE_CHANNEL_INSTALLATIONS, schemaName });
|
|
4752
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
4753
|
+
await this.#db.client.none(
|
|
4754
|
+
`INSERT INTO ${tableName} ("id", "platform", "agentId", "status", "webhookId", "data", "configHash", "error", "createdAt", "updatedAt")
|
|
4755
|
+
VALUES ($1, $2, $3, $4, $5, $6::jsonb, $7, $8, $9, $10)
|
|
4756
|
+
ON CONFLICT ("id") DO UPDATE SET
|
|
4757
|
+
"platform" = EXCLUDED."platform",
|
|
4758
|
+
"agentId" = EXCLUDED."agentId",
|
|
4759
|
+
"status" = EXCLUDED."status",
|
|
4760
|
+
"webhookId" = EXCLUDED."webhookId",
|
|
4761
|
+
"data" = EXCLUDED."data",
|
|
4762
|
+
"configHash" = EXCLUDED."configHash",
|
|
4763
|
+
"error" = EXCLUDED."error",
|
|
4764
|
+
"updatedAt" = EXCLUDED."updatedAt"`,
|
|
4765
|
+
[
|
|
4766
|
+
installation.id,
|
|
4767
|
+
installation.platform,
|
|
4768
|
+
installation.agentId,
|
|
4769
|
+
installation.status,
|
|
4770
|
+
installation.webhookId ?? null,
|
|
4771
|
+
JSON.stringify(installation.data),
|
|
4772
|
+
installation.configHash ?? null,
|
|
4773
|
+
installation.error ?? null,
|
|
4774
|
+
installation.createdAt?.toISOString() ?? now,
|
|
4775
|
+
now
|
|
4776
|
+
]
|
|
4777
|
+
);
|
|
4778
|
+
}
|
|
4779
|
+
async getInstallation(id) {
|
|
4780
|
+
const schemaName = getSchemaName2(this.#schema);
|
|
4781
|
+
const tableName = getTableName2({ indexName: storage.TABLE_CHANNEL_INSTALLATIONS, schemaName });
|
|
4782
|
+
const row = await this.#db.client.oneOrNone(`SELECT * FROM ${tableName} WHERE "id" = $1`, [id]);
|
|
4783
|
+
return row ? this.#parseInstallationRow(row) : null;
|
|
4784
|
+
}
|
|
4785
|
+
async getInstallationByAgent(platform, agentId) {
|
|
4786
|
+
const schemaName = getSchemaName2(this.#schema);
|
|
4787
|
+
const tableName = getTableName2({ indexName: storage.TABLE_CHANNEL_INSTALLATIONS, schemaName });
|
|
4788
|
+
const row = await this.#db.client.oneOrNone(
|
|
4789
|
+
`SELECT * FROM ${tableName} WHERE "platform" = $1 AND "agentId" = $2 ORDER BY CASE "status" WHEN 'active' THEN 0 WHEN 'pending' THEN 1 ELSE 2 END, "updatedAt" DESC LIMIT 1`,
|
|
4790
|
+
[platform, agentId]
|
|
4791
|
+
);
|
|
4792
|
+
return row ? this.#parseInstallationRow(row) : null;
|
|
4793
|
+
}
|
|
4794
|
+
async getInstallationByWebhookId(webhookId) {
|
|
4795
|
+
const schemaName = getSchemaName2(this.#schema);
|
|
4796
|
+
const tableName = getTableName2({ indexName: storage.TABLE_CHANNEL_INSTALLATIONS, schemaName });
|
|
4797
|
+
const row = await this.#db.client.oneOrNone(`SELECT * FROM ${tableName} WHERE "webhookId" = $1`, [webhookId]);
|
|
4798
|
+
return row ? this.#parseInstallationRow(row) : null;
|
|
4799
|
+
}
|
|
4800
|
+
async listInstallations(platform) {
|
|
4801
|
+
const schemaName = getSchemaName2(this.#schema);
|
|
4802
|
+
const tableName = getTableName2({ indexName: storage.TABLE_CHANNEL_INSTALLATIONS, schemaName });
|
|
4803
|
+
const rows = await this.#db.client.manyOrNone(
|
|
4804
|
+
`SELECT * FROM ${tableName} WHERE "platform" = $1 ORDER BY "createdAt" DESC`,
|
|
4805
|
+
[platform]
|
|
4806
|
+
);
|
|
4807
|
+
return rows.map((row) => this.#parseInstallationRow(row));
|
|
4808
|
+
}
|
|
4809
|
+
async deleteInstallation(id) {
|
|
4810
|
+
const schemaName = getSchemaName2(this.#schema);
|
|
4811
|
+
const tableName = getTableName2({ indexName: storage.TABLE_CHANNEL_INSTALLATIONS, schemaName });
|
|
4812
|
+
await this.#db.client.none(`DELETE FROM ${tableName} WHERE "id" = $1`, [id]);
|
|
4813
|
+
}
|
|
4814
|
+
async saveConfig(config) {
|
|
4815
|
+
const schemaName = getSchemaName2(this.#schema);
|
|
4816
|
+
const tableName = getTableName2({ indexName: storage.TABLE_CHANNEL_CONFIG, schemaName });
|
|
4817
|
+
await this.#db.client.none(
|
|
4818
|
+
`INSERT INTO ${tableName} ("platform", "data", "updatedAt")
|
|
4819
|
+
VALUES ($1, $2::jsonb, $3)
|
|
4820
|
+
ON CONFLICT ("platform") DO UPDATE SET
|
|
4821
|
+
"data" = EXCLUDED."data",
|
|
4822
|
+
"updatedAt" = EXCLUDED."updatedAt"`,
|
|
4823
|
+
[config.platform, JSON.stringify(config.data), config.updatedAt.toISOString()]
|
|
4824
|
+
);
|
|
4825
|
+
}
|
|
4826
|
+
async getConfig(platform) {
|
|
4827
|
+
const schemaName = getSchemaName2(this.#schema);
|
|
4828
|
+
const tableName = getTableName2({ indexName: storage.TABLE_CHANNEL_CONFIG, schemaName });
|
|
4829
|
+
const row = await this.#db.client.oneOrNone(`SELECT * FROM ${tableName} WHERE "platform" = $1`, [platform]);
|
|
4830
|
+
if (!row) return null;
|
|
4831
|
+
return {
|
|
4832
|
+
platform: row.platform,
|
|
4833
|
+
data: typeof row.data === "string" ? JSON.parse(row.data) : row.data,
|
|
4834
|
+
updatedAt: new Date(row.updatedAt)
|
|
4835
|
+
};
|
|
4836
|
+
}
|
|
4837
|
+
async deleteConfig(platform) {
|
|
4838
|
+
const schemaName = getSchemaName2(this.#schema);
|
|
4839
|
+
const tableName = getTableName2({ indexName: storage.TABLE_CHANNEL_CONFIG, schemaName });
|
|
4840
|
+
await this.#db.client.none(`DELETE FROM ${tableName} WHERE "platform" = $1`, [platform]);
|
|
4841
|
+
}
|
|
4842
|
+
#parseInstallationRow(row) {
|
|
4843
|
+
return {
|
|
4844
|
+
id: row.id,
|
|
4845
|
+
platform: row.platform,
|
|
4846
|
+
agentId: row.agentId,
|
|
4847
|
+
status: row.status,
|
|
4848
|
+
webhookId: row.webhookId || void 0,
|
|
4849
|
+
data: typeof row.data === "string" ? JSON.parse(row.data) : row.data,
|
|
4850
|
+
configHash: row.configHash || void 0,
|
|
4851
|
+
error: row.error || void 0,
|
|
4852
|
+
createdAt: row.createdAt instanceof Date ? row.createdAt : new Date(row.createdAt),
|
|
4853
|
+
updatedAt: row.updatedAt instanceof Date ? row.updatedAt : new Date(row.updatedAt)
|
|
4854
|
+
};
|
|
4855
|
+
}
|
|
4856
|
+
};
|
|
4661
4857
|
function jsonbArg(value) {
|
|
4662
4858
|
return value === void 0 || value === null ? null : JSON.stringify(value);
|
|
4663
4859
|
}
|
|
@@ -12930,7 +13126,7 @@ function getTableName6({ indexName, schemaName }) {
|
|
|
12930
13126
|
return schemaName ? `${schemaName}.${quotedIndexName}` : quotedIndexName;
|
|
12931
13127
|
}
|
|
12932
13128
|
function sanitizeJsonForPg(jsonString) {
|
|
12933
|
-
return jsonString.replace(
|
|
13129
|
+
return jsonString.replace(/\\\\?u(0000|[Dd][89A-Fa-f][0-9A-Fa-f]{2})/g, "").replace(/(^|[^\\])(\\(?!["\\/bfnrtu]))/g, "$1\\\\");
|
|
12934
13130
|
}
|
|
12935
13131
|
var WorkflowsPG = class _WorkflowsPG extends storage.WorkflowsStorage {
|
|
12936
13132
|
#db;
|
|
@@ -14034,7 +14230,8 @@ var ALL_DOMAINS = [
|
|
|
14034
14230
|
WorkflowsPG,
|
|
14035
14231
|
DatasetsPG,
|
|
14036
14232
|
ExperimentsPG,
|
|
14037
|
-
BackgroundTasksPG
|
|
14233
|
+
BackgroundTasksPG,
|
|
14234
|
+
ChannelsPG
|
|
14038
14235
|
];
|
|
14039
14236
|
function exportSchemas(schemaName) {
|
|
14040
14237
|
const statements = [];
|
|
@@ -14089,7 +14286,8 @@ var PostgresStore = class extends storage.MastraCompositeStore {
|
|
|
14089
14286
|
blobs: new BlobsPG(domainConfig),
|
|
14090
14287
|
datasets: new DatasetsPG(domainConfig),
|
|
14091
14288
|
experiments: new ExperimentsPG(domainConfig),
|
|
14092
|
-
backgroundTasks: new BackgroundTasksPG(domainConfig)
|
|
14289
|
+
backgroundTasks: new BackgroundTasksPG(domainConfig),
|
|
14290
|
+
channels: new ChannelsPG(domainConfig)
|
|
14093
14291
|
};
|
|
14094
14292
|
} catch (e) {
|
|
14095
14293
|
throw new error.MastraError(
|
|
@@ -14281,6 +14479,7 @@ Example Complex Query:
|
|
|
14281
14479
|
exports.AgentsPG = AgentsPG;
|
|
14282
14480
|
exports.BackgroundTasksPG = BackgroundTasksPG;
|
|
14283
14481
|
exports.BlobsPG = BlobsPG;
|
|
14482
|
+
exports.ChannelsPG = ChannelsPG;
|
|
14284
14483
|
exports.DatasetsPG = DatasetsPG;
|
|
14285
14484
|
exports.ExperimentsPG = ExperimentsPG;
|
|
14286
14485
|
exports.MCPClientsPG = MCPClientsPG;
|