Skip to content

Commit

Permalink
Merge branch 'main' into feature/content-releases
Browse files Browse the repository at this point in the history
  • Loading branch information
markkaylor committed Dec 14, 2023
2 parents fdb3a2d + a3bd045 commit 62eeed5
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,27 @@ import axios, { AxiosInstance } from 'axios';

import { wrapAxiosInstance } from '../wrapAxiosInstance';

jest.mock('axios', () => ({
create: jest.fn(() => ({
request: jest.fn(),
})),
}));

const axiosInstance = axios.create({
baseURL: 'https://some-domain.com/api/',
timeout: 1000,
headers: { 'X-Custom-Header': 'foobar' },
});

describe('wrapAxiosInstance', () => {
const env = process.env;
const originalWarn = console.warn;

beforeEach(() => {
console.warn = jest.fn();
});

afterEach(() => {
process.env = env;
console.warn = originalWarn;
});

it('has the right methods', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { Entity } from '../../../../types';

export type ID = Entity.ID;
Original file line number Diff line number Diff line change
@@ -1,37 +1,11 @@
import type { Attribute, Common, Utils, Entity } from '../../../types';
import type { Attribute, Common, Utils } from '../../../../types';
import type { OmitRelationsWithoutTarget, RelationInputValue } from './relation';
import type { ID } from './id';
import type * as Literals from './literals';

export type NonFilterableKind = Extract<Attribute.Kind, 'password' | 'dynamiczone'>;
export type FilterableKind = Exclude<Attribute.Kind, NonFilterableKind>;

export type GetNonFilterableKeys<TSchemaUID extends Common.UID.Schema> = Utils.Object.KeysBy<
Attribute.GetAll<TSchemaUID>,
Attribute.OfType<NonFilterableKind>,
string
>;

export type GetScalarKeys<TSchemaUID extends Common.UID.Schema> = Exclude<
Attribute.GetKeysByType<TSchemaUID, Attribute.NonPopulatableKind>,
GetNonFilterableKeys<TSchemaUID>
>;

export type GetNestedKeys<TSchemaUID extends Common.UID.Schema> = Exclude<
Attribute.GetKeysWithTarget<TSchemaUID>,
GetNonFilterableKeys<TSchemaUID>
>;

export type ID = Entity.ID;

export type BooleanValue = boolean | 'true' | 'false' | 't' | 'f' | '1' | '0' | 1 | 0;

export type NumberValue = string | number;

export type DateValue = Attribute.DateValue | number;

export type TimeValue = Attribute.TimeValue | number;

export type DateTimeValue = Attribute.DateTimeValue | number;

export type TimeStampValue = Attribute.TimestampValue;
export * from './id';
export * from './utils';
export * from './literals';

/**
* List of possible values for the scalar attributes
Expand All @@ -49,23 +23,23 @@ export type ScalarValues = GetValue<
| Attribute.Integer
| Attribute.Blocks
| Attribute.JSON
// /!\ Password attributes are NOT filterable and should NOT be part of this union type.
// The member below has been commented on purpose to avoid adding it back without noticing.
// | Attribute.Password
| Attribute.RichText
| Attribute.String
| Attribute.Text
| Attribute.Time
| Attribute.Timestamp
| Attribute.UID<Common.UID.Schema>
// /!\ Password attributes are NOT filterable and should NOT be part of this union type.
// The member below has been commented on purpose to avoid adding it back without noticing.
// | Attribute.Password
>;

/**
* Attribute.GetValues override with extended values
*/
export type GetValues<TSchemaUID extends Common.UID.Schema> = {
id?: ID;
} & OmitRelationWithoutTarget<
} & OmitRelationsWithoutTarget<
TSchemaUID,
{
[TKey in Attribute.GetOptionalKeys<TSchemaUID>]?: GetValue<Attribute.Get<TSchemaUID, TKey>>;
Expand All @@ -74,11 +48,6 @@ export type GetValues<TSchemaUID extends Common.UID.Schema> = {
}
>;

export type OmitRelationWithoutTarget<TSchemaUID extends Common.UID.Schema, TValue> = Omit<
TValue,
Exclude<Attribute.GetKeysByType<TSchemaUID, 'relation'>, Attribute.GetKeysWithTarget<TSchemaUID>>
>;

/**
* Attribute.GetValue override with extended values
*
Expand All @@ -95,7 +64,7 @@ export type GetValue<TAttribute extends Attribute.Attribute> = Utils.Expression.
TAttribute extends Attribute.Relation<infer _TOrigin, infer TRelationKind, infer TTarget>
? Utils.Expression.If<
Utils.Expression.IsNotNever<TTarget>,
Attribute.RelationPluralityModifier<TRelationKind, ID>
RelationInputValue<TRelationKind>
>
: never
],
Expand Down Expand Up @@ -125,21 +94,21 @@ export type GetValue<TAttribute extends Attribute.Attribute> = Utils.Expression.
: never
],
// Boolean
[Utils.Expression.Extends<TAttribute, Attribute.Boolean>, BooleanValue],
[Utils.Expression.Extends<TAttribute, Attribute.Boolean>, Literals.BooleanValue],
// Number
[
Utils.Expression.Extends<
TAttribute,
Attribute.Integer | Attribute.BigInteger | Attribute.Float | Attribute.Decimal
>,
NumberValue
Literals.NumberValue
],
// Date / Time
[Utils.Expression.Extends<TAttribute, Attribute.Time>, TimeValue],
[Utils.Expression.Extends<TAttribute, Attribute.Date>, DateValue],
[Utils.Expression.Extends<TAttribute, Attribute.Time>, Literals.TimeValue],
[Utils.Expression.Extends<TAttribute, Attribute.Date>, Literals.DateValue],
[
Utils.Expression.Extends<TAttribute, Attribute.Timestamp | Attribute.DateTime>,
DateTimeValue
Literals.DateTimeValue
],
// Fallback
// If none of the above attribute type, fallback to the original Attribute.GetValue (while making sure it's an attribute)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { Attribute } from '../../../../types';

export type BooleanValue = boolean | 'true' | 'false' | 't' | 'f' | '1' | '0' | 1 | 0;

export type NumberValue = string | number;

export type DateValue = Attribute.DateValue | number;

export type TimeValue = Attribute.TimeValue | number;

export type DateTimeValue = Attribute.DateTimeValue | number;

export type TimeStampValue = Attribute.TimestampValue;
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import type { Attribute, Common, Utils } from '../../../../types';
import type { ID } from './id';

type ShortHand = ID;
type LongHand = { id: ID };

interface PositionalArguments {
before?: ID;
after?: ID;
start?: boolean;
end?: boolean;
}

type WithPositionArguments<T> = T & PositionalArguments;

type Set = { set: ShortHand[] | LongHand[] | null };
type Connect = { connect: ShortHand[] | WithPositionArguments<LongHand>[] };
type Disconnect = { disconnect: ShortHand[] | LongHand[] };

type FullUpdate = Set;
type PartialUpdate = Partial<Connect & Disconnect>;

type XOneInput = ShortHand | LongHand | null;
type XManyInput = ShortHand[] | LongHand[] | null | PartialUpdate | FullUpdate;

type RelationInputValue<TRelationKind extends Attribute.RelationKind.Any> = Utils.Expression.If<
Attribute.IsManyRelation<TRelationKind>,
XManyInput,
XOneInput
>;

type RelationsKeysWithoutTarget<TSchemaUID extends Common.UID.Schema> = Exclude<
Attribute.GetKeysByType<TSchemaUID, 'relation'>,
Attribute.GetKeysWithTarget<TSchemaUID>
>;

type OmitRelationsWithoutTarget<TSchemaUID extends Common.UID.Schema, TValue> = Omit<
TValue,
RelationsKeysWithoutTarget<TSchemaUID>
>;

export type { RelationInputValue, RelationsKeysWithoutTarget, OmitRelationsWithoutTarget };
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { Attribute, Common, Utils } from '../../../../types';

export type NonFilterableKind = Extract<Attribute.Kind, 'password' | 'dynamiczone'>;
export type FilterableKind = Exclude<Attribute.Kind, NonFilterableKind>;

export type GetNonFilterableKeys<TSchemaUID extends Common.UID.Schema> = Utils.Object.KeysBy<
Attribute.GetAll<TSchemaUID>,
Attribute.OfType<NonFilterableKind>,
string
>;

export type GetScalarKeys<TSchemaUID extends Common.UID.Schema> = Exclude<
Attribute.GetKeysByType<TSchemaUID, Attribute.NonPopulatableKind>,
GetNonFilterableKeys<TSchemaUID>
>;

export type GetNestedKeys<TSchemaUID extends Common.UID.Schema> = Exclude<
Attribute.GetKeysWithTarget<TSchemaUID>,
GetNonFilterableKeys<TSchemaUID>
>;
7 changes: 6 additions & 1 deletion packages/core/types/src/types/core/attributes/relation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ export type PickRelationsFromTo<
export type RelationPluralityModifier<
TRelationKind extends RelationKind.Any,
TValue
> = TRelationKind extends Utils.String.Suffix<string, 'Many'> ? TValue[] : TValue;
> = Utils.Expression.If<IsManyRelation<TRelationKind>, TValue[], TValue>;

export type IsManyRelation<TRelationKind extends RelationKind.Any> = Utils.Expression.Extends<
TRelationKind,
Utils.String.Suffix<string, 'Many'>
>;

export type RelationValue<
TRelationKind extends RelationKind.Any,
Expand Down
6 changes: 3 additions & 3 deletions packages/utils/pack-up/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Creates a new package at the given path, by default uses the inbuilt template se

### `build`

Builds your current package based on the configuration in your `package.json` and `package.config.ts` (if applicable).
Builds your current package based on the configuration in your `package.json` and `packup.config.ts` (if applicable).

- `--minify` – minifies the output (default `false`).
- `--sourcemap` – generates sourcemaps for the output (default `true`).
Expand All @@ -82,10 +82,10 @@ Watches your current package for changes and rebuilds when necessary.

## Configuration

`@strapi/pack-up` by default reads its configuration from your `package.json`. But sometimes you need more flexibility, to do this you can create a `package.config.ts` file in the root of your package.
`@strapi/pack-up` by default reads its configuration from your `package.json`. But sometimes you need more flexibility, to do this you can create a `packup.config.ts` file in the root of your package.

```ts
// package.config.ts
// packup.config.ts
import { defineConfig } from '@strapi/pack-up';

export default defineConfig({
Expand Down

0 comments on commit 62eeed5

Please sign in to comment.