@withstudiocms/sdk 0.1.0-beta.1 → 0.1.1

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 (55) hide show
  1. package/dist/consts.d.ts +10 -1
  2. package/dist/consts.js +12 -3
  3. package/dist/context.d.ts +36 -16
  4. package/dist/context.js +8 -1
  5. package/dist/errors.d.ts +9 -0
  6. package/dist/errors.js +6 -0
  7. package/dist/index.d.ts +341 -453
  8. package/dist/lib/pluginUtils.d.ts +4 -3
  9. package/dist/lib/pluginUtils.js +17 -10
  10. package/dist/lib/storage-manager.d.ts +10 -0
  11. package/dist/lib/storage-manager.js +17 -0
  12. package/dist/migrations/20251025T040912_init.d.ts +17 -0
  13. package/dist/migrations/20251025T040912_init.js +260 -0
  14. package/dist/migrations/20251130T150847_drop_deprecated.d.ts +13 -0
  15. package/dist/migrations/20251130T150847_drop_deprecated.js +262 -0
  16. package/dist/migrations/20251221T002125_url-mapping.d.ts +13 -0
  17. package/dist/migrations/20251221T002125_url-mapping.js +228 -0
  18. package/dist/migrator.d.ts +25 -0
  19. package/dist/migrator.js +21 -0
  20. package/dist/modules/auth/index.d.ts +60 -104
  21. package/dist/modules/auth/index.js +33 -9
  22. package/dist/modules/config/index.d.ts +5 -5
  23. package/dist/modules/config/index.js +26 -7
  24. package/dist/modules/delete/index.d.ts +2 -1
  25. package/dist/modules/delete/index.js +7 -2
  26. package/dist/modules/diffTracking/index.d.ts +8 -8
  27. package/dist/modules/diffTracking/index.js +7 -6
  28. package/dist/modules/get/index.d.ts +116 -16
  29. package/dist/modules/get/index.js +135 -22
  30. package/dist/modules/index.d.ts +326 -446
  31. package/dist/modules/init/index.d.ts +9 -9
  32. package/dist/modules/middleware/index.d.ts +2 -2
  33. package/dist/modules/notificationSettings/index.d.ts +3 -3
  34. package/dist/modules/plugins/index.d.ts +9 -8
  35. package/dist/modules/plugins/index.js +17 -6
  36. package/dist/modules/post/index.d.ts +29 -28
  37. package/dist/modules/post/index.js +47 -15
  38. package/dist/modules/resetTokenBucket/index.d.ts +1 -1
  39. package/dist/modules/resetTokenBucket/index.js +5 -2
  40. package/dist/modules/rest_api/index.d.ts +8 -8
  41. package/dist/modules/rest_api/index.js +7 -3
  42. package/dist/modules/update/index.d.ts +25 -25
  43. package/dist/modules/update/index.js +28 -10
  44. package/dist/modules/util/collectors.d.ts +14 -150
  45. package/dist/modules/util/collectors.js +41 -14
  46. package/dist/modules/util/folderTree.d.ts +4 -4
  47. package/dist/modules/util/folderTree.js +1 -1
  48. package/dist/modules/util/getFromNPM.d.ts +13 -5
  49. package/dist/modules/util/getFromNPM.js +8 -2
  50. package/dist/modules/util/index.d.ts +30 -166
  51. package/dist/modules/util/users.d.ts +7 -7
  52. package/dist/tables.d.ts +433 -0
  53. package/dist/tables.js +169 -0
  54. package/dist/types.d.ts +6 -7
  55. package/package.json +17 -5
@@ -35,7 +35,7 @@ export declare const SDKInitModule: Effect.Effect<{
35
35
  * @param config - The configuration to insert into the SiteConfig table.
36
36
  * @returns A promise that resolves to the inserted site configuration.
37
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").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
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
39
  /**
40
40
  * Initializes the StudioCMS Ghost User.
41
41
  *
@@ -44,17 +44,17 @@ export declare const SDKInitModule: Effect.Effect<{
44
44
  * @returns A promise that resolves to the ghost user record.
45
45
  */
46
46
  ghostUser: () => Effect.Effect<{
47
- readonly name: string;
48
47
  readonly id: string;
49
- readonly url: string | null | undefined;
50
- readonly email: string | null | undefined;
51
- readonly avatar: string | null | undefined;
48
+ readonly url?: string | null | undefined;
49
+ readonly name: string;
50
+ readonly email?: string | null | undefined;
51
+ readonly avatar?: string | null | undefined;
52
52
  readonly username: string;
53
- readonly password: string | null | undefined;
53
+ readonly password?: string | null | undefined;
54
54
  readonly updatedAt: Date;
55
55
  readonly createdAt: Date;
56
56
  readonly emailVerified: boolean;
57
- readonly notifications: string | null | undefined;
58
- }, import("@withstudiocms/kysely").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
59
- }, import("effect/ConfigError").ConfigError, import("../../context.js").DBClientLive | import("../../context.js").SDKDefaults | import("../../cache.js").CacheService | import("@withstudiocms/effect").Deepmerge>;
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
60
  export default SDKInitModule;
