Skip to content

Commit

Permalink
First Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
widoz committed Jan 21, 2024
0 parents commit 96fdb8d
Show file tree
Hide file tree
Showing 79 changed files with 16,636 additions and 0 deletions.
777 changes: 777 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const baseConfiguration = require('@wordpress/scripts/config/.eslintrc.js');

module.exports = {
...baseConfiguration,
ignorePatterns: [
...(baseConfiguration.ignorePatterns ?? []),
'**/sources/server/**/*.js',
],
rules: {
...baseConfiguration.rules,
'@typescript-eslint/array-type': ['error', { default: 'generic' }],
},
settings: {
'import/resolver': {
typescript: {},
},
},
};
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=lf
41 changes: 41 additions & 0 deletions .github/workflows/js-qa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: JS Quality Assurance

on:
pull_request:
push:
branches:
- main

paths:
- '**/workflows/*js*'
- '**.js'
- '**.jsx'
- '**.ts'
- '**.tsx'
- '**.json'

jobs:
build:
runs-on: ubuntu-latest
if: "!github.event.pull_request.draft"
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v2
with:
cache: 'yarn'
node-version: '16'

- name: Install
run: yarn install

- name: Coding Style
run: yarn cs

- name: Linting JavaScript
run: yarn lint:js

- name: Unit Tests
run: yarn test
34 changes: 34 additions & 0 deletions .github/workflows/php-qa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: PHP Quality Assurance
on:
pull_request:
push:
branches:
- main

paths:
- '**.php'

jobs:
build:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '--skip ci') && !github.event.pull_request.draft"
strategy:
matrix:
php-versions: [ '8.0' ]
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}

- name: Check syntax error in sources
run: find ./src/ ./tests/ -type f -name '*.php' -print0 | xargs -0 -L 1 -P 4 -- php -l

- name: Install dependencies
uses: "ramsey/composer-install@v1"

- name: Check code styles
run: composer cs
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/.idea/
/build/
/coverage
/vendor/
/node_modules/

composer.lock
7 changes: 7 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.psalm
.github

./coverage
./vendor
./node_modules
./build
16 changes: 16 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const prettierConfig = require('@wordpress/scripts/config/.prettierrc.js');

module.exports = {
...prettierConfig,
importOrder: [
'<THIRD_PARTY_MODULES>',
'^@jest/(.*)$',
'^@testing-library/(.*)$',
'^@faker-js/faker',
'^@wordpress/(.*)$',
'^[./]',
],
importOrderSeparation: true,
importOrderSortSpecifiers: false,
importOrderCaseInsensitive: false,
};
37 changes: 37 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"php.suggest.basic": true,
"php.validate.enable": true,
"php.validate.executablePath": "/usr/bin/php",
"php.format.codeStyle": "Off",
"phpCodeSniffer.standardCustom": "./phpcs.xml",
"phpCodeSniffer.standard": "Custom",
"phpCodeSniffer.autoExecutable": true,
"prettier.configPath": ".prettierrc.js",
"files.readonlyInclude": {
"**/node_modules/**": true,
"**/vendor/**": true
},
"favorites.resources": [
{
"filePath": "vendor/roots/wordpress-no-content/wp-includes/rest-api",
"group": "Default"
}
],
"typescript.tsdk": "node_modules/typescript/lib",
"sqltools.connections": [
{
"mysqlOptions": {
"authProtocol": "default",
"enableSsl": "Disabled"
},
"previewLimit": 50,
"server": "0.0.0.0",
"port": 52693,
"driver": "MariaDB",
"name": "WordPress",
"database": "wordpress",
"username": "root",
"password": "password"
}
]
}
15 changes: 15 additions & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"core": "./vendor/roots/wordpress-no-content",
"plugins": ["."],
"env": {
"development": {
"phpVersion": "8.0",
"mappings": {
"wp-content/plugins/wp-entities-search": "."
}
}
},
"config": {
"WP_ENVIRONMENT_TYPE": "local"
}
}
174 changes: 174 additions & 0 deletions @types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import React from 'react';

import { BaseEntityRecords, Context } from '@wordpress/core-data';

import type { Set } from '../sources/client/src';

export default EntitiesSearch;

