Skip to content

Commit

Permalink
Update pinejs-client-core to add support for using model specific typ…
Browse files Browse the repository at this point in the history
…ings

Update pinejs-client-core from 6.14.13 to 6.15.0

Change-type: minor
  • Loading branch information
Page- committed Jun 14, 2024
1 parent 20e59f9 commit dd28897
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 42 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@types/supertest": "^6.0.2",
"chai": "^4.4.1",
"chai-as-promised": "^7.1.2",
"pinejs-client-core": "^6.14.13",
"pinejs-client-core": "^6.15.0",
"supertest": "^7.0.0"
},
"versionist": {
Expand Down
140 changes: 99 additions & 41 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Params } from 'pinejs-client-core';
import type { AnyResource, Params, Resource } from 'pinejs-client-core';
import { PinejsClientCore } from 'pinejs-client-core';
import type * as express from 'express';
import type { CallbackHandler, Response, Test } from 'supertest';
Expand Down Expand Up @@ -45,18 +45,22 @@ interface BackendParams {
app: express.Express | string;
}

type Super = PinejsClientCore<unknown>;

/** A pine testing client fused with the api of supertest */
export class PineTest extends PinejsClientCore<unknown> {
export class PineTest<
Model extends {
[key in keyof Model]: Resource;
} = {
[key in string]: AnyResource;
},
> extends PinejsClientCore<unknown, Model> {
constructor(
params: Params,
params: Params<Model>,

Check failure on line 57 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (16.x)

Type 'Model' does not satisfy the constraint 'Resource'.

Check failure on line 57 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (18.x)

Type 'Model' does not satisfy the constraint 'Resource'.

Check failure on line 57 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (20.x)

Type 'Model' does not satisfy the constraint 'Resource'.

Check failure on line 57 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (22.x)

Type 'Model' does not satisfy the constraint 'Resource'.
public backendParams: BackendParams,
) {
super(params);
}

public get<T = any>(params: Params): PromiseResult<T> {
public get<T = any>(params: Params<Model>): PromiseResult<T> {

Check failure on line 63 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (16.x)

Property 'get' in type 'PineTest<Model>' is not assignable to the same property in base type 'PinejsClientCore<unknown, Model>'.

Check failure on line 63 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (16.x)

Type 'Model' does not satisfy the constraint 'Resource'.

Check failure on line 63 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (18.x)

Property 'get' in type 'PineTest<Model>' is not assignable to the same property in base type 'PinejsClientCore<unknown, Model>'.

Check failure on line 63 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (18.x)

Type 'Model' does not satisfy the constraint 'Resource'.

Check failure on line 63 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (20.x)

Property 'get' in type 'PineTest<Model>' is not assignable to the same property in base type 'PinejsClientCore<unknown, Model>'.

Check failure on line 63 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (20.x)

Type 'Model' does not satisfy the constraint 'Resource'.

Check failure on line 63 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (22.x)

Property 'get' in type 'PineTest<Model>' is not assignable to the same property in base type 'PinejsClientCore<unknown, Model>'.

Check failure on line 63 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (22.x)

Type 'Model' does not satisfy the constraint 'Resource'.
// Use a different const, since if we just re-assign `params`
// inside the `expect(() => {})` TS forgets that it's ensured
// to be a ParamsObj and will complain.
Expand Down Expand Up @@ -84,71 +88,123 @@ export class PineTest extends PinejsClientCore<unknown> {
}

public put(

Check failure on line 90 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (16.x)

Property 'put' in type 'PineTest<Model>' is not assignable to the same property in base type 'PinejsClientCore<unknown, Model>'.

Check failure on line 90 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (18.x)

Property 'put' in type 'PineTest<Model>' is not assignable to the same property in base type 'PinejsClientCore<unknown, Model>'.

Check failure on line 90 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (20.x)

Property 'put' in type 'PineTest<Model>' is not assignable to the same property in base type 'PinejsClientCore<unknown, Model>'.

Check failure on line 90 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (22.x)

Property 'put' in type 'PineTest<Model>' is not assignable to the same property in base type 'PinejsClientCore<unknown, Model>'.
params: { resource: NonNullable<Params['resource']> } & Params,
): PromiseResult<ResolvableReturnType<Super['put']>>;
params: {
resource: NonNullable<Params<Model>['resource']>;

Check failure on line 92 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (16.x)

Type 'Model' does not satisfy the constraint 'Resource'.

Check failure on line 92 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (18.x)

Type 'Model' does not satisfy the constraint 'Resource'.

Check failure on line 92 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (20.x)

Type 'Model' does not satisfy the constraint 'Resource'.

Check failure on line 92 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (22.x)

Type 'Model' does not satisfy the constraint 'Resource'.
} & Params<Model>,

Check failure on line 93 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (16.x)

Type 'Model' does not satisfy the constraint 'Resource'.

Check failure on line 93 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (18.x)

Type 'Model' does not satisfy the constraint 'Resource'.

Check failure on line 93 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (20.x)

Type 'Model' does not satisfy the constraint 'Resource'.

Check failure on line 93 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (22.x)

Type 'Model' does not satisfy the constraint 'Resource'.
): PromiseResult<
ResolvableReturnType<PinejsClientCore<unknown, Model>['put']>
>;
/**
* @deprecated PUTing via `url` is deprecated
*/
public put(

Check failure on line 100 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (16.x)

Property 'put' in type 'PineTest<Model>' is not assignable to the same property in base type 'PinejsClientCore<unknown, Model>'.

Check failure on line 100 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (18.x)

Property 'put' in type 'PineTest<Model>' is not assignable to the same property in base type 'PinejsClientCore<unknown, Model>'.

Check failure on line 100 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (20.x)

Property 'put' in type 'PineTest<Model>' is not assignable to the same property in base type 'PinejsClientCore<unknown, Model>'.

Check failure on line 100 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (22.x)

Property 'put' in type 'PineTest<Model>' is not assignable to the same property in base type 'PinejsClientCore<unknown, Model>'.
params: { resource?: undefined; url: NonNullable<Params['url']> } & Params,
): PromiseResult<ResolvableReturnType<Super['put']>>;
params: {
resource?: undefined;
url: NonNullable<Params<Model>['url']>;

Check failure on line 103 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (16.x)

Type 'Model' does not satisfy the constraint 'Resource'.

Check failure on line 103 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (18.x)

Type 'Model' does not satisfy the constraint 'Resource'.

Check failure on line 103 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (20.x)

Type 'Model' does not satisfy the constraint 'Resource'.

Check failure on line 103 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (22.x)

Type 'Model' does not satisfy the constraint 'Resource'.
} & Params<Model>,

Check failure on line 104 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (16.x)

Type 'Model' does not satisfy the constraint 'Resource'.

Check failure on line 104 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (18.x)

Type 'Model' does not satisfy the constraint 'Resource'.

Check failure on line 104 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (20.x)

Type 'Model' does not satisfy the constraint 'Resource'.

Check failure on line 104 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (22.x)

Type 'Model' does not satisfy the constraint 'Resource'.
): PromiseResult<
ResolvableReturnType<PinejsClientCore<unknown, Model>['put']>
>;
public put(

Check failure on line 108 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (16.x)

Property 'put' in type 'PineTest<Model>' is not assignable to the same property in base type 'PinejsClientCore<unknown, Model>'.

Check failure on line 108 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (18.x)

Property 'put' in type 'PineTest<Model>' is not assignable to the same property in base type 'PinejsClientCore<unknown, Model>'.

Check failure on line 108 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (20.x)

Property 'put' in type 'PineTest<Model>' is not assignable to the same property in base type 'PinejsClientCore<unknown, Model>'.

Check failure on line 108 in src/index.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (22.x)

Property 'put' in type 'PineTest<Model>' is not assignable to the same property in base type 'PinejsClientCore<unknown, Model>'.
params: Params,
): PromiseResult<ResolvableReturnType<Super['put']>> {
return super.put(params as Parameters<Super['put']>[0]) as PromiseResult<
ResolvableReturnType<Super['put']>
params: Params<Model>,
): PromiseResult<
ResolvableReturnType<PinejsClientCore<unknown, Model>['put']>
> {
return super.put(
params as Parameters<PinejsClientCore<unknown, Model>['put']>[0],
) as PromiseResult<
ResolvableReturnType<PinejsClientCore<unknown, Model>['put']>
>;
}

public patch(
params: { resource: NonNullable<Params['resource']> } & Params,
): PromiseResult<ResolvableReturnType<Super['patch']>>;
params: {
resource: NonNullable<Params<Model>['resource']>;
} & Params<Model>,
): PromiseResult<
ResolvableReturnType<PinejsClientCore<unknown, Model>['patch']>
>;
/**
* @deprecated PATCHing via `url` is deprecated
*/
public patch(
params: { resource?: undefined; url: NonNullable<Params['url']> } & Params,
): PromiseResult<ResolvableReturnType<Super['patch']>>;
params: {
resource?: undefined;
url: NonNullable<Params<Model>['url']>;
} & Params<Model>,
): PromiseResult<
ResolvableReturnType<PinejsClientCore<unknown, Model>['patch']>
>;
public patch(
params: Params,
): PromiseResult<ResolvableReturnType<Super['patch']>> {
params: Params<Model>,
): PromiseResult<
ResolvableReturnType<PinejsClientCore<unknown, Model>['patch']>
> {
return super.patch(
params as Parameters<Super['patch']>[0],
) as PromiseResult<ResolvableReturnType<Super['patch']>>;
params as Parameters<PinejsClientCore<unknown, Model>['patch']>[0],
) as PromiseResult<
ResolvableReturnType<PinejsClientCore<unknown, Model>['patch']>
>;
}