@@ -51,6 +51,6 @@ import CacheService from '../../cache.js';
51
51
  * // yield* Effect.flatMap(SDKMiddlewareModule, ({ verifyCache }) => verifyCache)
52
52
  */
53
53
  export declare const SDKMiddlewareModule: Effect.Effect<{
54
- verifyCache: () => Effect.Effect<void, import("effect/ParseResult").ParseError | import("@withstudiocms/kysely").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 | CacheService | import("@withstudiocms/effect").Deepmerge>;
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
56
  export default SDKMiddlewareModule;
@@ -47,11 +47,11 @@ export declare const SDKNotificationSettingsModule: Effect.Effect<{
47
47
  /**
48
48
  * Retrieves the site-wide notification settings.
49
49
  */
50
- get: () => Effect.Effect<import("../../types.js").DynamicConfigEntry<StudioCMSNotificationSettings>, import("@withstudiocms/kysely").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
50
+ get: () => Effect.Effect<import("../../types.js").DynamicConfigEntry<StudioCMSNotificationSettings>, import("@withstudiocms/kysely/client").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
51
51
  /**
52
52
  * Updates the site-wide notification settings.
53
53
  */
54
- update: (settings: Omit<StudioCMSNotificationSettings, "_config_version">) => Effect.Effect<import("../../types.js").DynamicConfigEntry<StudioCMSNotificationSettings>, import("@withstudiocms/kysely").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
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
55
  };
56
- }, never, import("../../context.js").DBClientLive | SDKDefaults | import("../../cache.js").CacheService | import("@withstudiocms/effect").Deepmerge>;
56
+ }, never, import("../../context.js").DBClientLive | SDKDefaults | import("../../context.js").StorageManagerResolver | import("../../cache.js").CacheService | import("@withstudiocms/effect").Deepmerge>;
57
57
  export default SDKNotificationSettingsModule;
@@ -1,6 +1,7 @@
1
1
  import { Effect, Schema } from '@withstudiocms/effect';
2
2
  import CacheService from '../../cache.js';
3
3
  import { DBClientLive } from '../../context.js';
4
+ import { StudioCMSSDKError } from '../../errors.js';
4
5
  import { type PluginDataEntry, type RecursiveSimplifyMutable, type UsePluginDataOpts, type UsePluginDataOptsBase } from '../../lib/pluginUtils.js';
5
6
  /**
6
7
  * SDKPluginsModule
@@ -119,26 +120,26 @@ export declare const SDKPluginsModule: Effect.Effect<{
119
120
  */
120
121
  usePluginData: {
121
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>): {
122
- getEntries: (filter?: (data: PluginDataEntry<R>[]) => PluginDataEntry<R>[]) => Effect.Effect<PluginDataEntry<R>[], Error, never>;
123
+ getEntries: (filter?: (data: PluginDataEntry<R>[]) => PluginDataEntry<R>[]) => Effect.Effect<PluginDataEntry<R>[], StudioCMSSDKError, never>;
123
124
  getEntry: (id: string) => {
124
125
  generatedId: () => Effect.Effect<string, never, never>;
125
- select: () => Effect.Effect<PluginDataEntry<R> | undefined, Error, never>;
126
- insert: (data: R) => Effect.Effect<PluginDataEntry<R>, Error, never>;
127
- update: (data: R) => Effect.Effect<PluginDataEntry<R>, Error, 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>;
128
129
  };
129
130
  };
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>): {
131
132
  generatedId: () => Effect.Effect<string, never, never>;
132
- select: () => Effect.Effect<PluginDataEntry<R> | undefined, Error, never>;
133
- insert: (data: R) => Effect.Effect<PluginDataEntry<R>, Error, never>;
134
- update: (data: R) => Effect.Effect<PluginDataEntry<R>, Error, 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>;
135
136
  };
136
137
  };
