@voidhash/mimic-sdk 1.0.0-beta.18

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.
Files changed (94) hide show
  1. package/LICENSE.md +663 -0
  2. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/defineProperty.cjs +14 -0
  3. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/defineProperty.mjs +14 -0
  4. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/objectSpread2.cjs +27 -0
  5. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/objectSpread2.mjs +27 -0
  6. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPrimitive.cjs +16 -0
  7. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPrimitive.mjs +16 -0
  8. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPropertyKey.cjs +11 -0
  9. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPropertyKey.mjs +11 -0
  10. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/typeof.cjs +18 -0
  11. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/typeof.mjs +12 -0
  12. package/dist/_virtual/rolldown_runtime.cjs +19 -0
  13. package/dist/_virtual/rolldown_runtime.mjs +18 -0
  14. package/dist/effect/CollectionHandle.cjs +93 -0
  15. package/dist/effect/CollectionHandle.d.cts +31 -0
  16. package/dist/effect/CollectionHandle.d.cts.map +1 -0
  17. package/dist/effect/CollectionHandle.d.mts +31 -0
  18. package/dist/effect/CollectionHandle.d.mts.map +1 -0
  19. package/dist/effect/CollectionHandle.mjs +94 -0
  20. package/dist/effect/CollectionHandle.mjs.map +1 -0
  21. package/dist/effect/DatabaseHandle.cjs +61 -0
  22. package/dist/effect/DatabaseHandle.d.cts +25 -0
  23. package/dist/effect/DatabaseHandle.d.cts.map +1 -0
  24. package/dist/effect/DatabaseHandle.d.mts +25 -0
  25. package/dist/effect/DatabaseHandle.d.mts.map +1 -0
  26. package/dist/effect/DatabaseHandle.mjs +62 -0
  27. package/dist/effect/DatabaseHandle.mjs.map +1 -0
  28. package/dist/effect/HttpTransport.cjs +18 -0
  29. package/dist/effect/HttpTransport.d.cts +15 -0
  30. package/dist/effect/HttpTransport.d.cts.map +1 -0
  31. package/dist/effect/HttpTransport.d.mts +15 -0
  32. package/dist/effect/HttpTransport.d.mts.map +1 -0
  33. package/dist/effect/HttpTransport.mjs +19 -0
  34. package/dist/effect/HttpTransport.mjs.map +1 -0
  35. package/dist/effect/MimicSDK.cjs +84 -0
  36. package/dist/effect/MimicSDK.d.cts +40 -0
  37. package/dist/effect/MimicSDK.d.cts.map +1 -0
  38. package/dist/effect/MimicSDK.d.mts +40 -0
  39. package/dist/effect/MimicSDK.d.mts.map +1 -0
  40. package/dist/effect/MimicSDK.mjs +71 -0
  41. package/dist/effect/MimicSDK.mjs.map +1 -0
  42. package/dist/effect/errors.cjs +7 -0
  43. package/dist/effect/errors.d.cts +15 -0
  44. package/dist/effect/errors.d.cts.map +1 -0
  45. package/dist/effect/errors.d.mts +15 -0
  46. package/dist/effect/errors.d.mts.map +1 -0
  47. package/dist/effect/errors.mjs +8 -0
  48. package/dist/effect/errors.mjs.map +1 -0
  49. package/dist/effect/index.cjs +35 -0
  50. package/dist/effect/index.d.cts +8 -0
  51. package/dist/effect/index.d.mts +8 -0
  52. package/dist/effect/index.mjs +8 -0
  53. package/dist/effect/types.d.cts +34 -0
  54. package/dist/effect/types.d.cts.map +1 -0
  55. package/dist/effect/types.d.mts +34 -0
  56. package/dist/effect/types.d.mts.map +1 -0
  57. package/dist/index.cjs +7 -0
  58. package/dist/index.d.cts +6 -0
  59. package/dist/index.d.mts +6 -0
  60. package/dist/index.mjs +5 -0
  61. package/dist/promise/CollectionHandle.cjs +49 -0
  62. package/dist/promise/CollectionHandle.d.cts +32 -0
  63. package/dist/promise/CollectionHandle.d.cts.map +1 -0
  64. package/dist/promise/CollectionHandle.d.mts +32 -0
  65. package/dist/promise/CollectionHandle.d.mts.map +1 -0
  66. package/dist/promise/CollectionHandle.mjs +50 -0
  67. package/dist/promise/CollectionHandle.mjs.map +1 -0
  68. package/dist/promise/DatabaseHandle.cjs +38 -0
  69. package/dist/promise/DatabaseHandle.d.cts +22 -0
  70. package/dist/promise/DatabaseHandle.d.cts.map +1 -0
  71. package/dist/promise/DatabaseHandle.d.mts +22 -0
  72. package/dist/promise/DatabaseHandle.d.mts.map +1 -0
  73. package/dist/promise/DatabaseHandle.mjs +39 -0
  74. package/dist/promise/DatabaseHandle.mjs.map +1 -0
  75. package/dist/promise/MimicSDK.cjs +55 -0
  76. package/dist/promise/MimicSDK.d.cts +40 -0
  77. package/dist/promise/MimicSDK.d.cts.map +1 -0
  78. package/dist/promise/MimicSDK.d.mts +40 -0
  79. package/dist/promise/MimicSDK.d.mts.map +1 -0
  80. package/dist/promise/MimicSDK.mjs +56 -0
  81. package/dist/promise/MimicSDK.mjs.map +1 -0
  82. package/package.json +44 -0
  83. package/src/effect/CollectionHandle.ts +120 -0
  84. package/src/effect/DatabaseHandle.ts +76 -0
  85. package/src/effect/HttpTransport.ts +43 -0
  86. package/src/effect/MimicSDK.ts +118 -0
  87. package/src/effect/errors.ts +7 -0
  88. package/src/effect/index.ts +15 -0
  89. package/src/effect/types.ts +35 -0
  90. package/src/index.ts +12 -0
  91. package/src/promise/CollectionHandle.ts +67 -0
  92. package/src/promise/DatabaseHandle.ts +50 -0
  93. package/src/promise/MimicSDK.ts +69 -0
  94. package/src/promise/index.ts +3 -0