public post(
params: { resource: NonNullable<Params['resource']> } & Params,
): PromiseResult<ResolvableReturnType<Super['post']>>;
params: {
resource: NonNullable<Params<Model>['resource']>;
} & Params<Model>,
): PromiseResult<
ResolvableReturnType<PinejsClientCore<unknown, Model>['post']>
>;
/**
* @deprecated POSTing via `url` is deprecated
*/
public post(
params: { resource?: undefined; url: NonNullable<Params['url']> } & Params,
): PromiseResult<ResolvableReturnType<Super['post']>>;
params: {
resource?: undefined;
url: NonNullable<Params<Model>['url']>;
} & Params<Model>,
): PromiseResult<
ResolvableReturnType<PinejsClientCore<unknown, Model>['post']>
>;
public post(
params: Params,
): PromiseResult<ResolvableReturnType<Super['post']>> {
return super.post(params as Parameters<Super['post']>[0]) as PromiseResult<
ResolvableReturnType<Super['post']>
params: Params<Model>,
): PromiseResult<
ResolvableReturnType<PinejsClientCore<unknown, Model>['post']>
> {
return super.post(
params as Parameters<PinejsClientCore<unknown, Model>['post']>[0],
) as PromiseResult<
ResolvableReturnType<PinejsClientCore<unknown, Model>['post']>
>;
}

