Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update cli and fix linting errors #713

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions .eslintrc

This file was deleted.

4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ node_modules
.sonarlint
.scannerwork
.nyc_output
coverage
/coverage
npm-debug.log
/dist
docs
.rete-cli
.sonar
6 changes: 6 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import tseslint from 'typescript-eslint';
import configs from 'rete-cli/configs/eslint.mjs';

export default tseslint.config(
...configs
)
3,798 changes: 2,100 additions & 1,698 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
},
"devDependencies": {
"jest-environment-jsdom": "^29.1.2",
"rete-cli": "^1.0.3",
"typescript": "4.8.4"
"rete-cli": "~2.0.1"
},
"dependencies": {
"@babel/runtime": "^7.21.0"
Expand Down
8 changes: 4 additions & 4 deletions src/presets/classic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@
*/
type InputControlOptions<N> = {
/** Whether the control is readonly. Default is `false` */
readonly?: boolean,
readonly?: boolean
/** Initial value of the control */
initial?: N,
initial?: N
/** Callback function that is called when the control value changes */
change?: (value: N) => void
}
Expand All @@ -150,7 +150,7 @@
constructor(public type: T, public options?: InputControlOptions<N>) {
super()
this.id = getUID()
this.readonly = options?.readonly
this.readonly = options?.readonly ?? false

if (typeof options?.initial !== 'undefined') this.value = options.initial
}
Expand All @@ -161,7 +161,7 @@
*/
setValue(value?: N) {
this.value = value
if (this.options?.change) this.options.change(value)
if (this.options?.change) this.options.change(value!)

Check warning on line 164 in src/presets/classic.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Forbidden non-null assertion

Check warning on line 164 in src/presets/classic.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The 'value!' has unsafe '!' type assertion

Check warning on line 164 in src/presets/classic.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Forbidden non-null assertion

Check warning on line 164 in src/presets/classic.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The 'value!' has unsafe '!' type assertion
}
}

Expand Down Expand Up @@ -190,7 +190,7 @@
/**
* Node controls
*/
controls: Controls = {} as Controls

Check warning on line 193 in src/presets/classic.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The '{} as Controls' has unsafe 'as' type assertion

Check warning on line 193 in src/presets/classic.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The '{} as Controls' has unsafe 'as' type assertion
/**
* Whether the node is selected. Default is `false`
*/
Expand All @@ -200,8 +200,8 @@
this.id = getUID()
}

hasInput<K extends keyof Inputs>(key: K) {

Check warning on line 203 in src/presets/classic.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Type parameter K is used only once in the function signature

Check warning on line 203 in src/presets/classic.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Type parameter K is used only once in the function signature
return Object.prototype.hasOwnProperty.call(this.inputs, key)

Check warning on line 204 in src/presets/classic.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The type of 'prototype' is 'any'

Check warning on line 204 in src/presets/classic.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The type of 'prototype' is 'any'
}

addInput<K extends keyof Inputs>(key: K, input: Input<Exclude<Inputs[K], undefined>>) {
Expand All @@ -211,11 +211,11 @@
}

removeInput(key: keyof Inputs) {
delete this.inputs[key]

Check warning on line 214 in src/presets/classic.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Do not delete dynamically computed property keys

Check warning on line 214 in src/presets/classic.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Do not delete dynamically computed property keys
}

hasOutput<K extends keyof Outputs>(key: K) {

Check warning on line 217 in src/presets/classic.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Type parameter K is used only once in the function signature

Check warning on line 217 in src/presets/classic.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Type parameter K is used only once in the function signature
return Object.prototype.hasOwnProperty.call(this.outputs, key)

Check warning on line 218 in src/presets/classic.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The type of 'prototype' is 'any'

Check warning on line 218 in src/presets/classic.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The type of 'prototype' is 'any'
}

addOutput<K extends keyof Outputs>(key: K, output: Output<Exclude<Outputs[K], undefined>>) {
Expand All @@ -225,10 +225,10 @@
}

removeOutput(key: keyof Outputs) {
delete this.outputs[key]

Check warning on line 228 in src/presets/classic.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Do not delete dynamically computed property keys

Check warning on line 228 in src/presets/classic.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Do not delete dynamically computed property keys
}

hasControl<K extends keyof Controls>(key: K) {

Check warning on line 231 in src/presets/classic.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Type parameter K is used only once in the function signature

Check warning on line 231 in src/presets/classic.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Type parameter K is used only once in the function signature
return Object.prototype.hasOwnProperty.call(this.controls, key)
}

