@withstudiocms/sdk 0.0.0-beta.0 → 0.1.0-beta.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.
- package/LICENSE +21 -0
- package/README.md +21 -0
- package/dist/cache.d.ts +109 -0
- package/dist/cache.js +94 -0
- package/dist/consts.d.ts +28 -0
- package/dist/consts.js +26 -0
- package/dist/context.d.ts +188 -0
- package/dist/context.js +33 -0
- package/dist/index.d.ts +1136 -0
- package/dist/index.js +24 -0
- package/dist/lib/diff.d.ts +39 -0
- package/dist/lib/diff.js +29 -0
- package/dist/lib/logger.d.ts +31 -0
- package/dist/lib/logger.js +131 -0
- package/dist/lib/pluginUtils.d.ts +221 -0
- package/dist/lib/pluginUtils.js +80 -0
- package/dist/modules/auth/index.d.ts +463 -0
- package/dist/modules/auth/index.js +412 -0
- package/dist/modules/clear/index.d.ts +72 -0
- package/dist/modules/clear/index.js +52 -0
- package/dist/modules/config/consts.d.ts +32 -0
- package/dist/modules/config/consts.js +18 -0
- package/dist/modules/config/index.d.ts +100 -0
- package/dist/modules/config/index.js +205 -0
- package/dist/modules/config/templates/mailer.d.ts +36 -0
- package/dist/modules/config/templates/mailer.js +218 -0
- package/dist/modules/config/type-utils.d.ts +13 -0
- package/dist/modules/config/type-utils.js +11 -0
- package/dist/modules/delete/index.d.ts +140 -0
- package/dist/modules/delete/index.js +274 -0
- package/dist/modules/diffTracking/index.d.ts +188 -0
- package/dist/modules/diffTracking/index.js +276 -0
- package/dist/modules/get/index.d.ts +272 -0
- package/dist/modules/get/index.js +466 -0
- package/dist/modules/index.d.ts +1003 -0
- package/dist/modules/index.js +37 -0
- package/dist/modules/init/index.d.ts +60 -0
- package/dist/modules/init/index.js +38 -0
- package/dist/modules/middleware/index.d.ts +56 -0
- package/dist/modules/middleware/index.js +50 -0
- package/dist/modules/notificationSettings/index.d.ts +57 -0
- package/dist/modules/notificationSettings/index.js +39 -0
- package/dist/modules/plugins/index.d.ts +166 -0
- package/dist/modules/plugins/index.js +261 -0
- package/dist/modules/post/index.d.ts +305 -0
- package/dist/modules/post/index.js +305 -0
- package/dist/modules/resetTokenBucket/index.d.ts +91 -0
- package/dist/modules/resetTokenBucket/index.js +93 -0
- package/dist/modules/rest_api/index.d.ts +92 -0
- package/dist/modules/rest_api/index.js +113 -0
- package/dist/modules/update/index.d.ts +184 -0
- package/dist/modules/update/index.js +174 -0
- package/dist/modules/util/collectors.d.ts +261 -0
- package/dist/modules/util/collectors.js +141 -0
- package/dist/modules/util/folderTree.d.ts +100 -0
- package/dist/modules/util/folderTree.js +176 -0
- package/dist/modules/util/generators.d.ts +83 -0
- package/dist/modules/util/generators.js +106 -0
- package/dist/modules/util/getFromNPM.d.ts +191 -0
- package/dist/modules/util/getFromNPM.js +100 -0
- package/dist/modules/util/index.d.ts +236 -0
- package/dist/modules/util/index.js +20 -0
- package/dist/modules/util/parsers.d.ts +60 -0
- package/dist/modules/util/parsers.js +43 -0
- package/dist/modules/util/slugify.d.ts +22 -0
- package/dist/modules/util/slugify.js +19 -0
- package/dist/modules/util/users.d.ts +99 -0
- package/dist/modules/util/users.js +78 -0
- package/dist/types.d.ts +360 -0
- package/dist/types.js +10 -0
- package/package.json +55 -7
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { Effect, Schema } from "@withstudiocms/effect";
|
|
2
|
+
import { StudioCMSPluginData } from "@withstudiocms/kysely";
|
|
3
|
+
import CacheService from "../../cache.js";
|
|
4
|
+
import { cacheKeyGetters, cacheTags } from "../../consts.js";
|
|
5
|
+
import { DBClientLive } from "../../context.js";
|
|
6
|
+
import {
|
|
7
|
+
parseData,
|
|
8
|
+
parsedDataResponse,
|
|
9
|
+
SelectPluginDataRespondOrFail
|
|
10
|
+
} from "../../lib/pluginUtils.js";
|
|
11
|
+
const cacheKey = cacheKeyGetters.plugins;
|
|
12
|
+
const cacheOpts = { tags: cacheTags.plugins };
|
|
13
|
+
const SDKPluginsModule = Effect.gen(function* () {
|
|
14
|
+
const [{ withCodec }, { memoize, invalidateTags, set }] = yield* Effect.all([
|
|
15
|
+
DBClientLive,
|
|
16
|
+
CacheService
|
|
17
|
+
]);
|
|
18
|
+
const _dbBatchRequest = withCodec({
|
|
19
|
+
encoder: Schema.Struct({
|
|
20
|
+
batchSize: Schema.Number,
|
|
21
|
+
offset: Schema.Number
|
|
22
|
+
}),
|
|
23
|
+
decoder: Schema.Array(StudioCMSPluginData.Select),
|
|
24
|
+
callbackFn: (db, { batchSize, offset }) => db(
|
|
25
|
+
(client) => client.selectFrom("StudioCMSPluginData").selectAll().limit(batchSize).offset(offset).execute()
|
|
26
|
+
)
|
|
27
|
+
});
|
|
28
|
+
const _dbGetEntriesPluginData = withCodec({
|
|
29
|
+
encoder: Schema.String,
|
|
30
|
+
decoder: Schema.Array(StudioCMSPluginData.Select),
|
|
31
|
+
callbackFn: (db, pluginId) => db(
|
|
32
|
+
(client) => client.selectFrom("StudioCMSPluginData").selectAll().where("id", "like", `${pluginId}-%`).execute()
|
|
33
|
+
)
|
|
34
|
+
});
|
|
35
|
+
const _dbSelectPluginDataEntry = withCodec({
|
|
36
|
+
encoder: Schema.String,
|
|
37
|
+
decoder: Schema.UndefinedOr(StudioCMSPluginData.Select),
|
|
38
|
+
callbackFn: (db, entryId) => db(
|
|
39
|
+
(client) => client.selectFrom("StudioCMSPluginData").selectAll().where("id", "=", entryId).executeTakeFirst()
|
|
40
|
+
)
|
|
41
|
+
});
|
|
42
|
+
const _dbInsertPluginDataEntry = withCodec({
|
|
43
|
+
encoder: StudioCMSPluginData.Insert,
|
|
44
|
+
decoder: StudioCMSPluginData.Select,
|
|
45
|
+
callbackFn: (db, entry) => db(
|
|
46
|
+
(client) => client.insertInto("StudioCMSPluginData").values(entry).returningAll().executeTakeFirstOrThrow()
|
|
47
|
+
)
|
|
48
|
+
});
|
|
49
|
+
const _dbUpdatePluginDataEntry = withCodec({
|
|
50
|
+
encoder: StudioCMSPluginData.Update,
|
|
51
|
+
decoder: StudioCMSPluginData.Select,
|
|
52
|
+
callbackFn: (db, entry) => db(
|
|
53
|
+
(client) => client.updateTable("StudioCMSPluginData").set(entry).where("id", "=", entry.id).returningAll().executeTakeFirstOrThrow()
|
|
54
|
+
)
|
|
55
|
+
});
|
|
56
|
+
const _initPluginDataCache = Effect.fn(
|
|
57
|
+
(BATCH_SIZE) => Effect.gen(function* () {
|
|
58
|
+
let batchSize = BATCH_SIZE || 100;
|
|
59
|
+
if (batchSize <= 0) {
|
|
60
|
+
batchSize = 100;
|
|
61
|
+
}
|
|
62
|
+
let offset = 0;
|
|
63
|
+
const sharedTimestamp = /* @__PURE__ */ new Date();
|
|
64
|
+
while (true) {
|
|
65
|
+
const entries = yield* _dbBatchRequest({ batchSize, offset });
|
|
66
|
+
if (entries.length === 0) break;
|
|
67
|
+
const cacheEntries = entries.map(
|
|
68
|
+
(entry) => [entry.id, { data: entry, lastCacheUpdate: sharedTimestamp }]
|
|
69
|
+
);
|
|
70
|
+
for (const [id, cacheData] of cacheEntries) {
|
|
71
|
+
yield* set(cacheKey(id), cacheData, cacheOpts);
|
|
72
|
+
}
|
|
73
|
+
offset += batchSize;
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
);
|
|
77
|
+
const _clearPluginDataCache = Effect.fn(() => invalidateTags(cacheTags.plugins));
|
|
78
|
+
const _selectPluginDataEntry = Effect.fn(
|
|
79
|
+
(id) => memoize(cacheKey(id), _dbSelectPluginDataEntry(id), cacheOpts)
|
|
80
|
+
);
|
|
81
|
+
const _insertPluginDataEntry = Effect.fn(
|
|
82
|
+
(data) => memoize(cacheKey(data.id), _dbInsertPluginDataEntry(data), cacheOpts)
|
|
83
|
+
);
|
|
84
|
+
const _updatePluginDataEntry = Effect.fn(
|
|
85
|
+
(data) => memoize(cacheKey(data.id), _dbUpdatePluginDataEntry(data), cacheOpts)
|
|
86
|
+
);
|
|
87
|
+
const _processEntryFromDB = Effect.fn(
|
|
88
|
+
(entry, validator) => parseData(entry.data, validator).pipe(
|
|
89
|
+
Effect.flatMap((validated) => parsedDataResponse(entry.id, validated))
|
|
90
|
+
)
|
|
91
|
+
);
|
|
92
|
+
const _processPluginDataDBEntries = (validator) => Effect.fn(
|
|
93
|
+
(entries) => Effect.all(entries.map((entry) => _processEntryFromDB(entry, validator)))
|
|
94
|
+
);
|
|
95
|
+
const _filterProcessedEntries = (filter) => (entries) => filter ? filter(entries) : entries;
|
|
96
|
+
const _getEntries = Effect.fn(
|
|
97
|
+
(pluginId, validator, filter) => _dbGetEntriesPluginData(pluginId).pipe(
|
|
98
|
+
Effect.flatMap(_processPluginDataDBEntries(validator)),
|
|
99
|
+
Effect.map(_filterProcessedEntries(filter))
|
|
100
|
+
)
|
|
101
|
+
);
|
|
102
|
+
const _selectPluginDataEntryRespondOrFail = Effect.fn(function* (id, mode) {
|
|
103
|
+
const existing = yield* _selectPluginDataEntry(id);
|
|
104
|
+
switch (mode) {
|
|
105
|
+
case SelectPluginDataRespondOrFail.ExistsNoFail: {
|
|
106
|
+
if (existing) return existing;
|
|
107
|
+
return void 0;
|
|
108
|
+
}
|
|
109
|
+
case SelectPluginDataRespondOrFail.ExistsShouldFail: {
|
|
110
|
+
if (existing)
|
|
111
|
+
return yield* Effect.fail(new Error(`Plugin data with ID ${id} already exists.`));
|
|
112
|
+
return void 0;
|
|
113
|
+
}
|
|
114
|
+
case SelectPluginDataRespondOrFail.NotExistsShouldFail: {
|
|
115
|
+
if (!existing)
|
|
116
|
+
return yield* Effect.fail(new Error(`Plugin data with ID ${id} does not exist.`));
|
|
117
|
+
return void 0;
|
|
118
|
+
}
|
|
119
|
+
default:
|
|
120
|
+
return yield* Effect.fail(new Error(`Invalid mode: ${mode}`));
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
const _select = Effect.fn(function* (generatedEntryId, validator) {
|
|
124
|
+
const existing = yield* _selectPluginDataEntryRespondOrFail(
|
|
125
|
+
generatedEntryId,
|
|
126
|
+
SelectPluginDataRespondOrFail.ExistsNoFail
|
|
127
|
+
);
|
|
128
|
+
if (!existing) return void 0;
|
|
129
|
+
const data = yield* parseData(existing.data, validator);
|
|
130
|
+
return yield* parsedDataResponse(generatedEntryId, data);
|
|
131
|
+
});
|
|
132
|
+
const _insert = Effect.fn(function* (generatedEntryId, data, validator) {
|
|
133
|
+
yield* _selectPluginDataEntryRespondOrFail(
|
|
134
|
+
generatedEntryId,
|
|
135
|
+
SelectPluginDataRespondOrFail.ExistsShouldFail
|
|
136
|
+
);
|
|
137
|
+
const parsedData = yield* parseData(data, validator);
|
|
138
|
+
const inserted = yield* _insertPluginDataEntry({
|
|
139
|
+
id: generatedEntryId,
|
|
140
|
+
data: JSON.stringify(parsedData)
|
|
141
|
+
});
|
|
142
|
+
return yield* parsedDataResponse(inserted.id, parsedData);
|
|
143
|
+
});
|
|
144
|
+
const _update = Effect.fn(function* (generatedEntryId, data, validator) {
|
|
145
|
+
yield* _selectPluginDataEntryRespondOrFail(
|
|
146
|
+
generatedEntryId,
|
|
147
|
+
SelectPluginDataRespondOrFail.NotExistsShouldFail
|
|
148
|
+
);
|
|
149
|
+
const parsedData = yield* parseData(data, validator);
|
|
150
|
+
const updated = yield* _updatePluginDataEntry({
|
|
151
|
+
id: generatedEntryId,
|
|
152
|
+
data: JSON.stringify(parsedData)
|
|
153
|
+
});
|
|
154
|
+
return yield* parsedDataResponse(updated.id, parsedData);
|
|
155
|
+
});
|
|
156
|
+
const buildReturn = (pluginId, entryId, validator) => {
|
|
157
|
+
const generatedEntryId = `${pluginId}-${entryId}`;
|
|
158
|
+
return {
|
|
159
|
+
/**
|
|
160
|
+
* Generates a unique ID for the plugin data entry.
|
|
161
|
+
*
|
|
162
|
+
* @returns An Effect that yields the generated ID. In the format `${pluginId}-${entryId}`
|
|
163
|
+
*/
|
|
164
|
+
generatedId: () => Effect.succeed(generatedEntryId),
|
|
165
|
+
/**
|
|
166
|
+
* Selects a plugin data entry by its ID, validating the data if a validator is provided.
|
|
167
|
+
*
|
|
168
|
+
* @returns An Effect that yields the selected plugin data entry or `undefined` if not found.
|
|
169
|
+
*/
|
|
170
|
+
select: () => _select(generatedEntryId, validator),
|
|
171
|
+
/**
|
|
172
|
+
* Inserts new plugin data into the database after validating the input.
|
|
173
|
+
*
|
|
174
|
+
* @param data - The plugin data to insert.
|
|
175
|
+
* @yields Throws an error if validation fails or if the entry already exists.
|
|
176
|
+
* @returns The parsed data response for the inserted entry.
|
|
177
|
+
*/
|
|
178
|
+
insert: (data) => _insert(generatedEntryId, data, validator),
|
|
179
|
+
/**
|
|
180
|
+
* Updates existing plugin data in the database after validating the input.
|
|
181
|
+
*
|
|
182
|
+
* @param data - The updated plugin data.
|
|
183
|
+
* @yields Throws an error if validation fails.
|
|
184
|
+
* @returns The parsed data response for the updated entry.
|
|
185
|
+
*/
|
|
186
|
+
update: (data) => _update(generatedEntryId, data, validator)
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
function usePluginData(pluginId, { entryId, validator } = {}) {
|
|
190
|
+
if (!entryId) {
|
|
191
|
+
return {
|
|
192
|
+
/**
|
|
193
|
+
* Retrieves all plugin data entries for the specified plugin ID.
|
|
194
|
+
*
|
|
195
|
+
* @template T - The type of the plugin data object.
|
|
196
|
+
* @param validator - Optional validator options for validating the plugin data.
|
|
197
|
+
* @returns An Effect that yields an array of `PluginDataEntry<T>` objects.
|
|
198
|
+
*/
|
|
199
|
+
getEntries: (filter) => _getEntries(pluginId, validator, filter),
|
|
200
|
+
getEntry: (id) => buildReturn(pluginId, id, validator)
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
return buildReturn(pluginId, entryId, validator);
|
|
204
|
+
}
|
|
205
|
+
class InferType {
|
|
206
|
+
_Schema;
|
|
207
|
+
$UsePluginData;
|
|
208
|
+
$Insert;
|
|
209
|
+
constructor(schema) {
|
|
210
|
+
if (!schema || !Schema.isSchema(schema)) {
|
|
211
|
+
throw new Error("InferType requires a valid Schema.Struct instance.");
|
|
212
|
+
}
|
|
213
|
+
this._Schema = schema;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return {
|
|
217
|
+
/**
|
|
218
|
+
* Provides a set of effectful operations for managing plugin data entries by plugin ID and optional entry ID.
|
|
219
|
+
*
|
|
220
|
+
* When an `entryId` is provided, returns an object with methods to:
|
|
221
|
+
* - Generate a unique plugin data entry ID.
|
|
222
|
+
* - Insert new plugin data after validation and duplicate checks.
|
|
223
|
+
* - Select and validate existing plugin data by ID.
|
|
224
|
+
* - Update existing plugin data after validation.
|
|
225
|
+
*
|
|
226
|
+
* When no `entryId` is provided, returns an object with a method to retrieve all entries for the given plugin.
|
|
227
|
+
*
|
|
228
|
+
* @param pluginId - The unique identifier for the plugin.
|
|
229
|
+
* @param entryId - (Optional) The unique identifier for the plugin data entry.
|
|
230
|
+
* @returns An object with effectful methods for plugin data management, varying by presence of `entryId`.
|
|
231
|
+
*/
|
|
232
|
+
usePluginData,
|
|
233
|
+
/**
|
|
234
|
+
* Initializes the plugin data cache by fetching all existing entries from the database
|
|
235
|
+
* and populating the in-memory cache with these entries.
|
|
236
|
+
*/
|
|
237
|
+
initPluginDataCache: _initPluginDataCache,
|
|
238
|
+
/**
|
|
239
|
+
* Clears the plugin data cache, removing all cached entries.
|
|
240
|
+
*
|
|
241
|
+
* @returns An Effect that resolves to `void` on success or an `Error` on failure.
|
|
242
|
+
*/
|
|
243
|
+
clearPluginDataCache: _clearPluginDataCache,
|
|
244
|
+
/**
|
|
245
|
+
* Utility class to infer types from a given Schema.
|
|
246
|
+
*
|
|
247
|
+
* @typeParam S - The schema type extending `Schema.Struct<any>`.
|
|
248
|
+
*
|
|
249
|
+
* @property _Schema - The schema instance used for type inference.
|
|
250
|
+
* @property usePluginData - The inferred type from the schema, used for plugin data.
|
|
251
|
+
* @property Insert - A recursively simplified, mutable version of the schema's type.
|
|
252
|
+
*
|
|
253
|
+
*/
|
|
254
|
+
InferType
|
|
255
|
+
};
|
|
256
|
+
});
|
|
257
|
+
var plugins_default = SDKPluginsModule;
|
|
258
|
+
export {
|
|
259
|
+
SDKPluginsModule,
|
|
260
|
+
plugins_default as default
|
|
261
|
+
};
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import { Effect } from '@withstudiocms/effect';
|
|
2
|
+
import { DBCallbackFailure, StudioCMSPageData, StudioCMSPermissions } from '@withstudiocms/kysely';
|
|
3
|
+
import CacheService from '../../cache.js';
|
|
4
|
+
import { DBClientLive } from '../../context.js';
|
|
5
|
+
import type { CombinedInsertContent } from '../../types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Represents the data required to insert a new page.
|
|
8
|
+
*/
|
|
9
|
+
export interface PageInsert {
|
|
10
|
+
pageData: OptionalId<string, (typeof StudioCMSPageData)['Insert']['Type']>;
|
|
11
|
+
pageContent: CombinedInsertContent;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Represents an array of PageInsert objects.
|
|
15
|
+
*/
|
|
16
|
+
export type MultiPageInsert = PageInsert[];
|
|
17
|
+
/**
|
|
18
|
+
* Utility type to make the 'id' property optional in a given type T.
|
|
19
|
+
*
|
|
20
|
+
* @template IDType - The type of the 'id' property.
|
|
21
|
+
* @template T - The original type containing the 'id' property.
|
|
22
|
+
*/
|
|
23
|
+
export type OptionalId<IDType, T> = Omit<T, 'id'> & {
|
|
24
|
+
id?: IDType;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Error class representing an existing permission for a user.
|
|
28
|
+
*/
|
|
29
|
+
export declare class PermissionExistsError {
|
|
30
|
+
readonly _tag = "PermissionExistsError";
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* SDKPostModule
|
|
34
|
+
*
|
|
35
|
+
* Effect generator that builds and returns the post/page-related SDK surface for database
|
|
36
|
+
* insert operations and related helpers. This module wires together database client and
|
|
37
|
+
* auxiliary services (clear/update/get/generator/cache) and exposes both single- and
|
|
38
|
+
* batch-oriented insertion APIs plus higher-level "main" operations that also trigger
|
|
39
|
+
* cache invalidation and UI updates.
|
|
40
|
+
*
|
|
41
|
+
* Remarks
|
|
42
|
+
* - The generator yields the following dependencies: DBClientLive, SDKClearModule,
|
|
43
|
+
* SDKUpdateModule, SDKGetModule, SDKGenerators, CacheService.
|
|
44
|
+
* - Low-level DB insert wrappers are created with `withCodec` and perform SQL operations
|
|
45
|
+
* against tables such as StudioCMSPageData, StudioCMSPageContent, StudioCMSPageDataTags,
|
|
46
|
+
* StudioCMSPageDataCategories, StudioCMSPermissions, StudioCMSDiffTracking,
|
|
47
|
+
* StudioCMSPageFolderStructure.
|
|
48
|
+
* - Helpers use Effect primitives (pipe, flatMap, tap, all, catchTag, succeed, fail)
|
|
49
|
+
* and utilities such as `crypto.randomUUID()` and a numeric id generator
|
|
50
|
+
* (`generateRandomIDNumber`) to ensure IDs when not provided.
|
|
51
|
+
* - Cache invalidation is performed via `invalidateTags(cacheTags.pages)` and certain
|
|
52
|
+
* operations also call `clear.*` and `update.*` to refresh derived state such as
|
|
53
|
+
* folder lists/trees.
|
|
54
|
+
* - Duplicate permission insertion is guarded: attempting to insert a permission for a
|
|
55
|
+
* user that already exists results in a PermissionExistsError which is mapped to a
|
|
56
|
+
* DBCallbackFailure with a descriptive message.
|
|
57
|
+
*
|
|
58
|
+
* Exposed API (returned object)
|
|
59
|
+
* - databaseEntry: object containing single-entry insert effects:
|
|
60
|
+
* - pages(pageData, pageContent): insert a page and its content (returns inserted ids)
|
|
61
|
+
* - pageContent(data): insert page content entry
|
|
62
|
+
* - tags(tag): insert a tag (ensures id)
|
|
63
|
+
* - categories(category): insert a category (ensures id)
|
|
64
|
+
* - permissions(userId, rank): insert a permission for a user (fails if already exists)
|
|
65
|
+
* - diffTracking(data): insert diff-tracking entry (ensures id)
|
|
66
|
+
* - folder(data): insert a folder structure entry (ensures id)
|
|
67
|
+
* - databaseEntries: object containing batch insert effects:
|
|
68
|
+
* - tags(array): insert multiple tags
|
|
69
|
+
* - categories(array): insert multiple categories
|
|
70
|
+
* - permissions(array): insert multiple permissions
|
|
71
|
+
* - pages(array): insert multiple pages with content
|
|
72
|
+
* - folder: higher-level folder insert that triggers update.folderList and update.folderTree
|
|
73
|
+
* - page: higher-level page insert that clears folder caches, invalidates page cache tags,
|
|
74
|
+
* and returns the freshly-read page via GET.page.byId
|
|
75
|
+
*
|
|
76
|
+
* Errors
|
|
77
|
+
* - DB operations propagate database-level errors from the SQL client.
|
|
78
|
+
* - Permission insertion collides are translated to DBCallbackFailure with a human-friendly
|
|
79
|
+
* cause string.
|
|
80
|
+
*
|
|
81
|
+
* Returns
|
|
82
|
+
* - An Effect that, when executed, yields the assembled API object described above.
|
|
83
|
+
*/
|
|
84
|
+
export declare const SDKPostModule: Effect.Effect<{
|
|
85
|
+
databaseEntry: {
|
|
86
|
+
/**
|
|
87
|
+
* Inserts a new page along with its content into the database.
|
|
88
|
+
*
|
|
89
|
+
* @param pageData - The data for the new page, excluding the ID.
|
|
90
|
+
* @param pageContent - The content for the new page.
|
|
91
|
+
* @returns An effect that resolves to an object containing the IDs of the newly inserted page data and content.
|
|
92
|
+
*/
|
|
93
|
+
pages: (pageData: OptionalId<string, {
|
|
94
|
+
readonly tags: string;
|
|
95
|
+
readonly id: string;
|
|
96
|
+
readonly description: string;
|
|
97
|
+
readonly slug: string;
|
|
98
|
+
readonly contentLang: string;
|
|
99
|
+
readonly updatedAt: string;
|
|
100
|
+
readonly package: string;
|
|
101
|
+
readonly title: string;
|
|
102
|
+
readonly showOnNav: boolean;
|
|
103
|
+
readonly publishedAt: string;
|
|
104
|
+
readonly heroImage: string | null | undefined;
|
|
105
|
+
readonly categories: string;
|
|
106
|
+
readonly authorId: string;
|
|
107
|
+
readonly contributorIds: string;
|
|
108
|
+
readonly showAuthor: boolean;
|
|
109
|
+
readonly showContributors: boolean;
|
|
110
|
+
readonly parentFolder: string | null | undefined;
|
|
111
|
+
readonly draft: boolean;
|
|
112
|
+
readonly augments: string;
|
|
113
|
+
}>, pageContent: CombinedInsertContent) => Effect.Effect<{
|
|
114
|
+
pageData: {
|
|
115
|
+
readonly id: string;
|
|
116
|
+
};
|
|
117
|
+
pageContent: {
|
|
118
|
+
readonly id: string;
|
|
119
|
+
};
|
|
120
|
+
}, DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
|
|
121
|
+
/**
|
|
122
|
+
* Inserts a new page content entry into the database.
|
|
123
|
+
*
|
|
124
|
+
* @param data - The page content data to be inserted.
|
|
125
|
+
* @returns An effect that resolves to the ID of the newly inserted page content.
|
|
126
|
+
*/
|
|
127
|
+
pageContent: (input: {
|
|
128
|
+
readonly id: string;
|
|
129
|
+
readonly contentId: string;
|
|
130
|
+
readonly contentLang: string;
|
|
131
|
+
readonly content: string;
|
|
132
|
+
}) => Effect.Effect<{
|
|
133
|
+
readonly id: string;
|
|
134
|
+
}, DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
|
|
135
|
+
/**
|
|
136
|
+
* Inserts a new page data tag into the database.
|
|
137
|
+
*
|
|
138
|
+
* @param tag - The tag data to be inserted.
|
|
139
|
+
* @returns An effect that resolves to the ID of the newly inserted tag.
|
|
140
|
+
*/
|
|
141
|
+
tags: (tag: OptionalId<number, {
|
|
142
|
+
readonly name: string;
|
|
143
|
+
readonly id: number;
|
|
144
|
+
readonly description: string;
|
|
145
|
+
readonly slug: string;
|
|
146
|
+
readonly meta: string;
|
|
147
|
+
}>) => Effect.Effect<{
|
|
148
|
+
readonly id: number;
|
|
149
|
+
}, DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError | import("../util/generators.js").GeneratorError, never>;
|
|
150
|
+
/**
|
|
151
|
+
* Inserts a new page data category into the database.
|
|
152
|
+
*
|
|
153
|
+
* @param category - The category data to be inserted.
|
|
154
|
+
* @returns An effect that resolves to the ID of the newly inserted category.
|
|
155
|
+
*/
|
|
156
|
+
categories: (category: OptionalId<number, {
|
|
157
|
+
readonly name: string;
|
|
158
|
+
readonly id: number;
|
|
159
|
+
readonly parent: number | null | undefined;
|
|
160
|
+
readonly description: string;
|
|
161
|
+
readonly slug: string;
|
|
162
|
+
readonly meta: string;
|
|
163
|
+
}>) => Effect.Effect<{
|
|
164
|
+
readonly id: number;
|
|
165
|
+
}, DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError | import("../util/generators.js").GeneratorError, never>;
|
|
166
|
+
/**
|
|
167
|
+
* Inserts a new permission entry for a user into the database.
|
|
168
|
+
*
|
|
169
|
+
* @param userId - The ID of the user for whom the permission is to be created.
|
|
170
|
+
* @param rank - The rank of the permission to be assigned.
|
|
171
|
+
* @returns An effect that resolves to the newly inserted permission entry.
|
|
172
|
+
*/
|
|
173
|
+
permissions: (userId: string, rank: "owner" | "admin" | "editor" | "visitor" | "unknown") => Effect.Effect<{
|
|
174
|
+
readonly user: string;
|
|
175
|
+
readonly rank: "owner" | "admin" | "editor" | "visitor" | "unknown";
|
|
176
|
+
}, DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
|
|
177
|
+
/**
|
|
178
|
+
* Inserts a new diff tracking entry into the database.
|
|
179
|
+
*
|
|
180
|
+
* @param data - The diff tracking data to be inserted.
|
|
181
|
+
* @returns An effect that resolves to the newly inserted diff tracking entry.
|
|
182
|
+
*/
|
|
183
|
+
diffTracking: (data: OptionalId<string, {
|
|
184
|
+
readonly id: string;
|
|
185
|
+
readonly userId: string;
|
|
186
|
+
readonly pageMetaData: string;
|
|
187
|
+
readonly pageId: string;
|
|
188
|
+
readonly timestamp: string | undefined;
|
|
189
|
+
readonly pageContentStart: string;
|
|
190
|
+
readonly diff: string | null | undefined;
|
|
191
|
+
}>) => Effect.Effect<{
|
|
192
|
+
readonly id: string;
|
|
193
|
+
readonly userId: string;
|
|
194
|
+
readonly pageMetaData: {
|
|
195
|
+
readonly [x: string]: unknown;
|
|
196
|
+
};
|
|
197
|
+
readonly pageId: string;
|
|
198
|
+
readonly timestamp: Date;
|
|
199
|
+
readonly pageContentStart: string;
|
|
200
|
+
readonly diff: string | null | undefined;
|
|
201
|
+
}, DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
|
|
202
|
+
/**
|
|
203
|
+
* Inserts a new folder structure entry into the database.
|
|
204
|
+
*
|
|
205
|
+
* @param data - The folder structure data to be inserted.
|
|
206
|
+
* @returns An effect that resolves to the newly inserted folder structure entry.
|
|
207
|
+
*/
|
|
208
|
+
folder: (data: OptionalId<string, {
|
|
209
|
+
readonly name: string;
|
|
210
|
+
readonly id: string;
|
|
211
|
+
readonly parent: string | null | undefined;
|
|
212
|
+
}>) => Effect.Effect<{
|
|
213
|
+
readonly name: string;
|
|
214
|
+
readonly id: string;
|
|
215
|
+
readonly parent: string | null | undefined;
|
|
216
|
+
}, DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
|
|
217
|
+
};
|
|
218
|
+
databaseEntries: {
|
|
219
|
+
/**
|
|
220
|
+
* Inserts an array of new page data tags into the database.
|
|
221
|
+
*
|
|
222
|
+
* @param tags - The array of tag data to be inserted.
|
|
223
|
+
* @returns An effect that resolves to an array of IDs of the newly inserted tags.
|
|
224
|
+
*/
|
|
225
|
+
tags: (tags: OptionalId<number, {
|
|
226
|
+
readonly name: string;
|
|
227
|
+
readonly id: number;
|
|
228
|
+
readonly description: string;
|
|
229
|
+
readonly slug: string;
|
|
230
|
+
readonly meta: string;
|
|
231
|
+
}>[]) => Effect.Effect<{
|
|
232
|
+
readonly id: number;
|
|
233
|
+
}[], DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError | import("../util/generators.js").GeneratorError, never>;
|
|
234
|
+
/**
|
|
235
|
+
* Inserts an array of new page data categories into the database.
|
|
236
|
+
*
|
|
237
|
+
* @param categories - The array of category data to be inserted.
|
|
238
|
+
* @returns An effect that resolves to an array of IDs of the newly inserted categories.
|
|
239
|
+
*/
|
|
240
|
+
categories: (categories: OptionalId<number, {
|
|
241
|
+
readonly name: string;
|
|
242
|
+
readonly id: number;
|
|
243
|
+
readonly parent: number | null | undefined;
|
|
244
|
+
readonly description: string;
|
|
245
|
+
readonly slug: string;
|
|
246
|
+
readonly meta: string;
|
|
247
|
+
}>[]) => Effect.Effect<{
|
|
248
|
+
readonly id: number;
|
|
249
|
+
}[], DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError | import("../util/generators.js").GeneratorError, never>;
|
|
250
|
+
/**
|
|
251
|
+
* Inserts an array of new permissions into the database.
|
|
252
|
+
*
|
|
253
|
+
* @param permissions - The array of permission data to be inserted.
|
|
254
|
+
* @returns An effect that resolves to an array of newly inserted permission entries.
|
|
255
|
+
*/
|
|
256
|
+
permissions: (permissions: {
|
|
257
|
+
userId: string;
|
|
258
|
+
rank: (typeof StudioCMSPermissions.Insert.Type)["rank"];
|
|
259
|
+
}[]) => Effect.Effect<{
|
|
260
|
+
readonly user: string;
|
|
261
|
+
readonly rank: "owner" | "admin" | "editor" | "visitor" | "unknown";
|
|
262
|
+
}[], DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
|
|
263
|
+
/**
|
|
264
|
+
* Inserts an array of new pages along with their content into the database.
|
|
265
|
+
*
|
|
266
|
+
* @param data - An array of PageInsert objects containing page data and content.
|
|
267
|
+
* @returns An effect that resolves to an array of objects containing the IDs of the newly inserted page data and content for each page.
|
|
268
|
+
*/
|
|
269
|
+
pages: (pages: MultiPageInsert) => Effect.Effect<{
|
|
270
|
+
pageData: {
|
|
271
|
+
readonly id: string;
|
|
272
|
+
};
|
|
273
|
+
pageContent: {
|
|
274
|
+
readonly id: string;
|
|
275
|
+
};
|
|
276
|
+
}[], DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, never>;
|
|
277
|
+
};
|
|
278
|
+
/**
|
|
279
|
+
* Inserts a new folder structure entry into the database, ensuring it has an ID.
|
|
280
|
+
*
|
|
281
|
+
* @param data - The folder structure data to be inserted.
|
|
282
|
+
* @returns An effect that resolves to the newly inserted folder structure entry.
|
|
283
|
+
*/
|
|
284
|
+
folder: (data: OptionalId<string, {
|
|
285
|
+
readonly name: string;
|
|
286
|
+
readonly id: string;
|
|
287
|
+
readonly parent: string | null | undefined;
|
|
288
|
+
}>) => Effect.Effect<{
|
|
289
|
+
readonly name: string;
|
|
290
|
+
readonly id: string;
|
|
291
|
+
readonly parent: string | null | undefined;
|
|
292
|
+
}, DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError | import("../util/folderTree.js").FolderTreeError, never>;
|
|
293
|
+
/**
|
|
294
|
+
* Inserts a new page along with its content into the database.
|
|
295
|
+
*
|
|
296
|
+
* @param pageData - The data for the new page, excluding the ID.
|
|
297
|
+
* @param pageContent - The content for the new page.
|
|
298
|
+
* @returns An effect that resolves to the newly inserted page data.
|
|
299
|
+
*/
|
|
300
|
+
page: (args_0: {
|
|
301
|
+
pageData: OptionalId<string, (typeof StudioCMSPageData)["Insert"]["Type"]>;
|
|
302
|
+
pageContent: CombinedInsertContent;
|
|
303
|
+
}) => 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
|
+
export default SDKPostModule;
|