-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core four progress, mostly strapi-adapter
- Loading branch information
Showing
52 changed files
with
1,478 additions
and
638 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.