@plasmicpkgs/plasmic-cms 0.0.297 → 0.0.298

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/index.js CHANGED
@@ -95,12 +95,8 @@ __export(src_exports, {
95
95
  cmsRowFieldValueMeta: () => cmsRowFieldValueMeta,
96
96
  cmsRowImageMeta: () => cmsRowImageMeta,
97
97
  cmsRowLinkMeta: () => cmsRowLinkMeta,
98
- fetchContent: () => fetchContent,
99
- fetchCount: () => fetchCount,
100
- fetchTables: () => fetchTables,
101
98
  mkApi: () => mkApi,
102
- registerAll: () => registerAll,
103
- registerAllCustomFunctions: () => registerAllCustomFunctions
99
+ registerAll: () => registerAll
104
100
  });
105
101
  module.exports = __toCommonJS(src_exports);
106
102
  var import_registerComponent = __toESM(require("@plasmicapp/host/registerComponent"));
@@ -109,6 +105,7 @@ var import_registerGlobalContext = __toESM(require("@plasmicapp/host/registerGlo
109
105
  // src/components.tsx
110
106
  var import_host2 = require("@plasmicapp/host");
111
107
  var import_query = require("@plasmicapp/query");
108
+ var import_cms = require("@plasmicpkgs/cms");
112
109
  var import_dayjs = __toESM(require("dayjs"));
113
110
  var import_react2 = __toESM(require("react"));
114
111
 
@@ -258,7 +255,7 @@ function makeDatabaseCacheKey(config) {
258
255
  if (!config) {
259
256
  return null;
260
257
  }
261
- const _a = config, { databaseToken } = _a, rest = __objRest(_a, ["databaseToken"]);
258
+ const _a = config, { databaseToken: _doNotExposeDatabaseToken } = _a, rest = __objRest(_a, ["databaseToken"]);
262
259
  return JSON.stringify(rest);
263
260
  }
264
261
  function DatabaseProvider({
@@ -413,41 +410,6 @@ function CountProvider({
413
410
  );
414
411
  }
415
412
 
416
- // src/util.ts
417
- function mkTableOptions(tables) {
418
- if (!tables) {
419
- return [];
420
- }
421
- return tables.map((table) => ({
422
- value: table.identifier,
423
- label: table.name
424
- }));
425
- }
426
- function mkFieldOptions(tables, tableIdentifier, types) {
427
- if (!tables) {
428
- return [];
429
- }
430
- const table = tables.find((t) => t.identifier === tableIdentifier);
431
- if (!table) {
432
- return [];
433
- }
434
- let fields = table.schema.fields;
435
- if (types) {
436
- fields = fields.filter((f) => types.includes(f.type));
437
- }
438
- const options = fields.map((f) => ({
439
- value: f.identifier,
440
- label: f.name || f.identifier
441
- }));
442
- if (!options.some((option) => option.value === "_id")) {
443
- options.push({
444
- label: "System-assigned ID",
445
- value: "_id"
446
- });
447
- }
448
- return options;
449
- }
450
-
451
413
  // src/components.tsx
452
414
  var modulePath = "@plasmicpkgs/plasmic-cms";
453
415
  var componentPrefix = "hostless-plasmic-cms";
@@ -574,7 +536,7 @@ var cmsQueryRepeaterMeta = {
574
536
  type: "choice",
575
537
  displayName: "Model",
576
538
  description: "CMS model (table) to query.",
577
- options: (_, ctx) => mkTableOptions(ctx == null ? void 0 : ctx.tables),
539
+ options: (_, ctx) => (0, import_cms._mkTableOptions)(ctx == null ? void 0 : ctx.tables),
578
540
  defaultValueHint: (_, ctx) => ctx == null ? void 0 : ctx.table
579
541
  },
580
542
  useDraft: {
@@ -604,13 +566,20 @@ var cmsQueryRepeaterMeta = {
604
566
  description: "Field (from model schema) to filter by",
605
567
  options: ({ table }, ctx) => {
606
568
  var _a;
607
- return mkFieldOptions(ctx == null ? void 0 : ctx.tables, (_a = ctx == null ? void 0 : ctx.table) != null ? _a : table, [
608
- "number" /* NUMBER */,
609
- "boolean" /* BOOLEAN */,
610
- "text" /* TEXT */,
611
- "long-text" /* LONG_TEXT */,
612
- "ref" /* REF */
613
- ]);
569
+ return (0, import_cms._mkFieldOptions)(
570
+ ctx == null ? void 0 : ctx.tables,
571
+ (_a = ctx == null ? void 0 : ctx.table) != null ? _a : table,
572
+ [
573
+ import_cms._CmsMetaType.NUMBER,
574
+ import_cms._CmsMetaType.BOOLEAN,
575
+ import_cms._CmsMetaType.TEXT,
576
+ import_cms._CmsMetaType.LONG_TEXT,
577
+ import_cms._CmsMetaType.REF
578
+ ],
579
+ {
580
+ includeSystemId: true
581
+ }
582
+ );
614
583
  }
615
584
  },
616
585
  filterValue: {
@@ -622,13 +591,20 @@ var cmsQueryRepeaterMeta = {
622
591
  type: "choice",
623
592
  displayName: "Order by",
624
593
  description: "Field to order by.",
625
- options: (_, ctx) => mkFieldOptions(ctx == null ? void 0 : ctx.tables, ctx == null ? void 0 : ctx.table, [
626
- "number" /* NUMBER */,
627
- "boolean" /* BOOLEAN */,
628
- "date-time" /* DATE_TIME */,
629
- "long-text" /* LONG_TEXT */,
630
- "text" /* TEXT */
631
- ]),
594
+ options: (_, ctx) => (0, import_cms._mkFieldOptions)(
595
+ ctx == null ? void 0 : ctx.tables,
596
+ ctx == null ? void 0 : ctx.table,
597
+ [
598
+ import_cms._CmsMetaType.NUMBER,
599
+ import_cms._CmsMetaType.BOOLEAN,
600
+ import_cms._CmsMetaType.DATE_TIME,
601
+ import_cms._CmsMetaType.LONG_TEXT,
602
+ import_cms._CmsMetaType.TEXT
603
+ ],
604
+ {
605
+ includeSystemId: true
606
+ }
607
+ ),
632
608
  hidden: (ps) => ps.mode === "count"
633
609
  },
634
610
  desc: {
@@ -660,7 +636,9 @@ var cmsQueryRepeaterMeta = {
660
636
  description: "Fields from the CMS model to include with each row; by default, all fields are included",
661
637
  options: ({ table }, ctx) => {
662
638
  var _a;
663
- return mkFieldOptions(ctx == null ? void 0 : ctx.tables, (_a = ctx == null ? void 0 : ctx.table) != null ? _a : table);
639
+ return (0, import_cms._mkFieldOptions)(ctx == null ? void 0 : ctx.tables, (_a = ctx == null ? void 0 : ctx.table) != null ? _a : table, void 0, {
640
+ includeRefStars: true
641
+ });
664
642
  },
665
643
  hidden: (ps) => ps.mode === "count"
666
644
  },
@@ -819,7 +797,7 @@ var cmsRowFieldMeta = {
819
797
  },
820
798
  helpText: "Pick model from a CMS Data Fetcher",
821
799
  description: "Usually not used! Only with multiple CMS Data Loaders, use this to choose which to show. Otherwise, go select the CMS Data Loader if you want to load different data.",
822
- options: (_, ctx) => mkTableOptions(ctx == null ? void 0 : ctx.tables),
800
+ options: (_, ctx) => (0, import_cms._mkTableOptions)(ctx == null ? void 0 : ctx.tables),
823
801
  defaultValueHint: (_, ctx) => ctx == null ? void 0 : ctx.table
824
802
  },
825
803
  field: {
@@ -828,21 +806,21 @@ var cmsRowFieldMeta = {
828
806
  description: "Field (from model schema) to use.",
829
807
  options: ({ table }, ctx) => {
830
808
  var _a;
831
- return mkFieldOptions(ctx == null ? void 0 : ctx.tables, (_a = ctx == null ? void 0 : ctx.table) != null ? _a : table, [
832
- "number" /* NUMBER */,
833
- "boolean" /* BOOLEAN */,
834
- "text" /* TEXT */,
835
- "long-text" /* LONG_TEXT */,
836
- "date-time" /* DATE_TIME */,
837
- "rich-text" /* RICH_TEXT */,
838
- "image" /* IMAGE */,
839
- "file" /* FILE */,
840
- "enum" /* ENUM */
809
+ return (0, import_cms._mkFieldOptions)(ctx == null ? void 0 : ctx.tables, (_a = ctx == null ? void 0 : ctx.table) != null ? _a : table, [
810
+ import_cms._CmsMetaType.NUMBER,
811
+ import_cms._CmsMetaType.BOOLEAN,
812
+ import_cms._CmsMetaType.TEXT,
813
+ import_cms._CmsMetaType.LONG_TEXT,
814
+ import_cms._CmsMetaType.DATE_TIME,
815
+ import_cms._CmsMetaType.RICH_TEXT,
816
+ import_cms._CmsMetaType.IMAGE,
817
+ import_cms._CmsMetaType.FILE,
818
+ import_cms._CmsMetaType.ENUM
841
819
  ]);
842
820
  },
843
821
  defaultValueHint: (_, ctx) => {
844
822
  var _a, _b;
845
- return ((_a = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _a.name) || ((_b = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _b.identifier);
823
+ return ((_a = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _a.label) || ((_b = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _b.identifier);
846
824
  }
847
825
  },
848
826
  dateFormat: {
@@ -863,7 +841,7 @@ var cmsRowFieldMeta = {
863
841
  if (!fieldMeta) {
864
842
  return true;
865
843
  }
866
- return fieldMeta.type !== "date-time" /* DATE_TIME */;
844
+ return fieldMeta.type !== import_cms._CmsMetaType.DATE_TIME;
867
845
  },
868
846
  options: [
869
847
  {
@@ -962,9 +940,9 @@ function CmsRowField(_a) {
962
940
  tables,
963
941
  field,
964
942
  typeFilters: [
965
- "text" /* TEXT */,
966
- "long-text" /* LONG_TEXT */,
967
- "rich-text" /* RICH_TEXT */
943
+ import_cms._CmsMetaType.TEXT,
944
+ import_cms._CmsMetaType.LONG_TEXT,
945
+ import_cms._CmsMetaType.RICH_TEXT
968
946
  ]
969
947
  }) : void 0;
970
948
  if (tables) {
@@ -985,7 +963,7 @@ function CmsRowField(_a) {
985
963
  if (!data) {
986
964
  return null;
987
965
  }
988
- if (fieldMeta.type === "date-time" /* DATE_TIME */ && dateFormat) {
966
+ if (fieldMeta.type === import_cms._CmsMetaType.DATE_TIME && dateFormat) {
989
967
  data = (0, import_dayjs.default)(data).format(dateFormat);
990
968
  }
991
969
  return data ? renderValue(data, fieldMeta.type, __spreadValues({
@@ -1007,7 +985,7 @@ var cmsCountFieldMeta = {
1007
985
  },
1008
986
  helpText: "Pick model from a CMS Data Fetcher",
1009
987
  description: "Usually not used! Only with multiple CMS Data Loaders, use this to choose which to show. Otherwise, go select the CMS Data Loader if you want to load different data.",
1010
- options: (_, ctx) => mkTableOptions(ctx == null ? void 0 : ctx.tables),
988
+ options: (_, ctx) => (0, import_cms._mkTableOptions)(ctx == null ? void 0 : ctx.tables),
1011
989
  defaultValueHint: (_, ctx) => ctx == null ? void 0 : ctx.table
1012
990
  }
1013
991
  }
@@ -1034,12 +1012,13 @@ function CmsCount(_a) {
1034
1012
  return /* @__PURE__ */ import_react2.default.createElement("div", __spreadValues({ className }, rest), new Intl.NumberFormat().format(res.count));
1035
1013
  }
1036
1014
  }
1037
- var DEFAULT_TYPE_FILTERS = ["text" /* TEXT */];
1015
+ var DEFAULT_TYPE_FILTERS = [import_cms._CmsMetaType.TEXT];
1038
1016
  function deriveInferredTableField(opts) {
1039
1017
  var _a;
1040
1018
  const { table, tables, field, typeFilters } = opts;
1041
- if (!table)
1019
+ if (!table) {
1042
1020
  return void 0;
1021
+ }
1043
1022
  const schema = (_a = tables == null ? void 0 : tables.find((t) => t.identifier === table)) == null ? void 0 : _a.schema;
1044
1023
  const fieldMeta = field ? schema == null ? void 0 : schema.fields.find((f) => f.identifier === field) : schema == null ? void 0 : schema.fields.find(
1045
1024
  (f) => (typeFilters != null ? typeFilters : DEFAULT_TYPE_FILTERS).includes(f.type)
@@ -1051,15 +1030,16 @@ function assertNever(_) {
1051
1030
  }
1052
1031
  function renderValue(value, type, props) {
1053
1032
  switch (type) {
1054
- case "number" /* NUMBER */:
1055
- case "boolean" /* BOOLEAN */:
1056
- case "text" /* TEXT */:
1057
- case "long-text" /* LONG_TEXT */:
1058
- case "date-time" /* DATE_TIME */:
1059
- case "enum" /* ENUM */:
1060
- case "ref" /* REF */:
1033
+ case import_cms._CmsMetaType.NUMBER:
1034
+ case import_cms._CmsMetaType.BOOLEAN:
1035
+ case import_cms._CmsMetaType.TEXT:
1036
+ case import_cms._CmsMetaType.LONG_TEXT:
1037
+ case import_cms._CmsMetaType.DATE_TIME:
1038
+ case import_cms._CmsMetaType.ENUM:
1039
+ case import_cms._CmsMetaType.REF:
1040
+ case import_cms._CmsMetaType.COLOR:
1061
1041
  return /* @__PURE__ */ import_react2.default.createElement("div", __spreadValues({}, props), value);
1062
- case "rich-text" /* RICH_TEXT */:
1042
+ case import_cms._CmsMetaType.RICH_TEXT:
1063
1043
  return /* @__PURE__ */ import_react2.default.createElement(
1064
1044
  "div",
1065
1045
  __spreadValues({
@@ -1067,7 +1047,7 @@ function renderValue(value, type, props) {
1067
1047
  style: { whiteSpace: "normal" }
1068
1048
  }, props)
1069
1049
  );
1070
- case "image" /* IMAGE */:
1050
+ case import_cms._CmsMetaType.IMAGE:
1071
1051
  if (value && typeof value === "object" && value.url && value.imageMeta) {
1072
1052
  return /* @__PURE__ */ import_react2.default.createElement(
1073
1053
  "img",
@@ -1079,11 +1059,14 @@ function renderValue(value, type, props) {
1079
1059
  );
1080
1060
  }
1081
1061
  return null;
1082
- case "file" /* FILE */:
1062
+ case import_cms._CmsMetaType.FILE:
1083
1063
  if (value && typeof value === "object" && value.url && value.name) {
1084
1064
  return /* @__PURE__ */ import_react2.default.createElement("a", __spreadValues({ href: value.url, target: "_blank" }, props), value.name);
1085
1065
  }
1086
1066
  return null;
1067
+ case import_cms._CmsMetaType.LIST:
1068
+ case import_cms._CmsMetaType.OBJECT:
1069
+ return null;
1087
1070
  default:
1088
1071
  assertNever(type);
1089
1072
  }
@@ -1111,7 +1094,7 @@ var cmsRowLinkMeta = {
1111
1094
  },
1112
1095
  helpText: "Pick model from a CMS Data Fetcher",
1113
1096
  description: "Usually not used! Only with multiple CMS Data Loaders, use this to choose which to show. Otherwise, go select the CMS Data Loader if you want to load different data.",
1114
- options: (_, ctx) => mkTableOptions(ctx == null ? void 0 : ctx.tables),
1097
+ options: (_, ctx) => (0, import_cms._mkTableOptions)(ctx == null ? void 0 : ctx.tables),
1115
1098
  defaultValueHint: (_, ctx) => ctx == null ? void 0 : ctx.table
1116
1099
  },
1117
1100
  field: {
@@ -1120,11 +1103,11 @@ var cmsRowLinkMeta = {
1120
1103
  description: "Field (from model schema) to use.",
1121
1104
  options: ({ table }, ctx) => {
1122
1105
  var _a;
1123
- return mkFieldOptions(ctx == null ? void 0 : ctx.tables, (_a = ctx == null ? void 0 : ctx.table) != null ? _a : table);
1106
+ return (0, import_cms._mkFieldOptions)(ctx == null ? void 0 : ctx.tables, (_a = ctx == null ? void 0 : ctx.table) != null ? _a : table);
1124
1107
  },
1125
1108
  defaultValueHint: (_, ctx) => {
1126
1109
  var _a, _b;
1127
- return ((_a = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _a.name) || ((_b = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _b.identifier);
1110
+ return ((_a = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _a.label) || ((_b = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _b.identifier);
1128
1111
  }
1129
1112
  },
1130
1113
  hrefProp: {
@@ -1172,7 +1155,7 @@ function CmsRowLink({
1172
1155
  table: res.table,
1173
1156
  tables,
1174
1157
  field,
1175
- typeFilters: ["file" /* FILE */, "text" /* TEXT */]
1158
+ typeFilters: [import_cms._CmsMetaType.FILE, import_cms._CmsMetaType.TEXT]
1176
1159
  });
1177
1160
  if (tables) {
1178
1161
  setControlContextData == null ? void 0 : setControlContextData({
@@ -1192,7 +1175,7 @@ function CmsRowLink({
1192
1175
  const childrenWithProps = import_react2.default.Children.map(children, (child) => {
1193
1176
  if (import_react2.default.isValidElement(child)) {
1194
1177
  return import_react2.default.cloneElement(child, {
1195
- [hrefProp]: fieldMeta.type === "file" /* FILE */ ? value.url : prefix || suffix ? `${prefix || ""}${value}${suffix || ""}` : value
1178
+ [hrefProp]: fieldMeta.type === import_cms._CmsMetaType.FILE ? value.url : prefix || suffix ? `${prefix || ""}${value}${suffix || ""}` : value
1196
1179
  });
1197
1180
  }
1198
1181
  return child;
@@ -1221,7 +1204,7 @@ var cmsRowImageMeta = {
1221
1204
  },
1222
1205
  helpText: "Pick model from a CMS Data Fetcher",
1223
1206
  description: "Usually not used! Only with multiple CMS Data Loaders, use this to choose which to show. Otherwise, go select the CMS Data Loader if you want to load different data.",
1224
- options: (_, ctx) => mkTableOptions(ctx == null ? void 0 : ctx.tables),
1207
+ options: (_, ctx) => (0, import_cms._mkTableOptions)(ctx == null ? void 0 : ctx.tables),
1225
1208
  defaultValueHint: (_, ctx) => ctx == null ? void 0 : ctx.table
1226
1209
  },
1227
1210
  field: {
@@ -1230,11 +1213,11 @@ var cmsRowImageMeta = {
1230
1213
  description: "Field (from model schema) to use.",
1231
1214
  options: ({ table }, ctx) => {
1232
1215
  var _a;
1233
- return mkFieldOptions(ctx == null ? void 0 : ctx.tables, (_a = ctx == null ? void 0 : ctx.table) != null ? _a : table, ["image" /* IMAGE */]);
1216
+ return (0, import_cms._mkFieldOptions)(ctx == null ? void 0 : ctx.tables, (_a = ctx == null ? void 0 : ctx.table) != null ? _a : table, [import_cms._CmsMetaType.IMAGE]);
1234
1217
  },
1235
1218
  defaultValueHint: (_, ctx) => {
1236
1219
  var _a, _b;
1237
- return ((_a = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _a.name) || ((_b = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _b.identifier);
1220
+ return ((_a = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _a.label) || ((_b = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _b.identifier);
1238
1221
  }
1239
1222
  },
1240
1223
  srcProp: {
@@ -1262,7 +1245,7 @@ function CmsRowImage({
1262
1245
  table: res.table,
1263
1246
  tables,
1264
1247
  field,
1265
- typeFilters: ["image" /* IMAGE */]
1248
+ typeFilters: [import_cms._CmsMetaType.IMAGE]
1266
1249
  });
1267
1250
  if (tables) {
1268
1251
  setControlContextData == null ? void 0 : setControlContextData({
@@ -1311,7 +1294,7 @@ var cmsRowFieldValueMeta = {
1311
1294
  },
1312
1295
  helpText: "Pick model from a CMS Data Fetcher",
1313
1296
  description: "Usually not used! Only with multiple CMS Data Loaders, use this to choose which to show. Otherwise, go select the CMS Data Loader if you want to load different data.",
1314
- options: (_, ctx) => mkTableOptions(ctx == null ? void 0 : ctx.tables),
1297
+ options: (_, ctx) => (0, import_cms._mkTableOptions)(ctx == null ? void 0 : ctx.tables),
1315
1298
  defaultValueHint: (_, ctx) => ctx == null ? void 0 : ctx.table
1316
1299
  },
1317
1300
  field: {
@@ -1320,11 +1303,11 @@ var cmsRowFieldValueMeta = {
1320
1303
  description: "Field (from model schema) to use.",
1321
1304
  options: ({ table }, ctx) => {
1322
1305
  var _a;
1323
- return mkFieldOptions(ctx == null ? void 0 : ctx.tables, (_a = ctx == null ? void 0 : ctx.table) != null ? _a : table);
1306
+ return (0, import_cms._mkFieldOptions)(ctx == null ? void 0 : ctx.tables, (_a = ctx == null ? void 0 : ctx.table) != null ? _a : table);
1324
1307
  },
1325
1308
  defaultValueHint: (_, ctx) => {
1326
1309
  var _a, _b;
1327
- return ((_a = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _a.name) || ((_b = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _b.identifier);
1310
+ return ((_a = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _a.label) || ((_b = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _b.identifier);
1328
1311
  }
1329
1312
  },
1330
1313
  valueProp: {
@@ -1359,7 +1342,7 @@ function CmsRowFieldValue(_a) {
1359
1342
  table: res.table,
1360
1343
  tables,
1361
1344
  field,
1362
- typeFilters: ["text" /* TEXT */]
1345
+ typeFilters: [import_cms._CmsMetaType.TEXT]
1363
1346
  });
1364
1347
  if (tables) {
1365
1348
  setControlContextData == null ? void 0 : setControlContextData({
@@ -1382,152 +1365,6 @@ function CmsRowFieldValue(_a) {
1382
1365
  return /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, null, childrenWithProps);
1383
1366
  }
1384
1367
 
1385
- // src/custom-functions.ts
1386
- var import_registerFunction = __toESM(require("@plasmicapp/host/registerFunction"));
1387
- function getCmsHost() {
1388
- var _a;
1389
- return (_a = globalThis["__PLASMIC_CMS_HOST__"]) != null ? _a : DEFAULT_HOST;
1390
- }
1391
- function createTableOptions(_args, ctx) {
1392
- if (!(ctx == null ? void 0 : ctx.tables)) {
1393
- return [];
1394
- }
1395
- return ctx.tables.map((table) => ({
1396
- value: table.identifier,
1397
- label: table.name
1398
- }));
1399
- }
1400
- var sharedTableFnContext = (cmsId, cmsPublicToken, ..._args) => {
1401
- if (!cmsId || !cmsPublicToken) {
1402
- return {
1403
- dataKey: "",
1404
- fetcher: () => __async(void 0, null, function* () {
1405
- return { tables: [] };
1406
- })
1407
- };
1408
- }
1409
- return {
1410
- dataKey: `cms_tables/${JSON.stringify({
1411
- cmsId,
1412
- cmsPublicToken
1413
- })}`,
1414
- fetcher: () => __async(void 0, null, function* () {
1415
- const api = mkApi({
1416
- databaseId: cmsId,
1417
- databaseToken: cmsPublicToken,
1418
- host: getCmsHost()
1419
- });
1420
- const tables = yield api.fetchTables();
1421
- return { tables };
1422
- })
1423
- };
1424
- };
1425
- var cmsIdParam = {
1426
- name: "cmsId",
1427
- type: "string",
1428
- description: "The cms ID"
1429
- };
1430
- var cmsPublicTokenParam = {
1431
- name: "cmsPublicToken",
1432
- type: "string",
1433
- description: "The cms public token"
1434
- };
1435
- var tableIdParam = {
1436
- name: "tableId",
1437
- type: "choice",
1438
- options: createTableOptions
1439
- };
1440
- var paramsParam = {
1441
- name: "params",
1442
- type: "object",
1443
- description: "The parameters to filter the content (e.g., for sorting, limit, offset, advanced queries)"
1444
- };
1445
- var useDraftParam = {
1446
- name: "useDraft",
1447
- type: "boolean",
1448
- description: "Whether to use draft data. Defaults to false."
1449
- };
1450
- var localeParam = {
1451
- name: "locale",
1452
- type: "string",
1453
- description: "The locale to use. Defaults to empty string."
1454
- };
1455
- function fetchTables(cmsId, cmsPublicToken) {
1456
- return __async(this, null, function* () {
1457
- const api = mkApi({
1458
- databaseId: cmsId,
1459
- databaseToken: cmsPublicToken,
1460
- host: getCmsHost()
1461
- });
1462
- return api.fetchTables();
1463
- });
1464
- }
1465
- function fetchContent(cmsId, cmsPublicToken, tableId, params, useDraft, locale) {
1466
- return __async(this, null, function* () {
1467
- const api = mkApi({
1468
- databaseId: cmsId,
1469
- databaseToken: cmsPublicToken,
1470
- host: getCmsHost(),
1471
- useDraft,
1472
- locale
1473
- });
1474
- return api.query(tableId, params);
1475
- });
1476
- }
1477
- function fetchCount(cmsId, cmsPublicToken, tableId, params, useDraft) {
1478
- return __async(this, null, function* () {
1479
- const api = mkApi({
1480
- databaseId: cmsId,
1481
- databaseToken: cmsPublicToken,
1482
- host: getCmsHost(),
1483
- useDraft
1484
- });
1485
- return api.count(tableId, params);
1486
- });
1487
- }
1488
- function registerAllCustomFunctions(loader) {
1489
- function _registerFunction(fn, meta) {
1490
- if (loader) {
1491
- loader.registerFunction(fn, meta);
1492
- } else {
1493
- (0, import_registerFunction.default)(fn, meta);
1494
- }
1495
- }
1496
- _registerFunction(fetchTables, {
1497
- name: "fetchTables",
1498
- description: "Fetches the tables from the cms",
1499
- importPath: "@plasmicpkgs/plasmic-cms",
1500
- params: [cmsIdParam, cmsPublicTokenParam]
1501
- });
1502
- _registerFunction(fetchContent, {
1503
- name: "fetchContent",
1504
- description: "Fetch content from a cms table",
1505
- importPath: "@plasmicpkgs/plasmic-cms",
1506
- params: [
1507
- cmsIdParam,
1508
- cmsPublicTokenParam,
1509
- tableIdParam,
1510
- paramsParam,
1511
- useDraftParam,
1512
- localeParam
1513
- ],
1514
- fnContext: sharedTableFnContext
1515
- });
1516
- _registerFunction(fetchCount, {
1517
- name: "fetchCount",
1518
- description: "Fetch the count of entries from a cms table",
1519
- importPath: "@plasmicpkgs/plasmic-cms",
1520
- params: [
1521
- cmsIdParam,
1522
- cmsPublicTokenParam,
1523
- tableIdParam,
1524
- paramsParam,
1525
- useDraftParam
1526
- ],
1527
- fnContext: sharedTableFnContext
1528
- });
1529
- }
1530
-
1531
1368
  // src/index.tsx
1532
1369
  function registerAll(loader) {
1533
1370
  const _registerComponent = (Component, defaultMeta) => {