@stryke/capnp 0.2.6 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/compile.cjs DELETED
@@ -1,67 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.capnpc = capnpc;
7
- var _helpers = require("@stryke/fs/helpers");
8
- var _writeFile = require("@stryke/fs/write-file");
9
- var _filePathFns = require("@stryke/path/file-path-fns");
10
- var _joinPaths = require("@stryke/path/join-paths");
11
- var _compiler = require("capnp-es/compiler");
12
- var _nodeBuffer = require("node:buffer");
13
- var _nodeChild_process = require("node:child_process");
14
- var _nodeFs = require("node:fs");
15
- async function k() {
16
- if (process.stdin.isTTY) return _nodeBuffer.Buffer.alloc(0);
17
- const i = [];
18
- process.stdin.on("data", t => {
19
- i.push(t);
20
- }), await new Promise(t => {
21
- process.stdin.on("end", t);
22
- });
23
- const e = _nodeBuffer.Buffer.alloc(i.reduce((t, n) => t + n.byteLength, 0));
24
- let c = 0;
25
- for (const t of i) t.copy(e, c), c += t.byteLength;
26
- return e;
27
- }
28
- async function capnpc(i) {
29
- try {
30
- const {
31
- ts: e = !0,
32
- js: c = !1,
33
- dts: t = !1,
34
- outDir: n,
35
- tsconfig: d
36
- } = i;
37
- let f = await k();
38
- if (f.byteLength === 0) {
39
- const o = [];
40
- n ? o.push(`-o-:${n}`) : o.push("-o-"), f = await new Promise(a => {
41
- (0, _nodeChild_process.exec)(`capnpc ${o.join(" ")} ${o.join(" ")}`, {
42
- encoding: "buffer"
43
- }, (r, s, u) => {
44
- if (u.length > 0 && process.stderr.write(u), r) throw r;
45
- a(s);
46
- });
47
- });
48
- }
49
- const l = await (0, _compiler.compileAll)(f, {
50
- ts: e,
51
- js: c,
52
- dts: t,
53
- tsconfig: d
54
- });
55
- for (const [o, a] of l.files) {
56
- let r = o;
57
- if (!(0, _nodeFs.existsSync)((0, _filePathFns.findFilePath)(r))) {
58
- const s = `/${r}`;
59
- (0, _nodeFs.existsSync)((0, _filePathFns.findFilePath)(s)) && (r = s);
60
- }
61
- n && (r = (0, _joinPaths.joinPaths)(n, o)), await (0, _helpers.createDirectory)((0, _filePathFns.findFilePath)(r)), await (0, _writeFile.writeFile)(r, a.replace(/^\s+/gm, s => " ".repeat(s.length / 2)));
62
- }
63
- return l;
64
- } catch (e) {
65
- throw e instanceof Error ? (console.error(`Error: ${e.message}`), e.stack && console.error(e.stack)) : console.error("An unknown error occurred:", e), e;
66
- }
67
- }
package/dist/compile.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import type { CapnpcOptions, CapnpcResult } from "./types";
2
- export declare function capnpc(options: CapnpcOptions): Promise<CapnpcResult>;
package/dist/compile.mjs DELETED
@@ -1 +0,0 @@
1
- import{createDirectory as w}from"@stryke/fs/helpers";import{writeFile as y}from"@stryke/fs/write-file";import{findFilePath as p}from"@stryke/path/file-path-fns";import{joinPaths as g}from"@stryke/path/join-paths";import{compileAll as B}from"capnp-es/compiler";import{Buffer as m}from"node:buffer";import{exec as P}from"node:child_process";import{existsSync as h}from"node:fs";async function k(){if(process.stdin.isTTY)return m.alloc(0);const i=[];process.stdin.on("data",t=>{i.push(t)}),await new Promise(t=>{process.stdin.on("end",t)});const e=m.alloc(i.reduce((t,n)=>t+n.byteLength,0));let c=0;for(const t of i)t.copy(e,c),c+=t.byteLength;return e}export async function capnpc(i){try{const{ts:e=!0,js:c=!1,dts:t=!1,outDir:n,tsconfig:d}=i;let f=await k();if(f.byteLength===0){const o=[];n?o.push(`-o-:${n}`):o.push("-o-"),f=await new Promise(a=>{P(`capnpc ${o.join(" ")} ${o.join(" ")}`,{encoding:"buffer"},(r,s,u)=>{if(u.length>0&&process.stderr.write(u),r)throw r;a(s)})})}const l=await B(f,{ts:e,js:c,dts:t,tsconfig:d});for(const[o,a]of l.files){let r=o;if(!h(p(r))){const s=`/${r}`;h(p(s))&&(r=s)}n&&(r=g(n,o)),await w(p(r)),await y(r,a.replace(/^\s+/gm,s=>" ".repeat(s.length/2)))}return l}catch(e){throw e instanceof Error?(console.error(`Error: ${e.message}`),e.stack&&console.error(e.stack)):console.error("An unknown error occurred:",e),e}}
package/dist/index.cjs DELETED
@@ -1,27 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _compile = require("./compile.cjs");
7
- Object.keys(_compile).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _compile[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _compile[key];
14
- }
15
- });
16
- });
17
- var _types = require("./types.cjs");
18
- Object.keys(_types).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _types[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function () {
24
- return _types[key];
25
- }
26
- });
27
- });
package/dist/index.d.ts DELETED
@@ -1,10 +0,0 @@
1
- /**
2
- * The capnp library used by Storm Software for building NodeJS applications.
3
- *
4
- * @remarks
5
- * A package for running the Cap&#39;n Proto compiler in a TypeScript application
6
- *
7
- * @packageDocumentation
8
- */
9
- export * from "./compile";
10
- export * from "./types";
package/dist/index.mjs DELETED
@@ -1 +0,0 @@
1
- export*from"./compile";export*from"./types";
package/dist/types.cjs DELETED
@@ -1 +0,0 @@
1
- "use strict";
package/dist/types.d.ts DELETED
@@ -1,30 +0,0 @@
1
- import type { CodeGeneratorRequest, CodeGeneratorRequest_RequestedFile, CodeGeneratorRequest_RequestedFile_Import, Field, Node } from "capnp-es/capnp/schema";
2
- import type ts from "typescript";
3
- export interface CodeGeneratorFileContext {
4
- concreteLists: Array<[string, Field]>;
5
- file: CodeGeneratorRequest_RequestedFile;
6
- generatedNodeIds: string[];
7
- generatedResultsPromiseIds: Set<bigint>;
8
- imports: CodeGeneratorRequest_RequestedFile_Import[];
9
- nodes: Node[];
10
- req: CodeGeneratorRequest;
11
- statements: ts.Statement[];
12
- tsPath: string;
13
- constructor: (req: CodeGeneratorRequest, file: CodeGeneratorRequest_RequestedFile) => any;
14
- toString: () => string;
15
- }
16
- export interface CodeGeneratorContext {
17
- files: CodeGeneratorFileContext[];
18
- }
19
- export interface CapnpcOptions {
20
- ts?: boolean;
21
- js?: boolean;
22
- dts?: boolean;
23
- tsconfig?: ts.CompilerOptions;
24
- outDir: string;
25
- sources?: string[];
26
- }
27
- export interface CapnpcResult {
28
- ctx: CodeGeneratorContext;
29
- files: Map<string, string>;
30
- }
package/dist/types.mjs DELETED
File without changes