@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
@@ -0,0 +1,37 @@
1
+ import AUTH from "./auth/index.js";
2
+ import CLEAR from "./clear/index.js";
3
+ import CONFIG from "./config/index.js";
4
+ import DELETE from "./delete/index.js";
5
+ import diffTracking from "./diffTracking/index.js";
6
+ import GET from "./get/index.js";
7
+ import INIT from "./init/index.js";
8
+ import MIDDLEWARES from "./middleware/index.js";
9
+ import notificationSettings from "./notificationSettings/index.js";
10
+ import PLUGINS from "./plugins/index.js";
11
+ import POST from "./post/index.js";
12
+ import resetTokenBucket from "./resetTokenBucket/index.js";
13
+ import REST_API from "./rest_api/index.js";
14
+ import UPDATE from "./update/index.js";
15
+ import UTIL from "./util/index.js";
16
+ const SDKModules = {
17
+ AUTH,
18
+ CLEAR,
19
+ CONFIG,
20
+ DELETE,
21
+ diffTracking,
22
+ GET,
23
+ INIT,
24
+ MIDDLEWARES,
25
+ notificationSettings,
26
+ PLUGINS,
27
+ POST,
28
+ resetTokenBucket,
29
+ REST_API,
30
+ UPDATE,
31
+ UTIL
32
+ };
33
+ var modules_default = SDKModules;
34
+ export {
35
+ SDKModules,
36
+ modules_default as default
37
+ };
@@ -0,0 +1,60 @@
1
+ import { Effect } from '@withstudiocms/effect';
2
+ /**
3
+ * Initializes and exposes core StudioCMS SDK initialization utilities as an Effect.
4
+ *
5
+ * This module is an Effect.gen that awaits the SDK configuration and authentication modules
6
+ * (SDKConfigModule and SDKAuthModule) and returns a small initialization surface for
7
+ * higher-level SDK setup tasks.
8
+ *
9
+ * The returned object has two primary members:
10
+ * - siteConfig: a function that initializes the StudioCMS SiteConfig table with the provided configuration.
11
+ * Use this to seed or update the persisted site configuration used by the SDK.
12
+ * - ghostUser: a function that returns the system "ghost" user record. The ghost user is a default
13
+ * actor used for system-level actions and to replace deleted users when needed.
14
+ *
15
+ * Remarks:
16
+ * - This Effect does not itself perform site or user initialization on import; it resolves to an object
17
+ * exposing operations that perform those tasks when invoked.
18
+ * - If SDKConfigModule or SDKAuthModule fail to initialize, this Effect will fail accordingly.
19
+ *
20
+ *
21
+ * Example:
22
+ * ```ts
23
+ * // inside an Effect.gen context
24
+ * const init = yield* SDKInitModule;
25
+ * // initialize site configuration
26
+ * yield* init.siteConfig(mySiteConfig);
27
+ * // fetch the ghost user
28
+ * const ghost = yield* init.ghostUser();
29
+ * ```
30
+ */
31
+ export declare const SDKInitModule: Effect.Effect<{
32
+ /**
33
+ * Initializes the StudioCMS SiteConfig table with the provided configuration.
34
+ *
35
+ * @param config - The configuration to insert into the SiteConfig table.
36
+ * @returns A promise that resolves to the inserted site configuration.
37
+ */
38
+ siteConfig: (data: import("../../types.js").ConfigFinal<import("../../types.js").StudioCMSSiteConfig>) => Effect.Effect<import("../../types.js").DynamicConfigEntry<import("../../types.js").StudioCMSSiteConfig>, import("@withstudiocms/kysely/client").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
39
+ /**
40
+ * Initializes the StudioCMS Ghost User.
41
+ *
42
+ * The ghost user is a default user that is used to perform actions on behalf of the system as well as to replace deleted users.
43
+ *
44
+ * @returns A promise that resolves to the ghost user record.
45
+ */
46
+ ghostUser: () => Effect.Effect<{
47
+ readonly id: string;
48
+ readonly url?: string | null | undefined;
49
+ readonly name: string;
50
+ readonly email?: string | null | undefined;
51
+ readonly avatar?: string | null | undefined;
52
+ readonly username: string;
53
+ readonly password?: string | null | undefined;
54
+ readonly updatedAt: Date;
55
+ readonly createdAt: Date;
56
+ readonly emailVerified: boolean;
57
+ readonly notifications?: string | null | undefined;
58
+ }, import("@withstudiocms/kysely/client").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
59
+ }, import("effect/ConfigError").ConfigError, import("../../context.js").DBClientLive | import("../../context.js").SDKDefaults | import("../../context.js").StorageManagerResolver | import("../../cache.js").CacheService | import("@withstudiocms/effect").Deepmerge>;
60
+ export default SDKInitModule;
@@ -0,0 +1,38 @@
1
+ import { Effect } from "@withstudiocms/effect";
2
+ import SDKAuthModule from "../auth/index.js";
3
+ import SDKConfigModule from "../config/index.js";
4
+ const SDKInitModule = Effect.gen(function* () {
5
+ const [
6
+ {
7
+ siteConfig: { init: initSiteConfig }
8
+ },
9
+ {
10
+ user: {
11
+ ghost: { get: initGhostUser }
12
+ }
13
+ }
14
+ ] = yield* Effect.all([SDKConfigModule, SDKAuthModule]);
15
+ const INIT = {
16
+ /**
17
+ * Initializes the StudioCMS SiteConfig table with the provided configuration.
18
+ *
19
+ * @param config - The configuration to insert into the SiteConfig table.
20
+ * @returns A promise that resolves to the inserted site configuration.
21
+ */
22
+ siteConfig: initSiteConfig,
23
+ /**
24
+ * Initializes the StudioCMS Ghost User.
25
+ *
26
+ * The ghost user is a default user that is used to perform actions on behalf of the system as well as to replace deleted users.
27
+ *
28
+ * @returns A promise that resolves to the ghost user record.
29
+ */
30
+ ghostUser: initGhostUser
31
+ };
32
+ return INIT;
33
+ });
34
+ var init_default = SDKInitModule;
35
+ export {
36
+ SDKInitModule,
37
+ init_default as default
38
+ };
@@ -0,0 +1,56 @@
1
+ import { Effect } from '@withstudiocms/effect';
2
+ import CacheService from '../../cache.js';
3
+ /**
4
+ * SDKMiddlewareModule
5
+ *
6
+ * Initializes and exposes middleware-related effects for the SDK.
7
+ *
8
+ * This module composes several underlying services (SDKGetModule, SDKPluginsModule,
9
+ * CacheService) to produce a memoized effect that verifies and populates middleware
10
+ * caches used across the application. The verification process updates:
11
+ * - pages (with a forced refresh)
12
+ * - folder tree
13
+ * - page-folder tree
14
+ * - folder list
15
+ * - site configuration
16
+ * - plugin data cache
17
+ *
18
+ * The verification effect logs the start and end of the operation and measures the
19
+ * duration for performance monitoring.
20
+ *
21
+ * The primary exported value is:
22
+ * - verifyCache: a memoized Effect that runs the full cache verification pipeline.
23
+ *
24
+ * Key behaviors and guarantees
25
+ * - Memoized: verifyCache is wrapped with a memoization layer (tags: middleware)
26
+ * and configured with a TTL of 30 minutes to avoid redundant executions.
27
+ * - Side effects: the effect performs network/cache updates and logging.
28
+ * - Concurrency: repeated invocations while a verification is in progress will
29
+ * leverage the memoization to avoid duplicating work for the same cache key.
30
+ * - Failure semantics: failures from any underlying update (pages, folder tree,
31
+ * plugin initialization, etc.) will propagate through the effect; callers should
32
+ * handle or surface errors as appropriate.
33
+ * - Cancellation: the effect follows the cancellation semantics of the underlying
34
+ * Effect runtime (i.e., it may be cancelable depending on the implementation of
35
+ * the composed effects).
36
+ *
37
+ * Usage:
38
+ * - Run or schedule verifyCache to ensure middleware caches are initialized and kept
39
+ * fresh. Because it is memoized with a TTL, it is inexpensive to call repeatedly
40
+ * from different parts of the system.
41
+ *
42
+ * @remarks
43
+ * - This module has implicit dependencies on SDKGetModule, SDKPluginsModule and
44
+ * CacheService; it should be provided/loaded within the same Effect environment.
45
+ *
46
+ * @returns An object containing:
47
+ * - verifyCache: a memoized Effect that verifies and initializes middleware caches.
48
+ *
49
+ * @example
50
+ * // Example invocation (pseudocode)
51
+ * // yield* Effect.flatMap(SDKMiddlewareModule, ({ verifyCache }) => verifyCache)
52
+ */
53
+ export declare const SDKMiddlewareModule: Effect.Effect<{
54
+ verifyCache: () => Effect.Effect<void, import("effect/Cause").UnknownException | import("effect/ParseResult").ParseError | import("@withstudiocms/kysely/client").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").QueryParseError | import("@withstudiocms/kysely/core/errors").QueryError | import("@withstudiocms/kysely/core/errors").NotFoundError | import("../util/folderTree.js").FolderTreeError | import("../util/collectors.js").CollectorError | import("../get/index.js").PaginateError, never>;
55
+ }, never, import("../../context.js").DBClientLive | import("../../context.js").SDKDefaults | import("../../context.js").StorageManagerResolver | CacheService | import("@withstudiocms/effect").Deepmerge>;
56
+ export default SDKMiddlewareModule;
@@ -0,0 +1,50 @@
1
+ import { Duration, Effect } from "@withstudiocms/effect";
2
+ import CacheService from "../../cache.js";
3
+ import { cacheKeyGetters, cacheTags } from "../../consts.js";
4
+ import SDKGetModule from "../get/index.js";
5
+ import SDKPluginsModule from "../plugins/index.js";
6
+ const SDKMiddlewareModule = Effect.gen(function* () {
7
+ const [
8
+ {
9
+ pages: updatePages,
10
+ folderTree: updateFolderTree,
11
+ pageFolderTree: updatePageFolderTree,
12
+ folderList: updateFolderList,
13
+ siteConfig: updateSiteConfig
14
+ },
15
+ { initPluginDataCache },
16
+ { memoize }
17
+ ] = yield* Effect.all([SDKGetModule, SDKPluginsModule, CacheService]);
18
+ const _verifyCacheEffect = Effect.log("Verifying middleware caches...").pipe(
19
+ Effect.map(() => Date.now()),
20
+ Effect.flatMap(
21
+ (startTime) => Effect.all({
22
+ pages: updatePages(true),
23
+ folderTree: updateFolderTree(),
24
+ pageFolderTree: updatePageFolderTree(),
25
+ folderList: updateFolderList(),
26
+ siteConfig: updateSiteConfig(),
27
+ pluginData: initPluginDataCache(),
28
+ startTime: Effect.succeed(startTime)
29
+ })
30
+ ),
31
+ Effect.flatMap(({ startTime }) => Effect.succeed({ startTime, endTime: Date.now() })),
32
+ Effect.flatMap(
33
+ ({ startTime, endTime }) => Effect.log(`Middleware caches verified in ${endTime - startTime}ms.`)
34
+ )
35
+ );
36
+ const verifyCache = Effect.fn(
37
+ () => memoize(cacheKeyGetters.middleware(), _verifyCacheEffect, {
38
+ tags: cacheTags.middleware,
39
+ ttl: Duration.minutes(30)
40
+ }).pipe(Effect.tap(() => Effect.logDebug("Completed middleware cache verification.")))
41
+ );
42
+ return {
43
+ verifyCache
44
+ };
45
+ });
46
+ var middleware_default = SDKMiddlewareModule;
47
+ export {
48
+ SDKMiddlewareModule,
49
+ middleware_default as default
50
+ };
@@ -0,0 +1,57 @@
1
+ import { Effect } from '@withstudiocms/effect';
2
+ import { SDKDefaults } from '../../context.js';
3
+ import type { StudioCMSNotificationSettings } from '../../types.js';
4
+ /**
5
+ * SDKNotificationSettingsModule
6
+ *
7
+ * Effect-based module that exposes site-scoped notification settings operations.
8
+ *
9
+ * This module depends on SDKConfigModule and SDKDefaults to read the current
10
+ * notification configuration and to obtain default settings when none exist.
11
+ *
12
+ * The yielded object has the shape:
13
+ * {
14
+ * site: {
15
+ * get: Effect<...>, // retrieves the site notification settings, initializing with defaults if absent
16
+ * update: Effect<...> // updates the site notification settings (accepts settings without `_config_version`)
17
+ * }
18
+ * }
19
+ *
20
+ * Behavior:
21
+ * - get: Reads the current `notificationConfig`. If a configuration is present, it is returned.
22
+ * If not present, the configuration is initialized using `NotificationSettingsDefaults` and the
23
+ * initialized value is returned.
24
+ *
25
+ * - update: Persists new site notification settings. The provided `settings` argument should omit
26
+ * the internal `_config_version` field (i.e. `Omit<StudioCMSNotificationSettings, '_config_version'>`).
27
+ *
28
+ * Remarks:
29
+ * - The module is created inside an Effect.gen generator and therefore must be run within the
30
+ * surrounding Effect runtime to obtain the returned operations.
31
+ * - All operations are effectful and should be composed/run via the project's Effect primitives.
32
+ *
33
+ * Example:
34
+ * ```ts
35
+ * const module = yield* Effect.runPromise(SDKNotificationSettingsModule);
36
+ * const current = yield* Effect.runPromise(module.site.get());
37
+ * yield* Effect.runPromise(module.site.update({ ...new_settings }));
38
+ * ```
39
+ *
40
+ * @returns An Effect that yields an object with a `site` namespace containing `get` and `update` operations for site notification settings.
41
+ */
42
+ export declare const SDKNotificationSettingsModule: Effect.Effect<{
43
+ /**
44
+ * Site-specific notification settings.
45
+ */
46
+ site: {
47
+ /**
48
+ * Retrieves the site-wide notification settings.
49
+ */
50
+ get: () => Effect.Effect<import("../../types.js").DynamicConfigEntry<StudioCMSNotificationSettings>, import("@withstudiocms/kysely/client").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
51
+ /**
52
+ * Updates the site-wide notification settings.
53
+ */
54
+ update: (settings: Omit<StudioCMSNotificationSettings, "_config_version">) => Effect.Effect<import("../../types.js").DynamicConfigEntry<StudioCMSNotificationSettings>, import("@withstudiocms/kysely/client").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
55
+ };
56
+ }, never, import("../../context.js").DBClientLive | SDKDefaults | import("../../context.js").StorageManagerResolver | import("../../cache.js").CacheService | import("@withstudiocms/effect").Deepmerge>;
57
+ export default SDKNotificationSettingsModule;
@@ -0,0 +1,39 @@
1
+ import { Effect } from "@withstudiocms/effect";
2
+ import { SDKDefaults } from "../../context.js";
3
+ import { SDKConfigModule } from "../config/index.js";
4
+ const SDKNotificationSettingsModule = Effect.gen(function* () {
5
+ const [{ notificationConfig }, { NotificationSettingsDefaults }] = yield* Effect.all([
6
+ SDKConfigModule,
7
+ SDKDefaults
8
+ ]);
9
+ const _getNotificationConfig = Effect.fn(
10
+ () => notificationConfig.get().pipe(
11
+ Effect.flatMap(
12
+ (data) => data ? Effect.succeed(data) : notificationConfig.init(NotificationSettingsDefaults)
13
+ )
14
+ )
15
+ );
16
+ const _updateNotificationConfig = Effect.fn(
17
+ (settings) => notificationConfig.update(settings)
18
+ );
19
+ return {
20
+ /**
21
+ * Site-specific notification settings.
22
+ */
23
+ site: {
24
+ /**
25
+ * Retrieves the site-wide notification settings.
26
+ */
27
+ get: _getNotificationConfig,
28
+ /**
29
+ * Updates the site-wide notification settings.
30
+ */
31
+ update: _updateNotificationConfig
32
+ }
33
+ };
34
+ });
35
+ var notificationSettings_default = SDKNotificationSettingsModule;
36
+ export {
37
+ SDKNotificationSettingsModule,
38
+ notificationSettings_default as default
39
+ };
@@ -0,0 +1,167 @@
1
+ import { Effect, Schema } from '@withstudiocms/effect';
2
+ import CacheService from '../../cache.js';
3
+ import { DBClientLive } from '../../context.js';
4
+ import { StudioCMSSDKError } from '../../errors.js';
5
+ import { type PluginDataEntry, type RecursiveSimplifyMutable, type UsePluginDataOpts, type UsePluginDataOptsBase } from '../../lib/pluginUtils.js';
6
+ /**
7
+ * SDKPluginsModule
8
+ *
9
+ * Effect-based module that provides a complete set of utilities for managing plugin-scoped
10
+ * data entries persisted in the `StudioCMSPluginData` table and cached in an application cache.
11
+ * The module is implemented as an Effect.gen and depends on a database client and a cache
12
+ * service. It combines typed codecs, validation, database operations, and caching/memoization
13
+ * to provide a safe and ergonomic API for plugin authors.
14
+ *
15
+ * Key responsibilities
16
+ * - Database access:
17
+ * - Batched reads of plugin data for cache initialization.
18
+ * - Select, insert and update operations for single plugin data entries.
19
+ * - All DB operations are wrapped with codecs to validate/encode inputs and decode results.
20
+ *
21
+ * - Caching:
22
+ * - Per-entry memoization via a cache key derived from the plugin+entry id.
23
+ * - Batch cache population via `initPluginDataCache`.
24
+ * - Cache invalidation support via `clearPluginDataCache` (invalidates plugin tags).
25
+ * - Cache entries include a shared timestamp for a single initialization run.
26
+ *
27
+ * - Validation and parsing:
28
+ * - Data payloads are parsed and optionally validated with provided validator options
29
+ * before being inserted/updated or returned to callers.
30
+ * - Helpers wrap parsed results into a consistent `PluginDataEntry<T>` response.
31
+ *
32
+ * Public API (returned object)
33
+ * - usePluginData(pluginId, opts?)
34
+ * Overloaded function:
35
+ * 1) usePluginData(pluginId, opts?: UsePluginDataOptsBase<T>)
36
+ * - Returns:
37
+ * - getEntries(filter?) => Effect<PluginDataEntry<R>[], Error, never>
38
+ * Retrieves all entries for a pluginId, optionally applying an in-memory filter
39
+ * after validation and parsing.
40
+ * - getEntry(id) => builder object (generatedId, select, insert, update)
41
+ * Returns a per-entry builder for convenience when working with many entries.
42
+ *
43
+ * 2) usePluginData(pluginId, opts?: UsePluginDataOpts<T>) (when entryId provided in opts)
44
+ * - Returns a per-entry API:
45
+ * - generatedId(): Effect<string, never, never> -- returns `${pluginId}-${entryId}`.
46
+ * - select(): Effect<PluginDataEntry<R> | undefined, Error, never> -- reads, validates and returns parsed data.
47
+ * - insert(data: R): Effect<PluginDataEntry<R>, Error, never> -- validates and inserts a new entry.
48
+ * - update(data: R): Effect<PluginDataEntry<R>, Error, never> -- validates and updates an existing entry.
49
+ *
50
+ * - Generic behavior:
51
+ * - `T` is the schema or object type used for validation.
52
+ * - `R` is the resolved/public type used in returned `PluginDataEntry<R>`.
53
+ * - All operations return Effects and preserve typed validation semantics.
54
+ *
55
+ * - initPluginDataCache(BATCH_SIZE)
56
+ * - Walks the `StudioCMSPluginData` table in batches and populates the cache with
57
+ * all existing entries. Uses a single timestamp for each initialization run to
58
+ * mark `lastCacheUpdate` consistently across entries.
59
+ * - Batch size defaults and safety: accepts a batch size, coerces non-positive values
60
+ * to a sane default (e.g. 100).
61
+ *
62
+ * - clearPluginDataCache()
63
+ * - Invalidates cache entries for plugin data using configured cache tags.
64
+ *
65
+ * - InferType<S extends Schema.Struct<any>>
66
+ * - Utility class for inferring and re-exporting schema-derived types (e.g. the
67
+ * simplified/recursive `Insert` type) to help consumers derive correct generics
68
+ * for `usePluginData`.
69
+ *
70
+ * Error semantics
71
+ * - DB/validation errors are surfaced as Effect failures (Error).
72
+ * - Insert/update operations perform existence checks and will fail on duplicate inserts
73
+ * or updates to non-existent entries (controlled internally via SelectPluginDataRespondOrFail).
74
+ *
75
+ * Implementation notes (high-level)
76
+ * - DB interactions are performed via a `withCodec` wrapper that enforces input/output
77
+ * shapes at the codec boundary.
78
+ * - Per-entry caching is implemented using `memoize(cacheKey(id), dbCall, cacheOpts)`.
79
+ * - Initialization uses a batched DB query and writes entries into the cache via `set`.
80
+ * - Processing path for DB entries:
81
+ * 1) Read raw DB entry (JSON string payload).
82
+ * 2) parseData -> validate (if validator provided).
83
+ * 3) Wrap into consistent `PluginDataEntry<T>` response.
84
+ *
85
+ * Example usage
86
+ * @example
87
+ * // Get all entries for plugin "com.example"
88
+ * const sdk = yield* SDKPluginsModule;
89
+ * const getAll = sdk.usePluginData('com.example');
90
+ * const entries = yield* getAll.getEntries();
91
+ *
92
+ * // Work with a specific entry
93
+ * const entryApi = sdk.usePluginData('com.example', { entryId: 'myEntry', validator: mySchema });
94
+ * const existing = yield* entryApi.select();
95
+ * const inserted = yield* entryApi.insert({ foo: 'bar' });
96
+ *
97
+ * Thread-safety & concurrency
98
+ * - Cache and DB operations are effectful and composable; callers should coordinate
99
+ * concurrent modifications as needed (e.g. optimistic strategies) depending on application needs.
100
+ *
101
+ * Notes for contributors
102
+ * - Keep codecs and validators up-to-date with DB schema.
103
+ * - Ensure cache tag names and key generation remain stable to avoid stale cache bugs.
104
+ */
105
+ export declare const SDKPluginsModule: Effect.Effect<{
106
+ /**
107
+ * Provides a set of effectful operations for managing plugin data entries by plugin ID and optional entry ID.
108
+ *
109
+ * When an `entryId` is provided, returns an object with methods to:
110
+ * - Generate a unique plugin data entry ID.
111
+ * - Insert new plugin data after validation and duplicate checks.
112
+ * - Select and validate existing plugin data by ID.
113
+ * - Update existing plugin data after validation.
114
+ *
115
+ * When no `entryId` is provided, returns an object with a method to retrieve all entries for the given plugin.
116
+ *
117
+ * @param pluginId - The unique identifier for the plugin.
118
+ * @param entryId - (Optional) The unique identifier for the plugin data entry.
119
+ * @returns An object with effectful methods for plugin data management, varying by presence of `entryId`.
120
+ */
121
+ usePluginData: {
122
+ <T extends Schema.Struct<Schema.Struct.Fields> | object, R extends object = T extends Schema.Struct<any> ? RecursiveSimplifyMutable<T["Type"]> : T>(pluginId: string, opts?: UsePluginDataOptsBase<T>): {
123
+ getEntries: (filter?: (data: PluginDataEntry<R>[]) => PluginDataEntry<R>[]) => Effect.Effect<PluginDataEntry<R>[], StudioCMSSDKError, never>;
124
+ getEntry: (id: string) => {
125
+ generatedId: () => Effect.Effect<string, never, never>;
126
+ select: () => Effect.Effect<PluginDataEntry<R> | undefined, StudioCMSSDKError, never>;
127
+ insert: (data: R) => Effect.Effect<PluginDataEntry<R>, StudioCMSSDKError, never>;
128
+ update: (data: R) => Effect.Effect<PluginDataEntry<R>, StudioCMSSDKError, never>;
129
+ };
130
+ };
131
+ <T extends Schema.Struct<Schema.Struct.Fields> | object, R extends object = T extends Schema.Struct<any> ? RecursiveSimplifyMutable<T["Type"]> : T>(pluginId: string, opts?: UsePluginDataOpts<T>): {
132
+ generatedId: () => Effect.Effect<string, never, never>;
133
+ select: () => Effect.Effect<PluginDataEntry<R> | undefined, StudioCMSSDKError, never>;
134
+ insert: (data: R) => Effect.Effect<PluginDataEntry<R>, StudioCMSSDKError, never>;
135
+ update: (data: R) => Effect.Effect<PluginDataEntry<R>, StudioCMSSDKError, never>;
136
+ };
137
+ };
138
+ /**
139
+ * Initializes the plugin data cache by fetching all existing entries from the database
140
+ * and populating the in-memory cache with these entries.
141
+ */
142
+ initPluginDataCache: (BATCH_SIZE?: number | undefined) => Effect.Effect<void, import("@withstudiocms/kysely/client").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
143
+ /**
144
+ * Clears the plugin data cache, removing all cached entries.
145
+ *
146
+ * @returns An Effect that resolves to `void` on success or an `Error` on failure.
147
+ */
148
+ clearPluginDataCache: () => Effect.Effect<void, never, never>;
149
+ /**
150
+ * Utility class to infer types from a given Schema.
151
+ *
152
+ * @typeParam S - The schema type extending `Schema.Struct<any>`.
153
+ *
154
+ * @property _Schema - The schema instance used for type inference.
155
+ * @property usePluginData - The inferred type from the schema, used for plugin data.
156
+ * @property Insert - A recursively simplified, mutable version of the schema's type.
157
+ *
158
+ */
159
+ InferType: {
160
+ new <S extends Schema.Struct<any>, R = RecursiveSimplifyMutable<S["Type"]>>(schema: S): {
161
+ readonly _Schema: S;
162
+ readonly $UsePluginData: S;
163
+ readonly $Insert: R;
164
+ };
165
+ };
166
+ }, never, DBClientLive | CacheService>;
167
+ export default SDKPluginsModule;