@seshuk/payload-plugin-openapi 0.2.2 → 1.0.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/README.md +67 -25
- package/dist/_tooling/telemetry.js +168 -0
- package/dist/_tooling/telemetry.js.map +1 -0
- package/dist/cli/generateSpec.d.ts +2 -0
- package/dist/cli/generateSpec.js +40 -0
- package/dist/cli/generateSpec.js.map +1 -0
- package/dist/index.d.ts +8 -9
- package/dist/index.js +76 -65
- package/dist/index.js.map +1 -0
- package/dist/{endpoints → server/endpoints}/interactiveAuth.d.ts +2 -2
- package/dist/server/endpoints/interactiveAuth.js +25 -0
- package/dist/server/endpoints/interactiveAuth.js.map +1 -0
- package/dist/server/endpoints/spec.d.ts +5 -0
- package/dist/server/endpoints/spec.js +39 -0
- package/dist/server/endpoints/spec.js.map +1 -0
- package/dist/server/options/resolveOptions.d.ts +4 -0
- package/dist/server/options/resolveOptions.js +65 -0
- package/dist/server/options/resolveOptions.js.map +1 -0
- package/dist/server/spec/build.d.ts +14 -0
- package/dist/server/spec/build.js +40 -0
- package/dist/server/spec/build.js.map +1 -0
- package/dist/server/spec/buildDocument.d.ts +16 -0
- package/dist/server/spec/buildDocument.js +287 -0
- package/dist/server/spec/buildDocument.js.map +1 -0
- package/dist/server/spec/components.d.ts +61 -0
- package/dist/server/spec/components.js +265 -0
- package/dist/server/spec/components.js.map +1 -0
- package/dist/{spec → server/spec}/downconvert.d.ts +2 -1
- package/dist/server/spec/downconvert.js +69 -0
- package/dist/server/spec/downconvert.js.map +1 -0
- package/dist/server/spec/entitySchemas.d.ts +16 -0
- package/dist/server/spec/entitySchemas.js +207 -0
- package/dist/server/spec/entitySchemas.js.map +1 -0
- package/dist/{spec → server/spec}/fields.d.ts +2 -1
- package/dist/server/spec/fields.js +47 -0
- package/dist/server/spec/fields.js.map +1 -0
- package/dist/server/spec/filters.d.ts +12 -0
- package/dist/server/spec/filters.js +91 -0
- package/dist/server/spec/filters.js.map +1 -0
- package/dist/server/spec/hierarchy.d.ts +11 -0
- package/dist/server/spec/hierarchy.js +38 -0
- package/dist/server/spec/hierarchy.js.map +1 -0
- package/dist/{spec → server/spec}/names.d.ts +2 -2
- package/dist/server/spec/names.js +43 -0
- package/dist/server/spec/names.js.map +1 -0
- package/dist/server/spec/params.d.ts +57 -0
- package/dist/server/spec/params.js +394 -0
- package/dist/server/spec/params.js.map +1 -0
- package/dist/server/spec/paths/auth.d.ts +10 -0
- package/dist/server/spec/paths/auth.js +190 -0
- package/dist/server/spec/paths/auth.js.map +1 -0
- package/dist/server/spec/paths/collections.d.ts +11 -0
- package/dist/server/spec/paths/collections.js +314 -0
- package/dist/server/spec/paths/collections.js.map +1 -0
- package/dist/server/spec/paths/custom.d.ts +10 -0
- package/dist/server/spec/paths/custom.js +42 -0
- package/dist/server/spec/paths/custom.js.map +1 -0
- package/dist/server/spec/paths/globals.d.ts +11 -0
- package/dist/server/spec/paths/globals.js +87 -0
- package/dist/server/spec/paths/globals.js.map +1 -0
- package/dist/server/spec/paths/jobs.d.ts +9 -0
- package/dist/server/spec/paths/jobs.js +98 -0
- package/dist/server/spec/paths/jobs.js.map +1 -0
- package/dist/server/spec/paths/system.d.ts +8 -0
- package/dist/server/spec/paths/system.js +137 -0
- package/dist/server/spec/paths/system.js.map +1 -0
- package/dist/server/spec/paths/versions.d.ts +22 -0
- package/dist/server/spec/paths/versions.js +185 -0
- package/dist/server/spec/paths/versions.js.map +1 -0
- package/dist/server/spec/security.d.ts +33 -0
- package/dist/server/spec/security.js +97 -0
- package/dist/server/spec/security.js.map +1 -0
- package/dist/server/spec/tags.d.ts +34 -0
- package/dist/server/spec/tags.js +83 -0
- package/dist/server/spec/tags.js.map +1 -0
- package/dist/server/telemetry.d.ts +31 -0
- package/dist/server/telemetry.js +33 -0
- package/dist/server/telemetry.js.map +1 -0
- package/dist/server/ui/createUiPlugin.d.ts +16 -0
- package/dist/server/ui/createUiPlugin.js +33 -0
- package/dist/server/ui/createUiPlugin.js.map +1 -0
- package/dist/{ui → server/ui}/html.d.ts +5 -3
- package/dist/server/ui/html.js +11 -0
- package/dist/server/ui/html.js.map +1 -0
- package/dist/server/ui/scalar.d.ts +4 -0
- package/dist/server/ui/scalar.js +17 -0
- package/dist/server/ui/scalar.js.map +1 -0
- package/dist/server/ui/swagger.d.ts +4 -0
- package/dist/server/ui/swagger.js +18 -0
- package/dist/server/ui/swagger.js.map +1 -0
- package/dist/shared/constants.d.ts +4 -0
- package/dist/shared/constants.js +6 -0
- package/dist/shared/constants.js.map +1 -0
- package/dist/shared/translations/index.d.ts +5 -0
- package/dist/{translations → shared/translations}/index.js +49 -47
- package/dist/shared/translations/index.js.map +1 -0
- package/dist/shared/translations/locales/ar.d.ts +3 -0
- package/dist/shared/translations/locales/ar.js +99 -0
- package/dist/shared/translations/locales/ar.js.map +1 -0
- package/dist/shared/translations/locales/az.d.ts +3 -0
- package/dist/shared/translations/locales/az.js +99 -0
- package/dist/shared/translations/locales/az.js.map +1 -0
- package/dist/shared/translations/locales/bg.d.ts +3 -0
- package/dist/shared/translations/locales/bg.js +99 -0
- package/dist/shared/translations/locales/bg.js.map +1 -0
- package/dist/shared/translations/locales/bnBd.d.ts +3 -0
- package/dist/shared/translations/locales/bnBd.js +99 -0
- package/dist/shared/translations/locales/bnBd.js.map +1 -0
- package/dist/shared/translations/locales/bnIn.d.ts +3 -0
- package/dist/shared/translations/locales/bnIn.js +99 -0
- package/dist/shared/translations/locales/bnIn.js.map +1 -0
- package/dist/shared/translations/locales/ca.d.ts +3 -0
- package/dist/shared/translations/locales/ca.js +99 -0
- package/dist/shared/translations/locales/ca.js.map +1 -0
- package/dist/shared/translations/locales/cs.d.ts +3 -0
- package/dist/shared/translations/locales/cs.js +99 -0
- package/dist/shared/translations/locales/cs.js.map +1 -0
- package/dist/shared/translations/locales/da.d.ts +3 -0
- package/dist/shared/translations/locales/da.js +99 -0
- package/dist/shared/translations/locales/da.js.map +1 -0
- package/dist/shared/translations/locales/de.d.ts +3 -0
- package/dist/shared/translations/locales/de.js +99 -0
- package/dist/shared/translations/locales/de.js.map +1 -0
- package/dist/shared/translations/locales/en.d.ts +3 -0
- package/dist/shared/translations/locales/en.js +99 -0
- package/dist/shared/translations/locales/en.js.map +1 -0
- package/dist/shared/translations/locales/es.d.ts +3 -0
- package/dist/shared/translations/locales/es.js +99 -0
- package/dist/shared/translations/locales/es.js.map +1 -0
- package/dist/shared/translations/locales/et.d.ts +3 -0
- package/dist/shared/translations/locales/et.js +99 -0
- package/dist/shared/translations/locales/et.js.map +1 -0
- package/dist/shared/translations/locales/fa.d.ts +3 -0
- package/dist/shared/translations/locales/fa.js +99 -0
- package/dist/shared/translations/locales/fa.js.map +1 -0
- package/dist/shared/translations/locales/fr.d.ts +3 -0
- package/dist/shared/translations/locales/fr.js +99 -0
- package/dist/shared/translations/locales/fr.js.map +1 -0
- package/dist/shared/translations/locales/he.d.ts +3 -0
- package/dist/shared/translations/locales/he.js +99 -0
- package/dist/shared/translations/locales/he.js.map +1 -0
- package/dist/shared/translations/locales/hr.d.ts +3 -0
- package/dist/shared/translations/locales/hr.js +99 -0
- package/dist/shared/translations/locales/hr.js.map +1 -0
- package/dist/shared/translations/locales/hu.d.ts +3 -0
- package/dist/shared/translations/locales/hu.js +99 -0
- package/dist/shared/translations/locales/hu.js.map +1 -0
- package/dist/shared/translations/locales/hy.d.ts +3 -0
- package/dist/shared/translations/locales/hy.js +99 -0
- package/dist/shared/translations/locales/hy.js.map +1 -0
- package/dist/shared/translations/locales/id.d.ts +3 -0
- package/dist/shared/translations/locales/id.js +99 -0
- package/dist/shared/translations/locales/id.js.map +1 -0
- package/dist/shared/translations/locales/is.d.ts +3 -0
- package/dist/shared/translations/locales/is.js +99 -0
- package/dist/shared/translations/locales/is.js.map +1 -0
- package/dist/shared/translations/locales/it.d.ts +3 -0
- package/dist/shared/translations/locales/it.js +99 -0
- package/dist/shared/translations/locales/it.js.map +1 -0
- package/dist/shared/translations/locales/ja.d.ts +3 -0
- package/dist/shared/translations/locales/ja.js +99 -0
- package/dist/shared/translations/locales/ja.js.map +1 -0
- package/dist/shared/translations/locales/ko.d.ts +3 -0
- package/dist/shared/translations/locales/ko.js +99 -0
- package/dist/shared/translations/locales/ko.js.map +1 -0
- package/dist/shared/translations/locales/lt.d.ts +3 -0
- package/dist/shared/translations/locales/lt.js +99 -0
- package/dist/shared/translations/locales/lt.js.map +1 -0
- package/dist/shared/translations/locales/lv.d.ts +3 -0
- package/dist/shared/translations/locales/lv.js +99 -0
- package/dist/shared/translations/locales/lv.js.map +1 -0
- package/dist/shared/translations/locales/my.d.ts +3 -0
- package/dist/shared/translations/locales/my.js +99 -0
- package/dist/shared/translations/locales/my.js.map +1 -0
- package/dist/shared/translations/locales/nb.d.ts +3 -0
- package/dist/shared/translations/locales/nb.js +99 -0
- package/dist/shared/translations/locales/nb.js.map +1 -0
- package/dist/shared/translations/locales/nl.d.ts +3 -0
- package/dist/shared/translations/locales/nl.js +99 -0
- package/dist/shared/translations/locales/nl.js.map +1 -0
- package/dist/shared/translations/locales/pl.d.ts +3 -0
- package/dist/shared/translations/locales/pl.js +99 -0
- package/dist/shared/translations/locales/pl.js.map +1 -0
- package/dist/shared/translations/locales/pt.d.ts +3 -0
- package/dist/shared/translations/locales/pt.js +99 -0
- package/dist/shared/translations/locales/pt.js.map +1 -0
- package/dist/shared/translations/locales/ro.d.ts +3 -0
- package/dist/shared/translations/locales/ro.js +99 -0
- package/dist/shared/translations/locales/ro.js.map +1 -0
- package/dist/shared/translations/locales/rs.d.ts +3 -0
- package/dist/shared/translations/locales/rs.js +99 -0
- package/dist/shared/translations/locales/rs.js.map +1 -0
- package/dist/shared/translations/locales/rsLatin.d.ts +3 -0
- package/dist/shared/translations/locales/rsLatin.js +99 -0
- package/dist/shared/translations/locales/rsLatin.js.map +1 -0
- package/dist/shared/translations/locales/ru.d.ts +3 -0
- package/dist/shared/translations/locales/ru.js +99 -0
- package/dist/shared/translations/locales/ru.js.map +1 -0
- package/dist/shared/translations/locales/sk.d.ts +3 -0
- package/dist/shared/translations/locales/sk.js +99 -0
- package/dist/shared/translations/locales/sk.js.map +1 -0
- package/dist/shared/translations/locales/sl.d.ts +3 -0
- package/dist/shared/translations/locales/sl.js +99 -0
- package/dist/shared/translations/locales/sl.js.map +1 -0
- package/dist/shared/translations/locales/sv.d.ts +3 -0
- package/dist/shared/translations/locales/sv.js +99 -0
- package/dist/shared/translations/locales/sv.js.map +1 -0
- package/dist/shared/translations/locales/ta.d.ts +3 -0
- package/dist/shared/translations/locales/ta.js +99 -0
- package/dist/shared/translations/locales/ta.js.map +1 -0
- package/dist/shared/translations/locales/th.d.ts +3 -0
- package/dist/shared/translations/locales/th.js +99 -0
- package/dist/shared/translations/locales/th.js.map +1 -0
- package/dist/shared/translations/locales/tr.d.ts +3 -0
- package/dist/shared/translations/locales/tr.js +99 -0
- package/dist/shared/translations/locales/tr.js.map +1 -0
- package/dist/shared/translations/locales/uk.d.ts +3 -0
- package/dist/shared/translations/locales/uk.js +99 -0
- package/dist/shared/translations/locales/uk.js.map +1 -0
- package/dist/shared/translations/locales/vi.d.ts +3 -0
- package/dist/shared/translations/locales/vi.js +99 -0
- package/dist/shared/translations/locales/vi.js.map +1 -0
- package/dist/shared/translations/locales/zh.d.ts +3 -0
- package/dist/shared/translations/locales/zh.js +99 -0
- package/dist/shared/translations/locales/zh.js.map +1 -0
- package/dist/shared/translations/locales/zhTw.d.ts +3 -0
- package/dist/shared/translations/locales/zhTw.js +99 -0
- package/dist/shared/translations/locales/zhTw.js.map +1 -0
- package/dist/shared/translations/types.d.ts +106 -0
- package/dist/shared/translations/types.js +1 -0
- package/dist/shared/types/index.d.ts +397 -0
- package/dist/shared/types/index.js +1 -0
- package/dist/{utils.d.ts → shared/utils.d.ts} +1 -0
- package/dist/shared/utils.js +13 -0
- package/dist/shared/utils.js.map +1 -0
- package/package.json +57 -34
- package/dist/bin/generateSpec.d.ts +0 -25
- package/dist/bin/generateSpec.js +0 -61
- package/dist/constants.d.ts +0 -1
- package/dist/constants.js +0 -2
- package/dist/endpoints/interactiveAuth.js +0 -27
- package/dist/endpoints/spec.d.ts +0 -5
- package/dist/endpoints/spec.js +0 -39
- package/dist/options.d.ts +0 -2
- package/dist/options.js +0 -45
- package/dist/spec/build.d.ts +0 -14
- package/dist/spec/build.js +0 -36
- package/dist/spec/buildDocument.d.ts +0 -15
- package/dist/spec/buildDocument.js +0 -268
- package/dist/spec/components.d.ts +0 -44
- package/dist/spec/components.js +0 -265
- package/dist/spec/downconvert.js +0 -74
- package/dist/spec/entitySchemas.d.ts +0 -15
- package/dist/spec/entitySchemas.js +0 -250
- package/dist/spec/fields.js +0 -44
- package/dist/spec/filters.d.ts +0 -11
- package/dist/spec/filters.js +0 -83
- package/dist/spec/names.js +0 -37
- package/dist/spec/params.d.ts +0 -55
- package/dist/spec/params.js +0 -436
- package/dist/spec/paths/auth.d.ts +0 -9
- package/dist/spec/paths/auth.js +0 -274
- package/dist/spec/paths/collections.d.ts +0 -9
- package/dist/spec/paths/collections.js +0 -278
- package/dist/spec/paths/custom.d.ts +0 -9
- package/dist/spec/paths/custom.js +0 -41
- package/dist/spec/paths/globals.d.ts +0 -9
- package/dist/spec/paths/globals.js +0 -78
- package/dist/spec/paths/jobs.d.ts +0 -7
- package/dist/spec/paths/jobs.js +0 -130
- package/dist/spec/paths/versions.d.ts +0 -19
- package/dist/spec/paths/versions.js +0 -252
- package/dist/spec/security.d.ts +0 -19
- package/dist/spec/security.js +0 -96
- package/dist/spec/tags.d.ts +0 -27
- package/dist/spec/tags.js +0 -79
- package/dist/translations/index.d.ts +0 -6
- package/dist/translations/locales/ar.d.ts +0 -2
- package/dist/translations/locales/ar.js +0 -81
- package/dist/translations/locales/az.d.ts +0 -2
- package/dist/translations/locales/az.js +0 -81
- package/dist/translations/locales/bg.d.ts +0 -2
- package/dist/translations/locales/bg.js +0 -81
- package/dist/translations/locales/bnBd.d.ts +0 -2
- package/dist/translations/locales/bnBd.js +0 -81
- package/dist/translations/locales/bnIn.d.ts +0 -2
- package/dist/translations/locales/bnIn.js +0 -81
- package/dist/translations/locales/ca.d.ts +0 -2
- package/dist/translations/locales/ca.js +0 -81
- package/dist/translations/locales/cs.d.ts +0 -2
- package/dist/translations/locales/cs.js +0 -81
- package/dist/translations/locales/da.d.ts +0 -2
- package/dist/translations/locales/da.js +0 -81
- package/dist/translations/locales/de.d.ts +0 -2
- package/dist/translations/locales/de.js +0 -81
- package/dist/translations/locales/en.d.ts +0 -2
- package/dist/translations/locales/en.js +0 -81
- package/dist/translations/locales/es.d.ts +0 -2
- package/dist/translations/locales/es.js +0 -81
- package/dist/translations/locales/et.d.ts +0 -2
- package/dist/translations/locales/et.js +0 -81
- package/dist/translations/locales/fa.d.ts +0 -2
- package/dist/translations/locales/fa.js +0 -81
- package/dist/translations/locales/fr.d.ts +0 -2
- package/dist/translations/locales/fr.js +0 -81
- package/dist/translations/locales/he.d.ts +0 -2
- package/dist/translations/locales/he.js +0 -81
- package/dist/translations/locales/hr.d.ts +0 -2
- package/dist/translations/locales/hr.js +0 -81
- package/dist/translations/locales/hu.d.ts +0 -2
- package/dist/translations/locales/hu.js +0 -81
- package/dist/translations/locales/hy.d.ts +0 -2
- package/dist/translations/locales/hy.js +0 -81
- package/dist/translations/locales/id.d.ts +0 -2
- package/dist/translations/locales/id.js +0 -81
- package/dist/translations/locales/is.d.ts +0 -2
- package/dist/translations/locales/is.js +0 -81
- package/dist/translations/locales/it.d.ts +0 -2
- package/dist/translations/locales/it.js +0 -81
- package/dist/translations/locales/ja.d.ts +0 -2
- package/dist/translations/locales/ja.js +0 -81
- package/dist/translations/locales/ko.d.ts +0 -2
- package/dist/translations/locales/ko.js +0 -81
- package/dist/translations/locales/lt.d.ts +0 -2
- package/dist/translations/locales/lt.js +0 -81
- package/dist/translations/locales/lv.d.ts +0 -2
- package/dist/translations/locales/lv.js +0 -81
- package/dist/translations/locales/my.d.ts +0 -2
- package/dist/translations/locales/my.js +0 -81
- package/dist/translations/locales/nb.d.ts +0 -2
- package/dist/translations/locales/nb.js +0 -81
- package/dist/translations/locales/nl.d.ts +0 -2
- package/dist/translations/locales/nl.js +0 -81
- package/dist/translations/locales/pl.d.ts +0 -2
- package/dist/translations/locales/pl.js +0 -81
- package/dist/translations/locales/pt.d.ts +0 -2
- package/dist/translations/locales/pt.js +0 -81
- package/dist/translations/locales/ro.d.ts +0 -2
- package/dist/translations/locales/ro.js +0 -81
- package/dist/translations/locales/rs.d.ts +0 -2
- package/dist/translations/locales/rs.js +0 -81
- package/dist/translations/locales/rsLatin.d.ts +0 -2
- package/dist/translations/locales/rsLatin.js +0 -81
- package/dist/translations/locales/ru.d.ts +0 -2
- package/dist/translations/locales/ru.js +0 -81
- package/dist/translations/locales/sk.d.ts +0 -2
- package/dist/translations/locales/sk.js +0 -81
- package/dist/translations/locales/sl.d.ts +0 -2
- package/dist/translations/locales/sl.js +0 -81
- package/dist/translations/locales/sv.d.ts +0 -2
- package/dist/translations/locales/sv.js +0 -81
- package/dist/translations/locales/ta.d.ts +0 -2
- package/dist/translations/locales/ta.js +0 -81
- package/dist/translations/locales/th.d.ts +0 -2
- package/dist/translations/locales/th.js +0 -81
- package/dist/translations/locales/tr.d.ts +0 -2
- package/dist/translations/locales/tr.js +0 -81
- package/dist/translations/locales/uk.d.ts +0 -2
- package/dist/translations/locales/uk.js +0 -81
- package/dist/translations/locales/vi.d.ts +0 -2
- package/dist/translations/locales/vi.js +0 -81
- package/dist/translations/locales/zh.d.ts +0 -2
- package/dist/translations/locales/zh.js +0 -81
- package/dist/translations/locales/zhTw.d.ts +0 -2
- package/dist/translations/locales/zhTw.js +0 -81
- package/dist/translations/types.d.ts +0 -87
- package/dist/translations/types.js +0 -1
- package/dist/types.d.ts +0 -192
- package/dist/types.js +0 -1
- package/dist/ui/createUiPlugin.d.ts +0 -14
- package/dist/ui/createUiPlugin.js +0 -28
- package/dist/ui/html.js +0 -8
- package/dist/ui/scalar.d.ts +0 -1
- package/dist/ui/scalar.js +0 -12
- package/dist/ui/swagger.d.ts +0 -1
- package/dist/ui/swagger.js +0 -12
- package/dist/utils.js +0 -13
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { createSchemaName, listSchemaName, refTo, schemaName, updateSchemaName } from "../names.js";
|
|
2
|
+
import { ERRORS, docAccessOperation, errorResponses, jsonOk, jsonResponse, uploadRequestBody, validateOperation } from "../components.js";
|
|
3
|
+
import { makeT } from "../../../shared/translations/index.js";
|
|
4
|
+
import { buildListParams, buildParamSchemas, commonReadParams, validateParams, writeParams } from "../params.js";
|
|
5
|
+
const buildCollectionPaths = ({ collection, ctx, security = {}, access = false }) => {
|
|
6
|
+
const t = makeT(ctx.i18n);
|
|
7
|
+
const name = schemaName(collection.slug);
|
|
8
|
+
const base = `${ctx.apiRoute}/${collection.slug}`;
|
|
9
|
+
const docRef = { $ref: refTo(name) };
|
|
10
|
+
const listRef = { $ref: refTo(listSchemaName(name)) };
|
|
11
|
+
const createRef = { $ref: refTo(createSchemaName(name)) };
|
|
12
|
+
const updateRef = { $ref: refTo(updateSchemaName(name)) };
|
|
13
|
+
const idType = ctx.defaultIDType === "number" ? "integer" : "string";
|
|
14
|
+
const { read: secRead, create: secCreate, update: secUpdate, delete: secDelete, validate: secValidate } = security;
|
|
15
|
+
const allowBulk = collection.disableBulkEdit !== true;
|
|
16
|
+
const allowDuplicate = collection.disableDuplicate !== true;
|
|
17
|
+
const paramSchemas = buildParamSchemas({
|
|
18
|
+
fields: collection.fields,
|
|
19
|
+
ctx
|
|
20
|
+
});
|
|
21
|
+
const refs = {
|
|
22
|
+
select: true,
|
|
23
|
+
populate: Boolean(paramSchemas.populate),
|
|
24
|
+
joins: Boolean(paramSchemas.joins)
|
|
25
|
+
};
|
|
26
|
+
const isUpload = Boolean(collection.upload);
|
|
27
|
+
const fileRequiredOnCreate = typeof collection.upload === "object" ? collection.upload.filesRequiredOnCreate !== false : true;
|
|
28
|
+
const requestBody = (ref, fileRequired) => isUpload ? uploadRequestBody({
|
|
29
|
+
bodyRef: ref,
|
|
30
|
+
fileRequired,
|
|
31
|
+
t
|
|
32
|
+
}) : { content: { "application/json": { schema: ref } } };
|
|
33
|
+
const mutationSchema = {
|
|
34
|
+
type: "object",
|
|
35
|
+
properties: {
|
|
36
|
+
message: { type: "string" },
|
|
37
|
+
doc: docRef
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const listResponse = {
|
|
41
|
+
...jsonOk(t("collectionList"), listRef),
|
|
42
|
+
...errorResponses(ERRORS.list, t)
|
|
43
|
+
};
|
|
44
|
+
const findByIdResponse = {
|
|
45
|
+
...jsonOk(t("collectionDoc"), docRef),
|
|
46
|
+
...errorResponses(ERRORS.read, t)
|
|
47
|
+
};
|
|
48
|
+
const createResponse = {
|
|
49
|
+
"201": jsonResponse(t("collectionCreated"), mutationSchema),
|
|
50
|
+
...errorResponses(ERRORS.create, t)
|
|
51
|
+
};
|
|
52
|
+
const updateResponse = {
|
|
53
|
+
...jsonOk(t("collectionUpdated"), mutationSchema),
|
|
54
|
+
...errorResponses(ERRORS.update, t)
|
|
55
|
+
};
|
|
56
|
+
const deleteResponse = {
|
|
57
|
+
...jsonOk(t("collectionDeleted"), mutationSchema),
|
|
58
|
+
...errorResponses(ERRORS.delete, t)
|
|
59
|
+
};
|
|
60
|
+
const bulkSchema = {
|
|
61
|
+
type: "object",
|
|
62
|
+
properties: {
|
|
63
|
+
message: { type: "string" },
|
|
64
|
+
docs: {
|
|
65
|
+
type: "array",
|
|
66
|
+
items: docRef
|
|
67
|
+
},
|
|
68
|
+
errors: {
|
|
69
|
+
type: "array",
|
|
70
|
+
items: {
|
|
71
|
+
type: "object",
|
|
72
|
+
properties: {
|
|
73
|
+
message: { type: "string" },
|
|
74
|
+
id: { type: idType }
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const bulkUpdateResponse = {
|
|
81
|
+
...jsonOk(t("collectionBulkUpdate"), bulkSchema),
|
|
82
|
+
...errorResponses(ERRORS.update, t)
|
|
83
|
+
};
|
|
84
|
+
const bulkDeleteResponse = {
|
|
85
|
+
...jsonOk(t("collectionBulkDelete"), bulkSchema),
|
|
86
|
+
...errorResponses(ERRORS.delete, t)
|
|
87
|
+
};
|
|
88
|
+
const countResponse = {
|
|
89
|
+
...jsonOk(t("collectionCount"), {
|
|
90
|
+
type: "object",
|
|
91
|
+
properties: { totalDocs: { type: "integer" } }
|
|
92
|
+
}),
|
|
93
|
+
...errorResponses(ERRORS.list, t)
|
|
94
|
+
};
|
|
95
|
+
const listParams = buildListParams({
|
|
96
|
+
base: name,
|
|
97
|
+
fields: collection.fields,
|
|
98
|
+
ctx,
|
|
99
|
+
refs
|
|
100
|
+
});
|
|
101
|
+
const bulkParams = listParams.filter((p) => p.name === "where");
|
|
102
|
+
const bulkUpdateParams = listParams.filter((p) => [
|
|
103
|
+
"limit",
|
|
104
|
+
"sort",
|
|
105
|
+
"where"
|
|
106
|
+
].includes(p.name));
|
|
107
|
+
const write = (operation) => writeParams({
|
|
108
|
+
base: name,
|
|
109
|
+
entity: collection,
|
|
110
|
+
ctx,
|
|
111
|
+
refs,
|
|
112
|
+
operation
|
|
113
|
+
});
|
|
114
|
+
const deleteParams = write("delete");
|
|
115
|
+
const bulkOps = allowBulk ? {
|
|
116
|
+
patch: {
|
|
117
|
+
tags: [name],
|
|
118
|
+
operationId: `update${name}`,
|
|
119
|
+
parameters: [...bulkUpdateParams, ...write("update")],
|
|
120
|
+
requestBody: requestBody(updateRef, false),
|
|
121
|
+
responses: bulkUpdateResponse,
|
|
122
|
+
security: secUpdate
|
|
123
|
+
},
|
|
124
|
+
delete: {
|
|
125
|
+
tags: [name],
|
|
126
|
+
operationId: `delete${name}`,
|
|
127
|
+
parameters: [...bulkParams, ...deleteParams],
|
|
128
|
+
responses: bulkDeleteResponse,
|
|
129
|
+
security: secDelete
|
|
130
|
+
}
|
|
131
|
+
} : {};
|
|
132
|
+
const paths = {
|
|
133
|
+
[base]: {
|
|
134
|
+
get: {
|
|
135
|
+
tags: [name],
|
|
136
|
+
operationId: `find${name}`,
|
|
137
|
+
parameters: buildListParams({
|
|
138
|
+
base: name,
|
|
139
|
+
fields: collection.fields,
|
|
140
|
+
ctx,
|
|
141
|
+
refs
|
|
142
|
+
}),
|
|
143
|
+
responses: listResponse,
|
|
144
|
+
security: secRead
|
|
145
|
+
},
|
|
146
|
+
post: {
|
|
147
|
+
tags: [name],
|
|
148
|
+
operationId: `create${name}`,
|
|
149
|
+
parameters: write("create"),
|
|
150
|
+
requestBody: requestBody(createRef, fileRequiredOnCreate),
|
|
151
|
+
responses: createResponse,
|
|
152
|
+
security: secCreate
|
|
153
|
+
},
|
|
154
|
+
...bulkOps
|
|
155
|
+
},
|
|
156
|
+
[`${base}/count`]: { get: {
|
|
157
|
+
tags: [name],
|
|
158
|
+
operationId: `count${name}`,
|
|
159
|
+
parameters: bulkParams,
|
|
160
|
+
responses: countResponse,
|
|
161
|
+
security: secRead
|
|
162
|
+
} },
|
|
163
|
+
[`${base}/validate`]: { post: validateOperation({
|
|
164
|
+
tag: name,
|
|
165
|
+
operationId: `validate${name}`,
|
|
166
|
+
parameters: validateParams(ctx),
|
|
167
|
+
requestBody: {
|
|
168
|
+
...requestBody(createRef, false),
|
|
169
|
+
required: true
|
|
170
|
+
},
|
|
171
|
+
errors: ERRORS.create,
|
|
172
|
+
security: secValidate,
|
|
173
|
+
t
|
|
174
|
+
}) },
|
|
175
|
+
[`${base}/{id}`]: {
|
|
176
|
+
parameters: [{
|
|
177
|
+
name: "id",
|
|
178
|
+
in: "path",
|
|
179
|
+
required: true,
|
|
180
|
+
schema: { type: idType }
|
|
181
|
+
}],
|
|
182
|
+
get: {
|
|
183
|
+
tags: [name],
|
|
184
|
+
operationId: `find${name}ById`,
|
|
185
|
+
parameters: commonReadParams({
|
|
186
|
+
base: name,
|
|
187
|
+
ctx,
|
|
188
|
+
refs
|
|
189
|
+
}),
|
|
190
|
+
responses: findByIdResponse,
|
|
191
|
+
security: secRead
|
|
192
|
+
},
|
|
193
|
+
patch: {
|
|
194
|
+
tags: [name],
|
|
195
|
+
operationId: `update${name}ById`,
|
|
196
|
+
parameters: write("updateByID"),
|
|
197
|
+
requestBody: requestBody(updateRef, false),
|
|
198
|
+
responses: updateResponse,
|
|
199
|
+
security: secUpdate
|
|
200
|
+
},
|
|
201
|
+
delete: {
|
|
202
|
+
tags: [name],
|
|
203
|
+
operationId: `delete${name}ById`,
|
|
204
|
+
parameters: deleteParams,
|
|
205
|
+
responses: deleteResponse,
|
|
206
|
+
security: secDelete
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
paths[`${base}/{id}/validate`] = {
|
|
211
|
+
parameters: [{
|
|
212
|
+
name: "id",
|
|
213
|
+
in: "path",
|
|
214
|
+
required: true,
|
|
215
|
+
schema: { type: idType }
|
|
216
|
+
}],
|
|
217
|
+
post: validateOperation({
|
|
218
|
+
tag: name,
|
|
219
|
+
operationId: `validate${name}ById`,
|
|
220
|
+
parameters: validateParams(ctx),
|
|
221
|
+
requestBody: requestBody(updateRef, false),
|
|
222
|
+
errors: ERRORS.update,
|
|
223
|
+
security: secValidate,
|
|
224
|
+
t
|
|
225
|
+
})
|
|
226
|
+
};
|
|
227
|
+
if (allowDuplicate) paths[`${base}/{id}/duplicate`] = {
|
|
228
|
+
parameters: [{
|
|
229
|
+
name: "id",
|
|
230
|
+
in: "path",
|
|
231
|
+
required: true,
|
|
232
|
+
schema: { type: idType }
|
|
233
|
+
}],
|
|
234
|
+
post: {
|
|
235
|
+
tags: [name],
|
|
236
|
+
operationId: `duplicate${name}`,
|
|
237
|
+
parameters: write("duplicate"),
|
|
238
|
+
responses: {
|
|
239
|
+
...jsonOk(t("collectionDuplicated"), mutationSchema),
|
|
240
|
+
...errorResponses(ERRORS.create, t)
|
|
241
|
+
},
|
|
242
|
+
security: secCreate
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
if (access) {
|
|
246
|
+
const auth = collection.auth;
|
|
247
|
+
const operations = [
|
|
248
|
+
"create",
|
|
249
|
+
"read",
|
|
250
|
+
"update",
|
|
251
|
+
"delete",
|
|
252
|
+
"validate",
|
|
253
|
+
...auth && auth.maxLoginAttempts ? ["unlock"] : [],
|
|
254
|
+
...collection.versions ? ["readVersions"] : []
|
|
255
|
+
];
|
|
256
|
+
const accessOp = (operationId, errors) => docAccessOperation({
|
|
257
|
+
tag: name,
|
|
258
|
+
operationId,
|
|
259
|
+
operations,
|
|
260
|
+
bodyRef: updateRef,
|
|
261
|
+
errors,
|
|
262
|
+
t
|
|
263
|
+
});
|
|
264
|
+
paths[`${base}/access`] = { post: accessOp(`access${name}`, ["500"]) };
|
|
265
|
+
paths[`${base}/access/{id}`] = {
|
|
266
|
+
parameters: [{
|
|
267
|
+
name: "id",
|
|
268
|
+
in: "path",
|
|
269
|
+
required: true,
|
|
270
|
+
schema: { type: idType }
|
|
271
|
+
}],
|
|
272
|
+
post: accessOp(`access${name}ById`, ["404", "500"])
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
if (isUpload) {
|
|
276
|
+
const file = { content: { "*/*": { schema: {
|
|
277
|
+
type: "string",
|
|
278
|
+
format: "binary"
|
|
279
|
+
} } } };
|
|
280
|
+
paths[`${base}/file/{filename}`] = {
|
|
281
|
+
parameters: [{
|
|
282
|
+
name: "filename",
|
|
283
|
+
in: "path",
|
|
284
|
+
required: true,
|
|
285
|
+
schema: { type: "string" }
|
|
286
|
+
}],
|
|
287
|
+
get: {
|
|
288
|
+
tags: [name],
|
|
289
|
+
operationId: `get${name}File`,
|
|
290
|
+
responses: {
|
|
291
|
+
"200": {
|
|
292
|
+
description: t("fileServe"),
|
|
293
|
+
...file
|
|
294
|
+
},
|
|
295
|
+
"206": {
|
|
296
|
+
description: t("filePartial"),
|
|
297
|
+
...file
|
|
298
|
+
},
|
|
299
|
+
...errorResponses([
|
|
300
|
+
"400",
|
|
301
|
+
"403",
|
|
302
|
+
"404",
|
|
303
|
+
"500"
|
|
304
|
+
], t)
|
|
305
|
+
},
|
|
306
|
+
security: secRead
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
return paths;
|
|
311
|
+
};
|
|
312
|
+
export { buildCollectionPaths };
|
|
313
|
+
|
|
314
|
+
//# sourceMappingURL=collections.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collections.js","names":[],"sources":["../../../../src/server/spec/paths/collections.ts"],"sourcesContent":["import type {\n PathsObject,\n ReferenceObject,\n RequestBodyObject,\n ResponsesObject,\n SchemaObject,\n} from '@scalar/openapi-types/3.2'\nimport type { SanitizedCollectionConfig } from 'payload'\n\nimport {\n ERRORS,\n docAccessOperation,\n errorResponses,\n jsonOk,\n jsonResponse,\n uploadRequestBody,\n validateOperation,\n} from '@/server/spec/components.js'\nimport { createSchemaName, listSchemaName, refTo, schemaName, updateSchemaName } from '@/server/spec/names.js'\nimport {\n buildListParams,\n buildParamSchemas,\n commonReadParams,\n type ReadParamRefs,\n validateParams,\n writeParams,\n type WriteOperation,\n} from '@/server/spec/params.js'\nimport type { EntitySecurity } from '@/server/spec/security.js'\nimport { makeT } from '@/shared/translations/index.js'\nimport type { BuildContext } from '@/shared/types/index.js'\n\nexport const buildCollectionPaths = ({\n collection,\n ctx,\n security = {},\n access = false,\n}: {\n collection: SanitizedCollectionConfig\n ctx: BuildContext\n security?: EntitySecurity\n access?: boolean\n}): PathsObject => {\n const t = makeT(ctx.i18n)\n const name = schemaName(collection.slug)\n const base = `${ctx.apiRoute}/${collection.slug}`\n const docRef: ReferenceObject = { $ref: refTo(name) }\n const listRef: ReferenceObject = { $ref: refTo(listSchemaName(name)) }\n const createRef: ReferenceObject = { $ref: refTo(createSchemaName(name)) }\n const updateRef: ReferenceObject = { $ref: refTo(updateSchemaName(name)) }\n const idType = ctx.defaultIDType === 'number' ? 'integer' : 'string'\n const { read: secRead, create: secCreate, update: secUpdate, delete: secDelete, validate: secValidate } = security\n\n const allowBulk = collection.disableBulkEdit !== true\n const allowDuplicate = collection.disableDuplicate !== true\n\n const paramSchemas = buildParamSchemas({ fields: collection.fields, ctx })\n const refs: ReadParamRefs = {\n select: true,\n populate: Boolean(paramSchemas.populate),\n joins: Boolean(paramSchemas.joins),\n }\n\n const isUpload = Boolean(collection.upload)\n const fileRequiredOnCreate =\n typeof collection.upload === 'object' ? collection.upload.filesRequiredOnCreate !== false : true\n\n const requestBody = (ref: ReferenceObject, fileRequired: boolean): RequestBodyObject =>\n isUpload\n ? uploadRequestBody({ bodyRef: ref, fileRequired, t })\n : { content: { 'application/json': { schema: ref } } }\n\n const mutationSchema: SchemaObject = {\n type: 'object',\n properties: { message: { type: 'string' }, doc: docRef },\n }\n\n const listResponse: ResponsesObject = {\n ...jsonOk(t('collectionList'), listRef),\n ...errorResponses(ERRORS.list, t),\n }\n const findByIdResponse: ResponsesObject = {\n ...jsonOk(t('collectionDoc'), docRef),\n ...errorResponses(ERRORS.read, t),\n }\n const createResponse: ResponsesObject = {\n '201': jsonResponse(t('collectionCreated'), mutationSchema),\n ...errorResponses(ERRORS.create, t),\n }\n const updateResponse: ResponsesObject = {\n ...jsonOk(t('collectionUpdated'), mutationSchema),\n ...errorResponses(ERRORS.update, t),\n }\n const deleteResponse: ResponsesObject = {\n ...jsonOk(t('collectionDeleted'), mutationSchema),\n ...errorResponses(ERRORS.delete, t),\n }\n\n const bulkSchema: SchemaObject = {\n type: 'object',\n properties: {\n message: { type: 'string' },\n docs: { type: 'array', items: docRef },\n errors: {\n type: 'array',\n items: {\n type: 'object',\n properties: { message: { type: 'string' }, id: { type: idType } },\n },\n },\n },\n }\n const bulkUpdateResponse: ResponsesObject = {\n ...jsonOk(t('collectionBulkUpdate'), bulkSchema),\n ...errorResponses(ERRORS.update, t),\n }\n const bulkDeleteResponse: ResponsesObject = {\n ...jsonOk(t('collectionBulkDelete'), bulkSchema),\n ...errorResponses(ERRORS.delete, t),\n }\n const countResponse: ResponsesObject = {\n ...jsonOk(t('collectionCount'), { type: 'object', properties: { totalDocs: { type: 'integer' } } }),\n ...errorResponses(ERRORS.list, t),\n }\n\n const listParams = buildListParams({ base: name, fields: collection.fields, ctx, refs })\n const bulkParams = listParams.filter((p) => p.name === 'where')\n const bulkUpdateParams = listParams.filter((p) => ['limit', 'sort', 'where'].includes(p.name))\n const write = (operation: WriteOperation) => writeParams({ base: name, entity: collection, ctx, refs, operation })\n const deleteParams = write('delete')\n\n const bulkOps = allowBulk\n ? {\n patch: {\n tags: [name],\n operationId: `update${name}`,\n parameters: [...bulkUpdateParams, ...write('update')],\n requestBody: requestBody(updateRef, false),\n responses: bulkUpdateResponse,\n security: secUpdate,\n },\n delete: {\n tags: [name],\n operationId: `delete${name}`,\n parameters: [...bulkParams, ...deleteParams],\n responses: bulkDeleteResponse,\n security: secDelete,\n },\n }\n : {}\n\n const paths: PathsObject = {\n [base]: {\n get: {\n tags: [name],\n operationId: `find${name}`,\n parameters: buildListParams({ base: name, fields: collection.fields, ctx, refs }),\n responses: listResponse,\n security: secRead,\n },\n post: {\n tags: [name],\n operationId: `create${name}`,\n parameters: write('create'),\n requestBody: requestBody(createRef, fileRequiredOnCreate),\n responses: createResponse,\n security: secCreate,\n },\n ...bulkOps,\n },\n [`${base}/count`]: {\n get: {\n tags: [name],\n operationId: `count${name}`,\n parameters: bulkParams,\n responses: countResponse,\n security: secRead,\n },\n },\n [`${base}/validate`]: {\n post: validateOperation({\n tag: name,\n operationId: `validate${name}`,\n parameters: validateParams(ctx),\n requestBody: { ...requestBody(createRef, false), required: true },\n errors: ERRORS.create,\n security: secValidate,\n t,\n }),\n },\n [`${base}/{id}`]: {\n parameters: [{ name: 'id', in: 'path', required: true, schema: { type: idType } }],\n get: {\n tags: [name],\n operationId: `find${name}ById`,\n parameters: commonReadParams({ base: name, ctx, refs }),\n responses: findByIdResponse,\n security: secRead,\n },\n patch: {\n tags: [name],\n operationId: `update${name}ById`,\n parameters: write('updateByID'),\n requestBody: requestBody(updateRef, false),\n responses: updateResponse,\n security: secUpdate,\n },\n delete: {\n tags: [name],\n operationId: `delete${name}ById`,\n parameters: deleteParams,\n responses: deleteResponse,\n security: secDelete,\n },\n },\n }\n\n paths[`${base}/{id}/validate`] = {\n parameters: [{ name: 'id', in: 'path', required: true, schema: { type: idType } }],\n post: validateOperation({\n tag: name,\n operationId: `validate${name}ById`,\n parameters: validateParams(ctx),\n requestBody: requestBody(updateRef, false),\n errors: ERRORS.update,\n security: secValidate,\n t,\n }),\n }\n\n if (allowDuplicate) {\n paths[`${base}/{id}/duplicate`] = {\n parameters: [{ name: 'id', in: 'path', required: true, schema: { type: idType } }],\n post: {\n tags: [name],\n operationId: `duplicate${name}`,\n parameters: write('duplicate'),\n responses: { ...jsonOk(t('collectionDuplicated'), mutationSchema), ...errorResponses(ERRORS.create, t) },\n security: secCreate,\n },\n }\n }\n\n if (access) {\n const auth = collection.auth\n const operations = [\n 'create',\n 'read',\n 'update',\n 'delete',\n 'validate',\n ...(auth && auth.maxLoginAttempts ? ['unlock'] : []),\n ...(collection.versions ? ['readVersions'] : []),\n ]\n const accessOp = (operationId: string, errors: typeof ERRORS.read) =>\n docAccessOperation({ tag: name, operationId, operations, bodyRef: updateRef, errors, t })\n paths[`${base}/access`] = { post: accessOp(`access${name}`, ['500']) }\n paths[`${base}/access/{id}`] = {\n parameters: [{ name: 'id', in: 'path', required: true, schema: { type: idType } }],\n post: accessOp(`access${name}ById`, ['404', '500']),\n }\n }\n\n if (isUpload) {\n const file = { content: { '*/*': { schema: { type: 'string', format: 'binary' } } } } as const\n paths[`${base}/file/{filename}`] = {\n parameters: [{ name: 'filename', in: 'path', required: true, schema: { type: 'string' } }],\n get: {\n tags: [name],\n operationId: `get${name}File`,\n responses: {\n '200': { description: t('fileServe'), ...file },\n '206': { description: t('filePartial'), ...file },\n ...errorResponses(['400', '403', '404', '500'], t),\n },\n security: secRead,\n },\n }\n }\n\n return paths\n}\n"],"mappings":";;;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GACA;GACA;GACA,GAAI,QAAQ,KAAK,mBAAmB,CAAC,QAAQ,IAAI,CAAC;GAClD,GAAI,WAAW,WAAW,CAAC,cAAc,IAAI,CAAC;EAChD;EACA,MAAM,YAAY,aAAqB,WACrC,mBAAmB;GAAE,KAAK;GAAM;GAAa;GAAY,SAAS;GAAW;GAAQ;EAAE,CAAC;EAC1F,MAAM,GAAG,KAAK,YAAY,EAAE,MAAM,SAAS,SAAS,QAAQ,CAAC,KAAK,CAAC,EAAE;EACrE,MAAM,GAAG,KAAK,iBAAiB;GAC7B,YAAY,CAAC;IAAE,MAAM;IAAM,IAAI;IAAQ,UAAU;IAAM,QAAQ,EAAE,MAAM,OAAO;GAAE,CAAC;GACjF,MAAM,SAAS,SAAS,KAAK,OAAO,CAAC,OAAO,KAAK,CAAC;EACpD;CACF;CAEA,IAAI,UAAU;EACZ,MAAM,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ;GAAE,MAAM;GAAU,QAAQ;EAAS,EAAE,EAAE,EAAE;EACpF,MAAM,GAAG,KAAK,qBAAqB;GACjC,YAAY,CAAC;IAAE,MAAM;IAAY,IAAI;IAAQ,UAAU;IAAM,QAAQ,EAAE,MAAM,SAAS;GAAE,CAAC;GACzF,KAAK;IACH,MAAM,CAAC,IAAI;IACX,aAAa,MAAM,KAAK;IACxB,WAAW;KACT,OAAO;MAAE,aAAa,EAAE,WAAW;MAAG,GAAG;KAAK;KAC9C,OAAO;MAAE,aAAa,EAAE,aAAa;MAAG,GAAG;KAAK;KAChD,GAAG,eAAe;MAAC;MAAO;MAAO;MAAO;KAAK,GAAG,CAAC;IACnD;IACA,UAAU;GACZ;EACF;CACF;CAEA,OAAO;AACT"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BuildContext } from "../../../shared/types/index.js";
|
|
2
|
+
import { SanitizedCollectionConfig, SanitizedConfig, SanitizedGlobalConfig } from "payload";
|
|
3
|
+
import { PathsObject } from "@scalar/openapi-types/3.2";
|
|
4
|
+
export declare const buildCustomEndpointPaths: ({ config, collections, globals, ctx }: {
|
|
5
|
+
config: SanitizedConfig;
|
|
6
|
+
collections: SanitizedCollectionConfig[];
|
|
7
|
+
globals: SanitizedGlobalConfig[];
|
|
8
|
+
ctx: BuildContext;
|
|
9
|
+
}) => PathsObject;
|
|
10
|
+
//# sourceMappingURL=custom.d.ts.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const getOpenapiMeta = (endpoint) => {
|
|
2
|
+
const meta = endpoint.custom?.openapi;
|
|
3
|
+
return meta && typeof meta === "object" ? meta : void 0;
|
|
4
|
+
};
|
|
5
|
+
const normalizePath = (prefix, path) => {
|
|
6
|
+
return `${prefix}${path.startsWith("/") ? path : `/${path}`}`.replace(/:([A-Za-z0-9_]+)/g, "{$1}");
|
|
7
|
+
};
|
|
8
|
+
const collect = ({ endpoints, prefix, out }) => {
|
|
9
|
+
if (!endpoints) return;
|
|
10
|
+
for (const endpoint of endpoints) {
|
|
11
|
+
const meta = getOpenapiMeta(endpoint);
|
|
12
|
+
if (!meta) continue;
|
|
13
|
+
const path = normalizePath(prefix, endpoint.path);
|
|
14
|
+
const method = endpoint.method.toLowerCase();
|
|
15
|
+
out[path] = {
|
|
16
|
+
...out[path],
|
|
17
|
+
[method]: { ...meta }
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const buildCustomEndpointPaths = ({ config, collections, globals, ctx }) => {
|
|
22
|
+
const out = {};
|
|
23
|
+
collect({
|
|
24
|
+
endpoints: config.endpoints,
|
|
25
|
+
prefix: ctx.apiRoute,
|
|
26
|
+
out
|
|
27
|
+
});
|
|
28
|
+
for (const collection of collections) collect({
|
|
29
|
+
endpoints: collection.endpoints,
|
|
30
|
+
prefix: `${ctx.apiRoute}/${collection.slug}`,
|
|
31
|
+
out
|
|
32
|
+
});
|
|
33
|
+
for (const global of globals) collect({
|
|
34
|
+
endpoints: global.endpoints,
|
|
35
|
+
prefix: `${ctx.apiRoute}/globals/${global.slug}`,
|
|
36
|
+
out
|
|
37
|
+
});
|
|
38
|
+
return out;
|
|
39
|
+
};
|
|
40
|
+
export { buildCustomEndpointPaths };
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=custom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom.js","names":[],"sources":["../../../../src/server/spec/paths/custom.ts"],"sourcesContent":["import type { OperationObject, PathsObject } from '@scalar/openapi-types/3.2'\nimport type { Endpoint, SanitizedCollectionConfig, SanitizedConfig, SanitizedGlobalConfig } from 'payload'\n\nimport type { BuildContext } from '@/shared/types/index.js'\n\nconst getOpenapiMeta = (endpoint: Endpoint): OperationObject | undefined => {\n const meta = endpoint.custom?.openapi\n return meta && typeof meta === 'object' ? (meta as OperationObject) : undefined\n}\n\nconst normalizePath = (prefix: string, path: string): string => {\n const joined = `${prefix}${path.startsWith('/') ? path : `/${path}`}`\n return joined.replace(/:([A-Za-z0-9_]+)/g, '{$1}')\n}\n\nconst collect = ({\n endpoints,\n prefix,\n out,\n}: {\n endpoints: Endpoint[] | false | undefined\n prefix: string\n out: PathsObject\n}): void => {\n if (!endpoints) return\n for (const endpoint of endpoints) {\n const meta = getOpenapiMeta(endpoint)\n if (!meta) continue\n const path = normalizePath(prefix, endpoint.path)\n const method = endpoint.method.toLowerCase()\n out[path] = { ...out[path], [method]: { ...meta } }\n }\n}\n\nexport const buildCustomEndpointPaths = ({\n config,\n collections,\n globals,\n ctx,\n}: {\n config: SanitizedConfig\n collections: SanitizedCollectionConfig[]\n globals: SanitizedGlobalConfig[]\n ctx: BuildContext\n}): PathsObject => {\n const out: PathsObject = {}\n collect({ endpoints: config.endpoints, prefix: ctx.apiRoute, out })\n for (const collection of collections) {\n collect({ endpoints: collection.endpoints, prefix: `${ctx.apiRoute}/${collection.slug}`, out })\n }\n for (const global of globals) {\n collect({ endpoints: global.endpoints, prefix: `${ctx.apiRoute}/globals/${global.slug}`, out })\n }\n return out\n}\n"],"mappings":"AAKA,MAAM,kBAAkB,aAAoD;CAC1E,MAAM,OAAO,SAAS,QAAQ;CAC9B,OAAO,QAAQ,OAAO,SAAS,WAAY,OAA2B,KAAA;AACxE;AAEA,MAAM,iBAAiB,QAAgB,SAAyB;CAE9D,OAAO,GADW,SAAS,KAAK,WAAW,GAAG,IAAI,OAAO,IAAI,SAC/C,QAAQ,qBAAqB,MAAM;AACnD;AAEA,MAAM,WAAW,EACf,WACA,QACA,UAKU;CACV,IAAI,CAAC,WAAW;CAChB,KAAK,MAAM,YAAY,WAAW;EAChC,MAAM,OAAO,eAAe,QAAQ;EACpC,IAAI,CAAC,MAAM;EACX,MAAM,OAAO,cAAc,QAAQ,SAAS,IAAI;EAChD,MAAM,SAAS,SAAS,OAAO,YAAY;EAC3C,IAAI,QAAQ;GAAE,GAAG,IAAI;IAAQ,SAAS,EAAE,GAAG,KAAK;EAAE;CACpD;AACF;AAEA,MAAa,4BAA4B,EACvC,QACA,aACA,SACA,UAMiB;CACjB,MAAM,MAAmB,CAAC;CAC1B,QAAQ;EAAE,WAAW,OAAO;EAAW,QAAQ,IAAI;EAAU;CAAI,CAAC;CAClE,KAAK,MAAM,cAAc,aACvB,QAAQ;EAAE,WAAW,WAAW;EAAW,QAAQ,GAAG,IAAI,SAAS,GAAG,WAAW;EAAQ;CAAI,CAAC;CAEhG,KAAK,MAAM,UAAU,SACnB,QAAQ;EAAE,WAAW,OAAO;EAAW,QAAQ,GAAG,IAAI,SAAS,WAAW,OAAO;EAAQ;CAAI,CAAC;CAEhG,OAAO;AACT"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BuildContext } from "../../../shared/types/index.js";
|
|
2
|
+
import { EntitySecurity } from "../security.js";
|
|
3
|
+
import { SanitizedGlobalConfig } from "payload";
|
|
4
|
+
import { PathsObject } from "@scalar/openapi-types/3.2";
|
|
5
|
+
export declare const buildGlobalPaths: ({ global, ctx, security, access }: {
|
|
6
|
+
global: SanitizedGlobalConfig;
|
|
7
|
+
ctx: BuildContext;
|
|
8
|
+
security?: EntitySecurity;
|
|
9
|
+
access?: boolean;
|
|
10
|
+
}) => PathsObject;
|
|
11
|
+
//# sourceMappingURL=globals.d.ts.map
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { globalSchemaName, refTo, updateSchemaName } from "../names.js";
|
|
2
|
+
import { ERRORS, docAccessOperation, errorResponses, jsonOk, validateOperation } from "../components.js";
|
|
3
|
+
import { makeT } from "../../../shared/translations/index.js";
|
|
4
|
+
import { buildParamSchemas, commonReadParams, validateParams, writeParams } from "../params.js";
|
|
5
|
+
const buildGlobalPaths = ({ global, ctx, security = {}, access = false }) => {
|
|
6
|
+
const t = makeT(ctx.i18n);
|
|
7
|
+
const name = globalSchemaName(global.slug);
|
|
8
|
+
const docRef = { $ref: refTo(name) };
|
|
9
|
+
const updateRef = { $ref: refTo(updateSchemaName(name)) };
|
|
10
|
+
const { read: secRead, update: secUpdate, validate: secValidate } = security;
|
|
11
|
+
const paramSchemas = buildParamSchemas({
|
|
12
|
+
fields: global.fields,
|
|
13
|
+
ctx
|
|
14
|
+
});
|
|
15
|
+
const refs = {
|
|
16
|
+
select: true,
|
|
17
|
+
populate: Boolean(paramSchemas.populate),
|
|
18
|
+
joins: Boolean(paramSchemas.joins)
|
|
19
|
+
};
|
|
20
|
+
const paths = {
|
|
21
|
+
[`${ctx.apiRoute}/globals/${global.slug}`]: {
|
|
22
|
+
get: {
|
|
23
|
+
tags: [name],
|
|
24
|
+
operationId: `find${name}`,
|
|
25
|
+
parameters: commonReadParams({
|
|
26
|
+
base: name,
|
|
27
|
+
ctx,
|
|
28
|
+
refs
|
|
29
|
+
}),
|
|
30
|
+
responses: {
|
|
31
|
+
...jsonOk(t("globalDoc"), docRef),
|
|
32
|
+
...errorResponses(ERRORS.globalRead, t)
|
|
33
|
+
},
|
|
34
|
+
security: secRead
|
|
35
|
+
},
|
|
36
|
+
post: {
|
|
37
|
+
tags: [name],
|
|
38
|
+
operationId: `update${name}`,
|
|
39
|
+
parameters: writeParams({
|
|
40
|
+
base: name,
|
|
41
|
+
entity: global,
|
|
42
|
+
ctx,
|
|
43
|
+
refs,
|
|
44
|
+
operation: "globalUpdate"
|
|
45
|
+
}),
|
|
46
|
+
requestBody: { content: { "application/json": { schema: updateRef } } },
|
|
47
|
+
responses: {
|
|
48
|
+
...jsonOk(t("globalDoc"), {
|
|
49
|
+
type: "object",
|
|
50
|
+
properties: {
|
|
51
|
+
message: { type: "string" },
|
|
52
|
+
result: docRef
|
|
53
|
+
}
|
|
54
|
+
}),
|
|
55
|
+
...errorResponses(ERRORS.globalUpdate, t)
|
|
56
|
+
},
|
|
57
|
+
security: secUpdate
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
[`${ctx.apiRoute}/globals/${global.slug}/validate`]: { post: validateOperation({
|
|
61
|
+
tag: name,
|
|
62
|
+
operationId: `validate${name}`,
|
|
63
|
+
parameters: validateParams(ctx),
|
|
64
|
+
requestBody: { content: { "application/json": { schema: updateRef } } },
|
|
65
|
+
errors: ERRORS.globalUpdate,
|
|
66
|
+
security: secValidate,
|
|
67
|
+
t
|
|
68
|
+
}) }
|
|
69
|
+
};
|
|
70
|
+
if (access) paths[`${ctx.apiRoute}/globals/${global.slug}/access`] = { post: docAccessOperation({
|
|
71
|
+
tag: name,
|
|
72
|
+
operationId: `access${name}`,
|
|
73
|
+
operations: [
|
|
74
|
+
"read",
|
|
75
|
+
"update",
|
|
76
|
+
"validate",
|
|
77
|
+
...global.versions ? ["readVersions"] : []
|
|
78
|
+
],
|
|
79
|
+
bodyRef: updateRef,
|
|
80
|
+
errors: ["500"],
|
|
81
|
+
t
|
|
82
|
+
}) };
|
|
83
|
+
return paths;
|
|
84
|
+
};
|
|
85
|
+
export { buildGlobalPaths };
|
|
86
|
+
|
|
87
|
+
//# sourceMappingURL=globals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"globals.js","names":[],"sources":["../../../../src/server/spec/paths/globals.ts"],"sourcesContent":["import type { PathsObject, ReferenceObject } from '@scalar/openapi-types/3.2'\nimport type { SanitizedGlobalConfig } from 'payload'\n\nimport { ERRORS, docAccessOperation, errorResponses, jsonOk, validateOperation } from '@/server/spec/components.js'\nimport { globalSchemaName, refTo, updateSchemaName } from '@/server/spec/names.js'\nimport {\n buildParamSchemas,\n commonReadParams,\n type ReadParamRefs,\n validateParams,\n writeParams,\n} from '@/server/spec/params.js'\nimport type { EntitySecurity } from '@/server/spec/security.js'\nimport { makeT } from '@/shared/translations/index.js'\nimport type { BuildContext } from '@/shared/types/index.js'\n\nexport const buildGlobalPaths = ({\n global,\n ctx,\n security = {},\n access = false,\n}: {\n global: SanitizedGlobalConfig\n ctx: BuildContext\n security?: EntitySecurity\n access?: boolean\n}): PathsObject => {\n const t = makeT(ctx.i18n)\n const name = globalSchemaName(global.slug)\n const docRef: ReferenceObject = { $ref: refTo(name) }\n const updateRef: ReferenceObject = { $ref: refTo(updateSchemaName(name)) }\n const { read: secRead, update: secUpdate, validate: secValidate } = security\n\n const paramSchemas = buildParamSchemas({ fields: global.fields, ctx })\n const refs: ReadParamRefs = {\n select: true,\n populate: Boolean(paramSchemas.populate),\n joins: Boolean(paramSchemas.joins),\n }\n\n const paths: PathsObject = {\n [`${ctx.apiRoute}/globals/${global.slug}`]: {\n get: {\n tags: [name],\n operationId: `find${name}`,\n parameters: commonReadParams({ base: name, ctx, refs }),\n responses: { ...jsonOk(t('globalDoc'), docRef), ...errorResponses(ERRORS.globalRead, t) },\n security: secRead,\n },\n post: {\n tags: [name],\n operationId: `update${name}`,\n parameters: writeParams({ base: name, entity: global, ctx, refs, operation: 'globalUpdate' }),\n requestBody: { content: { 'application/json': { schema: updateRef } } },\n responses: {\n ...jsonOk(t('globalDoc'), {\n type: 'object',\n properties: { message: { type: 'string' }, result: docRef },\n }),\n ...errorResponses(ERRORS.globalUpdate, t),\n },\n security: secUpdate,\n },\n },\n [`${ctx.apiRoute}/globals/${global.slug}/validate`]: {\n post: validateOperation({\n tag: name,\n operationId: `validate${name}`,\n parameters: validateParams(ctx),\n requestBody: { content: { 'application/json': { schema: updateRef } } },\n errors: ERRORS.globalUpdate,\n security: secValidate,\n t,\n }),\n },\n }\n\n if (access) {\n paths[`${ctx.apiRoute}/globals/${global.slug}/access`] = {\n post: docAccessOperation({\n tag: name,\n operationId: `access${name}`,\n operations: ['read', 'update', 'validate', ...(global.versions ? ['readVersions'] : [])],\n bodyRef: updateRef,\n errors: ['500'],\n t,\n }),\n }\n }\n\n return paths\n}\n"],"mappings":";;;;AAgBA,MAAa,oBAAoB,EAC/B,QACA,KACA,WAAW,CAAC,GACZ,SAAS,YAMQ;CACjB,MAAM,IAAI,MAAM,IAAI,IAAI;CACxB,MAAM,OAAO,iBAAiB,OAAO,IAAI;CACzC,MAAM,SAA0B,EAAE,MAAM,MAAM,IAAI,EAAE;CACpD,MAAM,YAA6B,EAAE,MAAM,MAAM,iBAAiB,IAAI,CAAC,EAAE;CACzE,MAAM,EAAE,MAAM,SAAS,QAAQ,WAAW,UAAU,gBAAgB;CAEpE,MAAM,eAAe,kBAAkB;EAAE,QAAQ,OAAO;EAAQ;CAAI,CAAC;CACrE,MAAM,OAAsB;EAC1B,QAAQ;EACR,UAAU,QAAQ,aAAa,QAAQ;EACvC,OAAO,QAAQ,aAAa,KAAK;CACnC;CAEA,MAAM,QAAqB;GACxB,GAAG,IAAI,SAAS,WAAW,OAAO,SAAS;GAC1C,KAAK;IACH,MAAM,CAAC,IAAI;IACX,aAAa,OAAO;IACpB,YAAY,iBAAiB;KAAE,MAAM;KAAM;KAAK;IAAK,CAAC;IACtD,WAAW;KAAE,GAAG,OAAO,EAAE,WAAW,GAAG,MAAM;KAAG,GAAG,eAAe,OAAO,YAAY,CAAC;IAAE;IACxF,UAAU;GACZ;GACA,MAAM;IACJ,MAAM,CAAC,IAAI;IACX,aAAa,SAAS;IACtB,YAAY,YAAY;KAAE,MAAM;KAAM,QAAQ;KAAQ;KAAK;KAAM,WAAW;IAAe,CAAC;IAC5F,aAAa,EAAE,SAAS,EAAE,oBAAoB,EAAE,QAAQ,UAAU,EAAE,EAAE;IACtE,WAAW;KACT,GAAG,OAAO,EAAE,WAAW,GAAG;MACxB,MAAM;MACN,YAAY;OAAE,SAAS,EAAE,MAAM,SAAS;OAAG,QAAQ;MAAO;KAC5D,CAAC;KACD,GAAG,eAAe,OAAO,cAAc,CAAC;IAC1C;IACA,UAAU;GACZ;EACF;GACC,GAAG,IAAI,SAAS,WAAW,OAAO,KAAK,aAAa,EACnD,MAAM,kBAAkB;GACtB,KAAK;GACL,aAAa,WAAW;GACxB,YAAY,eAAe,GAAG;GAC9B,aAAa,EAAE,SAAS,EAAE,oBAAoB,EAAE,QAAQ,UAAU,EAAE,EAAE;GACtE,QAAQ,OAAO;GACf,UAAU;GACV;EACF,CAAC,EACH;CACF;CAEA,IAAI,QACF,MAAM,GAAG,IAAI,SAAS,WAAW,OAAO,KAAK,YAAY,EACvD,MAAM,mBAAmB;EACvB,KAAK;EACL,aAAa,SAAS;EACtB,YAAY;GAAC;GAAQ;GAAU;GAAY,GAAI,OAAO,WAAW,CAAC,cAAc,IAAI,CAAC;EAAE;EACvF,SAAS;EACT,QAAQ,CAAC,KAAK;EACd;CACF,CAAC,EACH;CAGF,OAAO;AACT"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BuildContext } from "../../../shared/types/index.js";
|
|
2
|
+
import { SanitizedConfig } from "payload";
|
|
3
|
+
import { PathsObject, SecurityRequirementObject } from "@scalar/openapi-types/3.2";
|
|
4
|
+
export declare const buildJobsPaths: ({ config, ctx, security }: {
|
|
5
|
+
config: SanitizedConfig;
|
|
6
|
+
ctx: BuildContext;
|
|
7
|
+
security?: SecurityRequirementObject[];
|
|
8
|
+
}) => PathsObject;
|
|
9
|
+
//# sourceMappingURL=jobs.d.ts.map
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { errorResponses, jsonResponse } from "../components.js";
|
|
2
|
+
import { makeT } from "../../../shared/translations/index.js";
|
|
3
|
+
const boolParam = (name, description) => ({
|
|
4
|
+
name,
|
|
5
|
+
in: "query",
|
|
6
|
+
description,
|
|
7
|
+
schema: { type: "boolean" }
|
|
8
|
+
});
|
|
9
|
+
const collectQueues = (jobs) => {
|
|
10
|
+
const queues = /* @__PURE__ */ new Set(["default"]);
|
|
11
|
+
const add = (q) => {
|
|
12
|
+
if (typeof q === "string" && q) queues.add(q);
|
|
13
|
+
};
|
|
14
|
+
const fromSchedules = (items) => {
|
|
15
|
+
if (!Array.isArray(items)) return;
|
|
16
|
+
for (const item of items) for (const s of item.schedule ?? []) add(s.queue);
|
|
17
|
+
};
|
|
18
|
+
fromSchedules(jobs?.tasks);
|
|
19
|
+
fromSchedules(jobs?.workflows);
|
|
20
|
+
const autoRun = jobs?.autoRun;
|
|
21
|
+
if (Array.isArray(autoRun)) for (const cron of autoRun) add(cron.queue);
|
|
22
|
+
const processingOrder = jobs?.processingOrder;
|
|
23
|
+
if (processingOrder?.queues) for (const name of Object.keys(processingOrder.queues)) add(name);
|
|
24
|
+
return [...queues].toSorted();
|
|
25
|
+
};
|
|
26
|
+
const queueParam = (queues, ctx) => ({
|
|
27
|
+
name: "queue",
|
|
28
|
+
in: "query",
|
|
29
|
+
description: makeT(ctx.i18n)("jobsQueue", { queues: queues.map((q) => `\`${q}\``).join(", ") }),
|
|
30
|
+
schema: {
|
|
31
|
+
type: "string",
|
|
32
|
+
enum: queues
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
const buildJobsPaths = ({ config, ctx, security }) => {
|
|
36
|
+
const jobs = config.jobs;
|
|
37
|
+
if (!Boolean((jobs?.tasks)?.length || (jobs?.workflows)?.length)) return {};
|
|
38
|
+
const t = makeT(ctx.i18n);
|
|
39
|
+
const queue = queueParam(collectQueues(jobs), ctx);
|
|
40
|
+
const errors = errorResponses([
|
|
41
|
+
"401",
|
|
42
|
+
"403",
|
|
43
|
+
"500"
|
|
44
|
+
], t);
|
|
45
|
+
return {
|
|
46
|
+
[`${ctx.apiRoute}/payload-jobs/run`]: { get: {
|
|
47
|
+
tags: ["Jobs"],
|
|
48
|
+
operationId: "runJobs",
|
|
49
|
+
summary: t("jobsRunSummary"),
|
|
50
|
+
parameters: [
|
|
51
|
+
queue,
|
|
52
|
+
boolParam("allQueues", t("jobsRunAllQueues")),
|
|
53
|
+
{
|
|
54
|
+
name: "limit",
|
|
55
|
+
in: "query",
|
|
56
|
+
description: t("jobsLimit"),
|
|
57
|
+
schema: { type: "integer" }
|
|
58
|
+
},
|
|
59
|
+
boolParam("disableScheduling", t("jobsDisableScheduling")),
|
|
60
|
+
boolParam("silent", t("jobsSilent"))
|
|
61
|
+
],
|
|
62
|
+
responses: {
|
|
63
|
+
"200": jsonResponse(t("jobsRunResult"), {
|
|
64
|
+
type: "object",
|
|
65
|
+
properties: {
|
|
66
|
+
message: { type: "string" },
|
|
67
|
+
noJobsRemaining: { type: "boolean" },
|
|
68
|
+
remainingJobsFromQueried: { type: "integer" }
|
|
69
|
+
}
|
|
70
|
+
}),
|
|
71
|
+
...errors
|
|
72
|
+
},
|
|
73
|
+
security
|
|
74
|
+
} },
|
|
75
|
+
[`${ctx.apiRoute}/payload-jobs/handle-schedules`]: { get: {
|
|
76
|
+
tags: ["Jobs"],
|
|
77
|
+
operationId: "handleJobSchedules",
|
|
78
|
+
summary: t("jobsSchedulesSummary"),
|
|
79
|
+
parameters: [queue, boolParam("allQueues", t("jobsSchedulesAllQueues"))],
|
|
80
|
+
responses: {
|
|
81
|
+
"200": jsonResponse(t("jobsSchedulesResult"), {
|
|
82
|
+
type: "object",
|
|
83
|
+
properties: {
|
|
84
|
+
message: { type: "string" },
|
|
85
|
+
queued: { type: "integer" },
|
|
86
|
+
errored: { type: "integer" },
|
|
87
|
+
skipped: { type: "integer" }
|
|
88
|
+
}
|
|
89
|
+
}),
|
|
90
|
+
...errors
|
|
91
|
+
},
|
|
92
|
+
security
|
|
93
|
+
} }
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
export { buildJobsPaths };
|
|
97
|
+
|
|
98
|
+
//# sourceMappingURL=jobs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jobs.js","names":[],"sources":["../../../../src/server/spec/paths/jobs.ts"],"sourcesContent":["import type { ParameterObject, PathsObject, SecurityRequirementObject } from '@scalar/openapi-types/3.2'\nimport type { SanitizedConfig } from 'payload'\n\nimport { errorResponses, jsonResponse } from '@/server/spec/components.js'\nimport { makeT } from '@/shared/translations/index.js'\nimport type { BuildContext } from '@/shared/types/index.js'\n\nconst boolParam = (name: string, description: string): ParameterObject => ({\n name,\n in: 'query',\n description,\n schema: { type: 'boolean' },\n})\n\nconst collectQueues = (jobs: Record<string, unknown> | undefined): string[] => {\n const queues = new Set<string>(['default'])\n\n const add = (q: unknown) => {\n if (typeof q === 'string' && q) queues.add(q)\n }\n const fromSchedules = (items: unknown) => {\n if (!Array.isArray(items)) return\n for (const item of items as Array<{ schedule?: Array<{ queue?: unknown }> }>) {\n for (const s of item.schedule ?? []) add(s.queue)\n }\n }\n\n fromSchedules(jobs?.tasks)\n fromSchedules(jobs?.workflows)\n\n const autoRun = jobs?.autoRun\n if (Array.isArray(autoRun)) {\n for (const cron of autoRun as Array<{ queue?: unknown }>) add(cron.queue)\n }\n\n const processingOrder = jobs?.processingOrder as { queues?: Record<string, unknown> } | undefined\n if (processingOrder?.queues) {\n for (const name of Object.keys(processingOrder.queues)) add(name)\n }\n\n return [...queues].toSorted()\n}\n\nconst queueParam = (queues: string[], ctx: BuildContext): ParameterObject => ({\n name: 'queue',\n in: 'query',\n description: makeT(ctx.i18n)('jobsQueue', { queues: queues.map((q) => `\\`${q}\\``).join(', ') }),\n schema: { type: 'string', enum: queues },\n})\n\nexport const buildJobsPaths = ({\n config,\n ctx,\n security,\n}: {\n config: SanitizedConfig\n ctx: BuildContext\n security?: SecurityRequirementObject[]\n}): PathsObject => {\n const jobs = config.jobs as Record<string, unknown> | undefined\n const hasJobs = Boolean((jobs?.tasks as unknown[])?.length || (jobs?.workflows as unknown[])?.length)\n if (!hasJobs) return {}\n\n const t = makeT(ctx.i18n)\n const queue = queueParam(collectQueues(jobs), ctx)\n const errors = errorResponses(['401', '403', '500'], t)\n\n return {\n [`${ctx.apiRoute}/payload-jobs/run`]: {\n get: {\n tags: ['Jobs'],\n operationId: 'runJobs',\n summary: t('jobsRunSummary'),\n parameters: [\n queue,\n boolParam('allQueues', t('jobsRunAllQueues')),\n { name: 'limit', in: 'query', description: t('jobsLimit'), schema: { type: 'integer' } },\n boolParam('disableScheduling', t('jobsDisableScheduling')),\n boolParam('silent', t('jobsSilent')),\n ],\n responses: {\n '200': jsonResponse(t('jobsRunResult'), {\n type: 'object',\n properties: {\n message: { type: 'string' },\n noJobsRemaining: { type: 'boolean' },\n remainingJobsFromQueried: { type: 'integer' },\n },\n }),\n ...errors,\n },\n security,\n },\n },\n [`${ctx.apiRoute}/payload-jobs/handle-schedules`]: {\n get: {\n tags: ['Jobs'],\n operationId: 'handleJobSchedules',\n summary: t('jobsSchedulesSummary'),\n parameters: [queue, boolParam('allQueues', t('jobsSchedulesAllQueues'))],\n responses: {\n '200': jsonResponse(t('jobsSchedulesResult'), {\n type: 'object',\n properties: {\n message: { type: 'string' },\n queued: { type: 'integer' },\n errored: { type: 'integer' },\n skipped: { type: 'integer' },\n },\n }),\n ...errors,\n },\n security,\n },\n },\n }\n}\n"],"mappings":";;AAOA,MAAM,aAAa,MAAc,iBAA0C;CACzE;CACA,IAAI;CACJ;CACA,QAAQ,EAAE,MAAM,UAAU;AAC5B;AAEA,MAAM,iBAAiB,SAAwD;CAC7E,MAAM,yBAAS,IAAI,IAAY,CAAC,SAAS,CAAC;CAE1C,MAAM,OAAO,MAAe;EAC1B,IAAI,OAAO,MAAM,YAAY,GAAG,OAAO,IAAI,CAAC;CAC9C;CACA,MAAM,iBAAiB,UAAmB;EACxC,IAAI,CAAC,MAAM,QAAQ,KAAK,GAAG;EAC3B,K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AE;IACvF,UAAU,qBAAqB,EAAE,uBAAuB,CAAC;IACzD,UAAU,UAAU,EAAE,YAAY,CAAC;GACrC;GACA,WAAW;IACT,OAAO,aAAa,EAAE,eAAe,GAAG;KACtC,MAAM;KACN,YAAY;MACV,SAAS,EAAE,MAAM,SAAS;MAC1B,iBAAiB,EAAE,MAAM,UAAU;MACnC,0BAA0B,EAAE,MAAM,UAAU;KAC9C;IACF,CAAC;IACD,GAAG;GACL;GACA;EACF,EACF;GACC,GAAG,IAAI,SAAS,kCAAkC,EACjD,KAAK;GACH,MAAM,CAAC,MAAM;GACb,aAAa;GACb,SAAS,EAAE,sBAAsB;GACjC,YAAY,CAAC,OAAO,UAAU,aAAa,EAAE,wBAAwB,CAAC,CAAC;GACvE,WAAW;IACT,OAAO,aAAa,EAAE,qBAAqB,GAAG;KAC5C,MAAM;KACN,YAAY;MACV,SAAS,EAAE,MAAM,SAAS;MAC1B,QAAQ,EAAE,MAAM,UAAU;MAC1B,SAAS,EAAE,MAAM,UAAU;MAC3B,SAAS,EAAE,MAAM,UAAU;KAC7B;IACF,CAAC;IACD,GAAG;GACL;GACA;EACF,EACF;CACF;AACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BuildContext } from "../../../shared/types/index.js";
|
|
2
|
+
import { PathsObject } from "@scalar/openapi-types/3.2";
|
|
3
|
+
export declare const buildSystemPaths: ({ ctx, access, uploadSlugs }: {
|
|
4
|
+
ctx: BuildContext;
|
|
5
|
+
access: boolean;
|
|
6
|
+
uploadSlugs: string[];
|
|
7
|
+
}) => PathsObject;
|
|
8
|
+
//# sourceMappingURL=system.d.ts.map
|