Skip to content

Commit

Permalink
Merge branch 'release/release/0.13.22'
Browse files Browse the repository at this point in the history
  • Loading branch information
holtwick committed Oct 18, 2023
2 parents 35d9466 + 21da873 commit 79f0963
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "zeed",
"type": "module",
"version": "0.13.21",
"version": "0.13.22",
"description": "🌱 Simple foundation library",
"author": {
"name": "Dirk Holtwick",
Expand Down
7 changes: 7 additions & 0 deletions src/common/data/array.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
arrayMin,
arrayMinus,
arrayRemoveElement,
arraySetArrayInPlace,
arrayShuffleForce,
arraySorted,
arraySortedNumbers,
Expand All @@ -27,6 +28,12 @@ describe('Array', () => {
expect(r).toEqual([1, 3, 4])
})

it('should set in place items', () => {
const r = [1, 2, 3]
arraySetArrayInPlace(r, [9, 8, 7])
expect(r).toEqual([9, 8, 7])
})

it('should intersect', () => {
expect(arrayIntersection([1, 1, 2, 2, 3], [2, 2, 3, 5, 6])).toEqual([2, 3])
expect(arraySymmetricDifference([1, 1, 2, 2, 3], [2, 2, 3, 5, 6])).toEqual([
Expand Down
5 changes: 5 additions & 0 deletions src/common/data/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ export function arrayEmptyInPlace<T>(array: T[]): T[] {
return array
}

export function arraySetArrayInPlace<T>(array: T[], newContent: T[]): T[] {
array.splice(0, array.length, ...newContent)
return array
}

export function arraySorted<T>(
arr: Iterable<T> | ArrayLike<T>,
cond: ((a: T, b: T) => number) | undefined = cmp,
Expand Down
2 changes: 1 addition & 1 deletion src/common/msg/rpc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// From https://github.com/antfu/birpc/blob/main/src/index.ts MIT

import { LoggerInterface } from "../log/log-base"
import type { LoggerInterface } from '../log/log-base'

export type ArgumentsType<T> = T extends (...args: infer A) => any ? A : never
export type ReturnType<T> = T extends (...args: any) => infer R ? R : never
Expand Down
26 changes: 26 additions & 0 deletions src/common/pipes/types.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Pipe } from "./types"

describe("types.spec", () => {
it.skip("should pipe", async () => {
const p1: Pipe<object, string> = {
post(s) { }, // todo
on: (fn) => { }, // todo
serialize(o) {
return JSON.stringify(o)
},
deserialize(s) {
return JSON.parse(s)
},
}

async function echo(pipe: Pipe<any,any>, o: object) {
let resolve:any
pipe.on(fn => resolve = fn)
pipe.post(o)
return new Promise(resolve)
}

let x = await echo(p1, { a: 1 })
expect(x).toMatchInlineSnapshot()
})
})
31 changes: 31 additions & 0 deletions src/common/pipes/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Experiment to replace "Channel" by "Pipe".
// Different naming just to avoid confusion.
// Goal: Simplify things by removing event handling etc.

export interface Pipe<PipeObjectData = object, PipeRawData = PipeObjectData> {
/** Function to post raw message */
post: (data: PipeObjectData) => void

/** Listener to receive raw message */
on: (fn: (data: PipeObjectData) => void) => void

/** Custom function to serialize data */
serialize?: (data: PipeObjectData) => PipeRawData

/** Custom function to deserialize data */
deserialize?: (data: PipeRawData) => PipeObjectData
}

export interface PipeAsync<PipeObjectData = object, PipeRawData = PipeObjectData> {
/** Function to post raw message */
post: (data: PipeObjectData) => Promise<void>

/** Listener to receive raw message */
on: (fn: (data: PipeObjectData) => Promise<void>) => void

/** Custom function to serialize data */
serialize?: (data: PipeObjectData) => Promise<PipeRawData>

/** Custom function to deserialize data */
deserialize?: (data: PipeRawData) => Promise<PipeObjectData>
}

0 comments on commit 79f0963

Please sign in to comment.