@withstudiocms/sdk 0.0.0-beta.0 → 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.
Files changed (85) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +21 -0
  3. package/dist/cache.d.ts +109 -0
  4. package/dist/cache.js +94 -0
  5. package/dist/consts.d.ts +37 -0
  6. package/dist/consts.js +35 -0
  7. package/dist/context.d.ts +208 -0
  8. package/dist/context.js +40 -0
  9. package/dist/errors.d.ts +9 -0
  10. package/dist/errors.js +6 -0
  11. package/dist/index.d.ts +1024 -0
  12. package/dist/index.js +24 -0
  13. package/dist/lib/diff.d.ts +39 -0
  14. package/dist/lib/diff.js +29 -0
  15. package/dist/lib/logger.d.ts +31 -0
  16. package/dist/lib/logger.js +131 -0
  17. package/dist/lib/pluginUtils.d.ts +222 -0
  18. package/dist/lib/pluginUtils.js +87 -0
  19. package/dist/lib/storage-manager.d.ts +10 -0
  20. package/dist/lib/storage-manager.js +17 -0
  21. package/dist/migrations/20251025T040912_init.d.ts +17 -0
  22. package/dist/migrations/20251025T040912_init.js +260 -0
  23. package/dist/migrations/20251130T150847_drop_deprecated.d.ts +13 -0
  24. package/dist/migrations/20251130T150847_drop_deprecated.js +262 -0
  25. package/dist/migrations/20251221T002125_url-mapping.d.ts +13 -0
  26. package/dist/migrations/20251221T002125_url-mapping.js +228 -0
  27. package/dist/migrator.d.ts +25 -0
  28. package/dist/migrator.js +21 -0
  29. package/dist/modules/auth/index.d.ts +419 -0
  30. package/dist/modules/auth/index.js +436 -0
  31. package/dist/modules/clear/index.d.ts +72 -0
  32. package/dist/modules/clear/index.js +52 -0
  33. package/dist/modules/config/consts.d.ts +32 -0
  34. package/dist/modules/config/consts.js +18 -0
  35. package/dist/modules/config/index.d.ts +100 -0
  36. package/dist/modules/config/index.js +224 -0
  37. package/dist/modules/config/templates/mailer.d.ts +36 -0
  38. package/dist/modules/config/templates/mailer.js +218 -0
  39. package/dist/modules/config/type-utils.d.ts +13 -0
  40. package/dist/modules/config/type-utils.js +11 -0
  41. package/dist/modules/delete/index.d.ts +141 -0
  42. package/dist/modules/delete/index.js +279 -0
  43. package/dist/modules/diffTracking/index.d.ts +188 -0
  44. package/dist/modules/diffTracking/index.js +277 -0
  45. package/dist/modules/get/index.d.ts +372 -0
  46. package/dist/modules/get/index.js +579 -0
  47. package/dist/modules/index.d.ts +883 -0
  48. package/dist/modules/index.js +37 -0
  49. package/dist/modules/init/index.d.ts +60 -0
  50. package/dist/modules/init/index.js +38 -0
  51. package/dist/modules/middleware/index.d.ts +56 -0
  52. package/dist/modules/middleware/index.js +50 -0
  53. package/dist/modules/notificationSettings/index.d.ts +57 -0
  54. package/dist/modules/notificationSettings/index.js +39 -0
  55. package/dist/modules/plugins/index.d.ts +167 -0
  56. package/dist/modules/plugins/index.js +272 -0
  57. package/dist/modules/post/index.d.ts +306 -0
  58. package/dist/modules/post/index.js +337 -0
  59. package/dist/modules/resetTokenBucket/index.d.ts +91 -0
  60. package/dist/modules/resetTokenBucket/index.js +96 -0
  61. package/dist/modules/rest_api/index.d.ts +92 -0
  62. package/dist/modules/rest_api/index.js +117 -0
  63. package/dist/modules/update/index.d.ts +184 -0
  64. package/dist/modules/update/index.js +192 -0
  65. package/dist/modules/util/collectors.d.ts +125 -0
  66. package/dist/modules/util/collectors.js +168 -0
  67. package/dist/modules/util/folderTree.d.ts +100 -0
  68. package/dist/modules/util/folderTree.js +176 -0
  69. package/dist/modules/util/generators.d.ts +83 -0
  70. package/dist/modules/util/generators.js +106 -0
  71. package/dist/modules/util/getFromNPM.d.ts +199 -0
  72. package/dist/modules/util/getFromNPM.js +106 -0
  73. package/dist/modules/util/index.d.ts +100 -0
  74. package/dist/modules/util/index.js +20 -0
  75. package/dist/modules/util/parsers.d.ts +60 -0
  76. package/dist/modules/util/parsers.js +43 -0
  77. package/dist/modules/util/slugify.d.ts +22 -0
  78. package/dist/modules/util/slugify.js +19 -0
  79. package/dist/modules/util/users.d.ts +99 -0
  80. package/dist/modules/util/users.js +78 -0
  81. package/dist/tables.d.ts +433 -0
  82. package/dist/tables.js +169 -0
  83. package/dist/types.d.ts +359 -0
  84. package/dist/types.js +10 -0
  85. package/package.json +67 -7
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-present StudioCMS - withstudiocms (https://github.com/withstudiocms)
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,21 @@
1
+ # @withstudiocms/sdk
2
+
3
+ A comprehensive Software Development Kit for StudioCMS, providing a unified API for interacting with the CMS core functionality. Built with TypeScript and Effect-ts for type-safety and functional programming patterns, with Kysely DB (`@withstudiocms/kysely`) for dynamic database storage.
4
+
5
+ **Note:** This is an Internal to StudioCMS package. Not intended to be used directly.
6
+
7
+ ## Features
8
+ - **Authentication Module** - User authentication and session management
9
+ - **Configuration Management** - Type-safe configuration handling with validation
10
+ - **Database Operations** - CRUD operations with Effect-ts error handling
11
+ - **Plugin System** - Utilities for plugin development and integration
12
+ - **Caching Layer** - Built-in caching with query memoization and invalidation
13
+ - **Middleware Utilities** - Request handling and middleware composition
14
+ - **Diff Tracking** - Track changes and modifications
15
+ - **REST API Helpers** - Utilities for building REST endpoints
16
+ - **Notification Settings** - User notification preference management
17
+ - **Token Bucket** - Rate limiting and token management
18
+
19
+ ## License
20
+
21
+ [MIT Licensed](./LICENSE)
@@ -0,0 +1,109 @@
1
+ import { Duration, Effect } from '@withstudiocms/effect';
2
+ import { CacheStores } from './context.js';
3
+ /**
4
+ * Represents a cache entry with a value, expiration time, and associated tags.
5
+ *
6
+ * @template A - The type of the cached value.
7
+ */
8
+ export interface CacheEntry<A> {
9
+ value: A;
10
+ expiresAt: number;
11
+ lastUpdatedAt: number;
12
+ tags: Set<string>;
13
+ }
14
+ /**
15
+ * Represents the status of a cache entry, including expiration and tags.
16
+ */
17
+ export interface CacheEntryStatus {
18
+ expiresAt: Date;
19
+ lastUpdatedAt: Date;
20
+ tags: Set<string>;
21
+ }
22
+ /**
23
+ * Error indicating that a requested cache entry was not found.
24
+ */
25
+ export declare class CacheMissError {
26
+ readonly _tag = "CacheMissError";
27
+ }
28
+ /**
29
+ * Helper function to return a non-null value or fail with CacheMissError.
30
+ *
31
+ * @template A - The type of the value.
32
+ * @param value - The value to check.
33
+ * @returns An Effect that yields the value or fails with CacheMissError.
34
+ */
35
+ export declare const returnNonNull: <A>(value: A | null) => Effect.Effect<A, CacheMissError>;
36
+ declare const CacheService_base: Effect.Service.Class<CacheService, "@withstudiocms/sdk/cache/CacheService", {
37
+ readonly effect: Effect.Effect<{
38
+ get: <A>(key: string) => Effect.Effect<A | null, never, never>;
39
+ set: <A>(key: string, value: A, options?: {
40
+ ttl?: Duration.Duration;
41
+ tags?: string[];
42
+ }) => Effect.Effect<void, never, never>;
43
+ delete: (key: string) => Effect.Effect<void, never, never>;
44
+ invalidateTags: (tags: string[]) => Effect.Effect<void, never, never>;
45
+ clear: () => Effect.Effect<void, never, never>;
46
+ memoize: <A, E, R>(key: string, effect: Effect.Effect<A, E, R>, options?: {
47
+ ttl?: Duration.Duration;
48
+ tags?: string[];
49
+ }) => Effect.Effect<A, E, R>;
50
+ getCacheStatus: (id: string) => Effect.Effect<{
51
+ expiresAt: Date;
52
+ lastUpdatedAt: Date;
53
+ tags: Set<string>;
54
+ } | null, never, never>;
55
+ }, never, CacheStores>;
56
+ }>;
57
+ /**
58
+ * In-memory caching service implemented as an Effect.Service.
59
+ *
60
+ * Provides a small, memory-resident key/value cache with optional per-entry TTL
61
+ * and tag-based invalidation. Designed to be used from Effects; each operation
62
+ * returns an Effect that performs the requested action.
63
+ *
64
+ * @remarks
65
+ * - Storage: entries are stored in a Map keyed by string. Each entry contains:
66
+ * - value: the cached value (generic)
67
+ * - expiresAt: absolute expiration time in milliseconds since epoch
68
+ * - tags: a Set of associated tag strings
69
+ * - Tag index: a separate Map from tag -> Set<key> is maintained to support
70
+ * fast invalidation of all entries associated with a given tag.
71
+ * - Expiration behavior: entries are checked for expiration lazily. An entry
72
+ * that has expired will be removed when it is accessed (via get) or when
73
+ * explicit invalidation/delete/clear is performed. There is no background
74
+ * eviction thread.
75
+ * - Default TTL: when setting an entry without an explicit ttl option, the
76
+ * service uses Duration.minutes(5) as the default time-to-live.
77
+ * - Concurrency / process model: this is an in-memory, single-process cache.
78
+ * It is not persisted and is not safe for cross-process sharing.
79
+ *
80
+ * Public API (high-level):
81
+ * - get<A>(key: string): Effect<..., A | null>
82
+ * Retrieve the value for a key. Returns null if the key is missing or expired.
83
+ *
84
+ * - set<A>(key: string, value: A, options?: { ttl?: Duration, tags?: string[] }): Effect<..., void>
85
+ * Store a value with an optional TTL and optional tags. Tags are used for
86
+ * later invalidation. Existing tag->key index entries are updated.
87
+ *
88
+ * - delete(key: string): Effect<..., void>
89
+ * Remove a single key and remove its references from the tag index.
90
+ *
91
+ * - invalidateTags(tags: string[]): Effect<..., void>
92
+ * Invalidate (delete) all keys associated with any of the provided tags and
93
+ * remove those tags from the tag index.
94
+ *
95
+ * - clear(): Effect<..., void>
96
+ * Remove all keys and clear the tag index.
97
+ *
98
+ * @example
99
+ * // Pseudocode (Effect-aware)
100
+ * const cache = yield* CacheService; // obtain CacheService from environment
101
+ * yield* cache.set('user:1', userObj, { ttl: Duration.minutes(10), tags: ['users', 'recent'] });
102
+ * const user = yield* cache.get<User>('user:1'); // returns userObj | null
103
+ * yield* cache.invalidateTags(['users']); // removes all entries tagged 'users'
104
+ *
105
+ * @public
106
+ */
107
+ export declare class CacheService extends CacheService_base {
108
+ }
109
+ export default CacheService;
package/dist/cache.js ADDED
@@ -0,0 +1,94 @@
1
+ import { Clock, Duration, Effect } from "@withstudiocms/effect";
2
+ import { CacheStores } from "./context.js";
3
+ class CacheMissError {
4
+ _tag = "CacheMissError";
5
+ }
6
+ const returnNonNull = (value) => value !== null ? Effect.succeed(value) : Effect.fail(new CacheMissError());
7
+ class CacheService extends Effect.Service()(
8
+ "@withstudiocms/sdk/cache/CacheService",
9
+ {
10
+ effect: Effect.gen(function* () {
11
+ const { store, tagIndex } = yield* CacheStores;
12
+ const get = (key) => Effect.gen(function* () {
13
+ const now = yield* Clock.currentTimeMillis;
14
+ const entry = store.get(key);
15
+ if (!entry) return null;
16
+ if (entry.expiresAt < now) {
17
+ store.delete(key);
18
+ return null;
19
+ }
20
+ return entry.value;
21
+ });
22
+ const set = (key, value, options) => Effect.gen(function* () {
23
+ const now = yield* Clock.currentTimeMillis;
24
+ const ttl = options?.ttl ?? Duration.minutes(5);
25
+ const tags = new Set(options?.tags ?? []);
26
+ const expiresAt = now + Duration.toMillis(ttl);
27
+ store.set(key, { value, expiresAt, tags, lastUpdatedAt: now });
28
+ for (const tag of tags) {
29
+ if (!tagIndex.has(tag)) {
30
+ tagIndex.set(tag, /* @__PURE__ */ new Set());
31
+ }
32
+ tagIndex.get(tag)?.add(key);
33
+ }
34
+ });
35
+ const deleteKey = (key) => Effect.sync(() => {
36
+ const entry = store.get(key);
37
+ if (entry) {
38
+ for (const tag of entry.tags) {
39
+ tagIndex.get(tag)?.delete(key);
40
+ }
41
+ }
42
+ store.delete(key);
43
+ });
44
+ const invalidateTags = (tags) => Effect.sync(() => {
45
+ for (const tag of tags) {
46
+ const keys = tagIndex.get(tag);
47
+ if (keys) {
48
+ for (const key of keys) {
49
+ store.delete(key);
50
+ }
51
+ tagIndex.delete(tag);
52
+ }
53
+ }
54
+ });
55
+ const clear = () => Effect.sync(() => {
56
+ store.clear();
57
+ tagIndex.clear();
58
+ });
59
+ const memoize = (key, effect, options) => get(key).pipe(
60
+ Effect.flatMap(returnNonNull),
61
+ Effect.catchTag(
62
+ "CacheMissError",
63
+ () => effect.pipe(Effect.tap((result) => set(key, result, options)))
64
+ )
65
+ );
66
+ const getCacheStatus = Effect.fn(
67
+ (id) => Effect.gen(function* () {
68
+ const now = yield* Clock.currentTimeMillis;
69
+ const entry = store.get(id);
70
+ if (!entry || entry.expiresAt < now) {
71
+ if (entry && entry.expiresAt < now) {
72
+ store.delete(id);
73
+ }
74
+ return null;
75
+ }
76
+ return {
77
+ expiresAt: new Date(entry.expiresAt),
78
+ lastUpdatedAt: new Date(entry.lastUpdatedAt),
79
+ tags: entry.tags
80
+ };
81
+ })
82
+ );
83
+ return { get, set, delete: deleteKey, invalidateTags, clear, memoize, getCacheStatus };
84
+ })
85
+ }
86
+ ) {
87
+ }
88
+ var cache_default = CacheService;
89
+ export {
90
+ CacheMissError,
91
+ CacheService,
92
+ cache_default as default,
93
+ returnNonNull
94
+ };
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Cache tags used throughout the SDK.
3
+ */
4
+ export declare const cacheTags: {
5
+ dynamicConfig: string[];
6
+ npmPackage: string[];
7
+ plugins: string[];
8
+ folder: string[];
9
+ folderTree: string[];
10
+ folderList: string[];
11
+ pages: string[];
12
+ pageFolderTree: string[];
13
+ middleware: string[];
14
+ taxonomy: string[];
15
+ tags: string[];
16
+ categories: string[];
17
+ };
18
+ /**
19
+ * Functions to generate cache keys for various SDK operations.
20
+ */
21
+ export declare const cacheKeyGetters: {
22
+ dynamicConfig: (id: string) => string;
23
+ npmPackage: (name: string, version: string) => string;
24
+ plugins: (name: string) => string;
25
+ folder: (folderId: string) => string;
26
+ folderTree: () => string;
27
+ folderList: () => string;
28
+ page: (pageId: string) => string;
29
+ pageFolderTree: () => string;
30
+ middleware: () => string;
31
+ tags: () => string;
32
+ categories: () => string;
33
+ categoryById: (categoryId: number) => string;
34
+ categoryBySlug: (slug: string) => string;
35
+ tagById: (tagId: number) => string;
36
+ tagBySlug: (slug: string) => string;
37
+ };
package/dist/consts.js ADDED
@@ -0,0 +1,35 @@
1
+ const cacheTags = {
2
+ dynamicConfig: ["dynamic-config"],
3
+ npmPackage: ["npm-package"],
4
+ plugins: ["plugins"],
5
+ folder: ["folder"],
6
+ folderTree: ["folder-tree"],
7
+ folderList: ["folder-list"],
8
+ pages: ["pages"],
9
+ pageFolderTree: ["page-folder-tree"],
10
+ middleware: ["middleware"],
11
+ taxonomy: ["taxonomy"],
12
+ tags: ["tags"],
13
+ categories: ["categories"]
14
+ };
15
+ const cacheKeyGetters = {
16
+ dynamicConfig: (id) => `dynamic-config:${id}`,
17
+ npmPackage: (name, version) => `npm-package:${name.replace("/", "-")}:${version}`,
18
+ plugins: (name) => `plugins:${name}`,
19
+ folder: (folderId) => `folder:${folderId}`,
20
+ folderTree: () => "folder-tree",
21
+ folderList: () => "folder-list",
22
+ page: (pageId) => `page:${pageId}`,
23
+ pageFolderTree: () => "page-folder-tree",
24
+ middleware: () => "middleware",
25
+ tags: () => "tags",
26
+ categories: () => "categories",
27
+ categoryById: (categoryId) => `category:${categoryId}`,
28
+ categoryBySlug: (slug) => `category-slug:${slug}`,
29
+ tagById: (tagId) => `tag:${tagId}`,
30
+ tagBySlug: (slug) => `tag-slug:${slug}`
31
+ };
32
+ export {
33
+ cacheKeyGetters,
34
+ cacheTags
35
+ };
@@ -0,0 +1,208 @@
1
+ import { Context, Layer } from '@withstudiocms/effect';
2
+ import type { DBClientInterface } from '@withstudiocms/kysely/client';
3
+ import type { CacheEntry } from './cache.js';
4
+ import type { StudioCMSDatabaseSchema } from './tables.js';
5
+ declare const DBClientLive_base: Context.TagClass<DBClientLive, "@withstudiocms/sdk/context/DBClientLive", DBClientInterface<{
6
+ readonly StudioCMSUsersTable: {
7
+ readonly id: string;
8
+ readonly name: string;
9
+ readonly username: string;
10
+ readonly updatedAt: import("kysely").ColumnType<string, string, string>;
11
+ readonly createdAt: import("kysely").ColumnType<string, string | undefined, undefined>;
12
+ readonly emailVerified: number;
13
+ readonly url?: string | null | undefined;
14
+ readonly email?: string | null | undefined;
15
+ readonly avatar?: string | null | undefined;
16
+ readonly password?: string | null | undefined;
17
+ readonly notifications?: string | null | undefined;
18
+ };
19
+ readonly StudioCMSOAuthAccounts: {
20
+ readonly providerUserId: string;
21
+ readonly provider: string;
22
+ readonly userId: string;
23
+ };
24
+ readonly StudioCMSSessionTable: {
25
+ readonly id: string;
26
+ readonly userId: string;
27
+ readonly expiresAt: import("kysely").ColumnType<string, string, string>;
28
+ };
29
+ readonly StudioCMSAPIKeys: {
30
+ readonly id: string;
31
+ readonly userId: string;
32
+ readonly key: string;
33
+ readonly creationDate: import("kysely").ColumnType<string, string | undefined, undefined>;
34
+ readonly description?: string | null | undefined;
35
+ };
36
+ readonly StudioCMSUserResetTokens: {
37
+ readonly id: string;
38
+ readonly userId: string;
39
+ readonly token: string;
40
+ };
41
+ readonly StudioCMSPermissions: {
42
+ readonly user: string;
43
+ readonly rank: "owner" | "admin" | "editor" | "visitor" | "unknown";
44
+ };
45
+ readonly StudioCMSPageFolderStructure: {
46
+ readonly id: string;
47
+ readonly name: string;
48
+ readonly parent?: string | null | undefined;
49
+ };
50
+ readonly StudioCMSPageData: {
51
+ readonly id: string;
52
+ readonly updatedAt: import("kysely").ColumnType<string, string, string>;
53
+ readonly description: string;
54
+ readonly package: string;
55
+ readonly title: string;
56
+ readonly showOnNav: number;
57
+ readonly publishedAt: import("kysely").ColumnType<string, string, string>;
58
+ readonly slug: string;
59
+ readonly contentLang: string;
60
+ readonly categories: import("kysely").ColumnType<string, string, string>;
61
+ readonly tags: import("kysely").ColumnType<string, string, string>;
62
+ readonly authorId: string;
63
+ readonly contributorIds: import("kysely").ColumnType<string, string, string>;
64
+ readonly showAuthor: number;
65
+ readonly showContributors: number;
66
+ readonly draft: number;
67
+ readonly augments: import("kysely").ColumnType<string, string, string>;
68
+ readonly heroImage?: string | null | undefined;
69
+ readonly parentFolder?: string | null | undefined;
70
+ };
71
+ readonly StudioCMSDiffTracking: {
72
+ readonly id: string;
73
+ readonly userId: string;
74
+ readonly pageId: string;
75
+ readonly timestamp: import("kysely").ColumnType<string, string | undefined, undefined>;
76
+ readonly pageMetaData: import("kysely").ColumnType<string, string, string>;
77
+ readonly pageContentStart: string;
78
+ readonly diff?: string | null | undefined;
79
+ };
80
+ readonly StudioCMSPageDataTags: {
81
+ readonly id: number;
82
+ readonly name: string;
83
+ readonly description: string;
84
+ readonly slug: string;
85
+ readonly meta: import("kysely").ColumnType<string, string, string>;
86
+ };
87
+ readonly StudioCMSPageDataCategories: {
88
+ readonly id: number;
89
+ readonly name: string;
90
+ readonly description: string;
91
+ readonly slug: string;
92
+ readonly meta: import("kysely").ColumnType<string, string, string>;
93
+ readonly parent?: number | null | undefined;
94
+ };
95
+ readonly StudioCMSPageContent: {
96
+ readonly id: string;
97
+ readonly contentLang: string;
98
+ readonly contentId: string;
99
+ readonly content: string;
100
+ };
101
+ readonly StudioCMSEmailVerificationTokens: {
102
+ readonly id: string;
103
+ readonly userId: string;
104
+ readonly expiresAt: import("kysely").ColumnType<string, string, string>;
105
+ readonly token: string;
106
+ };
107
+ readonly StudioCMSPluginData: {
108
+ readonly id: string;
109
+ readonly data: import("kysely").ColumnType<string, string, string>;
110
+ };
111
+ readonly StudioCMSDynamicConfigSettings: {
112
+ readonly id: string;
113
+ readonly data: import("kysely").ColumnType<string, string, string>;
114
+ };
115
+ readonly StudioCMSStorageManagerUrlMappings: {
116
+ readonly url: string;
117
+ readonly updatedAt: number;
118
+ readonly createdAt: import("kysely").ColumnType<number, number | undefined, undefined>;
119
+ readonly identifier: string;
120
+ readonly isPermanent: import("kysely").ColumnType<number, boolean, boolean>;
121
+ readonly expiresAt?: number | null | undefined;
122
+ };
123
+ }>>;
124
+ /**
125
+ * Context tag representing the database client interface for StudioCMS.
126
+ *
127
+ * This tag can be used to access the database client instance throughout the SDK,
128
+ * allowing for database operations to be performed in a type-safe manner.
129
+ */
130
+ export declare class DBClientLive extends DBClientLive_base {
131
+ /**
132
+ * Provides a live layer for the DBClient context tag using the given database client.
133
+ *
134
+ * @param db - The database client instance to be provided.
135
+ * @returns A layer that provides the DBClient context tag.
136
+ */
137
+ static Live: (db: DBClientInterface<StudioCMSDatabaseSchema>) => Layer.Layer<DBClientLive, never, never>;
138
+ }
139
+ /**
140
+ * Interface representing the default SDK options.
141
+ */
142
+ export interface SDKDefaultOpts {
143
+ GhostUserDefaults: {
144
+ id: string;
145
+ name: string;
146
+ username: string;
147
+ avatar: string;
148
+ };
149
+ NotificationSettingsDefaults: {
150
+ emailVerification: boolean;
151
+ oAuthBypassVerification: boolean;
152
+ requireEditorVerification: boolean;
153
+ requireAdminVerification: boolean;
154
+ };
155
+ }
156
+ declare const SDKDefaults_base: Context.TagClass<SDKDefaults, "@withstudiocms/sdk/context/SDKDefaults", SDKDefaultOpts>;
157
+ /**
158
+ * Context tag representing the default SDK options.
159
+ *
160
+ * This tag can be used to access default configuration options for the SDK,
161
+ * such as default user settings.
162
+ */
163
+ export declare class SDKDefaults extends SDKDefaults_base {
164
+ /**
165
+ * Provides a live layer for the SDKDefaults context tag using the given options.
166
+ *
167
+ * @param opts - The options to be provided.
168
+ * @returns A layer that provides the SDKDefaults context tag.
169
+ */
170
+ static live: (opts: SDKDefaultOpts) => Layer.Layer<SDKDefaults, never, never>;
171
+ }
172
+ /**
173
+ * Interface representing the SDK context, combining the database client and default options.
174
+ */
175
+ export interface SDKContext {
176
+ db: DBClientInterface<StudioCMSDatabaseSchema>;
177
+ defaults: SDKDefaultOpts;
178
+ cache: {
179
+ store: Map<string, CacheEntry<unknown>>;
180
+ tagIndex: Map<string, Set<string>>;
181
+ };
182
+ storageManagerResolver: (identifier: string) => Promise<string>;
183
+ }
184
+ declare const CacheStores_base: Context.TagClass<CacheStores, "@withstudiocms/sdk/context/CacheStores", {
185
+ store: Map<string, CacheEntry<unknown>>;
186
+ tagIndex: Map<string, Set<string>>;
187
+ }>;
188
+ export declare class CacheStores extends CacheStores_base {
189
+ static live: (cache: SDKContext["cache"]) => Layer.Layer<CacheStores, never, never>;
190
+ }
191
+ declare const StorageManagerResolver_base: Context.TagClass<StorageManagerResolver, "@withstudiocms/sdk/context/StorageManagerResolver", (identifier: string) => Promise<string>>;
192
+ /**
193
+ * Context tag representing the storage manager resolver function.
194
+ *
195
+ * This tag can be used to access the function responsible for resolving storage manager URLs
196
+ * based on given identifiers.
197
+ */
198
+ export declare class StorageManagerResolver extends StorageManagerResolver_base {
199
+ static live: (resolver: SDKContext["storageManagerResolver"]) => Layer.Layer<StorageManagerResolver, never, never>;
200
+ }
201
+ /**
202
+ * Combines the database client and SDK default options into a single SDK context layer.
203
+ *
204
+ * @param context - An object containing the database client and default SDK options.
205
+ * @returns A merged layer that provides both the DBClient and SDKDefaults context tags.
206
+ */
207
+ export declare const makeSDKContext: (context: SDKContext) => Layer.Layer<DBClientLive | SDKDefaults | CacheStores | StorageManagerResolver, never, never>;
208
+ export {};
@@ -0,0 +1,40 @@
1
+ import { Context, Layer } from "@withstudiocms/effect";
2
+ class DBClientLive extends Context.Tag("@withstudiocms/sdk/context/DBClientLive")() {
3
+ /**
4
+ * Provides a live layer for the DBClient context tag using the given database client.
5
+ *
6
+ * @param db - The database client instance to be provided.
7
+ * @returns A layer that provides the DBClient context tag.
8
+ */
9
+ static Live = (db) => Layer.succeed(this, db);
10
+ }
11
+ class SDKDefaults extends Context.Tag("@withstudiocms/sdk/context/SDKDefaults")() {
12
+ /**
13
+ * Provides a live layer for the SDKDefaults context tag using the given options.
14
+ *
15
+ * @param opts - The options to be provided.
16
+ * @returns A layer that provides the SDKDefaults context tag.
17
+ */
18
+ static live = (opts) => Layer.succeed(this, opts);
19
+ }
20
+ class CacheStores extends Context.Tag("@withstudiocms/sdk/context/CacheStores")() {
21
+ static live = (cache) => Layer.succeed(this, cache);
22
+ }
23
+ class StorageManagerResolver extends Context.Tag(
24
+ "@withstudiocms/sdk/context/StorageManagerResolver"
25
+ )() {
26
+ static live = (resolver) => Layer.succeed(this, resolver);
27
+ }
28
+ const makeSDKContext = (context) => Layer.mergeAll(
29
+ DBClientLive.Live(context.db),
30
+ SDKDefaults.live(context.defaults),
31
+ CacheStores.live(context.cache),
32
+ StorageManagerResolver.live(context.storageManagerResolver)
33
+ );
34
+ export {
35
+ CacheStores,
36
+ DBClientLive,
37
+ SDKDefaults,
38
+ StorageManagerResolver,
39
+ makeSDKContext
40
+ };
@@ -0,0 +1,9 @@
1
+ declare const StudioCMSSDKError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
2
+ readonly _tag: "StudioCMSSDKError";
3
+ } & Readonly<A>;
4
+ export declare class StudioCMSSDKError extends StudioCMSSDKError_base<{
5
+ message: string;
6
+ cause?: unknown;
7
+ }> {
8
+ }
9
+ export {};
package/dist/errors.js ADDED
@@ -0,0 +1,6 @@
1
+ import { Data } from "@withstudiocms/effect";
2
+ class StudioCMSSDKError extends Data.TaggedError("StudioCMSSDKError") {
3
+ }
4
+ export {
5
+ StudioCMSSDKError
6
+ };