@@ -0,0 +1,120 @@
1
+ import { Effect } from "effect";
2
+ import type { Primitive } from "@voidhash/mimic";
3
+ import { RpcClient } from "effect/unstable/rpc";
4
+ import { MimicRpcs } from "@voidhash/mimic-protocol";
5
+ import type { DocumentSnapshot, CreatedDocumentToken } from "./types";
6
+
7
+ const makeClient = () => RpcClient.make(MimicRpcs);
8
+
9
+ export class CollectionHandle<TSchema extends Primitive.AnyPrimitive> {
10
+ readonly id: string;
11
+ readonly databaseId: string;
12
+ readonly schema: TSchema;
13
+
14
+ constructor(id: string, databaseId: string, schema: TSchema) {
15
+ this.id = id;
16
+ this.databaseId = databaseId;
17
+ this.schema = schema;
18
+ }
19
+
20
+ create(data: Primitive.InferSetInput<TSchema>, options?: { id?: string }) {
21
+ const collectionId = this.id;
22
+ return Effect.scoped(
23
+ Effect.gen(function* () {
24
+ const client = yield* makeClient();
25
+ const result = yield* client.CreateDocument({
26
+ collectionId,
27
+ id: options?.id,
28
+ data,
29
+ });
30
+ return result as unknown as DocumentSnapshot<Primitive.InferState<TSchema>>;
31
+ }),
32
+ );
33
+ }
34
+
35
+ get(documentId: string) {
36
+ const collectionId = this.id;
37
+ return Effect.scoped(
38
+ Effect.gen(function* () {
39
+ const client = yield* makeClient();
40
+ const result = yield* client.GetDocument({
41
+ collectionId,
42
+ documentId,
43
+ });
44
+ return result as unknown as DocumentSnapshot<Primitive.InferState<TSchema>>;
45
+ }),
46
+ );
47
+ }
48
+
49
+ update(documentId: string, data: Primitive.InferUpdateInput<TSchema>) {
50
+ const collectionId = this.id;
51
+ return Effect.scoped(
52
+ Effect.gen(function* () {
53
+ const client = yield* makeClient();
54
+ const result = yield* client.UpdateDocument({
55
+ collectionId,
56
+ documentId,
57
+ data,
58
+ });
59
+ return { id: result.id, version: result.version };
60
+ }),
61
+ );
62
+ }
63
+
64
+ set(documentId: string, data: Primitive.InferSetInput<TSchema>) {
65
+ const collectionId = this.id;
66
+ return Effect.scoped(
67
+ Effect.gen(function* () {
68
+ const client = yield* makeClient();
69
+ const result = yield* client.SetDocument({
70
+ collectionId,
71
+ documentId,
72
+ data,
73
+ });
74
+ return { id: result.id, version: result.version };
75
+ }),
76
+ );
77
+ }
78
+
79
+ delete(documentId: string) {
80
+ const collectionId = this.id;
81
+ return Effect.scoped(
82
+ Effect.gen(function* () {
83
+ const client = yield* makeClient();
84
+ yield* client.DeleteDocument({
85
+ collectionId,
86
+ documentId,
87
+ });
88
+ }),
89
+ );
90
+ }
91
+
92
+ list() {
93
+ const collectionId = this.id;
94
+ return Effect.scoped(
95
+ Effect.gen(function* () {
96
+ const client = yield* makeClient();
97
+ const result = yield* client.ListDocuments({
98
+ collectionId,
99
+ });
100
+ return result as unknown as DocumentSnapshot<Primitive.InferState<TSchema>>[];
101
+ }),
102
+ );
103
+ }
104
+
105
+ createDocumentToken(documentId: string, permission: "read" | "write", expiresInSeconds?: number) {
106
+ const collectionId = this.id;
107
+ return Effect.scoped(
108
+ Effect.gen(function* () {
109
+ const client = yield* makeClient();
110
+ const result = yield* client.CreateDocumentToken({
111
+ collectionId,
112
+ documentId,
113
+ permission,
114
+ expiresInSeconds,
115
+ });
116
+ return { token: result.token } as CreatedDocumentToken;
117
+ }),
118
+ );
119
+ }
120
+ }
@@ -0,0 +1,76 @@
1
+ import { Effect } from "effect";
2
+ import { type Primitive, SchemaJSON } from "@voidhash/mimic";
3
+ import { RpcClient } from "effect/unstable/rpc";
4
+ import { MimicRpcs } from "@voidhash/mimic-protocol";
5
+ import { CollectionHandle } from "./CollectionHandle";
6
+ import type { CollectionInfo } from "./types";
7
+
8
+ const makeClient = () => RpcClient.make(MimicRpcs);
9
+
10
+ export class DatabaseHandle {
11
+ readonly id: string;
12
+ readonly name: string;
13
+ readonly description: string;
14
+
15
+ constructor(id: string, name: string, description: string) {
16
+ this.id = id;
17
+ this.name = name;
18
+ this.description = description;
19
+ }
20
+
21
+ createCollection<TSchema extends Primitive.AnyPrimitive>(name: string, schema: TSchema) {
22
+ const databaseId = this.id;
23
+ return Effect.scoped(
24
+ Effect.gen(function* () {
25
+ const client = yield* makeClient();
26
+ const schemaJson = SchemaJSON.toJSON(schema);
27
+ const result = yield* client.CreateCollection({
28
+ databaseId,
29
+ name,
30
+ schemaJson,
31
+ });
32
+ return new CollectionHandle<TSchema>(result.id, result.databaseId, schema);
33
+ }),
34
+ );
35
+ }
36
+
37
+ listCollections() {
38
+ const databaseId = this.id;
39
+ return Effect.scoped(
40
+ Effect.gen(function* () {
41
+ const client = yield* makeClient();
42
+ const result = yield* client.ListCollections({ databaseId });
43
+ return result as unknown as CollectionInfo[];
44
+ }),
45
+ );
46
+ }
47
+
48
+ deleteCollection(id: string) {
49
+ return Effect.scoped(
50
+ Effect.gen(function* () {
51
+ const client = yield* makeClient();
52
+ yield* client.DeleteCollection({ id });
53
+ }),
54
+ );
55
+ }
56
+
57
+ collection<TSchema extends Primitive.AnyPrimitive>(
58
+ id: string,
59
+ schema: TSchema,
60
+ ): CollectionHandle<TSchema> {
61
+ return new CollectionHandle<TSchema>(id, this.id, schema);
62
+ }
63
+
64
+ updateCollectionSchema(collectionId: string, schemaJson: unknown) {
65
+ return Effect.scoped(
66
+ Effect.gen(function* () {
67
+ const client = yield* makeClient();
68
+ const result = yield* client.UpdateCollectionSchema({
69
+ id: collectionId,
70
+ schemaJson,
71
+ });
72
+ return { id: result.id, schemaVersion: result.schemaVersion };
73
+ }),
74
+ );
75
+ }
76
+ }
@@ -0,0 +1,43 @@
1
+ import { Layer } from "effect";
2
+ import { RpcClient, RpcSerialization, RpcMiddleware } from "effect/unstable/rpc";
3
+ import { FetchHttpClient } from "effect/unstable/http";
4
+ import { AuthMiddleware } from "@voidhash/mimic-protocol";
5
+
6
+ export interface MimicClientConfig {
7
+ readonly url: string;
8
+ readonly username: string;
9
+ readonly password: string;
10
+ readonly timeout?: number;
11
+ }
12
+
13
+ export const MimicClientLayer = (config: MimicClientConfig) => {
14
+ const baseUrl = config.url.replace(/\/+$/, "");
15
+ const basicAuth = btoa(`${config.username}:${config.password}`);
16
+
17
+ const ProtocolLive = RpcClient.layerProtocolHttp({
18
+ url: `${baseUrl}/rpc`,
19
+ });
20
+
21
+ const SerializationLive = RpcSerialization.layerNdjson;
22
+
23
+ const AuthLive = RpcMiddleware.layerClient(
24
+ AuthMiddleware,
25
+ ({ next, request }) =>
26
+ next({
27
+ ...request,
28
+ headers: {
29
+ ...request.headers,
30
+ authorization: `Basic ${basicAuth}`,
31
+ },
32
+ }),
33
+ );
34
+
35
+ return Layer.mergeAll(
36
+ ProtocolLive.pipe(
37
+ Layer.provide(FetchHttpClient.layer),
38
+ Layer.provide(SerializationLive),
39
+ ),
40
+ SerializationLive,
41
+ AuthLive,
42
+ );
43
+ };
@@ -0,0 +1,118 @@
1
+ import { Effect } from "effect";
2
+ import { RpcClient, RpcSerialization, RpcClientError, RpcMiddleware } from "effect/unstable/rpc";
3
+ import { MimicRpcs, type AuthMiddleware } from "@voidhash/mimic-protocol";
4
+ import { DatabaseHandle } from "./DatabaseHandle";
5
+ import type { DatabaseInfo, UserInfo, GrantInfo } from "./types";
6
+
7
+ export type MimicRpcRequirements =
8
+ | RpcClient.Protocol
9
+ | RpcSerialization.RpcSerialization
10
+ | RpcMiddleware.ForClient<AuthMiddleware>;
11
+
12
+ const makeClient = () => RpcClient.make(MimicRpcs);
13
+
14
+ export const createDatabase = (options: {
15
+ name: string;
16
+ description?: string;
17
+ }) =>
18
+ Effect.scoped(
19
+ Effect.gen(function* () {
20
+ const client = yield* makeClient();
21
+ const result = yield* client.CreateDatabase({
22
+ name: options.name,
23
+ description: options.description ?? "",
24
+ });
25
+ return new DatabaseHandle(result.id, result.name, result.description);
26
+ }),
27
+ );
28
+
29
+ export const listDatabases = () =>
30
+ Effect.scoped(
31
+ Effect.gen(function* () {
32
+ const client = yield* makeClient();
33
+ const result = yield* client.ListDatabases(undefined as any);
34
+ return result as unknown as DatabaseInfo[];
35
+ }),
36
+ );
37
+
38
+ export const deleteDatabase = (id: string) =>
39
+ Effect.scoped(
40
+ Effect.gen(function* () {
41
+ const client = yield* makeClient();
42
+ yield* client.DeleteDatabase({ id });
43
+ }),
44
+ );
45
+
46
+ export const database = (id: string, name = "", description = ""): DatabaseHandle =>
47
+ new DatabaseHandle(id, name, description);
48
+
49
+ export const createUser = (options: {
50
+ username: string;
51
+ password: string;
52
+ }) =>
53
+ Effect.scoped(
54
+ Effect.gen(function* () {
55
+ const client = yield* makeClient();
56
+ const result = yield* client.CreateUser({
57
+ username: options.username,
58
+ password: options.password,
59
+ });
60
+ return { id: result.id, username: result.username };
61
+ }),
62
+ );
63
+
64
+ export const listUsers = () =>
65
+ Effect.scoped(
66
+ Effect.gen(function* () {
67
+ const client = yield* makeClient();
68
+ const result = yield* client.ListUsers(undefined as any);
69
+ return result as unknown as UserInfo[];
70
+ }),
71
+ );
72
+
73
+ export const deleteUser = (id: string) =>
74
+ Effect.scoped(
75
+ Effect.gen(function* () {
76
+ const client = yield* makeClient();
77
+ yield* client.DeleteUser({ id });
78
+ }),
79
+ );
80
+
81
+ export const grantPermission = (options: {
82
+ userId: string;
83
+ databaseId: string;
84
+ permission: "read" | "write" | "admin";
85
+ }) =>
86
+ Effect.scoped(
87
+ Effect.gen(function* () {
88
+ const client = yield* makeClient();
89
+ yield* client.GrantPermission({
90
+ userId: options.userId,
91
+ databaseId: options.databaseId,
92
+ permission: options.permission,
93
+ });
94
+ }),
95
+ );
96
+
97
+ export const revokePermission = (options: {
98
+ userId: string;
99
+ databaseId: string;
100
+ }) =>
101
+ Effect.scoped(
102
+ Effect.gen(function* () {
103
+ const client = yield* makeClient();
104
+ yield* client.RevokePermission({
105
+ userId: options.userId,
106
+ databaseId: options.databaseId,
107
+ });
108
+ }),
109
+ );
110
+
111
+ export const listGrants = (userId?: string) =>
112
+ Effect.scoped(
113
+ Effect.gen(function* () {
114
+ const client = yield* makeClient();
115
+ const result = yield* client.ListGrants({ userId });
116
+ return result as unknown as GrantInfo[];
117
+ }),
118
+ );
@@ -0,0 +1,7 @@
1
+ import { Data } from "effect";
2
+
3
+ export class MimicSDKError extends Data.TaggedError("MimicSDKError")<{
4
+ readonly message: string;
5
+ readonly method?: string;
6
+ readonly cause?: unknown;
7
+ }> {}
@@ -0,0 +1,15 @@
1
+ export { MimicClientLayer, type MimicClientConfig } from "./HttpTransport";
2
+ export { MimicSDKError } from "./errors";
3
+ export type {
4
+ DatabaseInfo,
5
+ CollectionInfo,
6
+ UserInfo,
7
+ GrantInfo,
8
+ CreatedDocumentToken,
9
+ DocumentSnapshot,
10
+ } from "./types";
11
+ export { DatabaseHandle } from "./DatabaseHandle";
12
+ export { CollectionHandle } from "./CollectionHandle";
13
+ export * as MimicSDK from "./MimicSDK";
14
+ export type { MimicRpcRequirements } from "./MimicSDK";
15
+ export { MimicRpcs, CurrentUser, AuthMiddleware } from "@voidhash/mimic-protocol";
@@ -0,0 +1,35 @@
1
+ export interface DatabaseInfo {
2
+ readonly id: string;
3
+ readonly name: string;
4
+ readonly description: string;
5
+ }
6
+
7
+ export interface CollectionInfo {
8
+ readonly id: string;
9
+ readonly databaseId: string;
10
+ readonly name: string;
11
+ }
12
+
13
+ export interface UserInfo {
14
+ readonly id: string;
15
+ readonly username: string;
16
+ readonly isSuperuser: boolean;
17
+ }
18
+
19
+ export interface GrantInfo {
20
+ readonly id: string;
21
+ readonly userId: string;
22
+ readonly databaseId: string;
23
+ readonly permission: string;
24
+ }
25
+
26
+ export interface CreatedDocumentToken {
27
+ readonly token: string;
28
+ }
29
+
30
+ export interface DocumentSnapshot<TState = unknown> {
31
+ readonly id: string;
32
+ readonly collectionId: string;
33
+ readonly state: TState;
34
+ readonly version: number;
35
+ }
package/src/index.ts ADDED
@@ -0,0 +1,12 @@
1
+ export { MimicSDK } from "./promise/MimicSDK";
2
+ export { DatabaseHandle } from "./promise/DatabaseHandle";
3
+ export { CollectionHandle } from "./promise/CollectionHandle";
4
+ export type {
5
+ DatabaseInfo,
6
+ CollectionInfo,
7
+ UserInfo,
8
+ GrantInfo,
9
+ CreatedDocumentToken,
10
+ DocumentSnapshot,
11
+ } from "./effect/types";
12
+ export type { MimicClientConfig } from "./effect/HttpTransport";
@@ -0,0 +1,67 @@
1
+ import type { ManagedRuntime } from "effect";
2
+ import type { Primitive } from "@voidhash/mimic";
3
+ import { CollectionHandle as EffectCollectionHandle } from "../effect/CollectionHandle";
4
+ import type { MimicRpcRequirements } from "../effect/MimicSDK";
5
+ import type { DocumentSnapshot, CreatedDocumentToken } from "../effect/types";
6
+
7
+ export class CollectionHandle<TSchema extends Primitive.AnyPrimitive> {
8
+ readonly id: string;
9
+ readonly databaseId: string;
10
+ readonly schema: TSchema;
11
+ private readonly _effect: EffectCollectionHandle<TSchema>;
12
+ private readonly _runtime: ManagedRuntime.ManagedRuntime<MimicRpcRequirements, never>;
13
+
14
+ constructor(
15
+ id: string,
16
+ databaseId: string,
17
+ schema: TSchema,
18
+ runtime: ManagedRuntime.ManagedRuntime<MimicRpcRequirements, never>,
19
+ ) {
20
+ this.id = id;
21
+ this.databaseId = databaseId;
22
+ this.schema = schema;
23
+ this._effect = new EffectCollectionHandle(id, databaseId, schema);
24
+ this._runtime = runtime;
25
+ }
26
+
27
+ async create(
28
+ data: Primitive.InferSetInput<TSchema>,
29
+ options?: { id?: string },
30
+ ): Promise<DocumentSnapshot<Primitive.InferState<TSchema>>> {
31
+ return this._runtime.runPromise(this._effect.create(data, options));
32
+ }
33
+
34
+ async get(documentId: string): Promise<DocumentSnapshot<Primitive.InferState<TSchema>>> {
35
+ return this._runtime.runPromise(this._effect.get(documentId));
36
+ }
37
+
38
+ async update(
39
+ documentId: string,
40
+ data: Primitive.InferUpdateInput<TSchema>,
41
+ ): Promise<{ id: string; version: number }> {
42
+ return this._runtime.runPromise(this._effect.update(documentId, data));
43
+ }
44
+
45
+ async set(
46
+ documentId: string,
47
+ data: Primitive.InferSetInput<TSchema>,
48
+ ): Promise<{ id: string; version: number }> {
49
+ return this._runtime.runPromise(this._effect.set(documentId, data));
50
+ }
51
+
52
+ async delete(documentId: string): Promise<void> {
53
+ return this._runtime.runPromise(this._effect.delete(documentId)) as Promise<void>;
54
+ }
55
+
56
+ async list(): Promise<DocumentSnapshot<Primitive.InferState<TSchema>>[]> {
57
+ return this._runtime.runPromise(this._effect.list());
58
+ }
59
+
60
+ async createDocumentToken(
61
+ documentId: string,
62
+ permission: "read" | "write",
63
+ expiresInSeconds?: number,
64
+ ): Promise<CreatedDocumentToken> {
65
+ return this._runtime.runPromise(this._effect.createDocumentToken(documentId, permission, expiresInSeconds));
66
+ }
67
+ }
@@ -0,0 +1,50 @@
1
+ import type { ManagedRuntime } from "effect";
2
+ import type { Primitive } from "@voidhash/mimic";
3
+ import { DatabaseHandle as EffectDatabaseHandle } from "../effect/DatabaseHandle";
4
+ import type { MimicRpcRequirements } from "../effect/MimicSDK";
5
+ import type { CollectionInfo } from "../effect/types";
6
+ import { CollectionHandle } from "./CollectionHandle";
7
+
8
+ export class DatabaseHandle {
9
+ readonly id: string;
10
+ readonly name: string;
11
+ readonly description: string;
12
+ private readonly _effect: EffectDatabaseHandle;
13
+ private readonly _runtime: ManagedRuntime.ManagedRuntime<MimicRpcRequirements, never>;
14
+
15
+ constructor(
16
+ id: string,
17
+ name: string,
18
+ description: string,
19
+ runtime: ManagedRuntime.ManagedRuntime<MimicRpcRequirements, never>,
20
+ ) {
21
+ this.id = id;
22
+ this.name = name;
23
+ this.description = description;
24
+ this._effect = new EffectDatabaseHandle(id, name, description);
25
+ this._runtime = runtime;
26
+ }
27
+
28
+ async createCollection<TSchema extends Primitive.AnyPrimitive>(
29
+ name: string,
30
+ schema: TSchema,
31
+ ): Promise<CollectionHandle<TSchema>> {
32
+ const info = await this._runtime.runPromise(this._effect.createCollection(name, schema));
33
+ return new CollectionHandle<TSchema>(info.id, info.databaseId, schema, this._runtime);
34
+ }
35
+
36
+ async listCollections(): Promise<CollectionInfo[]> {
37
+ return this._runtime.runPromise(this._effect.listCollections());
38
+ }
39
+
40
+ async deleteCollection(id: string): Promise<void> {
41
+ return this._runtime.runPromise(this._effect.deleteCollection(id)) as Promise<void>;
42
+ }
43
+
44
+ collection<TSchema extends Primitive.AnyPrimitive>(
45
+ id: string,
46
+ schema: TSchema,
47
+ ): CollectionHandle<TSchema> {
48
+ return new CollectionHandle<TSchema>(id, this.id, schema, this._runtime);
49
+ }
50
+ }
@@ -0,0 +1,69 @@
1
+ import { ManagedRuntime } from "effect";
2
+ import { MimicClientLayer, type MimicClientConfig } from "../effect/HttpTransport";
3
+ import type { MimicRpcRequirements } from "../effect/MimicSDK";
4
+ import * as EffectMimicSDK from "../effect/MimicSDK";
5
+ import type { DatabaseInfo, UserInfo, GrantInfo } from "../effect/types";
6
+ import { DatabaseHandle } from "./DatabaseHandle";
7
+
8
+ export class MimicSDK {
9
+ private readonly _runtime: ManagedRuntime.ManagedRuntime<MimicRpcRequirements, never>;
10
+
11
+ private constructor(runtime: ManagedRuntime.ManagedRuntime<MimicRpcRequirements, never>) {
12
+ this._runtime = runtime;
13
+ }
14
+
15
+ static create(options: MimicClientConfig): MimicSDK {
16
+ const layer = MimicClientLayer(options);
17
+ const runtime = ManagedRuntime.make(layer) as ManagedRuntime.ManagedRuntime<MimicRpcRequirements, never>;
18
+ return new MimicSDK(runtime);
19
+ }
20
+
21
+ async createDatabase(options: { name: string; description?: string }): Promise<DatabaseHandle> {
22
+ const result = await this._runtime.runPromise(EffectMimicSDK.createDatabase(options));
23
+ return new DatabaseHandle(result.id, result.name, result.description, this._runtime);
24
+ }
25
+
26
+ async listDatabases(): Promise<DatabaseInfo[]> {
27
+ return this._runtime.runPromise(EffectMimicSDK.listDatabases());
28
+ }
29
+
30
+ async deleteDatabase(id: string): Promise<void> {
31
+ return this._runtime.runPromise(EffectMimicSDK.deleteDatabase(id)) as Promise<void>;
32
+ }
33
+
34
+ database(id: string, name = "", description = ""): DatabaseHandle {
35
+ return new DatabaseHandle(id, name, description, this._runtime);
36
+ }
37
+
38
+ async createUser(options: { username: string; password: string }): Promise<{ id: string; username: string }> {
39
+ return this._runtime.runPromise(EffectMimicSDK.createUser(options));
40
+ }
41
+
42
+ async listUsers(): Promise<UserInfo[]> {
43
+ return this._runtime.runPromise(EffectMimicSDK.listUsers());
44
+ }
45
+
46
+ async deleteUser(id: string): Promise<void> {
47
+ return this._runtime.runPromise(EffectMimicSDK.deleteUser(id)) as Promise<void>;
48
+ }
49
+
50
+ async grantPermission(options: {
51
+ userId: string;
52
+ databaseId: string;
53
+ permission: "read" | "write" | "admin";
54
+ }): Promise<void> {
55
+ return this._runtime.runPromise(EffectMimicSDK.grantPermission(options)) as Promise<void>;
56
+ }
57
+
58
+ async revokePermission(options: { userId: string; databaseId: string }): Promise<void> {
59
+ return this._runtime.runPromise(EffectMimicSDK.revokePermission(options)) as Promise<void>;
60
+ }
61
+
62
+ async listGrants(userId?: string): Promise<GrantInfo[]> {
63
+ return this._runtime.runPromise(EffectMimicSDK.listGrants(userId));
64
+ }
65
+
66
+ async dispose(): Promise<void> {
67
+ return this._runtime.dispose();
68
+ }
69
+ }
@@ -0,0 +1,3 @@
1
+ export { MimicSDK } from "./MimicSDK";
2
+ export { DatabaseHandle } from "./DatabaseHandle";
3
+ export { CollectionHandle } from "./CollectionHandle";