@linked-claims/simple-store-prisma 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/README.md +66 -0
- package/dist/index.d.mts +50 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +26 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# @linked-claims/simple-store-prisma
|
|
2
|
+
|
|
3
|
+
Prisma-backed [`SimpleStore`](https://github.com/bluesky-social/atproto/tree/main/packages/simple-store) for ATProto OAuth — drop-in persistent storage for `NodeOAuthClient` state and sessions.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @linked-claims/simple-store-prisma
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Prisma schema
|
|
12
|
+
|
|
13
|
+
Add two models (or rename to taste) with the shape `{ key: String @id, value: Json }`:
|
|
14
|
+
|
|
15
|
+
```prisma
|
|
16
|
+
model OauthState {
|
|
17
|
+
key String @id
|
|
18
|
+
value Json
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
model OauthSession {
|
|
22
|
+
key String @id
|
|
23
|
+
value Json
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Then run:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npx prisma migrate dev --name add-oauth-stores
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { createPrismaSimpleStore } from '@linked-claims/simple-store-prisma'
|
|
37
|
+
import { NodeOAuthClient } from '@atproto/oauth-client-node'
|
|
38
|
+
import { PrismaClient } from '@prisma/client'
|
|
39
|
+
|
|
40
|
+
const prisma = new PrismaClient()
|
|
41
|
+
|
|
42
|
+
const client = new NodeOAuthClient({
|
|
43
|
+
stateStore: createPrismaSimpleStore(prisma.oauthState),
|
|
44
|
+
sessionStore: createPrismaSimpleStore(prisma.oauthSession),
|
|
45
|
+
// ...other options
|
|
46
|
+
})
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## API
|
|
50
|
+
|
|
51
|
+
### `createPrismaSimpleStore<V>(delegate)`
|
|
52
|
+
|
|
53
|
+
Creates a `SimpleStore<string, V>` backed by a Prisma model delegate.
|
|
54
|
+
|
|
55
|
+
- **`get(key)`** — `findUnique` by key; returns `undefined` if missing
|
|
56
|
+
- **`set(key, value)`** — `upsert` (atomic insert-or-update)
|
|
57
|
+
- **`del(key)`** — `deleteMany` by key (no-op if missing)
|
|
58
|
+
- **`clear()`** — `deleteMany()` with no filter
|
|
59
|
+
|
|
60
|
+
### `PrismaJsonKvDelegate`
|
|
61
|
+
|
|
62
|
+
Minimal interface matching any Prisma delegate for a `{ key, value }` model. No dependency on `@prisma/client` — works with any Prisma version.
|
|
63
|
+
|
|
64
|
+
## License
|
|
65
|
+
|
|
66
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Value, SimpleStore } from '@atproto-labs/simple-store';
|
|
2
|
+
export { SimpleStore, Value } from '@atproto-labs/simple-store';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Minimal interface matching any Prisma delegate for a model with
|
|
6
|
+
* `{ key: String @id, value: Json }` columns.
|
|
7
|
+
*
|
|
8
|
+
* Works with any Prisma version — no dependency on `@prisma/client`.
|
|
9
|
+
*/
|
|
10
|
+
interface PrismaJsonKvDelegate {
|
|
11
|
+
findUnique(args: {
|
|
12
|
+
where: {
|
|
13
|
+
key: string;
|
|
14
|
+
};
|
|
15
|
+
}): Promise<{
|
|
16
|
+
key: string;
|
|
17
|
+
value: unknown;
|
|
18
|
+
} | null>;
|
|
19
|
+
upsert(args: {
|
|
20
|
+
where: {
|
|
21
|
+
key: string;
|
|
22
|
+
};
|
|
23
|
+
create: {
|
|
24
|
+
key: string;
|
|
25
|
+
value: unknown;
|
|
26
|
+
};
|
|
27
|
+
update: {
|
|
28
|
+
value: unknown;
|
|
29
|
+
};
|
|
30
|
+
}): Promise<unknown>;
|
|
31
|
+
deleteMany(args?: {
|
|
32
|
+
where?: {
|
|
33
|
+
key: string;
|
|
34
|
+
};
|
|
35
|
+
}): Promise<unknown>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Creates a `SimpleStore<string, V>` backed by a Prisma model delegate.
|
|
39
|
+
*
|
|
40
|
+
* The delegate must point to a table with `{ key: String @id, value: Json }`.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* const stateStore = createPrismaSimpleStore<NodeSavedState>(prisma.oauthState)
|
|
45
|
+
* const sessionStore = createPrismaSimpleStore<NodeSavedSession>(prisma.oauthSession)
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
declare function createPrismaSimpleStore<V extends Value>(delegate: PrismaJsonKvDelegate): SimpleStore<string, V>;
|
|
49
|
+
|
|
50
|
+
export { type PrismaJsonKvDelegate, createPrismaSimpleStore };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Value, SimpleStore } from '@atproto-labs/simple-store';
|
|
2
|
+
export { SimpleStore, Value } from '@atproto-labs/simple-store';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Minimal interface matching any Prisma delegate for a model with
|
|
6
|
+
* `{ key: String @id, value: Json }` columns.
|
|
7
|
+
*
|
|
8
|
+
* Works with any Prisma version — no dependency on `@prisma/client`.
|
|
9
|
+
*/
|
|
10
|
+
interface PrismaJsonKvDelegate {
|
|
11
|
+
findUnique(args: {
|
|
12
|
+
where: {
|
|
13
|
+
key: string;
|
|
14
|
+
};
|
|
15
|
+
}): Promise<{
|
|
16
|
+
key: string;
|
|
17
|
+
value: unknown;
|
|
18
|
+
} | null>;
|
|
19
|
+
upsert(args: {
|
|
20
|
+
where: {
|
|
21
|
+
key: string;
|
|
22
|
+
};
|
|
23
|
+
create: {
|
|
24
|
+
key: string;
|
|
25
|
+
value: unknown;
|
|
26
|
+
};
|
|
27
|
+
update: {
|
|
28
|
+
value: unknown;
|
|
29
|
+
};
|
|
30
|
+
}): Promise<unknown>;
|
|
31
|
+
deleteMany(args?: {
|
|
32
|
+
where?: {
|
|
33
|
+
key: string;
|
|
34
|
+
};
|
|
35
|
+
}): Promise<unknown>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Creates a `SimpleStore<string, V>` backed by a Prisma model delegate.
|
|
39
|
+
*
|
|
40
|
+
* The delegate must point to a table with `{ key: String @id, value: Json }`.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* const stateStore = createPrismaSimpleStore<NodeSavedState>(prisma.oauthState)
|
|
45
|
+
* const sessionStore = createPrismaSimpleStore<NodeSavedSession>(prisma.oauthSession)
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
declare function createPrismaSimpleStore<V extends Value>(delegate: PrismaJsonKvDelegate): SimpleStore<string, V>;
|
|
49
|
+
|
|
50
|
+
export { type PrismaJsonKvDelegate, createPrismaSimpleStore };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/prisma-simple-store.ts
|
|
4
|
+
function createPrismaSimpleStore(delegate) {
|
|
5
|
+
return {
|
|
6
|
+
async get(key) {
|
|
7
|
+
const row = await delegate.findUnique({ where: { key } });
|
|
8
|
+
return row ? row.value : void 0;
|
|
9
|
+
},
|
|
10
|
+
async set(key, value) {
|
|
11
|
+
await delegate.upsert({
|
|
12
|
+
where: { key },
|
|
13
|
+
create: { key, value },
|
|
14
|
+
update: { value }
|
|
15
|
+
});
|
|
16
|
+
},
|
|
17
|
+
async del(key) {
|
|
18
|
+
await delegate.deleteMany({ where: { key } });
|
|
19
|
+
},
|
|
20
|
+
async clear() {
|
|
21
|
+
await delegate.deleteMany();
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
exports.createPrismaSimpleStore = createPrismaSimpleStore;
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/prisma-simple-store.ts"],"names":[],"mappings":";;;AAmCO,SAAS,wBACd,QAAA,EACwB;AACxB,EAAA,OAAO;AAAA,IACL,MAAM,IAAI,GAAA,EAAqC;AAC7C,MAAA,MAAM,GAAA,GAAM,MAAM,QAAA,CAAS,UAAA,CAAW,EAAE,KAAA,EAAO,EAAE,GAAA,EAAI,EAAG,CAAA;AACxD,MAAA,OAAO,GAAA,GAAO,IAAI,KAAA,GAAc,MAAA;AAAA,IAClC,CAAA;AAAA,IAEA,MAAM,GAAA,CAAI,GAAA,EAAa,KAAA,EAAyB;AAC9C,MAAA,MAAM,SAAS,MAAA,CAAO;AAAA,QACpB,KAAA,EAAO,EAAE,GAAA,EAAI;AAAA,QACb,MAAA,EAAQ,EAAE,GAAA,EAAK,KAAA,EAAM;AAAA,QACrB,MAAA,EAAQ,EAAE,KAAA;AAAM,OACjB,CAAA;AAAA,IACH,CAAA;AAAA,IAEA,MAAM,IAAI,GAAA,EAA4B;AACpC,MAAA,MAAM,SAAS,UAAA,CAAW,EAAE,OAAO,EAAE,GAAA,IAAO,CAAA;AAAA,IAC9C,CAAA;AAAA,IAEA,MAAM,KAAA,GAAuB;AAC3B,MAAA,MAAM,SAAS,UAAA,EAAW;AAAA,IAC5B;AAAA,GACF;AACF","file":"index.js","sourcesContent":["import type { SimpleStore, Value } from '@atproto-labs/simple-store'\n\n/**\n * Minimal interface matching any Prisma delegate for a model with\n * `{ key: String @id, value: Json }` columns.\n *\n * Works with any Prisma version — no dependency on `@prisma/client`.\n */\nexport interface PrismaJsonKvDelegate {\n findUnique(args: {\n where: { key: string }\n }): Promise<{ key: string; value: unknown } | null>\n\n upsert(args: {\n where: { key: string }\n create: { key: string; value: unknown }\n update: { value: unknown }\n }): Promise<unknown>\n\n deleteMany(args?: {\n where?: { key: string }\n }): Promise<unknown>\n}\n\n/**\n * Creates a `SimpleStore<string, V>` backed by a Prisma model delegate.\n *\n * The delegate must point to a table with `{ key: String @id, value: Json }`.\n *\n * @example\n * ```ts\n * const stateStore = createPrismaSimpleStore<NodeSavedState>(prisma.oauthState)\n * const sessionStore = createPrismaSimpleStore<NodeSavedSession>(prisma.oauthSession)\n * ```\n */\nexport function createPrismaSimpleStore<V extends Value>(\n delegate: PrismaJsonKvDelegate,\n): SimpleStore<string, V> {\n return {\n async get(key: string): Promise<V | undefined> {\n const row = await delegate.findUnique({ where: { key } })\n return row ? (row.value as V) : undefined\n },\n\n async set(key: string, value: V): Promise<void> {\n await delegate.upsert({\n where: { key },\n create: { key, value },\n update: { value },\n })\n },\n\n async del(key: string): Promise<void> {\n await delegate.deleteMany({ where: { key } })\n },\n\n async clear(): Promise<void> {\n await delegate.deleteMany()\n },\n }\n}\n"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// src/prisma-simple-store.ts
|
|
2
|
+
function createPrismaSimpleStore(delegate) {
|
|
3
|
+
return {
|
|
4
|
+
async get(key) {
|
|
5
|
+
const row = await delegate.findUnique({ where: { key } });
|
|
6
|
+
return row ? row.value : void 0;
|
|
7
|
+
},
|
|
8
|
+
async set(key, value) {
|
|
9
|
+
await delegate.upsert({
|
|
10
|
+
where: { key },
|
|
11
|
+
create: { key, value },
|
|
12
|
+
update: { value }
|
|
13
|
+
});
|
|
14
|
+
},
|
|
15
|
+
async del(key) {
|
|
16
|
+
await delegate.deleteMany({ where: { key } });
|
|
17
|
+
},
|
|
18
|
+
async clear() {
|
|
19
|
+
await delegate.deleteMany();
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { createPrismaSimpleStore };
|
|
25
|
+
//# sourceMappingURL=index.mjs.map
|
|
26
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/prisma-simple-store.ts"],"names":[],"mappings":";AAmCO,SAAS,wBACd,QAAA,EACwB;AACxB,EAAA,OAAO;AAAA,IACL,MAAM,IAAI,GAAA,EAAqC;AAC7C,MAAA,MAAM,GAAA,GAAM,MAAM,QAAA,CAAS,UAAA,CAAW,EAAE,KAAA,EAAO,EAAE,GAAA,EAAI,EAAG,CAAA;AACxD,MAAA,OAAO,GAAA,GAAO,IAAI,KAAA,GAAc,MAAA;AAAA,IAClC,CAAA;AAAA,IAEA,MAAM,GAAA,CAAI,GAAA,EAAa,KAAA,EAAyB;AAC9C,MAAA,MAAM,SAAS,MAAA,CAAO;AAAA,QACpB,KAAA,EAAO,EAAE,GAAA,EAAI;AAAA,QACb,MAAA,EAAQ,EAAE,GAAA,EAAK,KAAA,EAAM;AAAA,QACrB,MAAA,EAAQ,EAAE,KAAA;AAAM,OACjB,CAAA;AAAA,IACH,CAAA;AAAA,IAEA,MAAM,IAAI,GAAA,EAA4B;AACpC,MAAA,MAAM,SAAS,UAAA,CAAW,EAAE,OAAO,EAAE,GAAA,IAAO,CAAA;AAAA,IAC9C,CAAA;AAAA,IAEA,MAAM,KAAA,GAAuB;AAC3B,MAAA,MAAM,SAAS,UAAA,EAAW;AAAA,IAC5B;AAAA,GACF;AACF","file":"index.mjs","sourcesContent":["import type { SimpleStore, Value } from '@atproto-labs/simple-store'\n\n/**\n * Minimal interface matching any Prisma delegate for a model with\n * `{ key: String @id, value: Json }` columns.\n *\n * Works with any Prisma version — no dependency on `@prisma/client`.\n */\nexport interface PrismaJsonKvDelegate {\n findUnique(args: {\n where: { key: string }\n }): Promise<{ key: string; value: unknown } | null>\n\n upsert(args: {\n where: { key: string }\n create: { key: string; value: unknown }\n update: { value: unknown }\n }): Promise<unknown>\n\n deleteMany(args?: {\n where?: { key: string }\n }): Promise<unknown>\n}\n\n/**\n * Creates a `SimpleStore<string, V>` backed by a Prisma model delegate.\n *\n * The delegate must point to a table with `{ key: String @id, value: Json }`.\n *\n * @example\n * ```ts\n * const stateStore = createPrismaSimpleStore<NodeSavedState>(prisma.oauthState)\n * const sessionStore = createPrismaSimpleStore<NodeSavedSession>(prisma.oauthSession)\n * ```\n */\nexport function createPrismaSimpleStore<V extends Value>(\n delegate: PrismaJsonKvDelegate,\n): SimpleStore<string, V> {\n return {\n async get(key: string): Promise<V | undefined> {\n const row = await delegate.findUnique({ where: { key } })\n return row ? (row.value as V) : undefined\n },\n\n async set(key: string, value: V): Promise<void> {\n await delegate.upsert({\n where: { key },\n create: { key, value },\n update: { value },\n })\n },\n\n async del(key: string): Promise<void> {\n await delegate.deleteMany({ where: { key } })\n },\n\n async clear(): Promise<void> {\n await delegate.deleteMany()\n },\n }\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@linked-claims/simple-store-prisma",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Prisma-backed SimpleStore for ATProto OAuth (state + session persistence)",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsup",
|
|
22
|
+
"dev": "tsup --watch",
|
|
23
|
+
"test": "vitest",
|
|
24
|
+
"type-check": "tsc --noEmit",
|
|
25
|
+
"lint": "eslint src --ext .ts",
|
|
26
|
+
"format": "prettier --write 'src/**/*.ts'",
|
|
27
|
+
"prepublishOnly": "npm run build"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"atproto",
|
|
31
|
+
"bluesky",
|
|
32
|
+
"prisma",
|
|
33
|
+
"oauth",
|
|
34
|
+
"simple-store",
|
|
35
|
+
"linkedclaims"
|
|
36
|
+
],
|
|
37
|
+
"author": "",
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "https://github.com/Cooperation-org/simple-store-prisma.git"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@atproto-labs/simple-store": "^0.3.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/node": "^22.10.5",
|
|
51
|
+
"tsup": "^8.3.5",
|
|
52
|
+
"typescript": "^5.7.2",
|
|
53
|
+
"vitest": "^2.1.8"
|
|
54
|
+
},
|
|
55
|
+
"engines": {
|
|
56
|
+
"node": ">=18.0.0"
|
|
57
|
+
}
|
|
58
|
+
}
|