public delete(
params: { resource: NonNullable<Params['resource']> } & Params,
): PromiseResult<ResolvableReturnType<Super['delete']>>;
params: {
resource: NonNullable<Params<Model>['resource']>;
} & Params<Model>,
): PromiseResult<
ResolvableReturnType<PinejsClientCore<unknown, Model>['delete']>
>;
/**
* @deprecated DELETEing via `url` is deprecated
*/
public delete(
params: { resource?: undefined; url: NonNullable<Params['url']> } & Params,
): PromiseResult<ResolvableReturnType<Super['delete']>>;
params: {
resource?: undefined;
url: NonNullable<Params<Model>['url']>;
} & Params<Model>,
): PromiseResult<
ResolvableReturnType<PinejsClientCore<unknown, Model>['delete']>
>;
public delete(
params: Params,
): PromiseResult<ResolvableReturnType<Super['delete']>> {
params: Params<Model>,
): PromiseResult<
ResolvableReturnType<PinejsClientCore<unknown, Model>['delete']>
> {
return super.delete(
params as Parameters<Super['delete']>[0],
) as PromiseResult<ResolvableReturnType<Super['delete']>>;
params as Parameters<PinejsClientCore<unknown, Model>['delete']>[0],
) as PromiseResult<
ResolvableReturnType<PinejsClientCore<unknown, Model>['delete']>
>;
}

public upsert(): never {
Expand All @@ -159,13 +215,15 @@ export class PineTest extends PinejsClientCore<unknown> {
throw new Error('getOrCreate is not supported by pinejs-client-supertest');
}

public request(...args: Parameters<Super['request']>): PromiseResult<any> {
public request(
...args: Parameters<PinejsClientCore<unknown, Model>['request']>
): PromiseResult<any> {
return super.request(...args) as PromiseResult<any>;
}

protected callWithRetry<T>(
fnCall: () => Promise<T>,
retry?: Params['retry'],
retry?: Params<Model>['retry'],
): Promise<T> {
if ((retry ?? this.retry) === false) {
return fnCall();
Expand All @@ -181,7 +239,7 @@ export class PineTest extends PinejsClientCore<unknown> {
}: {
method: supportedMethod;
url: string;
body: Params['body'];
body: Params<Model>['body'];
user?: UserParam;
}) {
const { app } = this.backendParams;
Expand Down

0 comments on commit dd28897

Please sign in to comment.