Skip to content

Commit

Permalink
before moving to openapi-fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
Smoke3785 committed Nov 24, 2024
1 parent fff278c commit 7767d11
Show file tree
Hide file tree
Showing 15 changed files with 13,067 additions and 31 deletions.
11,226 changes: 11,226 additions & 0 deletions apps/iliad-server-showcase/src/@types/api.d.ts

Large diffs are not rendered by default.

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: Sun, 24 Nov 2024 01:41:31 GMT
// Generated on: Sun, 24 Nov 2024 20:30:40 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: Sun, 24 Nov 2024 01:41:31 GMT
// Generated on: Sun, 24 Nov 2024 20:30:40 GMT

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

Expand Down
17 changes: 16 additions & 1 deletion package-lock.json

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

16 changes: 8 additions & 8 deletions packages/strapi-adapter/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import {
StrapiInstance_default
} from "./chunk-7CRJWFUA.js";
} from "./chunk-WF6KSB3W.js";
import {
legacy_default
} from "./chunk-LYSBQDE6.js";
} from "./chunk-ZNKW75SW.js";
import "./chunk-7P62754R.js";
import "./chunk-AZ7NCBCO.js";
import "./chunk-FW7Y72NA.js";
import "./chunk-Q76N7JTV.js";
import "./chunk-K4LGOHM2.js";
import "./chunk-6TCAKOC4.js";
import "./chunk-L3CB575P.js";
import "./chunk-2QSIRKTA.js";
import "./chunk-EWC3LOEU.js";
import "./chunk-PPEM5JLR.js";
import "./chunk-PPCCCJ27.js";
import "./chunk-AANWBPDY.js";
import "./chunk-ZB2YJ3PK.js";
import "./chunk-VP54ABXQ.js";
import "./chunk-KX23GZAT.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";
Expand Down
2 changes: 2 additions & 0 deletions packages/strapi-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
"deasync": "^0.1.30",
"deepmerge": "^4.3.1",
"multiple-extend": "^0.1.3",
"openapi-fetch": "^0.13.0",
"openapi-typescript-helpers": "^0.0.15",
"pretty-bytes": "^6.1.1",
"qs": "^6.13.1",
"resolve-tspaths": "^0.8.22",
Expand Down
6 changes: 6 additions & 0 deletions packages/strapi-adapter/src/@types/strapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,9 @@ export type StrapiResponse<T extends Common.UID.ContentType> =
| APIResponse<T>;

export type { Common, Attribute, Utils };

// declare module "@strapi/strapi" {
// export module Shared {
// export interface Paths {}
// }
// }
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ export const defaultContentTypesSyncOptions: Recursive_OptionalFieldsOf<ContentT
names: {
contentTypes: "contentTypes.d.ts",
components: "components.d.ts",
api: "api.d.ts",
},
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type ContentTypesResponse = [string, string];
export type ContentTypesResponse = Array<string>;

export type ContentTypesSyncOptions = {
blockOnFirstDownload?: boolean;
Expand All @@ -9,6 +9,7 @@ export type ContentTypesSyncOptions = {
names?: {
contentTypes?: string;
components?: string;
api?: string;
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function writeContentTypes(
data: ContentTypesResponse
): StandardResponse<string> {
const { outDir, names } = options;
const [components, contentTypes] = data;
const [api, components, contentTypes] = data;

console.log("writing content types");
try {
Expand All @@ -30,6 +30,9 @@ function writeContentTypes(
fs.writeFileSync(`${outDir}/${names.components}`, components, {
encoding: "utf8",
});
fs.writeFileSync(`${outDir}/${names.api}`, api, {
encoding: "utf8",
});
} catch (error) {
console.error("Error writing content types", error);
return {
Expand All @@ -40,10 +43,10 @@ function writeContentTypes(
};
}

const contentTypesSize = Buffer.byteLength(contentTypes, "utf8");
const componentsSize = Buffer.byteLength(components, "utf8");
const diskSize = prettyBytes(
data.reduce((acc, curr) => acc + Buffer.byteLength(curr, "utf8"), 0)
);

const diskSize = prettyBytes(contentTypesSize + componentsSize);
return { data: diskSize };
}

Expand Down
35 changes: 20 additions & 15 deletions packages/strapi-adapter/src/strapiAdapter/StrapiAdapter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import {
QueryStringEntry,
CrudQueryFull,
CTUID,
// OPENAPI TYPINGS
HttpMethod,
FetchResponse,
} from "./types";
import { Feature, FeatureParams } from "../Feature";
import { StrapiUtils } from "@utils";
Expand All @@ -43,43 +46,45 @@ class StrapiAdapter extends Feature {
}

private normalizedFetch<T>(
method: RequestInit["method"],
method: HttpMethod,
url: string | URL,
options: RequestInit = {}
): Promise<StandardResponse<T>> {
): Promise<
StandardResponse<FetchResponse<Paths[Path][Method], Init, Media>>
> {
return this.hermes.fetch<T>(normalizeUrl(url), {
...options,
method,
});
}

// REST OPERATIONS
public async get<R>(
public async GET<R>(
url: string | URL,
options?: any
): Promise<StandardResponse<R>> {
return this.normalizedFetch<R>("GET", url, options);
return this.normalizedFetch<R>("get", url, options);
}

public async post<R>(
public async POST<R>(
url: string | URL,
options?: any
): Promise<StandardResponse<R>> {
return this.normalizedFetch<R>("POST", url, options);
return this.normalizedFetch<R>("post", url, options);
}

public async put<R>(
public async PUT<R>(
url: string | URL,
options?: any
): Promise<StandardResponse<R>> {
return this.normalizedFetch<R>("PUT", url, options);
return this.normalizedFetch<R>("put", url, options);
}

private async deleteREST<R>(
private async DELETE<R>(
url: string | URL,
options?: any
): Promise<StandardResponse<R>> {
return this.normalizedFetch<R>("DELETE", url, options);
return this.normalizedFetch<R>("delete", url, options);
}

// CRUD OPERATIONS
Expand All @@ -97,7 +102,7 @@ class StrapiAdapter extends Feature {
query: params,
});

return this.get<APIResponseData<UID>>(url);
return this.GET<APIResponseData<UID>>(url);
}

public async find<
Expand All @@ -112,7 +117,7 @@ class StrapiAdapter extends Feature {
query: params,
});

return this.get<APIResponseCollection<UID>>(url);
return this.GET<APIResponseCollection<UID>>(url);
}

public async create<
Expand All @@ -132,7 +137,7 @@ class StrapiAdapter extends Feature {
body: JSON.stringify({ data }),
};

return this.post<APIResponseData<UID>>(url, options);
return this.POST<APIResponseData<UID>>(url, options);
}

public async update<
Expand All @@ -153,7 +158,7 @@ class StrapiAdapter extends Feature {
body: JSON.stringify({ data }),
};

return this.put<APIResponseData<UID>>(url, options);
return this.PUT<APIResponseData<UID>>(url, options);
}

public async delete<
Expand All @@ -168,7 +173,7 @@ class StrapiAdapter extends Feature {
endpoint,
});

return this.deleteREST<APIResponseData<UID>>(url);
return this.DELETE<APIResponseData<UID>>(url);
}

// FINISH CRUD OPERATIONS, THEN MAKE RAW REST OPERATIONS.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,8 @@ export type QueryStringEntry<TContentTypeUID extends CTUID> =
| Params.Pick<TContentTypeUID, "populate">
| string
| "*";

// ========================================
// OPENAI TYPES
// ========================================
export * from "./openapi";
Loading

0 comments on commit 7767d11

Please sign in to comment.