Skip to content

Commit

Permalink
sync (#3)
Browse files Browse the repository at this point in the history
* feat(search): ugh, searches

* merge: main -> boilerplate

sync

fix(ci): pnpm, action!

feat: opensearch and optimization for using production config
and fuck you, elasticsearch

fix(ci): only build check on boilerplate branch

chore: reconfig opensearch index config bc tenant issue

fix(cfg): config fixes

fix(cfg): idiot's config construction

fix(cfg): typo in env variable XD

fix(cfg): url parse stuff left a slash

fix(cfg): prod reconfig according rest deployment?!

fix(cfg): debug in prod confirmed??!!?

fix(cfg): env forced?? note to myself pls squash this

refactor(script): debug in production friendly scripts setup

fix(scripts): make manage.py script executable

sorry was making it on windows

fix(scripts): more executables

same like above

fix(cfg): env stuff fix

fix(scripts): add shebang

chore: create table, just in case backup

fix(search): improve search by adding seo_titles

why dont they add it already, it built in and suppose to help search?

cleanup(models): cleanup unused pyfiles?
should be alr, it boot, check 0 fail, whatever

* bump(client): 1.0.0 -> 1.0.1

* bump(client): 1.0.1 -> 1.0.2

feat: model construction for blogpage, etc

* Squashed commit of the following:

commit 37fd61a
Author: stdpi <[email protected]>
Date:   Fri May 31 01:08:46 2024 +0700

    feat(models): remove date

    migrations compatible. wont squash this as this need to be rollback if doesn't fit stuff, since we alr have builtin whatever history thingy

commit c8d8098
Author: stdpi <[email protected]>
Date:   Fri May 31 01:05:34 2024 +0700

    feat(models): add "renditions?", exclusively to blog pages

    also some modification, to make the editor suckless, maybe

commit 0e6a46f
Author: stdpi <[email protected]>
Date:   Sun May 26 11:04:41 2024 +0700

    cleanup(models): cleanup unused pyfiles?
    should be alr, it boot, check 0 fail, whatever

commit 7f156c2
Author: stdpi <[email protected]>
Date:   Sun May 26 11:03:35 2024 +0700

    fix(search): improve search by adding seo_titles

    why dont they add it already, it built in and suppose to help search?

commit 1b9a6a4
Author: stdpi <[email protected]>
Date:   Sun May 26 10:25:42 2024 +0700

    chore: create table, just in case backup

commit ee36a41
Author: stdpi <[email protected]>
Date:   Sun May 26 10:05:03 2024 +0700

    refactor(script): debug in production friendly scripts setup

    fix(scripts): make manage.py script executable

    sorry was making it on windows

    fix(scripts): more executables

    same like above

    fix(cfg): env stuff fix

    fix(scripts): add shebang

commit c22fce9
Author: stdpi <[email protected]>
Date:   Sat May 25 23:20:03 2024 +0700

    fix(cfg): config fixes

    fix(cfg): idiot's config construction

    fix(cfg): typo in env variable XD

    fix(cfg): url parse stuff left a slash

    fix(cfg): prod reconfig according rest deployment?!

    fix(cfg): debug in prod confirmed??!!?

    fix(cfg): env forced?? note to myself pls squash this

commit f0b8435
Author: stdpi <[email protected]>
Date:   Sat May 25 23:08:51 2024 +0700

    chore: reconfig opensearch index config bc tenant issue

commit ed15aa5
Author: stdpi <[email protected]>
Date:   Sat May 25 18:16:53 2024 +0700

    fix(ci): only build check on boilerplate branch

commit 55afca2
Author: stdpi <[email protected]>
Date:   Sat May 25 18:01:23 2024 +0700

    feat: opensearch and optimization for using production config
    and fuck you, elasticsearch

commit 3bb7820
Author: stdpi <[email protected]>
Date:   Sat May 25 00:38:24 2024 +0700

    fix(ci): pnpm, action!

commit 620a779
Merge: 4afad7b b4f7217
Author: stdpi <[email protected]>
Date:   Sat May 25 00:35:16 2024 +0700

    Merge pull request #1 from Team-Fuho/boilerplate

    feat: add pre-bootstrap, barely working query system for model constr…

commit 4afad7b
Author: stdpi <[email protected]>
Date:   Sat May 25 00:32:25 2024 +0700

    cleanup: barely searchable, will implement secret sauce later

* feat: simplified

* feat: add models,

* fix: anything around stupid ts code (squashed)

fix: whatever
apparently 1.1.3 never works

fix: commonjs option?

fix: dfy2c

fix: wrong shcema

* tweak: image model n stuff

* Squashed commit of the following:

commit 70aec30
Author: stdpi <[email protected]>
Date:   Wed Jun 5 20:31:46 2024 +0700

    feat(models): why export date?

commit 411aba9
Author: stdpi <[email protected]>
Date:   Wed Jun 5 15:46:32 2024 +0700

    feat: bootstrap rendition machine

    note: theyr suck at panick

commit 1771d99
Author: stdpi <[email protected]>
Date:   Wed Jun 5 14:35:31 2024 +0700

    feat(models): gallery migration and base image model

commit 7e890f4
Author: stdpi <[email protected]>
Date:   Sun Jun 2 09:53:56 2024 +0700

    chore(models): make unfinished migs (squashed)

    migrate first, squash later

    chore: squash

commit 85b3cbc
Author: stdpi <[email protected]>
Date:   Sat Jun 1 15:31:12 2024 +0700

    fix(blog): fix thumbnail api func

* feat: date and serde field

* feat: serialization trait, blah blah

* squash+fix: hook + call + types fixes

fix: tehe, idiotic hook system

feat+refactor: id in generic

fix: improve type accuracy of response

feat: expand typing and calls, err handler

[ci]: bump, mysteriously unsynced file???

fix: make fields optional

bump

* fmt+feat+refactor: updated type, use biome to lnt for perf!

* [ci] fix: only lint, not fmt check during ci

still work bc last action did not commit package

* fix: patch mechanism that pass context from client, and modify the way hook processed that is not js-nerdy

* fix(test): contruct the uhm request
  • Loading branch information
hUwUtao authored Nov 22, 2024
1 parent c40b377 commit d3cfcef
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 25 deletions.
14 changes: 10 additions & 4 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ function ConstructModel() {

// aint this straight out stupid?
test("URL Serialization", () => {
const constructed = ConstructModel().requestBuilder({
offset: 1,
limit: 1,
})
const constructed = ConstructModel().requestBuilder(
{
host: "http://localhost:8000",
lang: "vi",
},
{
offset: 1,
limit: 1,
},
)
// console.log(constructed)
expect(constructed.url).eq(
"http://localhost:8000/api/v2/pages?type=blog.BlogPage&format=json&offset=1&limit=1",
Expand Down
63 changes: 42 additions & 21 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ export class Model<T> {
this.hook = hook
}

requestBuilder(options: GenericParameter, id?: number): Request {
requestBuilder(
ctx: Context,
options: GenericParameter,
id?: number,
): Request {
const params = new URLSearchParams(
Object.assign(
{
Expand All @@ -63,7 +67,7 @@ export class Model<T> {
),
),
)
const url = new URL(this.ctx.host)
const url = new URL(ctx.host)
url.pathname = `/api/v2/pages${(id && `/${id}`) || ""}`
url.search = params.toString()

Expand All @@ -72,13 +76,14 @@ export class Model<T> {
}

private async fetch<T>(
ctx: Context,
options: GenericParameter,
id?: number,
init?: RequestInit,
) {
return await new Promise<GenericResponse & T>((ok, err) =>
fetch(
this.requestBuilder(options, id),
this.requestBuilder(ctx, options, id),
Object.assign(
{
headers: {
Expand All @@ -100,42 +105,60 @@ export class Model<T> {
)
}

private hookTransform(r: GenericItemResponse<T>) {
const y = r
for (const h of this.hook) {
for (const f of h.fields) {
// @ts-ignore
r[f] = h.transform.from(r[f])
}
private hookTransform() {
// const y = { ...r }

// for (const h of this.hook) {
// for (const f of h.fields) {
// // @ts-ignore
// y[f] = h.transform.from(r[f])
// }
// }

// return y
if (!this) {
throw "WagtailClient: this Model is undefined?"
}
return y
return (r: GenericItemResponse<T>) =>
this.hook.reduce(
(x, h) =>
Object.assign(
x,
h.fields.map((f) => ({
// @ts-ignore
[f]: h.transform.from(r[f]),
})),
),
r as GenericItemResponse<T>,
)
}

/**
* @description to return many stuff, ofc
*/
async query(
ctx: Context,
options: GenericParameter,
init?: RequestInit,
): Promise<GenericResponse & GenericListResponse<T>> {
const query = this.fetch<GenericListResponse<T>>(
ctx,
options,
undefined,
init,
)
if (this.hook.length === 0) return query
return query.then((r) => {
return {
...r,
items: r.items.map(this.hookTransform),
}
})
return query.then((r) => ({
...r,
items: r.items.map(this.hookTransform()),
}))
}

/**
* @description to return one stuff
*/
async queryOne(
ctx: Context,
options: GenericParameter & {
/**
* @deprecated Everything by default
Expand All @@ -145,11 +168,9 @@ export class Model<T> {
id: number,
init?: RequestInit,
): Promise<GenericResponse & GenericItemResponse<T>> {
const query = this.fetch<GenericItemResponse<T>>(options, id, init)
const query = this.fetch<GenericItemResponse<T>>(ctx, options, id, init)
if (this.hook.length === 0) return query
return query.then((r) => {
return this.hookTransform(r)
})
return query.then((r) => this.hookTransform()(r))
}
}

Expand Down

0 comments on commit d3cfcef

Please sign in to comment.