@szymonpiatek/nextwordpress 0.0.2 → 0.0.3
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.cjs +305 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +165 -10
- package/dist/index.d.ts +165 -10
- package/dist/index.js +305 -10
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -331,6 +331,100 @@ function createPagesQueries(fetcher) {
|
|
|
331
331
|
return { getAllPages, getPageById, getPageBySlug };
|
|
332
332
|
}
|
|
333
333
|
|
|
334
|
+
// src/integrations/restApi/core/menus/queries.ts
|
|
335
|
+
function createMenusQueries(fetcher) {
|
|
336
|
+
const { wpFetch, wpFetchGraceful } = fetcher;
|
|
337
|
+
async function getMenus() {
|
|
338
|
+
return wpFetchGraceful("/wp-json/wp/v2/menus", [], void 0, ["wordpress", "menus"]);
|
|
339
|
+
}
|
|
340
|
+
async function getMenuById(id) {
|
|
341
|
+
return wpFetch(`/wp-json/wp/v2/menus/${id}`, void 0, ["wordpress", "menus", `menu-${id}`]);
|
|
342
|
+
}
|
|
343
|
+
async function getMenuBySlug(slug) {
|
|
344
|
+
const menus = await wpFetchGraceful("/wp-json/wp/v2/menus", [], { slug }, ["wordpress", "menus"]);
|
|
345
|
+
return menus[0];
|
|
346
|
+
}
|
|
347
|
+
async function getMenuItemsByMenuId(menuId) {
|
|
348
|
+
return wpFetchGraceful(
|
|
349
|
+
"/wp-json/wp/v2/menu-items",
|
|
350
|
+
[],
|
|
351
|
+
{ menus: menuId, per_page: 100, orderby: "menu_order", order: "asc" },
|
|
352
|
+
["wordpress", "menus", `menu-items-${menuId}`]
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
async function getMenuLocations() {
|
|
356
|
+
return wpFetchGraceful(
|
|
357
|
+
"/wp-json/wp/v2/menu-locations",
|
|
358
|
+
{},
|
|
359
|
+
void 0,
|
|
360
|
+
["wordpress", "menus", "menu-locations"]
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
async function getMenuByLocation(location) {
|
|
364
|
+
const locations = await getMenuLocations();
|
|
365
|
+
const loc = locations[location];
|
|
366
|
+
if (!loc || !loc.menu) return void 0;
|
|
367
|
+
const [menu, items] = await Promise.all([
|
|
368
|
+
getMenuById(loc.menu),
|
|
369
|
+
getMenuItemsByMenuId(loc.menu)
|
|
370
|
+
]);
|
|
371
|
+
return { menu, items };
|
|
372
|
+
}
|
|
373
|
+
return {
|
|
374
|
+
getMenus,
|
|
375
|
+
getMenuById,
|
|
376
|
+
getMenuBySlug,
|
|
377
|
+
getMenuItemsByMenuId,
|
|
378
|
+
getMenuLocations,
|
|
379
|
+
getMenuByLocation
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// src/integrations/restApi/core/comments/queries.ts
|
|
384
|
+
function createCommentsQueries(fetcher) {
|
|
385
|
+
const { wpFetch, wpFetchGraceful, wpFetchPaginatedGraceful, wpMutate } = fetcher;
|
|
386
|
+
async function getCommentsByPostId(postId, page = 1, perPage = 10) {
|
|
387
|
+
return wpFetchPaginatedGraceful(
|
|
388
|
+
"/wp-json/wp/v2/comments",
|
|
389
|
+
{ post: postId, per_page: perPage, page, status: "approve" },
|
|
390
|
+
["wordpress", "comments", `comments-post-${postId}`]
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
async function getAllCommentsByPostId(postId) {
|
|
394
|
+
return wpFetchGraceful(
|
|
395
|
+
"/wp-json/wp/v2/comments",
|
|
396
|
+
[],
|
|
397
|
+
{ post: postId, per_page: 100, status: "approve" },
|
|
398
|
+
["wordpress", "comments", `comments-post-${postId}`]
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
async function getCommentById(id) {
|
|
402
|
+
return wpFetch(`/wp-json/wp/v2/comments/${id}`, void 0, [
|
|
403
|
+
"wordpress",
|
|
404
|
+
"comments",
|
|
405
|
+
`comment-${id}`
|
|
406
|
+
]);
|
|
407
|
+
}
|
|
408
|
+
async function getCommentReplies(parentId) {
|
|
409
|
+
return wpFetchGraceful(
|
|
410
|
+
"/wp-json/wp/v2/comments",
|
|
411
|
+
[],
|
|
412
|
+
{ parent: parentId, per_page: 100, status: "approve" },
|
|
413
|
+
["wordpress", "comments", `comments-parent-${parentId}`]
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
async function createComment(input) {
|
|
417
|
+
return wpMutate("/wp-json/wp/v2/comments", input, "POST");
|
|
418
|
+
}
|
|
419
|
+
return {
|
|
420
|
+
getCommentsByPostId,
|
|
421
|
+
getAllCommentsByPostId,
|
|
422
|
+
getCommentById,
|
|
423
|
+
getCommentReplies,
|
|
424
|
+
createComment
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
|
|
334
428
|
// src/integrations/restApi/core/index.ts
|
|
335
429
|
function createWordPressClient(config) {
|
|
336
430
|
const fetcher = createFetcher(config);
|
|
@@ -340,7 +434,9 @@ function createWordPressClient(config) {
|
|
|
340
434
|
...createTagsQueries(fetcher),
|
|
341
435
|
...createAuthorsQueries(fetcher),
|
|
342
436
|
...createMediaQueries(fetcher),
|
|
343
|
-
...createPagesQueries(fetcher)
|
|
437
|
+
...createPagesQueries(fetcher),
|
|
438
|
+
...createMenusQueries(fetcher),
|
|
439
|
+
...createCommentsQueries(fetcher)
|
|
344
440
|
};
|
|
345
441
|
}
|
|
346
442
|
|
|
@@ -1262,6 +1358,194 @@ function createAuthorsQueries2(fetcher) {
|
|
|
1262
1358
|
return { getAuthors, getAuthorBySlug };
|
|
1263
1359
|
}
|
|
1264
1360
|
|
|
1361
|
+
// src/integrations/wpGraphQL/core/menus/queries.ts
|
|
1362
|
+
var MENU_ITEM_FIELDS = `
|
|
1363
|
+
id
|
|
1364
|
+
databaseId
|
|
1365
|
+
label
|
|
1366
|
+
url
|
|
1367
|
+
parentId
|
|
1368
|
+
order
|
|
1369
|
+
target
|
|
1370
|
+
cssClasses
|
|
1371
|
+
description
|
|
1372
|
+
connectedNode {
|
|
1373
|
+
node {
|
|
1374
|
+
__typename
|
|
1375
|
+
... on Page { id databaseId slug }
|
|
1376
|
+
... on Post { id databaseId slug }
|
|
1377
|
+
... on Category { id databaseId slug }
|
|
1378
|
+
... on Tag { id databaseId slug }
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
`;
|
|
1382
|
+
var MENU_FIELDS = `
|
|
1383
|
+
id
|
|
1384
|
+
databaseId
|
|
1385
|
+
name
|
|
1386
|
+
slug
|
|
1387
|
+
locations
|
|
1388
|
+
menuItems(first: 100) {
|
|
1389
|
+
nodes { ${MENU_ITEM_FIELDS} }
|
|
1390
|
+
}
|
|
1391
|
+
`;
|
|
1392
|
+
var GQL_GET_MENUS = `
|
|
1393
|
+
query GetMenus {
|
|
1394
|
+
menus(first: 100) {
|
|
1395
|
+
nodes { ${MENU_FIELDS} }
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
`;
|
|
1399
|
+
var GQL_GET_MENU_BY_ID = `
|
|
1400
|
+
query GetMenuById($id: ID!) {
|
|
1401
|
+
menu(id: $id, idType: DATABASE_ID) { ${MENU_FIELDS} }
|
|
1402
|
+
}
|
|
1403
|
+
`;
|
|
1404
|
+
var GQL_GET_MENU_BY_SLUG = `
|
|
1405
|
+
query GetMenuBySlug($id: ID!) {
|
|
1406
|
+
menu(id: $id, idType: SLUG) { ${MENU_FIELDS} }
|
|
1407
|
+
}
|
|
1408
|
+
`;
|
|
1409
|
+
var GQL_GET_MENUS_BY_LOCATION = `
|
|
1410
|
+
query GetMenusByLocation($location: MenuLocationEnum!) {
|
|
1411
|
+
menus(where: { location: $location }, first: 1) {
|
|
1412
|
+
nodes { ${MENU_FIELDS} }
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
`;
|
|
1416
|
+
function createMenusQueries2(fetcher) {
|
|
1417
|
+
const { gqlFetch, gqlFetchGraceful } = fetcher;
|
|
1418
|
+
async function getMenus() {
|
|
1419
|
+
const data = await gqlFetchGraceful(
|
|
1420
|
+
GQL_GET_MENUS,
|
|
1421
|
+
{ menus: { nodes: [] } },
|
|
1422
|
+
void 0,
|
|
1423
|
+
["wpgraphql", "gql-menus"]
|
|
1424
|
+
);
|
|
1425
|
+
return data.menus.nodes;
|
|
1426
|
+
}
|
|
1427
|
+
async function getMenuById(id) {
|
|
1428
|
+
const data = await gqlFetchGraceful(
|
|
1429
|
+
GQL_GET_MENU_BY_ID,
|
|
1430
|
+
{ menu: null },
|
|
1431
|
+
{ id: String(id) },
|
|
1432
|
+
["wpgraphql", "gql-menus", `gql-menu-${id}`]
|
|
1433
|
+
);
|
|
1434
|
+
return data.menu;
|
|
1435
|
+
}
|
|
1436
|
+
async function getMenuBySlug(slug) {
|
|
1437
|
+
const data = await gqlFetchGraceful(
|
|
1438
|
+
GQL_GET_MENU_BY_SLUG,
|
|
1439
|
+
{ menu: null },
|
|
1440
|
+
{ id: slug },
|
|
1441
|
+
["wpgraphql", "gql-menus", `gql-menu-${slug}`]
|
|
1442
|
+
);
|
|
1443
|
+
return data.menu;
|
|
1444
|
+
}
|
|
1445
|
+
async function getMenuByLocation(location) {
|
|
1446
|
+
const data = await gqlFetch(
|
|
1447
|
+
GQL_GET_MENUS_BY_LOCATION,
|
|
1448
|
+
{ location: location.toUpperCase() },
|
|
1449
|
+
["wpgraphql", "gql-menus", `gql-menu-location-${location}`]
|
|
1450
|
+
);
|
|
1451
|
+
return data.menus.nodes[0] ?? null;
|
|
1452
|
+
}
|
|
1453
|
+
async function getMenuItems(menuSlug) {
|
|
1454
|
+
const menu = await getMenuBySlug(menuSlug);
|
|
1455
|
+
return menu?.menuItems?.nodes ?? [];
|
|
1456
|
+
}
|
|
1457
|
+
return {
|
|
1458
|
+
getMenus,
|
|
1459
|
+
getMenuById,
|
|
1460
|
+
getMenuBySlug,
|
|
1461
|
+
getMenuByLocation,
|
|
1462
|
+
getMenuItems
|
|
1463
|
+
};
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
// src/integrations/wpGraphQL/core/comments/queries.ts
|
|
1467
|
+
var COMMENT_AUTHOR_FIELDS = `
|
|
1468
|
+
name
|
|
1469
|
+
url
|
|
1470
|
+
avatar { url width height }
|
|
1471
|
+
`;
|
|
1472
|
+
var COMMENT_FIELDS = `
|
|
1473
|
+
id
|
|
1474
|
+
databaseId
|
|
1475
|
+
content(format: RENDERED)
|
|
1476
|
+
date
|
|
1477
|
+
parentId
|
|
1478
|
+
status
|
|
1479
|
+
author { node { ${COMMENT_AUTHOR_FIELDS} } }
|
|
1480
|
+
`;
|
|
1481
|
+
var GQL_GET_COMMENTS_BY_POST = `
|
|
1482
|
+
query GetCommentsByPost($contentId: ID!, $first: Int, $after: String) {
|
|
1483
|
+
comments(
|
|
1484
|
+
first: $first
|
|
1485
|
+
after: $after
|
|
1486
|
+
where: { contentId: $contentId, status: "approve", parent: 0 }
|
|
1487
|
+
) {
|
|
1488
|
+
nodes {
|
|
1489
|
+
${COMMENT_FIELDS}
|
|
1490
|
+
replies(first: 100) {
|
|
1491
|
+
nodes { ${COMMENT_FIELDS} }
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
pageInfo { hasNextPage endCursor }
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
`;
|
|
1498
|
+
var GQL_GET_ALL_COMMENTS_BY_POST = `
|
|
1499
|
+
query GetAllCommentsByPost($contentId: ID!) {
|
|
1500
|
+
comments(
|
|
1501
|
+
first: 100
|
|
1502
|
+
where: { contentId: $contentId, status: "approve" }
|
|
1503
|
+
) {
|
|
1504
|
+
nodes { ${COMMENT_FIELDS} }
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
`;
|
|
1508
|
+
var GQL_GET_COMMENT_BY_ID = `
|
|
1509
|
+
query GetCommentById($id: ID!) {
|
|
1510
|
+
comment(id: $id, idType: DATABASE_ID) { ${COMMENT_FIELDS} }
|
|
1511
|
+
}
|
|
1512
|
+
`;
|
|
1513
|
+
function createCommentsQueries2(fetcher) {
|
|
1514
|
+
const { gqlFetchGraceful } = fetcher;
|
|
1515
|
+
async function getCommentsByPostId(postId, first = 10, after) {
|
|
1516
|
+
const data = await gqlFetchGraceful(
|
|
1517
|
+
GQL_GET_COMMENTS_BY_POST,
|
|
1518
|
+
{ comments: { nodes: [], pageInfo: { hasNextPage: false } } },
|
|
1519
|
+
{ contentId: String(postId), first, after },
|
|
1520
|
+
["wpgraphql", "gql-comments", `gql-comments-post-${postId}`]
|
|
1521
|
+
);
|
|
1522
|
+
return data.comments;
|
|
1523
|
+
}
|
|
1524
|
+
async function getAllCommentsByPostId(postId) {
|
|
1525
|
+
const data = await gqlFetchGraceful(
|
|
1526
|
+
GQL_GET_ALL_COMMENTS_BY_POST,
|
|
1527
|
+
{ comments: { nodes: [] } },
|
|
1528
|
+
{ contentId: String(postId) },
|
|
1529
|
+
["wpgraphql", "gql-comments", `gql-comments-post-${postId}`]
|
|
1530
|
+
);
|
|
1531
|
+
return data.comments.nodes;
|
|
1532
|
+
}
|
|
1533
|
+
async function getCommentById(id) {
|
|
1534
|
+
const data = await gqlFetchGraceful(
|
|
1535
|
+
GQL_GET_COMMENT_BY_ID,
|
|
1536
|
+
{ comment: null },
|
|
1537
|
+
{ id: String(id) },
|
|
1538
|
+
["wpgraphql", "gql-comments", `gql-comment-${id}`]
|
|
1539
|
+
);
|
|
1540
|
+
return data.comment;
|
|
1541
|
+
}
|
|
1542
|
+
return {
|
|
1543
|
+
getCommentsByPostId,
|
|
1544
|
+
getAllCommentsByPostId,
|
|
1545
|
+
getCommentById
|
|
1546
|
+
};
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1265
1549
|
// src/integrations/wpGraphQL/core/index.ts
|
|
1266
1550
|
function createWPGraphQLCoreClient(config) {
|
|
1267
1551
|
const fetcher = createWPGraphQLFetcher(config);
|
|
@@ -1270,7 +1554,9 @@ function createWPGraphQLCoreClient(config) {
|
|
|
1270
1554
|
...createPagesQueries2(fetcher),
|
|
1271
1555
|
...createCategoriesQueries3(fetcher),
|
|
1272
1556
|
...createTagsQueries3(fetcher),
|
|
1273
|
-
...createAuthorsQueries2(fetcher)
|
|
1557
|
+
...createAuthorsQueries2(fetcher),
|
|
1558
|
+
...createMenusQueries2(fetcher),
|
|
1559
|
+
...createCommentsQueries2(fetcher)
|
|
1274
1560
|
};
|
|
1275
1561
|
}
|
|
1276
1562
|
|
|
@@ -1446,22 +1732,31 @@ var PRODUCT_FIELDS = `
|
|
|
1446
1732
|
databaseId
|
|
1447
1733
|
slug
|
|
1448
1734
|
name
|
|
1735
|
+
status
|
|
1449
1736
|
description
|
|
1450
1737
|
shortDescription
|
|
1451
|
-
sku
|
|
1452
|
-
price
|
|
1453
|
-
regularPrice
|
|
1454
|
-
salePrice
|
|
1455
|
-
onSale
|
|
1456
|
-
stockStatus
|
|
1457
|
-
stockQuantity
|
|
1458
|
-
manageStock
|
|
1459
1738
|
type
|
|
1739
|
+
onSale
|
|
1460
1740
|
featuredImage { node { sourceUrl altText } }
|
|
1461
1741
|
galleryImages { nodes { sourceUrl altText } }
|
|
1462
1742
|
productCategories { nodes { databaseId name slug } }
|
|
1463
1743
|
productTags { nodes { databaseId name slug } }
|
|
1744
|
+
... on SimpleProduct {
|
|
1745
|
+
sku
|
|
1746
|
+
price
|
|
1747
|
+
regularPrice
|
|
1748
|
+
salePrice
|
|
1749
|
+
stockStatus
|
|
1750
|
+
stockQuantity
|
|
1751
|
+
manageStock
|
|
1752
|
+
}
|
|
1464
1753
|
... on VariableProduct {
|
|
1754
|
+
price
|
|
1755
|
+
regularPrice
|
|
1756
|
+
salePrice
|
|
1757
|
+
stockStatus
|
|
1758
|
+
stockQuantity
|
|
1759
|
+
manageStock
|
|
1465
1760
|
variations {
|
|
1466
1761
|
nodes {
|
|
1467
1762
|
id
|