@datar-platform/better-auth-dynamodb 0.1.0-alpha.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 +18 -0
- package/LICENSE +21 -0
- package/README.md +137 -0
- package/dist/adapter.d.ts +19 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +153 -0
- package/dist/adapter.js.map +1 -0
- package/dist/index-map.d.ts +33 -0
- package/dist/index-map.d.ts.map +1 -0
- package/dist/index-map.js +1 -0
- package/dist/index-map.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/pagination.d.ts +25 -0
- package/dist/pagination.d.ts.map +1 -0
- package/dist/pagination.js +86 -0
- package/dist/pagination.js.map +1 -0
- package/dist/planner.d.ts +36 -0
- package/dist/planner.d.ts.map +1 -0
- package/dist/planner.js +55 -0
- package/dist/planner.js.map +1 -0
- package/dist/stores/default/derive-index-map.d.ts +18 -0
- package/dist/stores/default/derive-index-map.d.ts.map +1 -0
- package/dist/stores/default/derive-index-map.js +46 -0
- package/dist/stores/default/derive-index-map.js.map +1 -0
- package/dist/stores/default/key-codec.d.ts +57 -0
- package/dist/stores/default/key-codec.d.ts.map +1 -0
- package/dist/stores/default/key-codec.js +106 -0
- package/dist/stores/default/key-codec.js.map +1 -0
- package/dist/stores/default/schema.d.ts +28 -0
- package/dist/stores/default/schema.d.ts.map +1 -0
- package/dist/stores/default/schema.js +91 -0
- package/dist/stores/default/schema.js.map +1 -0
- package/dist/stores/default/single-table-store.d.ts +26 -0
- package/dist/stores/default/single-table-store.d.ts.map +1 -0
- package/dist/stores/default/single-table-store.js +128 -0
- package/dist/stores/default/single-table-store.js.map +1 -0
- package/dist/types.d.ts +97 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/package.json +72 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { DBAdapterDebugLogOption } from "@better-auth/core/db/adapter";
|
|
2
|
+
import type { IndexMap } from "./index-map.js";
|
|
3
|
+
/** A single record as stored/returned. Better Auth handles field-level typing. */
|
|
4
|
+
export type StoreItem = Record<string, any>;
|
|
5
|
+
/** One page of a paginated query. `cursor` is opaque and store-defined. */
|
|
6
|
+
export interface QueryPage {
|
|
7
|
+
items: StoreItem[];
|
|
8
|
+
cursor?: unknown;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The storage seam. A `DynamoStore` knows how to persist and query records for
|
|
12
|
+
* a given model; it owns all physical key encoding. The generic adapter core
|
|
13
|
+
* drives it purely through logical index names + field values, so any store —
|
|
14
|
+
* the built-in single-table store or a custom one — plugs in the same way.
|
|
15
|
+
*
|
|
16
|
+
* Implementations should return the full item (including generated fields) from
|
|
17
|
+
* `put`/`update` so the adapter can hand it back to Better Auth.
|
|
18
|
+
*/
|
|
19
|
+
export interface DynamoStore {
|
|
20
|
+
/** Persist a new record and return it (with any store-generated fields). */
|
|
21
|
+
put(model: string, item: StoreItem): Promise<StoreItem>;
|
|
22
|
+
/** Fetch a single record by its primary `id`, or `null` if absent. */
|
|
23
|
+
getById(model: string, id: string): Promise<StoreItem | null>;
|
|
24
|
+
/** Patch the named fields on the record with the given `id` and return the new item. */
|
|
25
|
+
update(model: string, id: string, patch: StoreItem): Promise<StoreItem | null>;
|
|
26
|
+
/** Delete the record with the given `id`. No-op if it does not exist. */
|
|
27
|
+
deleteById(model: string, id: string): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Query a logical index. `key` holds the partition-key field values plus any
|
|
30
|
+
* leading sort-key field values the caller resolved. Returns one page; the
|
|
31
|
+
* core drains pages via `cursor` until exhausted.
|
|
32
|
+
*/
|
|
33
|
+
queryIndex(req: {
|
|
34
|
+
model: string;
|
|
35
|
+
index: string;
|
|
36
|
+
key: StoreItem;
|
|
37
|
+
limit?: number;
|
|
38
|
+
cursor?: unknown;
|
|
39
|
+
}): Promise<QueryPage>;
|
|
40
|
+
/**
|
|
41
|
+
* List every record of a model (the substitute for a full table scan when no
|
|
42
|
+
* index matches a query). Returns one page; the core drains via `cursor`.
|
|
43
|
+
*/
|
|
44
|
+
listByType(req: {
|
|
45
|
+
model: string;
|
|
46
|
+
limit?: number;
|
|
47
|
+
cursor?: unknown;
|
|
48
|
+
}): Promise<QueryPage>;
|
|
49
|
+
/**
|
|
50
|
+
* Optional fast count. Only used by the core when the query has no residual
|
|
51
|
+
* (in-memory) predicates. Return `null` to signal "no fast path, fall back to
|
|
52
|
+
* draining + counting".
|
|
53
|
+
*/
|
|
54
|
+
count?(req: {
|
|
55
|
+
model: string;
|
|
56
|
+
index?: string;
|
|
57
|
+
key?: StoreItem;
|
|
58
|
+
}): Promise<number | null>;
|
|
59
|
+
/**
|
|
60
|
+
* Optional schema generator, wired to the Better Auth CLI `generate` command.
|
|
61
|
+
* The built-in store emits a portable CloudFormation template; a custom store
|
|
62
|
+
* may emit whatever provisioning artifact fits its physical layout.
|
|
63
|
+
*/
|
|
64
|
+
createSchema?(opts: {
|
|
65
|
+
file?: string;
|
|
66
|
+
tables: unknown;
|
|
67
|
+
}): Promise<{
|
|
68
|
+
code: string;
|
|
69
|
+
path: string;
|
|
70
|
+
overwrite?: boolean;
|
|
71
|
+
}>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Public configuration for {@link dynamoAdapter}.
|
|
75
|
+
*
|
|
76
|
+
* Omit `store` to use the built-in single-table store (needs `tableName`).
|
|
77
|
+
* Omit `indexMap` to auto-derive access patterns from the Better Auth schema
|
|
78
|
+
* (`unique` fields -> lookup indexes, `references` fields -> by-parent indexes).
|
|
79
|
+
*/
|
|
80
|
+
export interface DynamoAdapterConfig {
|
|
81
|
+
/** Storage backend. Defaults to the built-in single-table store. */
|
|
82
|
+
store?: DynamoStore;
|
|
83
|
+
/** Access-pattern map. Defaults to schema-derived patterns. */
|
|
84
|
+
indexMap?: IndexMap;
|
|
85
|
+
/** DynamoDB table name (used only by the built-in store). */
|
|
86
|
+
tableName?: string;
|
|
87
|
+
/** AWS region (used only by the built-in store). */
|
|
88
|
+
region?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Override the DynamoDB endpoint (used only by the built-in store). Point this
|
|
91
|
+
* at DynamoDB Local or LocalStack, e.g. `http://localhost:4566`.
|
|
92
|
+
*/
|
|
93
|
+
endpoint?: string;
|
|
94
|
+
/** Better Auth debug logging, forwarded to the adapter factory. */
|
|
95
|
+
debugLogs?: DBAdapterDebugLogOption;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAE5E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,kFAAkF;AAClF,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAE5C,2EAA2E;AAC3E,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,WAAW;IAC1B,4EAA4E;IAC5E,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IAExD,sEAAsE;IACtE,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;IAE9D,wFAAwF;IACxF,MAAM,CACJ,KAAK,EAAE,MAAM,EACb,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,SAAS,GACf,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E,MAAM,CAAC;IACnB,oDAAoD;IACpD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mEAAmE;IACnE,SAAS,CAAC,EAAE,uBAAuB,CAAC;CACrC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@datar-platform/better-auth-dynamodb",
|
|
3
|
+
"version": "0.1.0-alpha.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "A generic DynamoDB adapter for Better Auth. Bring your own store or use the built-in single-table store.",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"keywords": [
|
|
17
|
+
"better-auth",
|
|
18
|
+
"better-auth-adapter",
|
|
19
|
+
"dynamodb",
|
|
20
|
+
"aws",
|
|
21
|
+
"auth"
|
|
22
|
+
],
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/joesome-Web-Services/datar-turbo.git",
|
|
26
|
+
"directory": "packages/better-auth-dynamodb"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://datar.co.za",
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=20"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"README.md",
|
|
35
|
+
"CHANGELOG.md",
|
|
36
|
+
"LICENSE"
|
|
37
|
+
],
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public",
|
|
40
|
+
"registry": "https://registry.npmjs.org/"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@aws-sdk/client-dynamodb": "^3.687.0",
|
|
44
|
+
"@aws-sdk/lib-dynamodb": "^3.687.0"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"better-auth": ">=1.5.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"better-auth": "1.5.4",
|
|
51
|
+
"eslint": "^9.38.0",
|
|
52
|
+
"prettier": "^3.6.2",
|
|
53
|
+
"typescript": "^5.9.3",
|
|
54
|
+
"vitest": "^2.1.8",
|
|
55
|
+
"@joesome-web-services/eslint-config-internal": "0.2.11",
|
|
56
|
+
"@joesome-web-services/prettier-config": "0.2.11",
|
|
57
|
+
"@joesome-web-services/vitest-config": "0.2.11",
|
|
58
|
+
"@joesome-web-services/tsconfig": "0.2.11"
|
|
59
|
+
},
|
|
60
|
+
"prettier": "@joesome-web-services/prettier-config",
|
|
61
|
+
"scripts": {
|
|
62
|
+
"build": "echo 'source (JIT) package — consumed via bundler transpilePackages, no build step. Run build:publish to emit dist for npm publish.'",
|
|
63
|
+
"build:publish": "tsc -p tsconfig.build.json",
|
|
64
|
+
"clean": "git clean -xdf .cache .turbo dist node_modules",
|
|
65
|
+
"format": "prettier --check . --ignore-path ../../.gitignore",
|
|
66
|
+
"lint": "eslint --flag unstable_native_nodejs_ts_config",
|
|
67
|
+
"typecheck": "tsgo --noEmit",
|
|
68
|
+
"test": "vitest run",
|
|
69
|
+
"test:e2e": "DYNAMO_E2E=1 vitest run test/localstack.test.ts",
|
|
70
|
+
"test:watch": "vitest"
|
|
71
|
+
}
|
|
72
|
+
}
|