@anysoftinc/anydb-sdk 0.1.1 → 0.3.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.
@@ -0,0 +1,26 @@
1
+ import type { QueryResult, Transaction, Datom, Entity, DatabaseInfo } from "./client";
2
+ export declare class DataScriptBackend {
3
+ private dbAlias;
4
+ constructor(storageAlias: string, dbName: string);
5
+ listDatabases(): Promise<string[]>;
6
+ createDatabase(): Promise<{
7
+ "db-created": string;
8
+ }>;
9
+ deleteDatabase(): Promise<{
10
+ "db-deleted": string;
11
+ }>;
12
+ transact(txData: any[]): Promise<Transaction>;
13
+ query(query: any[], ...args: any[]): Promise<QueryResult>;
14
+ entity(entityId: any): Promise<Entity>;
15
+ datoms(index: "eavt" | "aevt" | "avet" | "vaet", options?: {
16
+ e?: any;
17
+ a?: any;
18
+ v?: any;
19
+ limit?: number;
20
+ offset?: number;
21
+ }): Promise<Datom[]>;
22
+ databaseInfo(): Promise<DatabaseInfo>;
23
+ }
24
+ export declare function isDataScriptAvailable(): boolean;
25
+ export declare function shouldUseDataScript(storageAlias: string): boolean;
26
+ //# sourceMappingURL=datascript-backend.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"datascript-backend.d.ts","sourceRoot":"","sources":["../src/datascript-backend.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,KAAK,EACL,MAAM,EACN,YAAY,EACb,MAAM,UAAU,CAAC;AAqClB,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,OAAO,CAAS;gBAEZ,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAW1C,aAAa,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAKlC,cAAc,IAAI,OAAO,CAAC;QAAE,YAAY,EAAE,MAAM,CAAA;KAAE,CAAC;IAKnD,cAAc,IAAI,OAAO,CAAC;QAAE,YAAY,EAAE,MAAM,CAAA;KAAE,CAAC;IAMnD,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IAgB7C,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IAUzD,MAAM,CAAC,QAAQ,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAatC,MAAM,CACV,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,EACxC,OAAO,GAAE;QACP,CAAC,CAAC,EAAE,GAAG,CAAC;QACR,CAAC,CAAC,EAAE,GAAG,CAAC;QACR,CAAC,CAAC,EAAE,GAAG,CAAC;QACR,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;KACZ,GACL,OAAO,CAAC,KAAK,EAAE,CAAC;IAiCb,YAAY,IAAI,OAAO,CAAC,YAAY,CAAC;CAM5C;AAGD,wBAAgB,qBAAqB,IAAI,OAAO,CAE/C;AAGD,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAGjE"}
@@ -0,0 +1,113 @@
1
+ import { stringifyEdn } from "./client";
2
+ // Load the DataScript backend if available
3
+ let datascriptBackend = null;
4
+ try {
5
+ // Try to load the compiled DataScript module
6
+ datascriptBackend =
7
+ globalThis.anydbDatascript ||
8
+ require("../dist-cljs/anydb.datascript.core.js");
9
+ }
10
+ catch (e) {
11
+ console.warn("DataScript backend not available. Run `npx shadow-cljs compile datascript` to enable client-only development mode.");
12
+ }
13
+ export class DataScriptBackend {
14
+ constructor(storageAlias, dbName) {
15
+ this.dbAlias = `${storageAlias}/${dbName}`;
16
+ if (!datascriptBackend) {
17
+ throw new Error("DataScript backend not loaded. Please compile ClojureScript modules first.");
18
+ }
19
+ }
20
+ // Database management
21
+ async listDatabases() {
22
+ if (!datascriptBackend)
23
+ throw new Error("DataScript backend not available");
24
+ return datascriptBackend.listDatabases();
25
+ }
26
+ async createDatabase() {
27
+ if (!datascriptBackend)
28
+ throw new Error("DataScript backend not available");
29
+ return datascriptBackend.createDatabase(this.dbAlias);
30
+ }
31
+ async deleteDatabase() {
32
+ if (!datascriptBackend)
33
+ throw new Error("DataScript backend not available");
34
+ return datascriptBackend.deleteDatabase(this.dbAlias);
35
+ }
36
+ // Transaction operations
37
+ async transact(txData) {
38
+ if (!datascriptBackend)
39
+ throw new Error("DataScript backend not available");
40
+ const txDataEdn = stringifyEdn(txData);
41
+ const result = datascriptBackend.transactData(this.dbAlias, txDataEdn);
42
+ // Convert to match Datomic API format
43
+ return {
44
+ "db-before": { "basis-t": -1, "db/alias": this.dbAlias },
45
+ "db-after": { "basis-t": -1, "db/alias": this.dbAlias },
46
+ "tx-data": result["tx-data"] || [],
47
+ tempids: result.tempids || {},
48
+ };
49
+ }
50
+ // Query operations
51
+ async query(query, ...args) {
52
+ if (!datascriptBackend)
53
+ throw new Error("DataScript backend not available");
54
+ const queryEdn = stringifyEdn(query);
55
+ const argsEdn = args.map((arg) => stringifyEdn(arg));
56
+ return datascriptBackend.queryData(queryEdn, this.dbAlias, ...argsEdn);
57
+ }
58
+ // Entity operations
59
+ async entity(entityId) {
60
+ if (!datascriptBackend)
61
+ throw new Error("DataScript backend not available");
62
+ const entity = datascriptBackend.getEntity(this.dbAlias, entityId);
63
+ // Ensure db/id is present
64
+ if (entity && !entity["db/id"]) {
65
+ entity["db/id"] = entityId;
66
+ }
67
+ return entity;
68
+ }
69
+ // Datoms operations
70
+ async datoms(index, options = {}) {
71
+ if (!datascriptBackend)
72
+ throw new Error("DataScript backend not available");
73
+ const components = [];
74
+ if (options.e !== undefined)
75
+ components.push(options.e);
76
+ if (options.a !== undefined)
77
+ components.push(options.a);
78
+ if (options.v !== undefined)
79
+ components.push(options.v);
80
+ let datoms = datascriptBackend.getDatoms(this.dbAlias, index, ...components);
81
+ // Apply client-side limit/offset since DataScript doesn't have built-in pagination
82
+ if (options.offset) {
83
+ datoms = datoms.slice(options.offset);
84
+ }
85
+ if (options.limit) {
86
+ datoms = datoms.slice(0, options.limit);
87
+ }
88
+ // Convert to Datomic datom format
89
+ return datoms.map((d) => ({
90
+ e: d.e || d[0],
91
+ a: d.a || d[1],
92
+ v: d.v || d[2],
93
+ tx: d.tx || d[3],
94
+ added: d.added !== false, // Default to true
95
+ }));
96
+ }
97
+ // Database info (mock for compatibility)
98
+ async databaseInfo() {
99
+ return {
100
+ "basis-t": -1, // DataScript doesn't have basis-t concept
101
+ "db/alias": this.dbAlias,
102
+ };
103
+ }
104
+ }
105
+ // Utility to check if DataScript backend is available
106
+ export function isDataScriptAvailable() {
107
+ return datascriptBackend !== null;
108
+ }
109
+ // Utility to detect if we should use DataScript backend
110
+ export function shouldUseDataScript(storageAlias) {
111
+ // Explicit opt-in: use DataScript when storage alias is exactly "datascript"
112
+ return storageAlias === "datascript";
113
+ }
@@ -1,5 +1,10 @@
1
1
  import type { Adapter } from "next-auth/adapters";