137
138
  /**
138
139
  * Initializes the plugin data cache by fetching all existing entries from the database
139
140
  * and populating the in-memory cache with these entries.
140
141
  */
141
- initPluginDataCache: (BATCH_SIZE?: number | undefined) => Effect.Effect<void, import("@withstudiocms/kysely").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
142
+ initPluginDataCache: (BATCH_SIZE?: number | undefined) => Effect.Effect<void, import("@withstudiocms/kysely/client").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
142
143
  /**
143
144
  * Clears the plugin data cache, removing all cached entries.
144
145
  *
@@ -1,13 +1,14 @@
1
1
  import { Effect, Schema } from "@withstudiocms/effect";
2
- import { StudioCMSPluginData } from "@withstudiocms/kysely";
3
2
  import CacheService from "../../cache.js";
4
3
  import { cacheKeyGetters, cacheTags } from "../../consts.js";
5
4
  import { DBClientLive } from "../../context.js";
5
+ import { StudioCMSSDKError } from "../../errors.js";
6
6
  import {
7
7
  parseData,
8
8
  parsedDataResponse,
9
9
  SelectPluginDataRespondOrFail
10
10
  } from "../../lib/pluginUtils.js";
11
+ import { StudioCMSPluginData } from "../../tables.js";
11
12
  const cacheKey = cacheKeyGetters.plugins;
12
13
  const cacheOpts = { tags: cacheTags.plugins };
13
14
  const SDKPluginsModule = Effect.gen(function* () {
@@ -43,14 +44,20 @@ const SDKPluginsModule = Effect.gen(function* () {
43
44
  encoder: StudioCMSPluginData.Insert,
44
45
  decoder: StudioCMSPluginData.Select,
45
46
  callbackFn: (db, entry) => db(
46
- (client) => client.insertInto("StudioCMSPluginData").values(entry).returningAll().executeTakeFirstOrThrow()
47
+ (client) => client.transaction().execute(async (trx) => {
48
+ await trx.insertInto("StudioCMSPluginData").values(entry).executeTakeFirstOrThrow();
49
+ return await trx.selectFrom("StudioCMSPluginData").selectAll().where("id", "=", entry.id).executeTakeFirstOrThrow();
50
+ })
47
51
  )
48
52
  });
49
53
  const _dbUpdatePluginDataEntry = withCodec({
50
54
  encoder: StudioCMSPluginData.Update,
51
55
  decoder: StudioCMSPluginData.Select,
52
56
  callbackFn: (db, entry) => db(
53
- (client) => client.updateTable("StudioCMSPluginData").set(entry).where("id", "=", entry.id).returningAll().executeTakeFirstOrThrow()
57
+ (client) => client.transaction().execute(async (trx) => {
58
+ await trx.updateTable("StudioCMSPluginData").set(entry).where("id", "=", entry.id).executeTakeFirstOrThrow();
59
+ return await trx.selectFrom("StudioCMSPluginData").selectAll().where("id", "=", entry.id).executeTakeFirstOrThrow();
60
+ })
54
61
  )
55
62
  });
56
63
  const _initPluginDataCache = Effect.fn(
@@ -108,16 +115,20 @@ const SDKPluginsModule = Effect.gen(function* () {
108
115
  }
109
116
  case SelectPluginDataRespondOrFail.ExistsShouldFail: {
110
117
  if (existing)
111
- return yield* Effect.fail(new Error(`Plugin data with ID ${id} already exists.`));
118
+ return yield* new StudioCMSSDKError({
119
+ message: `Plugin data with ID ${id} already exists.`
120
+ });
112
121
  return void 0;
113
122
  }
114
123
  case SelectPluginDataRespondOrFail.NotExistsShouldFail: {
115
124
  if (!existing)
116
- return yield* Effect.fail(new Error(`Plugin data with ID ${id} does not exist.`));
125
+ return yield* new StudioCMSSDKError({
126
+ message: `Plugin data with ID ${id} does not exist.`
127
+ });
117
128
  return void 0;
118
129
  }
119
130
  default:
120
- return yield* Effect.fail(new Error(`Invalid mode: ${mode}`));
131
+ return yield* new StudioCMSSDKError({ message: `Invalid mode: ${mode}` });
121
132
  }
122
133
  });
123
134
  const _select = Effect.fn(function* (generatedEntryId, validator) {
@@ -1,7 +1,8 @@
1
1
  import { Effect } from '@withstudiocms/effect';
2
- import { DBCallbackFailure, StudioCMSPageData, StudioCMSPermissions } from '@withstudiocms/kysely';
2
+ import { DBCallbackFailure } from '@withstudiocms/kysely/client';
3
3
  import CacheService from '../../cache.js';
4
4
  import { DBClientLive } from '../../context.js';
5
+ import { StudioCMSPageData, StudioCMSPermissions } from '../../tables.js';
5
6
  import type { CombinedInsertContent } from '../../types.js';
6
7
  /**
7
8
  * Represents the data required to insert a new page.
@@ -91,23 +92,23 @@ export declare const SDKPostModule: Effect.Effect<{
91
92
  * @returns An effect that resolves to an object containing the IDs of the newly inserted page data and content.
92
93
  */
