@mastra/spanner 0.0.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/CHANGELOG.md +29 -0
- package/LICENSE.md +30 -0
- package/README.md +108 -0
- package/package.json +68 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# @mastra/spanner
|
|
2
|
+
|
|
3
|
+
## 2.0.0-alpha.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- Added a Google Cloud Spanner storage adapter (`@mastra/spanner`) targeting the GoogleSQL dialect. The adapter implements the `memory`, `workflows`, `scores`, `backgroundTasks`, `agents`, `mcpClients`, `mcpServers`, `skills`, `blobs`, `promptBlocks`, `scorerDefinitions`, `schedules`, and `observability` storage domains and works with both managed Cloud Spanner instances and the local Spanner emulator. The `schedules` domain plugs into Mastra's built-in `WorkflowScheduler` for cron-driven workflow triggers, and the `observability` domain persists AI tracing spans in `mastra_ai_spans` to power the Studio traces UI (JSON containment filters compile to per-key `JSON_VALUE` equality and `EXISTS` over `JSON_QUERY_ARRAY` since Spanner has no `@>` operator). ([#15955](https://github.com/mastra-ai/mastra/pull/15955))
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { SpannerStore } from '@mastra/spanner';
|
|
11
|
+
|
|
12
|
+
const storage = new SpannerStore({
|
|
13
|
+
id: 'spanner-storage',
|
|
14
|
+
projectId: process.env.SPANNER_PROJECT_ID!,
|
|
15
|
+
instanceId: process.env.SPANNER_INSTANCE_ID!,
|
|
16
|
+
databaseId: process.env.SPANNER_DATABASE_ID!,
|
|
17
|
+
});
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [[`0cbece9`](https://github.com/mastra-ai/mastra/commit/0cbece9d832cb134a74cdbf3682d390a058215a4), [`7dfe1bc`](https://github.com/mastra-ai/mastra/commit/7dfe1bcfe71d261a6fd6bbf29b1dec49d78fb98f), [`70cb714`](https://github.com/mastra-ai/mastra/commit/70cb7149c8f16f478e15b58498254a53181750a4), [`7f9da22`](https://github.com/mastra-ai/mastra/commit/7f9da22efd5aa595e138a31de55a5f0f2f28b33d)]:
|
|
23
|
+
- @mastra/core@1.37.0-alpha.6
|
|
24
|
+
|
|
25
|
+
## 1.0.0
|
|
26
|
+
|
|
27
|
+
### Major Changes
|
|
28
|
+
|
|
29
|
+
- Initial stable release of the Google Cloud Spanner storage adapter for Mastra. Supports the GoogleSQL dialect with full storage-domain parity: `memory`, `workflows`, `scores`, `backgroundTasks`, `agents`, `mcpClients`, `mcpServers`, `skills`, `blobs`, `promptBlocks`, `scorerDefinitions`, `schedules` (cron-driven workflow triggers consumed by `WorkflowScheduler`), and `observability` (AI tracing spans persisted in `mastra_ai_spans` with the full trace read/write surface). Works against managed Spanner instances and the local Spanner emulator.
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Portions of this software are licensed as follows:
|
|
2
|
+
|
|
3
|
+
- All content that resides under any directory named "ee/" within this
|
|
4
|
+
repository, including but not limited to:
|
|
5
|
+
- `packages/core/src/auth/ee/`
|
|
6
|
+
- `packages/server/src/server/auth/ee/`
|
|
7
|
+
is licensed under the license defined in `ee/LICENSE`.
|
|
8
|
+
|
|
9
|
+
- All third-party components incorporated into the Mastra Software are
|
|
10
|
+
licensed under the original license provided by the owner of the
|
|
11
|
+
applicable component.
|
|
12
|
+
|
|
13
|
+
- Content outside of the above-mentioned directories or restrictions is
|
|
14
|
+
available under the "Apache License 2.0" as defined below.
|
|
15
|
+
|
|
16
|
+
# Apache License 2.0
|
|
17
|
+
|
|
18
|
+
Copyright (c) 2025 Kepler Software, Inc.
|
|
19
|
+
|
|
20
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
21
|
+
you may not use this file except in compliance with the License.
|
|
22
|
+
You may obtain a copy of the License at
|
|
23
|
+
|
|
24
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
25
|
+
|
|
26
|
+
Unless required by applicable law or agreed to in writing, software
|
|
27
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
28
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
29
|
+
See the License for the specific language governing permissions and
|
|
30
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# @mastra/spanner
|
|
2
|
+
|
|
3
|
+
Google Cloud Spanner storage adapter for Mastra. Implements the GoogleSQL dialect.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @mastra/spanner
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Prerequisites
|
|
12
|
+
|
|
13
|
+
- A Cloud Spanner instance and database created with the GoogleSQL dialect.
|
|
14
|
+
- Application credentials available to the Node.js client (Application Default Credentials, service account JSON, or `GOOGLE_APPLICATION_CREDENTIALS`).
|
|
15
|
+
- For local development, the [Spanner emulator](https://cloud.google.com/spanner/docs/emulator) running on `localhost:9010`.
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### Connecting to a managed Cloud Spanner database
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { SpannerStore } from '@mastra/spanner';
|
|
23
|
+
|
|
24
|
+
const store = new SpannerStore({
|
|
25
|
+
id: 'spanner-storage',
|
|
26
|
+
projectId: 'my-gcp-project',
|
|
27
|
+
instanceId: 'my-instance',
|
|
28
|
+
databaseId: 'mastra',
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Connecting to the Spanner emulator
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
process.env.SPANNER_EMULATOR_HOST = 'localhost:9010';
|
|
36
|
+
|
|
37
|
+
const store = new SpannerStore({
|
|
38
|
+
id: 'spanner-storage',
|
|
39
|
+
projectId: 'test-project',
|
|
40
|
+
instanceId: 'test-instance',
|
|
41
|
+
databaseId: 'test-db',
|
|
42
|
+
// Skip auth checks when talking to the emulator
|
|
43
|
+
spannerOptions: { servicePath: 'localhost', port: 9010, sslCreds: undefined },
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The store automatically detects the `SPANNER_EMULATOR_HOST` env var and uses
|
|
48
|
+
unauthenticated channels when set. You can also create the instance/database
|
|
49
|
+
through the emulator using the standard `gcloud` CLI.
|
|
50
|
+
|
|
51
|
+
### Pre-configured client or database
|
|
52
|
+
|
|
53
|
+
If you already manage a Spanner client elsewhere, pass the database directly:
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import { Spanner } from '@google-cloud/spanner';
|
|
57
|
+
import { SpannerStore } from '@mastra/spanner';
|
|
58
|
+
|
|
59
|
+
const spanner = new Spanner({ projectId: 'my-project' });
|
|
60
|
+
const database = spanner.instance('my-instance').database('mastra');
|
|
61
|
+
|
|
62
|
+
const store = new SpannerStore({
|
|
63
|
+
id: 'spanner-storage',
|
|
64
|
+
database,
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Notes on the GoogleSQL dialect
|
|
69
|
+
|
|
70
|
+
- Tables are created with the GoogleSQL dialect using `STRING(MAX)` for text/JSON
|
|
71
|
+
payloads, `INT64`, `FLOAT64`, `BOOL` and `TIMESTAMP`.
|
|
72
|
+
- DDL is applied through `database.updateSchema(...)` (long-running operation).
|
|
73
|
+
- Upserts use `INSERT OR UPDATE`. Deletes use `DELETE WHERE TRUE` (Spanner has no
|
|
74
|
+
`TRUNCATE`).
|
|
75
|
+
- Identifiers are quoted with backticks.
|
|
76
|
+
- The adapter does not use named schemas. Use a dedicated database for isolation.
|
|
77
|
+
|
|
78
|
+
## Storage domains
|
|
79
|
+
|
|
80
|
+
The adapter implements the following storage domains:
|
|
81
|
+
|
|
82
|
+
- `memory`: threads, messages, resources
|
|
83
|
+
- `workflows`: workflow snapshots and run state
|
|
84
|
+
- `scores`: evaluation scores
|
|
85
|
+
- `backgroundTasks`: background tool execution state
|
|
86
|
+
- `agents`: thin agent records and versioned config snapshots
|
|
87
|
+
- `mcpClients`: MCP client configurations with version history
|
|
88
|
+
- `mcpServers`: MCP server configurations with version history
|
|
89
|
+
- `skills`: skill records and versioned skill snapshots
|
|
90
|
+
- `blobs`: content-addressable blob store (used by the skills domain)
|
|
91
|
+
- `promptBlocks`: prompt block records and versioned template/rules snapshots
|
|
92
|
+
- `scorerDefinitions`: scorer definition records and versioned scoring-config snapshots
|
|
93
|
+
- `schedules`: cron-driven workflow schedules and trigger history (consumed by `WorkflowScheduler`)
|
|
94
|
+
- `observability`: AI tracing spans (per-trace and per-span records) used by the Studio traces UI
|
|
95
|
+
|
|
96
|
+
## Testing locally with the emulator
|
|
97
|
+
|
|
98
|
+
Start the emulator:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
docker compose up -d
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Then run the tests:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
ENABLE_TESTS=true pnpm test
|
|
108
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mastra/spanner",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Google Cloud Spanner provider for Mastra - db storage capabilities (GoogleSQL dialect)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.cjs"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
21
|
+
"license": "Apache-2.0",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@google-cloud/spanner": "^8.6.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/node": "22.19.15",
|
|
27
|
+
"@vitest/coverage-v8": "4.1.5",
|
|
28
|
+
"@vitest/ui": "4.1.5",
|
|
29
|
+
"eslint": "^10.2.1",
|
|
30
|
+
"tsup": "^8.5.1",
|
|
31
|
+
"typescript": "^6.0.3",
|
|
32
|
+
"vitest": "4.1.5",
|
|
33
|
+
"@internal/lint": "0.0.97",
|
|
34
|
+
"@mastra/core": "1.37.0-alpha.7",
|
|
35
|
+
"@internal/storage-test-utils": "0.0.93",
|
|
36
|
+
"@internal/types-builder": "0.0.72"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"@mastra/core": ">=1.0.0-0 <2.0.0-0"
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"dist",
|
|
43
|
+
"CHANGELOG.md"
|
|
44
|
+
],
|
|
45
|
+
"homepage": "https://mastra.ai",
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "git+https://github.com/mastra-ai/mastra.git",
|
|
49
|
+
"directory": "stores/spanner"
|
|
50
|
+
},
|
|
51
|
+
"bugs": {
|
|
52
|
+
"url": "https://github.com/mastra-ai/mastra/issues"
|
|
53
|
+
},
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": ">=22.13.0"
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build:lib": "tsup --silent --config tsup.config.ts",
|
|
59
|
+
"build:watch": "tsup --watch --silent --config tsup.config.ts",
|
|
60
|
+
"pretest": "docker compose up -d && (for i in $(seq 1 30); do nc -z localhost 9010 && exit 0; sleep 1; done; echo 'Spanner emulator did not become ready on localhost:9010 within 30s' >&2; exit 1)",
|
|
61
|
+
"test": "vitest run",
|
|
62
|
+
"posttest": "docker compose down -v",
|
|
63
|
+
"pretest:watch": "docker compose up -d",
|
|
64
|
+
"test:watch": "vitest watch",
|
|
65
|
+
"posttest:watch": "docker compose down -v",
|
|
66
|
+
"lint": "eslint ."
|
|
67
|
+
}
|
|
68
|
+
}
|