🤖 Merge PR #63307 Add types for ipp-printer by @mattsmithcode

* Add types for ipp-printer

* Reshape ipp-printer types
This commit is contained in:
Matt
2022-11-21 22:42:59 +00:00
committed by GitHub
parent fce54bcb5e
commit 0e227559d1
4 changed files with 115 additions and 0 deletions

72
types/ipp-printer/index.d.ts vendored Normal file
View File

@@ -0,0 +1,72 @@
// Type definitions for ipp-printer 1.0
// Project: https://github.com/watson/ipp-printer
// Definitions by: Matt Smith <https://github.com/mattsmithcode>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
import * as http from 'http';
import { Readable } from 'node:stream';
declare class Printer {
constructor(opts?: Printer.Options | string);
fallback: boolean;
jobs: Printer.Job[];
name: string;
port: number;
server: http.Server;
started: Date;
state: number;
uri: string;
on(event: 'job', handler: (job: Printer.Job) => void): Printer;
on(event: 'operation', handler: (operation: Printer.Operation) => void): Printer;
}
declare namespace Printer {
interface Attribute {
name: string;
tag: number;
value: string | number | Date;
}
interface AttributeGroup {
attributes: Attribute[];
tag: number;
}
class Job extends Readable {
compression: string;
createdAt: Date;
id: number;
name: string;
state: number;
uri: string;
userName: string;
attributes(filter?: ReadonlyArray<string>): Attribute[];
pause(): this;
resume(): this;
setEncoding(encoding: BufferEncoding): this;
unpipe(destination?: NodeJS.WritableStream): this;
wrap(oldStream: NodeJS.ReadableStream): this;
}
interface Operation {
version: { major: number, minor: number };
operationId: number;
requestId: number;
groups: AttributeGroup[];
}
interface Options {
fallback?: boolean;
name?: string;
port?: number;
server?: http.Server;
uri?: string;
zeroconf?: boolean;
}
}
export = Printer;

View File

@@ -0,0 +1,19 @@
import * as Printer from 'ipp-printer';
import * as fs from 'node:fs';
const printer = new Printer({
port: 631
});
printer.on('job', (job: Printer.Job) => {
console.log('[job %d] Printing document: %s', job.id, job.name);
const filename = `job-${job.id}.ps`;
const file = fs.createWriteStream(filename);
job.on('end', () => {
console.log('[job %d] Document saved as %s', job.id, filename);
});
job.pipe(file);
});

View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"ipp-printer-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "@definitelytyped/dtslint/dt.json" }