93
94
  pages: (pageData: OptionalId<string, {
94
- readonly tags: string;
95
95
  readonly id: string;
96
- readonly description: string;
97
- readonly slug: string;
98
- readonly contentLang: string;
99
96
  readonly updatedAt: string;
97
+ readonly description: string;
100
98
  readonly package: string;
101
99
  readonly title: string;
102
100
  readonly showOnNav: boolean;
103
101
  readonly publishedAt: string;
104
- readonly heroImage: string | null | undefined;
102
+ readonly slug: string;
103
+ readonly contentLang: string;
104
+ readonly heroImage?: string | null | undefined;
105
105
  readonly categories: string;
106
+ readonly tags: string;
106
107
  readonly authorId: string;
107
108
  readonly contributorIds: string;
108
109
  readonly showAuthor: boolean;
109
110
  readonly showContributors: boolean;
110
- readonly parentFolder: string | null | undefined;
111
+ readonly parentFolder?: string | null | undefined;
111
112
  readonly draft: boolean;
112
113
  readonly augments: string;
113
114
  }>, pageContent: CombinedInsertContent) => Effect.Effect<{
@@ -126,8 +127,8 @@ export declare const SDKPostModule: Effect.Effect<{
126
127
  */
127
128
  pageContent: (input: {
128
129
  readonly id: string;
129
- readonly contentId: string;
130
130
  readonly contentLang: string;
131
+ readonly contentId: string;
131
132
  readonly content: string;
132
133
  }) => Effect.Effect<{
133
134
  readonly id: string;
@@ -139,8 +140,8 @@ export declare const SDKPostModule: Effect.Effect<{
139
140
  * @returns An effect that resolves to the ID of the newly inserted tag.
140
141
  */
141
142
  tags: (tag: OptionalId<number, {
142
- readonly name: string;
143
143
  readonly id: number;
144
+ readonly name: string;
144
145
  readonly description: string;
145
146
  readonly slug: string;
146
147
  readonly meta: string;
@@ -154,10 +155,10 @@ export declare const SDKPostModule: Effect.Effect<{
154
155
  * @returns An effect that resolves to the ID of the newly inserted category.
155
156
  */
156
157
  categories: (category: OptionalId<number, {
157
- readonly name: string;
158
158
  readonly id: number;
159
- readonly parent: number | null | undefined;
159
+ readonly name: string;
160
160
  readonly description: string;
161
+ readonly parent?: number | null | undefined;
161
162
  readonly slug: string;
162
163
  readonly meta: string;
163
164
  }>) => Effect.Effect<{
@@ -183,21 +184,21 @@ export declare const SDKPostModule: Effect.Effect<{
183
184
  diffTracking: (data: OptionalId<string, {
184
185
  readonly id: string;
185
186
  readonly userId: string;
186
- readonly pageMetaData: string;
187
187
  readonly pageId: string;
188
188
  readonly timestamp: string | undefined;
189
+ readonly pageMetaData: string;
189
190
  readonly pageContentStart: string;
190
- readonly diff: string | null | undefined;
191
+ readonly diff?: string | null | undefined;
191
192
  }>) => Effect.Effect<{
192
193
  readonly id: string;
193
194
  readonly userId: string;
195
+ readonly pageId: string;
196
+ readonly timestamp: Date;
194
197
  readonly pageMetaData: {
195
198
  readonly [x: string]: unknown;
196
199
  };
197
- readonly pageId: string;
198
- readonly timestamp: Date;
199
200
  readonly pageContentStart: string;
200
- readonly diff: string | null | undefined;
201
+ readonly diff?: string | null | undefined;
201
202
  }, DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
202
203
  /**
203
204
  * Inserts a new folder structure entry into the database.
@@ -206,13 +207,13 @@ export declare const SDKPostModule: Effect.Effect<{
206
207
  * @returns An effect that resolves to the newly inserted folder structure entry.
207
208
  */
208
209
  folder: (data: OptionalId<string, {
209
- readonly name: string;
210
210
  readonly id: string;
211
- readonly parent: string | null | undefined;
212
- }>) => Effect.Effect<{
213
211
  readonly name: string;
212
+ readonly parent?: string | null | undefined;
213
+ }>) => Effect.Effect<{
214
214
  readonly id: string;
215
- readonly parent: string | null | undefined;
215
+ readonly name: string;
216
+ readonly parent?: string | null | undefined;
216
217
  }, DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
217
218
  };
218
219
  databaseEntries: {
@@ -223,8 +224,8 @@ export declare const SDKPostModule: Effect.Effect<{
223
224
  * @returns An effect that resolves to an array of IDs of the newly inserted tags.
224
225
  */
225
226
  tags: (tags: OptionalId<number, {
226
- readonly name: string;
227
227
  readonly id: number;
228
+ readonly name: string;
228
229
  readonly description: string;
229
230
  readonly slug: string;
230
231
  readonly meta: string;
@@ -238,10 +239,10 @@ export declare const SDKPostModule: Effect.Effect<{
238
239
  * @returns An effect that resolves to an array of IDs of the newly inserted categories.
239
240
  */
240
241
  categories: (categories: OptionalId<number, {
241
- readonly name: string;
242
242
  readonly id: number;
243
- readonly parent: number | null | undefined;
243
+ readonly name: string;
244
244
  readonly description: string;
245
+ readonly parent?: number | null | undefined;
245
246
  readonly slug: string;
246
247
  readonly meta: string;
247
248
  }>[]) => Effect.Effect<{
@@ -282,13 +283,13 @@ export declare const SDKPostModule: Effect.Effect<{
282
283
  * @returns An effect that resolves to the newly inserted folder structure entry.
283
284
  */
284
285
  folder: (data: OptionalId<string, {
285
- readonly name: string;
286
286
  readonly id: string;
287
- readonly parent: string | null | undefined;
288
- }>) => Effect.Effect<{
289
287
  readonly name: string;
288
+ readonly parent?: string | null | undefined;
289
+ }>) => Effect.Effect<{
290
290
  readonly id: string;
291
- readonly parent: string | null | undefined;
291
+ readonly name: string;
292
+ readonly parent?: string | null | undefined;
292
293
  }, DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError | import("../util/folderTree.js").FolderTreeError, never>;
293
294
  /**
294
295
  * Inserts a new page along with its content into the database.
@@ -301,5 +302,5 @@ export declare const SDKPostModule: Effect.Effect<{
301
302
  pageData: OptionalId<string, (typeof StudioCMSPageData)["Insert"]["Type"]>;
302
303
  pageContent: CombinedInsertContent;
303
304
  }) => Effect.Effect<import("../../types.js").CombinedPageData | undefined, import("effect/ParseResult").ParseError | 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>;
304
- }, import("effect/ConfigError").ConfigError, DBClientLive | import("../../context.js").SDKDefaults | CacheService | import("@withstudiocms/effect").Deepmerge>;
305
+ }, import("effect/ConfigError").ConfigError, DBClientLive | import("../../context.js").SDKDefaults | import("../../context.js").StorageManagerResolver | CacheService | import("@withstudiocms/effect").Deepmerge>;
305
306
  export default SDKPostModule;
@@ -1,6 +1,9 @@
1
1
  import { Effect, pipe, Schema } from "@withstudiocms/effect";
2
+ import { DBCallbackFailure } from "@withstudiocms/kysely/client";
3
+ import CacheService from "../../cache.js";
4
+ import { cacheTags } from "../../consts.js";
5
+ import { DBClientLive } from "../../context.js";
2
6
  import {
3
- DBCallbackFailure,
4
7
  StudioCMSDiffTracking,
5
8
  StudioCMSPageContent,
6
9
  StudioCMSPageData,
@@ -8,10 +11,7 @@ import {
8
11
  StudioCMSPageDataTags,
9
12
  StudioCMSPageFolderStructure,
10
13
  StudioCMSPermissions
11
- } from "@withstudiocms/kysely";
12
- import CacheService from "../../cache.js";
13
- import { cacheTags } from "../../consts.js";
14
- import { DBClientLive } from "../../context.js";
14
+ } from "../../tables.js";
15
15
  import SDKClearModule from "../clear/index.js";
16
16
  import SDKGetModule from "../get/index.js";
17
17
  import SDKUpdateModule from "../update/index.js";
@@ -34,7 +34,10 @@ const SDKPostModule = Effect.gen(function* () {
34
34
  id: Schema.String
35
35
  }),
36
36
  callbackFn: (db, data) => db(
37
- (client) => client.insertInto("StudioCMSPageData").values(data).returning("id").executeTakeFirstOrThrow()
37
+ (client) => client.transaction().execute(async (trx) => {
38
+ await trx.insertInto("StudioCMSPageData").values(data).executeTakeFirstOrThrow();
39
+ return await trx.selectFrom("StudioCMSPageData").select(["id"]).where("id", "=", data.id).executeTakeFirstOrThrow();
40
+ })
38
41
  )
39
42
  });
40
43
  const _insertPageContent = withCodec({
@@ -43,7 +46,10 @@ const SDKPostModule = Effect.gen(function* () {
43
46
  id: Schema.String
44
47
  }),
45
48
  callbackFn: (db, data) => db(
46
- (client) => client.insertInto("StudioCMSPageContent").values(data).returning("id").executeTakeFirstOrThrow()
49
+ (client) => client.transaction().execute(async (trx) => {
50
+ await trx.insertInto("StudioCMSPageContent").values(data).executeTakeFirstOrThrow();
51
+ return await trx.selectFrom("StudioCMSPageContent").select(["id"]).where("id", "=", data.id).executeTakeFirstOrThrow();
52
+ })
47
53
  )
48
54
  });
49
55
  const _insertTagData = withCodec({
@@ -52,7 +58,10 @@ const SDKPostModule = Effect.gen(function* () {
52
58
  id: Schema.Number
53
59
  }),
54
60
  callbackFn: (db, data) => db(
55
- (client) => client.insertInto("StudioCMSPageDataTags").values(data).returning("id").executeTakeFirstOrThrow()
61
+ (client) => client.transaction().execute(async (trx) => {
62
+ await trx.insertInto("StudioCMSPageDataTags").values(data).executeTakeFirstOrThrow();
63
+ return await trx.selectFrom("StudioCMSPageDataTags").select(["id"]).where("id", "=", data.id).executeTakeFirstOrThrow();
64
+ })
56
65
  )
57
66
  });
58
67
  const _insertCategoryData = withCodec({
@@ -61,7 +70,10 @@ const SDKPostModule = Effect.gen(function* () {
61
70
  id: Schema.Number
62
71
  }),
63
72
  callbackFn: (db, data) => db(
64
- (client) => client.insertInto("StudioCMSPageDataCategories").values(data).returning("id").executeTakeFirstOrThrow()
73
+ (client) => client.transaction().execute(async (trx) => {
74
+ await trx.insertInto("StudioCMSPageDataCategories").values(data).executeTakeFirstOrThrow();
75
+ return await trx.selectFrom("StudioCMSPageDataCategories").select(["id"]).where("id", "=", data.id).executeTakeFirstOrThrow();
76
+ })
65
77
  )
66
78
  });
67
79
  const _getUserPermission = withCodec({
@@ -75,21 +87,30 @@ const SDKPostModule = Effect.gen(function* () {
75
87
  encoder: StudioCMSPermissions.Insert,
76
88
  decoder: StudioCMSPermissions.Select,
77
89
  callbackFn: (db, data) => db(
78
- (client) => client.insertInto("StudioCMSPermissions").values(data).returningAll().executeTakeFirstOrThrow()
90
+ (client) => client.transaction().execute(async (trx) => {
91
+ await trx.insertInto("StudioCMSPermissions").values(data).executeTakeFirstOrThrow();
92
+ return await trx.selectFrom("StudioCMSPermissions").selectAll().where("user", "=", data.user).executeTakeFirstOrThrow();
93
+ })
79
94
  )
80
95
  });
81
96
  const _insertNewDiffTracking = withCodec({
82
97
  encoder: StudioCMSDiffTracking.Insert,
83
98
  decoder: StudioCMSDiffTracking.Select,
84
99
  callbackFn: (db, data) => db(
85
- (client) => client.insertInto("StudioCMSDiffTracking").values(data).returningAll().executeTakeFirstOrThrow()
100
+ (client) => client.transaction().execute(async (trx) => {
101
+ await trx.insertInto("StudioCMSDiffTracking").values(data).executeTakeFirstOrThrow();
102
+ return await trx.selectFrom("StudioCMSDiffTracking").selectAll().where("id", "=", data.id).executeTakeFirstOrThrow();
103
+ })
86
104
  )
87
105
  });
88
106
  const _insertNewFolder = withCodec({
89
107
  encoder: StudioCMSPageFolderStructure.Insert,
90
108
  decoder: StudioCMSPageFolderStructure.Select,
91
109
  callbackFn: (db, data) => db(
92
- (client) => client.insertInto("StudioCMSPageFolderStructure").values(data).returningAll().executeTakeFirstOrThrow()
110
+ (client) => client.transaction().execute(async (trx) => {
111
+ await trx.insertInto("StudioCMSPageFolderStructure").values(data).executeTakeFirstOrThrow();
112
+ return await trx.selectFrom("StudioCMSPageFolderStructure").selectAll().where("id", "=", data.id).executeTakeFirstOrThrow();
113
+ })
93
114
  )
94
115
  });
95
116
  const _randomUUIDString = Effect.fn(() => Effect.succeed(crypto.randomUUID().toString()));
@@ -126,17 +147,28 @@ const SDKPostModule = Effect.gen(function* () {
126
147
  )
127
148
  );
128
149
  const _pickIdOrGenerate = Effect.fn(function* (data) {
129
- const id = data.id || (yield* generateRandomIDNumber(9));
150
+ let id;
151
+ if ("id" in data && typeof data.id === "number" && !Number.isNaN(data.id) && data.id > 0) {
152
+ id = data.id;
153
+ } else {
154
+ id = yield* generateRandomIDNumber(9);
155
+ }
130
156
  return { id, ...data };
131
157
  });
132
158
  const _insertNewTag = Effect.fn(
133
- (tag) => _pickIdOrGenerate(tag).pipe(Effect.flatMap(_insertTagData))
159
+ (tag) => _pickIdOrGenerate(tag).pipe(
160
+ Effect.flatMap(_insertTagData),
161
+ Effect.tap(() => invalidateTags(cacheTags.tags))
162
+ )
134
163
  );
135
164
  const _insertTagArray = Effect.fn(
136
165
  (tags) => Effect.all(tags.map((tag) => _insertNewTag(tag)))
137
166
  );
138
167
  const _insertNewCategory = Effect.fn(
139
- (category) => _pickIdOrGenerate(category).pipe(Effect.flatMap(_insertCategoryData))
168
+ (category) => _pickIdOrGenerate(category).pipe(
169
+ Effect.flatMap(_insertCategoryData),
170
+ Effect.tap(() => invalidateTags(cacheTags.categories))
171
+ )
140
172
  );
141
173
  const _insertCategoryArray = Effect.fn(
142
174
  (categories) => Effect.all(categories.map((category) => _insertNewCategory(category)))
@@ -1,5 +1,5 @@
1
1
  import { Effect } from '@withstudiocms/effect';
2
- import { type DBCallbackFailure } from '@withstudiocms/kysely';
2
+ import type { DBCallbackFailure } from '@withstudiocms/kysely/client';
3
3
  import type { DatabaseError } from '@withstudiocms/kysely/core/errors';
4
4
  import { DBClientLive } from '../../context.js';
5
5
  /**
@@ -1,6 +1,6 @@
1
1
  import { Effect, Schema } from "@withstudiocms/effect";
2
- import { StudioCMSUserResetTokens } from "@withstudiocms/kysely";
3
2
  import { DBClientLive } from "../../context.js";
3
+ import { StudioCMSUserResetTokens } from "../../tables.js";
4
4
  import { SDKGenerators } from "../util/generators.js";
5
5
  class resetTokenBucketFail {
6
6
  _tag = "resetTokenBucketFail";
@@ -14,7 +14,10 @@ const SDKResetTokenBucketModule = Effect.gen(function* () {
14
14
  encoder: StudioCMSUserResetTokens.Insert,
15
15
  decoder: StudioCMSUserResetTokens.Select,
16
16
  callbackFn: (db, data) => db(
17
- (client) => client.insertInto("StudioCMSUserResetTokens").values(data).returningAll().executeTakeFirstOrThrow()
17
+ (client) => client.transaction().execute(async (trx) => {
18
+ await trx.insertInto("StudioCMSUserResetTokens").values(data).executeTakeFirstOrThrow();
19
+ return await trx.selectFrom("StudioCMSUserResetTokens").selectAll().where("id", "=", data.id).executeTakeFirstOrThrow();
20
+ })
18
21
  )
19
22
  });
20
23
  const _deleteTokenByUserId = withEncoder({
@@ -43,12 +43,12 @@ export declare const SDKRestAPIModule: Effect.Effect<{
43
43
  * @throws {LibSQLDatabaseError} If a database error occurs during the operation.
44
44
  */
45
45
  get: (input: string) => Effect.Effect<readonly {
46
- readonly key: string;
47
46
  readonly id: string;
48
- readonly description: string | null | undefined;
49
47
  readonly userId: string;
48
+ readonly key: string;
50
49
  readonly creationDate: Date;
51
- }[], import("@withstudiocms/kysely").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
50
+ readonly description?: string | null | undefined;
51
+ }[], import("@withstudiocms/kysely/client").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
52
52
  /**
53
53
  * Creates a new API token for a user with the specified description.
54
54
  *
@@ -58,12 +58,12 @@ export declare const SDKRestAPIModule: Effect.Effect<{
58
58
  * @throws {LibSQLDatabaseError} If a database error occurs during the operation.
59
59
  */
60
60
  new: (userId: string, description: string) => Effect.Effect<{
61
- readonly key: string;
62
61
  readonly id: string;
63
- readonly description: string | null | undefined;
64
62
  readonly userId: string;
63
+ readonly key: string;
65
64
  readonly creationDate: Date;
66
- }, import("@withstudiocms/kysely").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError | import("../util/generators.js").GeneratorError, never>;
65
+ readonly description?: string | null | undefined;
66
+ }, import("@withstudiocms/kysely/client").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError | import("../util/generators.js").GeneratorError, never>;
67
67
  /**
68
68
  * Deletes an API token for a user by its ID.
69
69
  *
@@ -75,7 +75,7 @@ export declare const SDKRestAPIModule: Effect.Effect<{
75
75
  delete: (input: {
76
76
  readonly userId: string;
77
77
  readonly tokenId: string;
78
- }) => Effect.Effect<import("kysely").DeleteResult[], import("@withstudiocms/kysely").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
78
+ }) => Effect.Effect<import("kysely").DeleteResult[], import("@withstudiocms/kysely/client").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
79
79
  /**
80
80
  * Verifies an API token and retrieves associated user information.
81
81
  *
@@ -86,7 +86,7 @@ export declare const SDKRestAPIModule: Effect.Effect<{
86
86
  userId: string;
87
87
  key: string;
88
88
  rank: "owner" | "admin" | "editor" | "visitor" | "unknown";
89
- }, import("@withstudiocms/kysely").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
89
+ }, import("@withstudiocms/kysely/client").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
90
90
  };
91
91
  }, import("effect/ConfigError").ConfigError, DBClientLive>;
92
92
  export default SDKRestAPIModule;
@@ -1,6 +1,6 @@
1
1
  import { Effect, Schema } from "@withstudiocms/effect";
2
- import { StudioCMSAPIKeys, StudioCMSPermissions } from "@withstudiocms/kysely";
3
2
  import { DBClientLive } from "../../context.js";
3
+ import { StudioCMSAPIKeys, StudioCMSPermissions } from "../../tables.js";
4
4
  import { SDKGenerators } from "../util/generators.js";
5
5
  const SDKRestAPIModule = Effect.gen(function* () {
6
6
  const [{ withCodec, withEncoder }, { generateToken }] = yield* Effect.all([
@@ -18,7 +18,10 @@ const SDKRestAPIModule = Effect.gen(function* () {
18
18
  encoder: StudioCMSAPIKeys.Insert,
19
19
  decoder: StudioCMSAPIKeys.Select,
20
20
  callbackFn: (db, tokenData) => db(
21
- (client) => client.insertInto("StudioCMSAPIKeys").values(tokenData).returningAll().executeTakeFirstOrThrow()
21
+ (client) => client.transaction().execute(async (trx) => {
22
+ await trx.insertInto("StudioCMSAPIKeys").values(tokenData).executeTakeFirstOrThrow();
23
+ return await trx.selectFrom("StudioCMSAPIKeys").selectAll().where("id", "=", tokenData.id).executeTakeFirstOrThrow();
24
+ })
22
25
  )
23
26
  });
24
27
  const _deleteToken = withEncoder({
@@ -51,7 +54,8 @@ const SDKRestAPIModule = Effect.gen(function* () {
51
54
  id: crypto.randomUUID(),
52
55
  key,
53
56
  userId,
54
- description
57
+ description,
58
+ creationDate: (/* @__PURE__ */ new Date()).toISOString()
55
59
  })
56
60
  )
57
61
  )