Skip to content

Commit

Permalink
fix: update cli and fix linting errors
Browse files Browse the repository at this point in the history
Ni55aN committed Aug 30, 2024
1 parent 05da7ba commit d219f95
Showing 13 changed files with 2,139 additions and 1,747 deletions.
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
@@ -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
@@ -28,8 +28,7 @@
},
"devDependencies": {
"jest-environment-jsdom": "^29.1.2",
"rete-cli": "^1.0.3",
"typescript": "4.8.4"
"rete-cli": "~2.0.0"
},
"dependencies": {
"@babel/runtime": "^7.21.0"
8 changes: 4 additions & 4 deletions src/presets/classic.ts
Original file line number Diff line number Diff line change
@@ -128,9 +128,9 @@ export class Control {
*/
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
}
@@ -150,7 +150,7 @@ export class InputControl<T extends 'text' | 'number', N = T extends 'text' ? st
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
}
@@ -161,7 +161,7 @@ export class InputControl<T extends 'text' | 'number', N = T extends 'text' ? st
*/
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

GitHub Actions / ci / ci

Forbidden non-null assertion

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

GitHub Actions / ci / ci

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

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

GitHub Actions / ci / ci

Forbidden non-null assertion

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

GitHub Actions / ci / ci

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

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

GitHub Actions / ci / ci

Forbidden non-null assertion

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

GitHub Actions / ci / ci

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

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

GitHub Actions / ci / ci

Forbidden non-null assertion

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

GitHub Actions / ci / ci

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

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
@@ -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
@@ -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 */
}
}
}
@@ -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
}
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
@@ -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

@@ -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>>

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
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'

@@ -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', () => {
@@ -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', () => {
2 changes: 1 addition & 1 deletion test/scope.test.ts
Original file line number Diff line number Diff line change
@@ -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>()

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'
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"]
}

0 comments on commit d219f95

Please sign in to comment.