Skip to content

Commit

Permalink
core four progress, mostly strapi-adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
Smoke3785 committed Nov 23, 2024
1 parent 75f13a5 commit c56f06b
Show file tree
Hide file tree
Showing 52 changed files with 1,478 additions and 638 deletions.
2 changes: 1 addition & 1 deletion apps/iliad-server-showcase/src/@types/components.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file is generated by a script (typeSync.ts) in the associate Strapi instance. Do not modify it directly.
// Generated on: Sat, 23 Nov 2024 03:03:15 GMT
// Generated on: Sat, 23 Nov 2024 05:25:54 GMT

import type { Schema, Attribute } from '@strapi/strapi';

Expand Down
2 changes: 1 addition & 1 deletion apps/iliad-server-showcase/src/@types/contentTypes.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file is generated by a script (typeSync.ts) in the associate Strapi instance. Do not modify it directly.
// Generated on: Sat, 23 Nov 2024 03:03:15 GMT
// Generated on: Sat, 23 Nov 2024 05:25:54 GMT

import type { Schema, Attribute } from '@strapi/strapi';

Expand Down
7 changes: 6 additions & 1 deletion apps/iliad-server-showcase/src/testing/strapi-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,18 @@ export const mainStrapiAdapterTest = async () => {
1,
99,
{
populate: '*',
sort: 'earliestVenueStart:asc',
filters: {
earliestVenueStart: { $gte: new Date().toISOString() },
},
populate: 'venues',
},
);

await strapi.getCollection<'api::event.event'>('events', 1, 99, {
populate: ['venues', 'venues.buttons'],
sort: 'earliestVenueStart:asc',
});

console.log({ data, error });
};
103 changes: 99 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/hermes/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@iliad.dev/hermes",
"version": "0.0.14",
"version": "0.0.15",
"description": "Normalizes responses from Axios and Fetch for use in Next.js projects.",
"main": "lib/index.cjs",
"module": "lib/index.js",
Expand Down
28 changes: 23 additions & 5 deletions packages/strapi-adapter/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
import {
StrapiInstance_default
} from "./chunk-7MXUIAYG.js";
import "./chunk-XENSUERP.js";
import "./chunk-KVY3UYXJ.js";
import "./chunk-HTT2MVX6.js";
import "./chunk-6TCAKOC4.js";
import "./chunk-6V46V7FR.js";
import "./chunk-2QSIRKTA.js";
import "./chunk-VBUHAH5E.js";
import "./chunk-6LFT4IRP.js";
import "./chunk-4AHPJ27J.js";
import {
utils_default
} from "./chunk-EGZ6UF72.js";
import "./chunk-AANWBPDY.js";
import "./chunk-6R3UZR5R.js";
import "./chunk-HKNJOMU2.js";
import "./chunk-PKBMQBKP.js";
import StrapiInstance from "./strapiAdapter/StrapiInstance";
import StrapiUtils from "./utils/utils";
var src_default = StrapiInstance;

// src/index.ts
var src_default = StrapiInstance_default;
export {
StrapiInstance,
StrapiUtils,
StrapiInstance_default as StrapiInstance,
utils_default as StrapiUtils,
src_default as default
};
128 changes: 3 additions & 125 deletions packages/strapi-adapter/lib/utils/utils.js
Original file line number Diff line number Diff line change
@@ -1,129 +1,7 @@
import {
utils_default
} from "../chunk-EGZ6UF72.js";
import "../chunk-PKBMQBKP.js";
import qs from "qs";
var StrapiUtils;
((StrapiUtils2) => {
function sanitizeQuery(query = "", addQueryPrefix = true) {
if (typeof query === "object") {
query = qs.stringify(query);
}
query = query.startsWith("&") ? query.slice(1) : query;
let qp = addQueryPrefix ? "?" : "";
query ? query = `${qp}${query}` : query = "";
return query.replaceAll("&?", "&");
}
StrapiUtils2.sanitizeQuery = sanitizeQuery;
function mergeQueries(...queries) {
}
StrapiUtils2.mergeQueries = mergeQueries;
async function coerceData(data = null, collection, id, extractSingleCollectionResponse = false, client) {
let result;
let apiResponse;
let type;
try {
if (!data) throw new Error("No data returned from Strapi");
apiResponse = data;
type = "attributes" in apiResponse?.data ? "entry" : "collection";
} catch (error) {
console.error(
`Error parsing entry ${collection}/${id}: ${error.message}`
);
return { data: void 0, error };
}
if (type === "entry") {
result = apiResponse.data;
} else {
if (extractSingleCollectionResponse) {
if (Array.isArray(apiResponse.data)) {
result = apiResponse.data[0];
} else {
result = apiResponse.data;
}
} else {
result = apiResponse;
}
}
return { data: result, error: void 0 };
}
StrapiUtils2.coerceData = coerceData;
function indexArrayFromMeta(meta) {
return Array(meta.pagination.pageCount).fill(0).map((_, i) => i + 2).slice(0, meta.pagination.pageCount - 1);
}
StrapiUtils2.indexArrayFromMeta = indexArrayFromMeta;
function mergeDefaultHermesOptions(options = {}) {
return {
verboseLogging: false,
extractData: false,
...options
};
}
StrapiUtils2.mergeDefaultHermesOptions = mergeDefaultHermesOptions;
async function extractStrapiData(input) {
function isObject(obj) {
return obj !== null && typeof obj === "object";
}
function isArray(obj) {
return Array.isArray(obj);
}
function isEntryObject(value) {
return isObject(value) && "id" in value && "attributes" in value;
}
function isRelation(value) {
if (!("data" in value)) return false;
if (isArray(value.data) && value.data.every(
(item) => isObject(item) && "id" in item && "attributes" in item
))
return true;
if (isObject(value.data) && "id" in value.data && "attributes" in value.data)
return true;
return false;
}
async function recursivelyExtractAttributes(input2) {
switch (true) {
case isArray(input2): {
const a_promises = input2.map(
async (item) => recursivelyExtractAttributes(item)
);
return await Promise.all(a_promises);
}
case isObject(input2): {
let _input = { ...input2 };
if (isRelation(input2)) {
return await recursivelyExtractAttributes(input2.data);
}
if (isEntryObject(input2)) {
const { id, attributes, ...rest } = input2;
_input = {
...{
id,
...attributes
},
...rest
};
}
const e_promises = Object.entries(_input).map(
async ([key, value]) => [
key,
await recursivelyExtractAttributes(value)
]
);
return Object.fromEntries(await Promise.all(e_promises));
}
default: {
return input2;
}
}
}
let initialInput;
if (input?.data) {
initialInput = input.data;
} else {
initialInput = input;
}
return await recursivelyExtractAttributes(initialInput);
}
StrapiUtils2.extractStrapiData = extractStrapiData;
})(StrapiUtils || (StrapiUtils = {}));
var utils_default = StrapiUtils;
export {
utils_default as default
};
3 changes: 2 additions & 1 deletion packages/strapi-adapter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@iliad.dev/strapi-adapter",
"version": "0.0.42",
"version": "0.0.43",
"description": "Utility functions to simplify interactions with Strapi backend.",
"repository": {
"type": "git",
Expand Down Expand Up @@ -33,6 +33,7 @@
"multiple-extend": "^0.1.3",
"pretty-bytes": "^6.1.1",
"qs": "^6.12.1",
"resolve-tspaths": "^0.8.22",
"typescript": "^5.2.2",
"typescript-mix": "^3.1.3"
},
Expand Down
Loading

0 comments on commit c56f06b

Please sign in to comment.