2
- import type { DatomicDatabase } from "./client";
2
+ import type { AnyDBClient } from "./client";
3
+ /**
4
+ * Creates NextAuth cookie configuration with proper security settings
5
+ * Uses __Host- prefix and secure cookies in production, regular cookies in development
6
+ */
7
+ export declare function createNextAuthCookies(cookieIdentifier: string): Record<string, any>;
3
8
  /**
4
9
  * Creates a NextAuth.js adapter for AnyDB/Datomic
5
10
  *
@@ -19,5 +24,5 @@ import type { DatomicDatabase } from "./client";
19
24
  * });
20
25
  * ```
21
26
  */
22
- export declare function AnyDBAdapter(db: DatomicDatabase): Adapter;
27
+ export declare function AnyDBAdapter(db: AnyDBClient): Adapter;
23
28
  //# sourceMappingURL=nextauth-adapter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"nextauth-adapter.d.ts","sourceRoot":"","sources":["../src/nextauth-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAkB,MAAM,oBAAoB,CAAC;AAClE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAmHhD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAAC,EAAE,EAAE,eAAe,GAAG,OAAO,CA4PzD"}
1
+ {"version":3,"file":"nextauth-adapter.d.ts","sourceRoot":"","sources":["../src/nextauth-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAkB,MAAM,oBAAoB,CAAC;AAClE,OAAO,KAAK,EAAE,WAAW,EAAiB,MAAM,UAAU,CAAC;AAG3D;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,gBAAgB,EAAE,MAAM,GACvB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAkCrB;AA2DD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAAC,EAAE,EAAE,WAAW,GAAG,OAAO,CAqXrD"}