@blinkk/root-cms 2.0.10 → 2.1.2-alpha.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.
- package/dist/app.js +108 -41
- package/dist/cli.js +20 -9
- package/dist/{client-Vr32ZRmC.d.ts → client-BKO9Ikqy.d.ts} +4 -4
- package/dist/client.d.ts +1 -1
- package/dist/client.js +1 -1
- package/dist/core.d.ts +3 -4
- package/dist/core.js +19 -15
- package/dist/functions.d.ts +2 -2
- package/dist/functions.js +3 -3
- package/dist/plugin.d.ts +1 -1
- package/dist/plugin.js +109 -33
- package/dist/project.d.ts +14 -4
- package/dist/project.js +68 -8
- package/dist/{schema-KpQGOA1Z.d.ts → schema-FB6Ck9sN.d.ts} +39 -9
- package/dist/ui/signin.js +168 -72
- package/dist/ui/ui.css +1 -1
- package/dist/ui/ui.js +491 -288
- package/package.json +24 -22
package/dist/plugin.js
CHANGED
|
@@ -51,21 +51,21 @@ __export(generate_types_exports, {
|
|
|
51
51
|
generateSchemaDts: () => generateSchemaDts,
|
|
52
52
|
generateTypes: () => generateTypes
|
|
53
53
|
});
|
|
54
|
-
import { promises as
|
|
55
|
-
import
|
|
56
|
-
import { fileURLToPath } from "
|
|
54
|
+
import { promises as fs3 } from "fs";
|
|
55
|
+
import path4 from "path";
|
|
56
|
+
import { fileURLToPath } from "url";
|
|
57
57
|
import { loadRootConfig, viteSsrLoadModule } from "@blinkk/root/node";
|
|
58
58
|
import * as dom from "dts-dom";
|
|
59
59
|
async function generateTypes() {
|
|
60
60
|
const rootDir = process.cwd();
|
|
61
61
|
const rootConfig = await loadRootConfig(rootDir, { command: "root-cms" });
|
|
62
|
-
const modulePath =
|
|
62
|
+
const modulePath = path4.resolve(__dirname, "./project.js");
|
|
63
63
|
const project = await viteSsrLoadModule(
|
|
64
64
|
rootConfig,
|
|
65
65
|
modulePath
|
|
66
66
|
);
|
|
67
|
-
const schemas = project.getProjectSchemas();
|
|
68
|
-
const outputPath =
|
|
67
|
+
const schemas = await project.getProjectSchemas();
|
|
68
|
+
const outputPath = path4.resolve(rootDir, "root-cms.d.ts");
|
|
69
69
|
await generateSchemaDts(outputPath, schemas);
|
|
70
70
|
console.log("saved root-cms.d.ts!");
|
|
71
71
|
}
|
|
@@ -76,7 +76,7 @@ async function generateSchemaDts(outputPath, schemas) {
|
|
|
76
76
|
dtsFormatter.addSchemaFile(fileId, schema);
|
|
77
77
|
}
|
|
78
78
|
const output = dtsFormatter.toString();
|
|
79
|
-
await
|
|
79
|
+
await fs3.writeFile(outputPath, output, "utf-8");
|
|
80
80
|
}
|
|
81
81
|
function fieldProperty(field, options) {
|
|
82
82
|
const prop = dom.create.property(
|
|
@@ -129,12 +129,19 @@ function fieldType(field, options) {
|
|
|
129
129
|
if (field.types && Array.isArray(field.types)) {
|
|
130
130
|
const unionTypes = [];
|
|
131
131
|
field.types.forEach((schema) => {
|
|
132
|
-
|
|
132
|
+
let typeName;
|
|
133
|
+
if (typeof schema === "string") {
|
|
134
|
+
typeName = schema;
|
|
133
135
|
return;
|
|
136
|
+
} else {
|
|
137
|
+
typeName = schema.name;
|
|
134
138
|
}
|
|
135
|
-
|
|
139
|
+
if (!typeName) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const cleanName = alphanumeric(typeName);
|
|
136
143
|
const oneOfTypeId = `${cleanName}Fields`;
|
|
137
|
-
if (!options.oneOfTypes[oneOfTypeId]) {
|
|
144
|
+
if (typeof schema === "object" && !options.oneOfTypes[oneOfTypeId]) {
|
|
138
145
|
const oneOfTypeInterface = dom.create.interface(
|
|
139
146
|
oneOfTypeId,
|
|
140
147
|
dom.DeclarationFlags.Export
|
|
@@ -150,7 +157,7 @@ function fieldType(field, options) {
|
|
|
150
157
|
}
|
|
151
158
|
const oneOfOption = dom.create.namedTypeReference("RootCMSOneOfOption");
|
|
152
159
|
oneOfOption.typeArguments = [
|
|
153
|
-
dom.type.stringLiteral(
|
|
160
|
+
dom.type.stringLiteral(typeName),
|
|
154
161
|
dom.create.namedTypeReference(oneOfTypeId)
|
|
155
162
|
];
|
|
156
163
|
unionTypes.push(oneOfOption);
|
|
@@ -165,6 +172,10 @@ function fieldType(field, options) {
|
|
|
165
172
|
const referenceType = dom.create.namedTypeReference("RootCMSReference");
|
|
166
173
|
return referenceType;
|
|
167
174
|
}
|
|
175
|
+
if (field.type === "references") {
|
|
176
|
+
const referenceType = dom.create.namedTypeReference("RootCMSReference");
|
|
177
|
+
return dom.type.array(referenceType);
|
|
178
|
+
}
|
|
168
179
|
if (field.type === "richtext") {
|
|
169
180
|
const richtextType = dom.create.namedTypeReference("RootCMSRichText");
|
|
170
181
|
return richtextType;
|
|
@@ -190,7 +201,7 @@ var __dirname, TEMPLATE, DtsFormatter;
|
|
|
190
201
|
var init_generate_types = __esm({
|
|
191
202
|
"cli/generate-types.ts"() {
|
|
192
203
|
"use strict";
|
|
193
|
-
__dirname =
|
|
204
|
+
__dirname = path4.dirname(fileURLToPath(import.meta.url));
|
|
194
205
|
TEMPLATE = `/* eslint-disable */
|
|
195
206
|
/** Root.js CMS types. This file is autogenerated. */
|
|
196
207
|
|
|
@@ -264,7 +275,7 @@ export interface RootCMSDoc<Fields extends {}> {
|
|
|
264
275
|
/** Adds the types for a `.schema.ts` file to the `.d.ts` file. */
|
|
265
276
|
addSchemaFile(fileId, schema) {
|
|
266
277
|
const jsdoc = `Generated from \`${fileId}\`.`;
|
|
267
|
-
const typeId = alphanumeric(
|
|
278
|
+
const typeId = alphanumeric(path4.parse(fileId).name.split(".")[0]);
|
|
268
279
|
const oneOfTypes = {};
|
|
269
280
|
const fieldsTypeId = `${typeId}Fields`;
|
|
270
281
|
const fieldsType = dom.create.interface(
|
|
@@ -344,9 +355,10 @@ export interface RootCMSDoc<Fields extends {}> {
|
|
|
344
355
|
});
|
|
345
356
|
|
|
346
357
|
// core/plugin.ts
|
|
347
|
-
import { promises as
|
|
348
|
-
import
|
|
349
|
-
import { fileURLToPath as fileURLToPath2 } from "
|
|
358
|
+
import { promises as fs4 } from "fs";
|
|
359
|
+
import path5 from "path";
|
|
360
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
361
|
+
import { viteSsrLoadModule as viteSsrLoadModule2 } from "@blinkk/root/node";
|
|
350
362
|
import bodyParser from "body-parser";
|
|
351
363
|
import {
|
|
352
364
|
applicationDefault,
|
|
@@ -359,12 +371,14 @@ import * as jsonwebtoken from "jsonwebtoken";
|
|
|
359
371
|
import sirv from "sirv";
|
|
360
372
|
|
|
361
373
|
// core/api.ts
|
|
374
|
+
import { promises as fs2 } from "fs";
|
|
375
|
+
import path3 from "path";
|
|
362
376
|
import { multipartMiddleware } from "@blinkk/root/middleware";
|
|
363
377
|
|
|
364
378
|
// core/ai.ts
|
|
365
|
-
import crypto from "
|
|
366
|
-
import fs from "
|
|
367
|
-
import path from "
|
|
379
|
+
import crypto from "crypto";
|
|
380
|
+
import fs from "fs";
|
|
381
|
+
import path from "path";
|
|
368
382
|
import { vertexAI } from "@genkit-ai/vertexai";
|
|
369
383
|
import { Timestamp } from "firebase-admin/firestore";
|
|
370
384
|
import { genkit } from "genkit";
|
|
@@ -548,7 +562,7 @@ var ChatClient = class {
|
|
|
548
562
|
};
|
|
549
563
|
|
|
550
564
|
// core/client.ts
|
|
551
|
-
import crypto2 from "
|
|
565
|
+
import crypto2 from "crypto";
|
|
552
566
|
import {
|
|
553
567
|
FieldValue as FieldValue2,
|
|
554
568
|
Timestamp as Timestamp3
|
|
@@ -2045,7 +2059,7 @@ var BatchResponse = class {
|
|
|
2045
2059
|
};
|
|
2046
2060
|
|
|
2047
2061
|
// core/versions.ts
|
|
2048
|
-
import path2 from "
|
|
2062
|
+
import path2 from "path";
|
|
2049
2063
|
import { Timestamp as Timestamp4 } from "firebase-admin/firestore";
|
|
2050
2064
|
import glob from "tiny-glob";
|
|
2051
2065
|
var DOCUMENT_SAVE_OFFSET = 5 * 60 * 1e3;
|
|
@@ -2192,21 +2206,48 @@ function csvToArray(csvString) {
|
|
|
2192
2206
|
}
|
|
2193
2207
|
|
|
2194
2208
|
// core/api.ts
|
|
2209
|
+
function testValidCollectionId(id) {
|
|
2210
|
+
return /^[A-Za-z0-9_-]+$/.test(id);
|
|
2211
|
+
}
|
|
2195
2212
|
function api(server, options) {
|
|
2213
|
+
async function getCollectionSchema(req, collectionId) {
|
|
2214
|
+
if (req.viteServer) {
|
|
2215
|
+
const app = await options.getRenderer(req);
|
|
2216
|
+
return await app.getCollection(collectionId);
|
|
2217
|
+
}
|
|
2218
|
+
try {
|
|
2219
|
+
const schemaPath = path3.join(
|
|
2220
|
+
req.rootConfig.rootDir,
|
|
2221
|
+
"dist",
|
|
2222
|
+
"collections",
|
|
2223
|
+
`${collectionId}.schema.json`
|
|
2224
|
+
);
|
|
2225
|
+
const contents = await fs2.readFile(schemaPath, "utf8");
|
|
2226
|
+
return JSON.parse(contents);
|
|
2227
|
+
} catch (err) {
|
|
2228
|
+
if (err && err.code === "ENOENT") {
|
|
2229
|
+
return null;
|
|
2230
|
+
}
|
|
2231
|
+
throw err;
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2196
2234
|
server.use("/cms/api/collection.get", async (req, res) => {
|
|
2197
2235
|
if (req.method !== "POST" || !String(req.get("content-type")).startsWith("application/json")) {
|
|
2198
2236
|
res.status(400).json({ success: false, error: "BAD_REQUEST" });
|
|
2199
2237
|
return;
|
|
2200
2238
|
}
|
|
2201
2239
|
const reqBody = req.body || {};
|
|
2202
|
-
|
|
2240
|
+
const collectionId = String(reqBody.collectionId || "");
|
|
2241
|
+
if (!collectionId) {
|
|
2203
2242
|
res.status(400).json({ success: false, error: "MISSING_COLLECTION_ID" });
|
|
2204
2243
|
return;
|
|
2205
2244
|
}
|
|
2245
|
+
if (!testValidCollectionId(collectionId)) {
|
|
2246
|
+
res.status(400).json({ success: false, error: "INVALID_COLLECTION_ID" });
|
|
2247
|
+
return;
|
|
2248
|
+
}
|
|
2206
2249
|
try {
|
|
2207
|
-
const
|
|
2208
|
-
const collections = app.getCollections();
|
|
2209
|
-
const collection = collections[reqBody.collectionId];
|
|
2250
|
+
const collection = await getCollectionSchema(req, collectionId);
|
|
2210
2251
|
if (!collection) {
|
|
2211
2252
|
res.status(404).json({ success: false, error: "NOT_FOUND" });
|
|
2212
2253
|
return;
|
|
@@ -2373,7 +2414,31 @@ function api(server, options) {
|
|
|
2373
2414
|
}
|
|
2374
2415
|
|
|
2375
2416
|
// core/plugin.ts
|
|
2376
|
-
var __dirname2 =
|
|
2417
|
+
var __dirname2 = path5.dirname(fileURLToPath2(import.meta.url));
|
|
2418
|
+
async function writeCollectionSchemasToJson(rootConfig) {
|
|
2419
|
+
const modulePath = path5.resolve(__dirname2, "./project.js");
|
|
2420
|
+
const project = await viteSsrLoadModule2(
|
|
2421
|
+
rootConfig,
|
|
2422
|
+
modulePath
|
|
2423
|
+
);
|
|
2424
|
+
const outDir = path5.join(rootConfig.rootDir, "dist", "collections");
|
|
2425
|
+
await fs4.mkdir(outDir, { recursive: true });
|
|
2426
|
+
const fileIds = Object.keys(project.SCHEMA_MODULES);
|
|
2427
|
+
for (const fileId of fileIds) {
|
|
2428
|
+
if (!fileId.startsWith("/collections/")) {
|
|
2429
|
+
continue;
|
|
2430
|
+
}
|
|
2431
|
+
const collectionId = path5.basename(fileId).split(".")[0];
|
|
2432
|
+
const schema = await project.getCollectionSchema(collectionId);
|
|
2433
|
+
if (!schema) {
|
|
2434
|
+
console.warn(`collection is missing a default export: ${fileId}`);
|
|
2435
|
+
continue;
|
|
2436
|
+
}
|
|
2437
|
+
const jsonPath = path5.join(outDir, `${collectionId}.schema.json`);
|
|
2438
|
+
const data = JSON.stringify(schema, null, 2);
|
|
2439
|
+
await fs4.writeFile(jsonPath, data, "utf-8");
|
|
2440
|
+
}
|
|
2441
|
+
}
|
|
2377
2442
|
var SESSION_COOKIE_AUTH = "root-cms-auth";
|
|
2378
2443
|
var NONCONF_STATIC_PATHS = [
|
|
2379
2444
|
"/cms/static/signin.css",
|
|
@@ -2574,12 +2639,23 @@ function cmsPlugin(options) {
|
|
|
2574
2639
|
const databaseId = firebaseConfig.databaseId || "(default)";
|
|
2575
2640
|
return getFirestore(app, databaseId);
|
|
2576
2641
|
},
|
|
2642
|
+
hooks: {
|
|
2643
|
+
/**
|
|
2644
|
+
* Saves collection schema files from `collections/*.schema.ts` to
|
|
2645
|
+
* `dist/collections/*.schema.json` for prod builds.
|
|
2646
|
+
*/
|
|
2647
|
+
preBuild: async (rootConfig) => {
|
|
2648
|
+
await writeCollectionSchemasToJson(rootConfig);
|
|
2649
|
+
}
|
|
2650
|
+
},
|
|
2577
2651
|
/**
|
|
2578
2652
|
* A map of ssr files to include when running `root build`.
|
|
2579
2653
|
*/
|
|
2580
|
-
ssrInput: () =>
|
|
2581
|
-
|
|
2582
|
-
|
|
2654
|
+
ssrInput: () => {
|
|
2655
|
+
return {
|
|
2656
|
+
cms: path5.resolve(__dirname2, "./app.js")
|
|
2657
|
+
};
|
|
2658
|
+
},
|
|
2583
2659
|
/**
|
|
2584
2660
|
* Attaches CMS-specific middleware to the Root.js server.
|
|
2585
2661
|
*/
|
|
@@ -2587,13 +2663,13 @@ function cmsPlugin(options) {
|
|
|
2587
2663
|
server.use(bodyParser.json());
|
|
2588
2664
|
async function getRenderer(req) {
|
|
2589
2665
|
if (serverOptions.type === "dev") {
|
|
2590
|
-
const appFilePath =
|
|
2666
|
+
const appFilePath = path5.resolve(__dirname2, "./app.js");
|
|
2591
2667
|
const app3 = await req.viteServer.ssrLoadModule(
|
|
2592
2668
|
appFilePath
|
|
2593
2669
|
);
|
|
2594
2670
|
return app3;
|
|
2595
2671
|
}
|
|
2596
|
-
const appImportPath =
|
|
2672
|
+
const appImportPath = path5.resolve(
|
|
2597
2673
|
req.rootConfig.rootDir,
|
|
2598
2674
|
"dist/server/cms.js"
|
|
2599
2675
|
);
|
|
@@ -2665,7 +2741,7 @@ function cmsPlugin(options) {
|
|
|
2665
2741
|
}
|
|
2666
2742
|
next();
|
|
2667
2743
|
});
|
|
2668
|
-
const staticDir =
|
|
2744
|
+
const staticDir = path5.resolve(__dirname2, "ui");
|
|
2669
2745
|
server.use("/cms/static", sirv(staticDir, { dev: false }));
|
|
2670
2746
|
api(server, { getRenderer });
|
|
2671
2747
|
server.use("/cms", async (req, res) => {
|
|
@@ -2699,7 +2775,7 @@ function cmsPlugin(options) {
|
|
|
2699
2775
|
return plugin;
|
|
2700
2776
|
}
|
|
2701
2777
|
function fileExists(filepath) {
|
|
2702
|
-
return
|
|
2778
|
+
return fs4.access(filepath).then(() => true).catch(() => false);
|
|
2703
2779
|
}
|
|
2704
2780
|
export {
|
|
2705
2781
|
cmsPlugin
|
package/dist/project.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { S as Schema } from './schema-
|
|
2
|
-
import 'preact';
|
|
1
|
+
import { S as Schema, C as Collection } from './schema-FB6Ck9sN.js';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Loads various files or configurations from the project.
|
|
@@ -11,6 +10,17 @@ import 'preact';
|
|
|
11
10
|
interface SchemaModule {
|
|
12
11
|
default: Schema;
|
|
13
12
|
}
|
|
14
|
-
declare
|
|
13
|
+
declare const SCHEMA_MODULES: Record<string, SchemaModule>;
|
|
14
|
+
/**
|
|
15
|
+
* Returns a map of all `schema.ts` files defined in the project as
|
|
16
|
+
* fileId => schema. This is used by `generate-types.ts` to build the
|
|
17
|
+
* `root-cms.d.ts` file.
|
|
18
|
+
*/
|
|
19
|
+
declare function getProjectSchemas(): Promise<Record<string, Schema>>;
|
|
20
|
+
/**
|
|
21
|
+
* Returns a collection's schema definition as defined in
|
|
22
|
+
* `/collections/<id>.schema.ts`.
|
|
23
|
+
*/
|
|
24
|
+
declare function getCollectionSchema(collectionId: string): Promise<Collection | null>;
|
|
15
25
|
|
|
16
|
-
export { type SchemaModule, getProjectSchemas };
|
|
26
|
+
export { SCHEMA_MODULES, type SchemaModule, getCollectionSchema, getProjectSchemas };
|
package/dist/project.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
// core/project.ts
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
var SCHEMA_MODULES = import.meta.glob(
|
|
3
|
+
[
|
|
4
|
+
"/**/*.schema.ts",
|
|
5
|
+
"!/appengine/**/*.schema.ts",
|
|
6
|
+
"!/functions/**/*.schema.ts",
|
|
7
|
+
"!/gae/**/*.schema.ts"
|
|
8
|
+
],
|
|
9
|
+
{ eager: true }
|
|
10
|
+
);
|
|
11
|
+
async function getProjectSchemas() {
|
|
7
12
|
const schemas = {};
|
|
8
13
|
for (const fileId in SCHEMA_MODULES) {
|
|
9
|
-
if (IGNORED_SCHEMA_FOLDERS.some((prefix) => fileId.startsWith(prefix))) {
|
|
10
|
-
continue;
|
|
11
|
-
}
|
|
12
14
|
const schemaModule = SCHEMA_MODULES[fileId];
|
|
13
15
|
if (schemaModule.default) {
|
|
14
16
|
schemas[fileId] = schemaModule.default;
|
|
@@ -16,6 +18,64 @@ function getProjectSchemas() {
|
|
|
16
18
|
}
|
|
17
19
|
return schemas;
|
|
18
20
|
}
|
|
21
|
+
async function getCollectionSchema(collectionId) {
|
|
22
|
+
if (!testValidCollectionId(collectionId)) {
|
|
23
|
+
throw new Error(`invalid collection id: ${collectionId}`);
|
|
24
|
+
}
|
|
25
|
+
const fileId = `/collections/${collectionId}.schema.ts`;
|
|
26
|
+
const module = SCHEMA_MODULES[fileId];
|
|
27
|
+
if (!module.default) {
|
|
28
|
+
console.warn(`collection schema not exported in: ${fileId}`);
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const collection = module.default;
|
|
32
|
+
collection.id = collectionId;
|
|
33
|
+
return convertOneOfTypes(collection);
|
|
34
|
+
}
|
|
35
|
+
function testValidCollectionId(id) {
|
|
36
|
+
return /^[A-Za-z0-9_-]+$/.test(id);
|
|
37
|
+
}
|
|
38
|
+
function convertOneOfTypes(collection) {
|
|
39
|
+
const clone = structuredClone(collection);
|
|
40
|
+
const types = clone.types || {};
|
|
41
|
+
function handleOneOfField(field) {
|
|
42
|
+
const names = [];
|
|
43
|
+
(field.types || []).forEach((sub) => {
|
|
44
|
+
if (typeof sub === "string") {
|
|
45
|
+
names.push(sub);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (sub.name) {
|
|
49
|
+
names.push(sub.name);
|
|
50
|
+
if (!types[sub.name]) {
|
|
51
|
+
types[sub.name] = sub;
|
|
52
|
+
if (sub.fields) {
|
|
53
|
+
walk(sub);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
field.types = names;
|
|
59
|
+
}
|
|
60
|
+
function handleField(field) {
|
|
61
|
+
if (field.type === "oneof") {
|
|
62
|
+
handleOneOfField(field);
|
|
63
|
+
} else if (field.type === "object") {
|
|
64
|
+
walk(field);
|
|
65
|
+
} else if (field.type === "array" && field.of) {
|
|
66
|
+
handleField(field.of);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function walk(schema) {
|
|
70
|
+
const fields = schema?.fields || [];
|
|
71
|
+
fields.forEach(handleField);
|
|
72
|
+
}
|
|
73
|
+
walk(clone);
|
|
74
|
+
clone.types = types;
|
|
75
|
+
return clone;
|
|
76
|
+
}
|
|
19
77
|
export {
|
|
78
|
+
SCHEMA_MODULES,
|
|
79
|
+
getCollectionSchema,
|
|
20
80
|
getProjectSchemas
|
|
21
81
|
};
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { FunctionalComponent } from 'preact';
|
|
2
|
-
|
|
3
1
|
interface CommonFieldProps {
|
|
4
2
|
/** The type that defines the structure of the field and its UI component. */
|
|
5
3
|
type: string;
|
|
@@ -140,7 +138,7 @@ type ArrayField = CommonFieldProps & {
|
|
|
140
138
|
declare function array(field: Omit<ArrayField, 'type'>): ArrayField;
|
|
141
139
|
type OneOfField = CommonFieldProps & {
|
|
142
140
|
type: 'oneof';
|
|
143
|
-
types: Schema[];
|
|
141
|
+
types: Schema[] | string[];
|
|
144
142
|
};
|
|
145
143
|
declare function oneOf(field: Omit<OneOfField, 'type'>): OneOfField;
|
|
146
144
|
type RichTextField = CommonFieldProps & {
|
|
@@ -159,7 +157,17 @@ type ReferenceField = CommonFieldProps & {
|
|
|
159
157
|
buttonLabel?: string;
|
|
160
158
|
};
|
|
161
159
|
declare function reference(field: Omit<ReferenceField, 'type'>): ReferenceField;
|
|
162
|
-
type
|
|
160
|
+
type ReferencesField = CommonFieldProps & {
|
|
161
|
+
type: 'references';
|
|
162
|
+
/** List of collection ids the references can be chosen from. */
|
|
163
|
+
collections?: string[];
|
|
164
|
+
/** Initial collection to show when picking a reference. */
|
|
165
|
+
initialCollection?: string;
|
|
166
|
+
/** Label for the button. Defaults to "Select". */
|
|
167
|
+
buttonLabel?: string;
|
|
168
|
+
};
|
|
169
|
+
declare function references(field: Omit<ReferencesField, 'type'>): ReferencesField;
|
|
170
|
+
type Field = StringField | NumberField | DateField | DateTimeField | BooleanField | SelectField | MultiSelectField | ImageField | FileField | ObjectField | ArrayField | OneOfField | RichTextField | ReferenceField | ReferencesField;
|
|
163
171
|
/**
|
|
164
172
|
* Similar to {@link Field} but with a required `id`.
|
|
165
173
|
* TODO(stevenle): fix this.
|
|
@@ -198,10 +206,14 @@ interface Schema {
|
|
|
198
206
|
image?: string | string[];
|
|
199
207
|
};
|
|
200
208
|
}
|
|
209
|
+
type SchemaWithTypes = Schema & {
|
|
210
|
+
/** Reusable type definitions used by the schema, e.g. for oneOf() fields. */
|
|
211
|
+
types?: Record<string, Schema>;
|
|
212
|
+
};
|
|
201
213
|
declare function defineSchema(schema: Schema): Schema;
|
|
202
214
|
/** Defines the schema for a collection or reusable component. */
|
|
203
215
|
declare const define: typeof defineSchema;
|
|
204
|
-
type Collection =
|
|
216
|
+
type Collection = SchemaWithTypes & {
|
|
205
217
|
/**
|
|
206
218
|
* The ID of the collection. This comes from the schema filename, e.g
|
|
207
219
|
* `<id>.schema.ts`.
|
|
@@ -222,8 +234,6 @@ type Collection = Schema & {
|
|
|
222
234
|
* editor to render instant previews. If blank, defaults to the `url` config.
|
|
223
235
|
*/
|
|
224
236
|
previewUrl?: string;
|
|
225
|
-
/** Page component to render the collection for instant previews */
|
|
226
|
-
Component?: FunctionalComponent;
|
|
227
237
|
/**
|
|
228
238
|
* Defines the fields to use for document preview. Defaults to "title" and
|
|
229
239
|
* "image". Use dot notation for nested fields, e.g. "meta.title".
|
|
@@ -249,6 +259,23 @@ type Collection = Schema & {
|
|
|
249
259
|
autolock?: boolean;
|
|
250
260
|
/** Reason for the automatic publishing lock. */
|
|
251
261
|
autolockReason?: string;
|
|
262
|
+
/**
|
|
263
|
+
* Custom sort options available when listing documents in the CMS.
|
|
264
|
+
*
|
|
265
|
+
* NOTE: a new DB index may need to be created for the sort option. The first
|
|
266
|
+
* time using the sort option, you will get an error that provides a link for
|
|
267
|
+
* creating the index.
|
|
268
|
+
*/
|
|
269
|
+
sortOptions?: Array<{
|
|
270
|
+
/** Unique identifier for the sort option. */
|
|
271
|
+
id: string;
|
|
272
|
+
/** Label displayed in the CMS UI. */
|
|
273
|
+
label: string;
|
|
274
|
+
/** DB field path to sort by, e.g. 'fields.meta.title'. */
|
|
275
|
+
field: string;
|
|
276
|
+
/** Sort direction. Defaults to ascending. */
|
|
277
|
+
direction?: 'asc' | 'desc';
|
|
278
|
+
}>;
|
|
252
279
|
};
|
|
253
280
|
declare function defineCollection(collection: Omit<Collection, 'id'>): Omit<Collection, 'id'>;
|
|
254
281
|
declare const collection: typeof defineCollection;
|
|
@@ -269,8 +296,10 @@ type schema_ObjectField = ObjectField;
|
|
|
269
296
|
type schema_ObjectLikeField = ObjectLikeField;
|
|
270
297
|
type schema_OneOfField = OneOfField;
|
|
271
298
|
type schema_ReferenceField = ReferenceField;
|
|
299
|
+
type schema_ReferencesField = ReferencesField;
|
|
272
300
|
type schema_RichTextField = RichTextField;
|
|
273
301
|
type schema_Schema = Schema;
|
|
302
|
+
type schema_SchemaWithTypes = SchemaWithTypes;
|
|
274
303
|
type schema_SelectField = SelectField;
|
|
275
304
|
type schema_StringField = StringField;
|
|
276
305
|
declare const schema_array: typeof array;
|
|
@@ -288,11 +317,12 @@ declare const schema_number: typeof number;
|
|
|
288
317
|
declare const schema_object: typeof object;
|
|
289
318
|
declare const schema_oneOf: typeof oneOf;
|
|
290
319
|
declare const schema_reference: typeof reference;
|
|
320
|
+
declare const schema_references: typeof references;
|
|
291
321
|
declare const schema_richtext: typeof richtext;
|
|
292
322
|
declare const schema_select: typeof select;
|
|
293
323
|
declare const schema_string: typeof string;
|
|
294
324
|
declare namespace schema {
|
|
295
|
-
export { type schema_ArrayField as ArrayField, type schema_BooleanField as BooleanField, type schema_Collection as Collection, type schema_CommonFieldProps as CommonFieldProps, type schema_DateField as DateField, type schema_DateTimeField as DateTimeField, type schema_Field as Field, type schema_FieldWithId as FieldWithId, type schema_FileField as FileField, type schema_ImageField as ImageField, type schema_MultiSelectField as MultiSelectField, type schema_NumberField as NumberField, type schema_ObjectField as ObjectField, type schema_ObjectLikeField as ObjectLikeField, type schema_OneOfField as OneOfField, type schema_ReferenceField as ReferenceField, type schema_RichTextField as RichTextField, type schema_Schema as Schema, type schema_SelectField as SelectField, type schema_StringField as StringField, schema_array as array, schema_boolean as boolean, schema_collection as collection, schema_date as date, schema_datetime as datetime, schema_define as define, schema_defineCollection as defineCollection, schema_defineSchema as defineSchema, schema_file as file, schema_image as image, schema_multiselect as multiselect, schema_number as number, schema_object as object, schema_oneOf as oneOf, schema_reference as reference, schema_richtext as richtext, schema_select as select, schema_string as string };
|
|
325
|
+
export { type schema_ArrayField as ArrayField, type schema_BooleanField as BooleanField, type schema_Collection as Collection, type schema_CommonFieldProps as CommonFieldProps, type schema_DateField as DateField, type schema_DateTimeField as DateTimeField, type schema_Field as Field, type schema_FieldWithId as FieldWithId, type schema_FileField as FileField, type schema_ImageField as ImageField, type schema_MultiSelectField as MultiSelectField, type schema_NumberField as NumberField, type schema_ObjectField as ObjectField, type schema_ObjectLikeField as ObjectLikeField, type schema_OneOfField as OneOfField, type schema_ReferenceField as ReferenceField, type schema_ReferencesField as ReferencesField, type schema_RichTextField as RichTextField, type schema_Schema as Schema, type schema_SchemaWithTypes as SchemaWithTypes, type schema_SelectField as SelectField, type schema_StringField as StringField, schema_array as array, schema_boolean as boolean, schema_collection as collection, schema_date as date, schema_datetime as datetime, schema_define as define, schema_defineCollection as defineCollection, schema_defineSchema as defineSchema, schema_file as file, schema_image as image, schema_multiselect as multiselect, schema_number as number, schema_object as object, schema_oneOf as oneOf, schema_reference as reference, schema_references as references, schema_richtext as richtext, schema_select as select, schema_string as string };
|
|
296
326
|
}
|
|
297
327
|
|
|
298
|
-
export { type Schema as S, schema as s };
|
|
328
|
+
export { type Collection as C, type Schema as S, schema as s };
|