Expand Down
15 changes: 7 additions & 8 deletions src/scope.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/naming-convention */
import {
AcceptPartialUnion, CanAssignSignal, GetAssignmentReferences, GetNonAssignableElements, Tail
Expand All @@ -19,8 +20,8 @@ export type Pipe<T> = (data: T) => Promise<undefined | T> | undefined | T
export type CanAssignEach<D extends any[], F extends any[]> = D extends [infer H1, ...infer Tail1]
? (
F extends [infer H2, ...infer Tail2] ?
[CanAssignSignal<H1, H2>, ...CanAssignEach<Tail1, Tail2>]
: []
[CanAssignSignal<H1, H2>, ...CanAssignEach<Tail1, Tail2>]
: []
) : []

export type ScopeAsParameter<S extends Scope<any, any[]>, Current extends any[]> = (CanAssignEach<[S['__scope']['produces'], ...S['__scope']['parents']], Current>[number] extends true
Expand All @@ -45,8 +46,8 @@ export type NestedScope<S extends Scope<any, any[]>, Current extends any[]> = (C
export function useHelper<S extends Scope<any, any[]>, Signals>() {
type T1 = S['__scope']['parents'][number]
return {
debug<T extends GetNonAssignableElements<T1, Signals>>(f: (p: GetAssignmentReferences<T, Signals>) => T) {
f
debug<T extends GetNonAssignableElements<T1, Signals>>(_f: (p: GetAssignmentReferences<T, Signals>) => T) {
/* placeholder */
}
}
}
Expand Down Expand Up @@ -75,17 +76,15 @@ export class Signal<T> {
}
}

type Type<T> = {
new(...args: any[]): T;
} | (abstract new (...args: any[]) => T)
type Type<T> = (new(...args: any[]) => T) | (abstract new (...args: any[]) => T)

/**
* Base class for all plugins and the core. Provides a signals mechanism to modify the data
*/
export class Scope<Produces, Parents extends unknown[] = []> {
signal = new Signal<AcceptPartialUnion<Produces | Parents[number]>>()
parent?: any // Parents['length'] extends 0 ? undefined : Scope<Parents[0], Tail<Parents>>
__scope: {
__scope!: {
produces: Produces
parents: Parents
}
Expand Down
17 changes: 9 additions & 8 deletions src/utility-types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
export type AcceptPartialUnion<T> = T | any

export type Tail<T extends any[]> = ((...args: T) => void) extends (head: any, ...tail: infer U) => any ? U : never
Expand All @@ -11,7 +12,7 @@ export type UnionToIntersection<U> = (
: never

type StrictExcludeInner<T, U> = 0 extends (
U extends T ? [T] extends [U] ? 0 : never : never
U extends T ? [T] extends [U] ? 0 : never : never
) ? never : T
export type StrictExclude<T, U> = T extends unknown ? StrictExcludeInner<T, U> : never

Expand All @@ -25,17 +26,17 @@ export type FilterMatch<T extends any[], V> = T extends [infer Head, ...infer _T
? ([Head] extends [V]
? [Head, ...FilterMatch<_Tail, V>]
: FilterMatch<_Tail, V>
): []
) : []

export type CanAssignToAnyOf<Provides, Requires> = FilterMatch<UnionToTuple<Provides>, Requires> extends [] ? false : true

export type CanAssignEachTupleElemmentToAnyOf<Provides, Requires extends any[]> = Requires extends [infer Head, ...infer _Tail]
? CanAssignToAnyOf<Provides, Head> extends true ?
(_Tail extends []
? true
: CanAssignEachTupleElemmentToAnyOf<Provides, _Tail>
): false
: false
? CanAssignToAnyOf<Provides, Head> extends true ?
(_Tail extends []
? true
: CanAssignEachTupleElemmentToAnyOf<Provides, _Tail>
) : false
: false

export type CanAssignEachToAnyOf<Provides, Requires> = CanAssignEachTupleElemmentToAnyOf<Provides, UnionToTuple<Requires>>

Expand Down
6 changes: 1 addition & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
/* global globalThis*/

const nodeCrypto = () => import('node:crypto')

const crypto = globalThis.crypto as (typeof globalThis.crypto | Awaited<ReturnType<typeof nodeCrypto>>)
const crypto = globalThis.crypto as (typeof globalThis.crypto | typeof import('node:crypto'))

/**
* @returns A unique id
Expand Down
6 changes: 3 additions & 3 deletions test/presets/classic.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, it } from '@jest/globals'
import { afterEach, beforeEach, describe, expect, it } from '@jest/globals'

import { mockCryptoFromArray, resetCrypto } from '../mocks/crypto'

Expand Down Expand Up @@ -39,7 +39,7 @@ describe('ClassicPreset', () => {
node.addInput('a', input)

expect(node.hasInput('a')).toBeTruthy()
expect(node.inputs['a']).toBe(input)
expect(node.inputs.a).toBe(input)
})

it('throws error if Input already exists', () => {
Expand All @@ -66,7 +66,7 @@ describe('ClassicPreset', () => {
node.addOutput('a', output)

expect(node.hasOutput('a')).toBeTruthy()
expect(node.outputs['a']).toBe(output)
expect(node.outputs.a).toBe(output)
})

it('throws error if Output already exists', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/scope.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('Scope', () => {
expect(pipe).toHaveBeenCalledWith({ parent: 'test' })
})

it('should return a promise from emit', async () => {
it('should return a promise from emit', () => {
const scope = new Scope<Parent>('test')
const signal = jest.fn<() => Parent>()

Expand Down
2 changes: 1 addition & 1 deletion test/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, it, jest } from '@jest/globals'
import { afterEach, beforeEach, describe, expect, it, jest } from '@jest/globals'
import { Buffer } from 'buffer'

import { mockCryptoFromArray, mockCryptoFromBuffer, resetCrypto } from './mocks/crypto'
Expand Down
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"extends": "rete-cli/configs/tsconfig.json",
"compilerOptions": {
"target": "es5",
"downlevelIteration": true,
"isolatedModules": false,
"strict": true,
"skipLibCheck": true,
"lib": []

},
"include": ["src"]
"include": ["src", "test"]
}
Loading