// TODO Try to convert it to a module.
declare namespace EntitiesSearch {
type Post<C extends Context = 'view'> = BaseEntityRecords.Post<C>;
type PostType<C extends Context = 'view'> = BaseEntityRecords.Type<C>;
type Taxonomy<C extends Context = 'view'> = BaseEntityRecords.Taxonomy<C>;

type Entities<V> = Set<V>;
type Kind<V> = Set<V>;
type Options<V> = Set<ControlOption<V>>;

interface QueryArguments<V>
extends Partial<
Readonly<{
exclude: Set<V>;
include: Set<V>;
fields: EntitiesSearch.SearchQueryFields;
[p: string]: unknown;
}>
> {}

interface SearchEntityFields
extends Readonly<{
id: number;
title: string;
url: string;
type: string;
subtype: string;
}> {}

type SearchEntitiesFunction<E, K> = (
phrase: string,
kind: Kind<K>,
queryArguments?: EntitiesSearch.QueryArguments<E>
) => Promise<Options<E>>;

type ControlOption<V extends any> = Readonly<{
value: V;
label: string;
}>;

type SingularControl<V> = {
[K in keyof BaseControl<V>]: K extends 'value'
? V
: K extends 'onChange'
? (value: V) => void
: BaseControl<V>[K];
};

interface BaseControl<V>
extends Readonly<{
value: Set<V>;
options: Options<V>;
onChange(values: BaseControl<V>['value']): void;
}> {}

/*
* Hooks
*/
type ViewablePostType = Readonly<{
[K in keyof PostType<'edit'>]: K extends 'viewable'
? true
: PostType<'edit'>[K];
}>;

// TODO Need Type Test.
type ViewableTaxonomy = Readonly<{
[K in keyof Taxonomy<'edit'>]: K extends 'visibility'
? BaseEntityRecords.TaxonomyVisibility & {
publicly_queryable: true;
}
: Taxonomy<'edit'>[K];
}>;

type EntitiesRecords<Entity> = Readonly<{
records(): Set<Entity>;
isResolving(): boolean;
errored(): boolean;
succeed(): boolean;
}>;

/*
* Api
*/
type SearchQueryFields = ReadonlyArray<
keyof EntitiesSearch.SearchEntityFields
>;

/*
* Storage
*/
interface EntitiesState<
E,
K,
OptionSet = Set<EntitiesSearch.ControlOption<E>>
> extends Readonly<{
entities: Entities<E>;
kind: Kind<K>;
contextualEntitiesOptions: OptionSet;
currentEntitiesOptions: OptionSet;
selectedEntitiesOptions: OptionSet;
}> {}

type StoreAction<E, K> =
| {
type: 'UPDATE_ENTITIES';
entities: EntitiesState<E, K>['entities'];
}
| {
type: 'UPDATE_KIND';
kind: EntitiesState<E, K>['kind'];
}
| {
type: 'UPDATE_CURRENT_ENTITIES_OPTIONS';
currentEntitiesOptions: EntitiesState<
E,
K
>['currentEntitiesOptions'];
}
| {
type: 'UPDATE_CONTEXTUAL_ENTITIES_OPTIONS';
contextualEntitiesOptions: EntitiesState<
E,
K
>['contextualEntitiesOptions'];
}
| {
type: 'UPDATE_SELECTED_ENTITIES_OPTIONS';
selectedEntitiesOptions: EntitiesState<
E,
K
>['selectedEntitiesOptions'];
}
| {
type: 'CLEAN_ENTITIES_OPTIONS';
}
| {
type: 'UPDATE_ENTITIES_OPTIONS_FOR_NEW_KIND';
entitiesOptions: Set<EntitiesSearch.ControlOption<E>>;
kind: EntitiesState<E, K>['kind'];
};

/*
* Components
*/
interface SearchControl
extends Readonly<{
id?: string;
onChange(phrase: string | React.ChangeEvent<HTMLInputElement>);
}> {}

interface CompositeEntitiesKinds<E, K>
extends Readonly<{
kind: BaseControl<K>;
entities: Omit<BaseControl<E>, 'options'>;
searchEntities: SearchEntitiesFunction<E, K>;
children(
entities: CompositeEntitiesKinds<E, K>['entities'] & {
options: BaseControl<E>['options'];
},
kind: CompositeEntitiesKinds<E, K>['kind'],
search: (
phrase: Parameters<SearchEntitiesFunction<E, K>>[0]
) => ReturnType<SearchControl<E, K>['search']>
): React.ReactNode;
}> {}
}
38 changes: 38 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "widoz/wp-entities-search",
"description": "A WordPress package to search Entities including Rest API Endpoints and React Components",
"type": "library",
"license": "GPL-v2-or-later",
"autoload": {
"psr-4": {
"Widoz\\Wp\\EntitiesSearch\\": "sources/server/src/"
}
},
"authors": [
{
"name": "guido scialfa",
"email": "[email protected]"
}
],
"minimum-stability": "stable",
"require": {
"php": ">=8.0"
},
"require-dev": {
"inpsyde/modularity": "^1.5",
"inpsyde/php-coding-standards": "^1.0",
"roots/wordpress-no-content": "^6.3"
},
"config": {
"platform": {
"php": "8.0"
},
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"scripts": {
"cs": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs",
"cs:fix": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf"
}
}
Loading

0 comments on commit 96fdb8d

Please sign in to comment.