From 74ac652fb78111518a0496227bebbdf8abd09f36 Mon Sep 17 00:00:00 2001 From: mike dupont Date: Wed, 16 Oct 2024 01:09:25 -0400 Subject: [PATCH] running deno lint --- Makefile | 9 ++- cache.ts | 23 ++++---- clinic_report.ts | 115 +++++++++++++++++++++----------------- deno.lock | 125 +++++++++++++++++++++++++++++++++++++++++- filter.ts | 84 +++++++++++++--------------- functions.ts | 4 +- introspector.ts | 21 ++++++- main.ts | 2 +- main_test.ts | 31 +++++++++-- main_test1.ts | 30 ++++++++++ missing.ts | 4 +- process.ts | 2 +- process_files.ts | 96 ++++++++++++++++---------------- process_statements.ts | 37 ++++++++----- rdf_callbacks.ts | 9 +-- rdf_type.ts | 19 ++++--- statement.ts | 2 +- test_driver.ts | 44 +++++++++------ 18 files changed, 448 insertions(+), 209 deletions(-) create mode 100644 main_test1.ts diff --git a/Makefile b/Makefile index 214b99c..f4c331b 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,14 @@ +lint: + deno lint +test: + deno run --allow-env --allow-read main_test1.ts + +test3: + deno test --allow-read --trace-leaks filter: npx ts-node ./filter.ts -test: +test2: npx ts-node ./process.ts process_files: npx ts-node ./process_files.ts diff --git a/cache.ts b/cache.ts index bc9ee3c..bad341f 100644 --- a/cache.ts +++ b/cache.ts @@ -1,24 +1,27 @@ // -export function associate_cache(url: string, +export interface Struct { + newpath : string; +}; + +export function associate_cache(_url: string, hostname: string, url_parts :string[], - fn_parts:string[]): any { - const alen = url_parts.length-1; + fn_parts:string[]): Struct { + // const alen = url_parts.length-1; //const filename = url_parts[url_parts.length-1]; //console.log("cache url: " + url); //console.log("cache: parts:" + url_parts.slice(6,alen +1)); const hostname_base = hostname.split(".")[0] const newpath = "../inputs/" + hostname_base + url_parts.slice(0,4).join("/") + "/"+ fn_parts.join("."); //console.log("cache: slice:" + newpath); - //const htmlStream = fs.createReadStream(newpath); return { "newpath" : newpath }; } -export function save_cache(url:string, - hostname: string, - url_parts:string[], - fn_parts: string[], - cached:any, - results:any) {} +export function save_cache(_url:string, + _hostname: string, + _url_parts:string[], + _fn_parts: string[], + _cached:Struct, + _results:Struct):void {} diff --git a/clinic_report.ts b/clinic_report.ts index c792fc1..bb9f9de 100644 --- a/clinic_report.ts +++ b/clinic_report.ts @@ -1,11 +1,10 @@ -import { Functions } from "./functions.ts" +import type { Functions } from "./functions.ts" import { missing } from "./missing.ts" import { associate_cache, save_cache } from "./cache.ts" - -//const fs = require('node:fs'); +import type { Introspector,CallbackReturn,Callback } from "./introspector.ts"; import * as fs from 'node:fs'; -function process_chunk(line:string,callback:any) +function process_chunk(line:string,callback:Callback) { const begins = "module.exports=" if (line) { @@ -14,13 +13,15 @@ function process_chunk(line:string,callback:any) const bl = begins.length; //console.log("chunk: " + line.substring(bl,20)); const chunk = line.substring(bl,line.length); - let obj = JSON.parse(chunk) + const obj = JSON.parse(chunk) //let runnable = eval(line); //runnable.Run("module.exports").then((result:string)=>{console.log(result);}); // console.log(JSON.stringify(obj,null,2)); // callback.process_raw_module_export(obj); + if(callback.debug) { callback.debug("got chunk"); - return obj; + } + return obj; } } else { @@ -50,7 +51,7 @@ export interface iFrame { isInit: boolean; isWasm: boolean; value: number; - onStackTop: any; + onStackTop: string; children: iFrame[]; }; @@ -62,15 +63,17 @@ export interface iFrame { //unmerged -function frame_test(f: iFrame,parent:string,callback:any){ - function report_child(previousValue: iFrame, +function frame_test(f: iFrame,parent:string,callback:Callback){ + function report_child(_previousValue: iFrame, currentValue: iFrame, - currentIndex: number, - array: iFrame[], + _currentIndex: number, + _array: iFrame[], parent_name:string, - callback:any): iFrame { + callback:Callback): iFrame { - callback.debug("report child"); + if(callback.debug) { + callback.debug("report child"); + } if(!callback.filter_current_value(currentValue)) // if (! currentValue.name.includes("o1js")) { @@ -95,11 +98,13 @@ function frame_test(f: iFrame,parent:string,callback:any){ let sum = 0; if (currentValue){ - sum = sum + currentValue.value; // add the current value -// callback.debug("check") + sum = sum + currentValue.value; // add the current value + //if(callback.debug) { + // callback.debug("check") + //} sum = sum + frame_test(currentValue,name,callback); // add the children } - let ret = {value: sum} as iFrame // return a new object with just the value + const ret = {value: sum} as iFrame // return a new object with just the value return ret; } @@ -111,70 +116,80 @@ function frame_test(f: iFrame,parent:string,callback:any){ parent, callback); } + if(callback.debug) { callback.debug("reduce"); - let res = f.children.reduce(wrapper,{value:f.value} as iFrame); //recurse - //console.log(JSON.stringify(res.value)); - return res.value; + } + const res = f.children.reduce(wrapper,{value:f.value} as iFrame); //recurse + //console.log(JSON.stringify(res.value)); + return res.value; } -function createRunningSumFunctor(f:any,callback:any) { +function createRunningSumFunctor(f:Callback,callback:Introspector) { + if(callback.debug) { callback.debug("runningsum"); - let objects:object[] = []; + } + //let objects:object[] = []; let sum:number = 0; return function(value?: string): number { if (value !== undefined) { const obj = f(value,callback);// apply f if (obj !== undefined) { - function report_child2(value:object,index:number){ - if (value){ - let res = frame_test(value as iFrame, "root", callback); - sum = sum + res - } + const report_child2=(value:object,_index:number)=>{ + if (value){ + const res = frame_test(value as iFrame, "root", callback); + sum = sum + res } - //obj.merged.children.forEach(report); - obj.unmerged.children.forEach(report_child2); - //obj.merged.forEach(report); - //obj.unmerged.forEach(report); - - //sum.push(obj); + } + //obj.merged.children.forEach(report); + obj.unmerged.children.forEach(report_child2); + //obj.merged.forEach(report); + //obj.unmerged.forEach(report); + //sum.push(obj); } } return sum; }; } -function process_flame_report(filename:string, data:string, callback:any) { +function process_flame_report(filename:string, data:string, callback:Introspector) { + if(callback.debug) { callback.debug("flame"); - let sumfunc:any = createRunningSumFunctor(process_chunk,callback); - if (data) { - data.split("\n").forEach(sumfunc); - } - let sum:number = sumfunc(callback); - console.log(filename + "sum : " + sum); - return sum; + } + const sumfunc:Callback = createRunningSumFunctor(process_chunk,callback); + if (data) { + data.split("\n").forEach(sumfunc); + } + const sum:number = sumfunc(callback); + console.log(filename + "sum : " + sum); + return sum; } -function createProcessor(filename:string,callback:any) { - return function(err:any, data:string) { +function createProcessor(filename:string,callback:Introspector) { + return function(_err:string, data:string) { return process_flame_report(filename, data, callback); } } -function isp_clinic_flame_report(report_url:string, data:any, callback:any) { - //console.log("file: " + data.newpath); +function isp_clinic_flame_report(report_url:string, data:CallbackInput, callback:Introspector) { + //console.log("file: " + data.newpath); + if(callback.debug) { callback.debug("ispflame"); - let functor = createProcessor(data.newpath,callback); - fs.readFile(data.newpath, "utf-8",functor); - return "flame report:" + report_url; + } + const functor = createProcessor(data.newpath,callback); + fs.readFile(data.newpath, "utf-8",functor); + return "flame report:" + report_url; } const clinic_functions: Functions = { 'clinic-flame': isp_clinic_flame_report } -export function isp_clinic_report(report_url:string,callback:any):any { - callback.debug("clinit report"); +export function isp_clinic_report(report_url:string,callback:Introspector):CallbackReturn { + + if(callback.debug) { + callback.debug("clinic report"); + } const reportUrl = new URL(report_url); const parts = reportUrl.pathname.split("/"); const hostname = reportUrl.hostname; @@ -185,7 +200,7 @@ export function isp_clinic_report(report_url:string,callback:any):any { const callback_function = clinic_functions[fntype] // now lets construct a cache const cached = associate_cache(report_url,hostname,parts,fnparts); - var data = "missing"; + const data = "missing"; if (callback_function) { data = callback_function(report_url, cached, callback); diff --git a/deno.lock b/deno.lock index 5d23094..8939e52 100644 --- a/deno.lock +++ b/deno.lock @@ -2,7 +2,10 @@ "version": "4", "specifiers": { "jsr:@std/assert@1": "1.0.6", - "jsr:@std/internal@^1.0.4": "1.0.4" + "jsr:@std/internal@^1.0.4": "1.0.4", + "npm:@types/node@*": "22.5.4", + "npm:data-forge@1.10.2": "1.10.2", + "npm:n3@1.22.3": "1.22.3" }, "jsr": { "@std/assert@1.0.6": { @@ -15,6 +18,126 @@ "integrity": "62e8e4911527e5e4f307741a795c0b0a9e6958d0b3790716ae71ce085f755422" } }, + "npm": { + "@data-forge/serialization@1.0.1": { + "integrity": "sha512-EP7IWimh5JcDOISVoXvNIjUAqcPN1FkNWvuvjY3uzcswErxB8j93ldlUBvgvGEszqFRwMM3fpMF0HrISg5iBSQ==" + }, + "@types/node@22.5.4": { + "integrity": "sha512-FDuKUJQm/ju9fT/SeX/6+gBzoPzlVCzfzmGkwKvRHQVxi4BntVbyIwf6a4Xn62mrvndLiml6z/UBXIdEVjQLXg==", + "dependencies": [ + "undici-types" + ] + }, + "abort-controller@3.0.0": { + "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", + "dependencies": [ + "event-target-shim" + ] + }, + "base64-js@1.5.1": { + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==" + }, + "buffer@6.0.3": { + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "dependencies": [ + "base64-js", + "ieee754" + ] + }, + "clone@1.0.4": { + "integrity": "sha512-JQHZ2QMW6l3aH/j6xCqQThY/9OH4D/9ls34cgkUBiEeocRTU04tHfKPBsUK1PqZCUQM7GiA0IIXJSuXHI64Kbg==" + }, + "data-forge@1.10.2": { + "integrity": "sha512-VZv8NV5laRC+VXGkA6cccl5Hwkkbt1sUuphVPcICLMMhiRWzVcVEowfcaplhb/kzmDsuohpruzHZp3y5w9OnuA==", + "dependencies": [ + "@data-forge/serialization", + "dayjs", + "easy-table", + "json5", + "numeral", + "papaparse", + "typy" + ] + }, + "dayjs@1.11.13": { + "integrity": "sha512-oaMBel6gjolK862uaPQOVTA7q3TZhuSvuMQAAglQDOWYO9A91IrAOUJEyKVlqJlHE0vq5p5UXxzdPfMH/x6xNg==" + }, + "defaults@1.0.4": { + "integrity": "sha512-eFuaLoy/Rxalv2kr+lqMlUnrDWV+3j4pljOIJgLIhI058IQfWJ7vXhyEIHu+HtC738klGALYxOKDO0bQP3tg8A==", + "dependencies": [ + "clone" + ] + }, + "easy-table@1.1.0": { + "integrity": "sha512-oq33hWOSSnl2Hoh00tZWaIPi1ievrD9aFG82/IgjlycAnW9hHx5PkJiXpxPsgEE+H7BsbVQXFVFST8TEXS6/pA==", + "dependencies": [ + "wcwidth" + ] + }, + "event-target-shim@5.0.1": { + "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==" + }, + "events@3.3.0": { + "integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==" + }, + "ieee754@1.2.1": { + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==" + }, + "json5@2.2.3": { + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==" + }, + "n3@1.22.3": { + "integrity": "sha512-TAFTjk0ErUbvw65sWpvj86ombVMfB63SxsZXQnVC8Ms02rDbOiA26WlP3tilEnuh3LhUa5TPiB0FyoYsPZ/DmA==", + "dependencies": [ + "buffer", + "queue-microtask", + "readable-stream" + ] + }, + "numeral@2.0.6": { + "integrity": "sha512-qaKRmtYPZ5qdw4jWJD6bxEf1FJEqllJrwxCLIm0sQU/A7v2/czigzOb+C2uSiFsa9lBUzeH7M1oK+Q+OLxL3kA==" + }, + "papaparse@5.2.0": { + "integrity": "sha512-ylq1wgUSnagU+MKQtNeVqrPhZuMYBvOSL00DHycFTCxownF95gpLAk1HiHdUW77N8yxRq1qHXLdlIPyBSG9NSA==" + }, + "process@0.11.10": { + "integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==" + }, + "queue-microtask@1.2.3": { + "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==" + }, + "readable-stream@4.5.2": { + "integrity": "sha512-yjavECdqeZ3GLXNgRXgeQEdz9fvDDkNKyHnbHRFtOr7/LcfgBcmct7t/ET+HaCTqfh06OzoAxrkN/IfjJBVe+g==", + "dependencies": [ + "abort-controller", + "buffer", + "events", + "process", + "string_decoder" + ] + }, + "safe-buffer@5.2.1": { + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" + }, + "string_decoder@1.3.0": { + "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", + "dependencies": [ + "safe-buffer" + ] + }, + "typy@3.3.0": { + "integrity": "sha512-Du53deMF9X9pSM3gVXDjLBq14BUfZWSGKfmmR1kTlg953RaIZehfc8fQuoAiW+SRO6bJsP+59mv1tsH8vwKghg==" + }, + "undici-types@6.19.8": { + "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==" + }, + "wcwidth@1.0.1": { + "integrity": "sha512-XHPEwS0q6TaxcvG85+8EYkbiCux2XtWG2mkc47Ng2A77BQu9+DqIOJldST4HgPkuea7dvKSj5VgX3P1d4rW8Tg==", + "dependencies": [ + "defaults" + ] + } + }, "workspace": { "dependencies": [ "jsr:@std/assert@1" diff --git a/filter.ts b/filter.ts index cdf2875..2ee74c2 100644 --- a/filter.ts +++ b/filter.ts @@ -1,59 +1,49 @@ import { test_driver } from "./test_driver.ts"; -//test_driver(); - -//const dataForge = require('data-forge') +import type { Introspector,CallbackOutput,CallbackInput } from "./introspector.ts"; import * as dataForge from "npm:data-forge@1.10.2" -export function add_to_frame(results:any, - name:any, - value:any) { +export function add_to_frame(_results:string, + _name:string, + _value:string):void { console.log(name,value); } -export function find_calls(event:any, - filter:any) { +export function find_calls(_event:string, + _filter:string):void { } - -export interface Introspector { - (): any; - filter_current_value: any; - enter_test_driver:any - leave_test_driver:any - wrapper_rdf:any - debug:any -} - -export function test_frame(){ - console.log("hello"); - let empty_frame = new dataForge.DataFrame([]); - function filter_function_name(function_name:string) { - //console.log("filter"); - return true; +//(event: any) => DataFrame + +export function test_frame():void{ + console.log("hello test frame"); + const empty_frame = new dataForge.DataFrame([]); + + function filter_function_name(function_name:string):boolean { + console.log("filter"+function_name); + return true; + } + + // let visitor2 = function (event:CallbackInput) { + // return {name:"foo"} as CallbackOutput; + //} + + const visitor = function (_event: CallbackInput) : CallbackOutput{ + console.log("visitor"); + //function visit_function_name(function_name:string, function_value:any):void { + // add_to_frame(empty_frame,function_name, function_value); + //} + return function returnframe() { return empty_frame; }; + }; + + visitor.filter_current_value= filter_function_name; // save part of the callback + + visitor.debug= function(x:string):CallbackOutput{ + console.log("debug",x); + return {name:x}; } - var visitor = function (event:any) { - console.log("visitor"); - function visit_function_name(function_name:string, function_value:any) { - add_to_frame(empty_frame,function_name, function_value); - } - return empty_frame - }; - visitor.filter_current_value= filter_function_name; // save part of the callback - visitor.enter_test_driver= function(){ - //console.log("enter the test driver"); - } - visitor.debug= function(x:any){ - //console.log("debug",x); - } - visitor.wrapper_rdf= function(){ - //console.log("rdf"); - } - visitor.leave_test_driver= function(){ - //console.log("leave the test driver"); - } - test_driver(visitor); -}// test frame + test_driver(visitor); + console.log("frame count",empty_frame.count()); +}// test frame -//test_frame(); diff --git a/functions.ts b/functions.ts index d9cc5d4..5ecace7 100644 --- a/functions.ts +++ b/functions.ts @@ -1,3 +1,5 @@ + +import type { _Introspector, Callback } from "./introspector.ts"; export interface Functions { - [key: string]: any; + [key: string]: Callback; } diff --git a/introspector.ts b/introspector.ts index 3ff2b88..578eb8c 100644 --- a/introspector.ts +++ b/introspector.ts @@ -1,4 +1,23 @@ -export function isp_self(x: any) { +export type CallbackInput = { + name:string; +} +export type CallbackOutput = { + name:string; +} +export type Callback = (x: CallbackInput) => CallbackOutput; +export type StringCallback = (x: string) => CallbackOutput; +export type FilterFunctionCallback = (function_name: string) => boolean +//export type Example1 = (event: any) => DataFrame; +export interface Introspector { + (): Callback;// the default function + filter_current_value: FilterFunctionCallback; +// enter_test_driver:Callback +// leave_test_driver:Callback +// wrapper_rdf:Callback + debug:StringCallback +} + +export function isp_self(x: CallbackInput) :CallbackOutput { console.log("self"+ x); } diff --git a/main.ts b/main.ts index d52f783..8adcb80 100644 --- a/main.ts +++ b/main.ts @@ -7,4 +7,4 @@ if (import.meta.main) { console.log("Add 2 + 3 =", add(2, 3)); } -import { test_frame } from "./filter.ts"; \ No newline at end of file +//import { test_frame } from "./filter.ts"; \ No newline at end of file diff --git a/main_test.ts b/main_test.ts index 3d981e9..8651d1d 100644 --- a/main_test.ts +++ b/main_test.ts @@ -1,6 +1,29 @@ -import { assertEquals } from "@std/assert"; -import { add } from "./main.ts"; +//import { assertEquals } from "@std/assert"; +//import { add } from "./main.ts"; +import type { _Introspector, + CallbackOutput,CallbackInput } from "./introspector.ts"; +import { test_driver } from "./test_driver.ts"; +import { test_frame } from "./filter.ts"; -Deno.test(function addTest() { - assertEquals(add(2, 3), 5); +function foo(a:CallbackInput):CallbackOutput +{ + console.log(a); + return a; +} + + + +Deno.test(function driverTest() { + console.log("debug1"); + const callback =foo; + test_driver(callback); + console.log("debugb"); +}); +Deno.test(function frameTest() { + console.log("debug2"); + test_frame(); + console.log("debug3"); }); + + + diff --git a/main_test1.ts b/main_test1.ts new file mode 100644 index 0000000..cfb3db4 --- /dev/null +++ b/main_test1.ts @@ -0,0 +1,30 @@ +//import { assertEquals } from "@std/assert"; +//import { add } from "./main.ts"; +import type { _Introspector, + CallbackOutput,CallbackInput } from "./introspector.ts"; + +import { test_driver } from "./test_driver.ts"; +//import { test_frame } from "./filter.ts"; + +function foo(a:CallbackInput):CallbackOutput +{ + console.log(a); + return a; +} + +function main():void { + const callback =foo; + console.log("debug1"); + const a = test_driver(callback); + console.log("debugb",a); +} + +main(); + +//console.log("debug2"); +//test_frame(); +//console.log("debug3"); + + + + diff --git a/missing.ts b/missing.ts index debbd33..aa2054b 100644 --- a/missing.ts +++ b/missing.ts @@ -1,4 +1,6 @@ -export function missing(x: any) { +import type { RdfObject } from "./rdf.ts"; +import type { CallbackOutput } from "./introspector.ts"; +export function missing(x: RdfObject):CallbackOutput { if (x) { if (x._object) { if (x._object.id) { diff --git a/process.ts b/process.ts index fb9e733..4719ca4 100644 --- a/process.ts +++ b/process.ts @@ -1,4 +1,4 @@ import { test_driver } from "./test_driver.ts"; -let callback = function(){} +const callback = function(){} test_driver(callback); diff --git a/process_files.ts b/process_files.ts index 2b09bc2..1fb109a 100644 --- a/process_files.ts +++ b/process_files.ts @@ -1,35 +1,37 @@ -import { Functions } from "./functions.ts" -import { missing } from "./missing.ts" -import { associate_cache, save_cache } from "./cache.ts" +//import type { Functions } from "./functions.ts" +//import type { missing } from "./missing.ts" +//import type { +//associate_cache, +//save_cache } from "./cache.ts" //const fs = require('node:fs'); import * as fs from 'node:fs'; function process_chunk(line:string) { const chunk = line; - let obj = JSON.parse(chunk) + const obj = JSON.parse(chunk) return obj; } -export interface iFile { +//export interface iFile { //children: iFrame[]; -}; - -function file_test(f: iFile){ - function report_child(previousValue: iFile, currentValue: iFile, currentIndex: number, array: iFile[]): iFile { - let sum = 0; - if (currentValue){ - sum = sum + file_test(currentValue); // add the children - } - let ret = {value: sum} as iFile // return a new object with just the value - return ret; - } - // let res = f.children.reduce(report_child,{} as iFile); //recurse - //let res = 0; - return 0; -} - -function createRunningSumFunctor(f:any) { - let objects:object[] = []; +//}; + +// function file_test(f: iFile){ +// function report_child(previousValue: iFile, currentValue: iFile, currentIndex: number, array: iFile[]): iFile { +// let sum = 0; +// if (currentValue){ +// sum = sum + file_test(currentValue); // add the children +// } +// let ret = {value: sum} as iFile // return a new object with just the value +// return ret; +// } +// // let res = f.children.reduce(report_child,{} as iFile); //recurse +// //let res = 0; +// return 0; +// } + +function createRunningSumFunctor(_f:string) { + //let objects:object[] = []; let sum:string = ""; function process(value?: string): number { @@ -38,22 +40,22 @@ function createRunningSumFunctor(f:any) { } return 0; }; - function report(): number { - let obj = JSON.parse(sum) - return obj; - }; - return [process,report]; + function report(): number { + const obj = JSON.parse(sum) + return obj; + }; + return [process,report]; } function process_data(filename:string, data:string) { - let [sumfunc,report_func] = createRunningSumFunctor(process_chunk); + const [sumfunc,report_func] = createRunningSumFunctor(process_chunk); if (data) { data.split("\n").forEach(sumfunc); } - let sum:any = report_func() + const sum:number = report_func() - function reducesum(value:any, parent_name1:string){ + function reducesum(value:number, parent_name1:string){ let name1 = parent_name1 + "/" + "unknown"; @@ -63,7 +65,7 @@ function process_data(filename:string, data:string) { //console.log("reducesum",value); - function report3(empty:any,value:any, parent_name:string){ + function report3(_empty:number,value:number, parent_name:string){ //console.log("report3val:",value); if (value){ @@ -73,10 +75,10 @@ function process_data(filename:string, data:string) { } if (value.contents) { console.log("contents2:",value.contents.length, name); - function wrapper(empty:any,value:any){ - report3(empty,value,name); - } - value.contents.reduce(wrapper); + const wrapper=(empty:number,value:number)=>{ + report3(empty,value,name); + }; + value.contents.reduce(wrapper); } else { console.log("file:",name); @@ -96,20 +98,20 @@ function process_data(filename:string, data:string) { if (value.contents) { // console.log("contents len:",value.contents.length); console.log("contents name, len:",name1, value.contents.length); - function wrapper(empty:any,value:any){ - report3(empty,value,name1); - } - value.contents.reduce(wrapper); + const wrapper = (empty:number,value:number)=>{ + report3(empty,value,name1); + } + value.contents.reduce(wrapper); } } } - function wrapper(value:any){ + function wrapper(value:number){ reducesum(value, ""); } sum.reduce(wrapper); - function report(value:any,index:any){ + function report(value:number,index:number){ console.log("report1",value,index); } Object.getOwnPropertyNames(sum).forEach(report); @@ -118,16 +120,16 @@ function process_data(filename:string, data:string) { } function createProcessor(filename:string) { - return function(err:any, data:string) { + return function(_err:number, data:string) { return process_data(filename, data); } } function tree_json_file_parser(filename:string) { - console.log("file: " + filename); - let functor = createProcessor(filename); - fs.readFile(filename, "utf-8",functor); - return "json_report:"; + console.log("file: " + filename); + const functor = createProcessor(filename); + fs.readFile(filename, "utf-8",functor); + return "json_report:"; } export function read_file() { diff --git a/process_statements.ts b/process_statements.ts index a565715..9aa2c97 100644 --- a/process_statements.ts +++ b/process_statements.ts @@ -1,23 +1,30 @@ -import { RdfObject } from "./rdf.ts"; +import type { RdfObject } from "./rdf.ts"; import { find_function, set_function } from "./rdf_callbacks.ts"; import { missing } from "./missing.ts"; +import type { Introspector } from "./introspector.ts"; -export function process_statement (z:any,y:RdfObject,callback:any) { +export function process_statement (_z:Error,y:RdfObject,callback:Introspector) { //console.log(z); - if (y) { + if (y) { + if (callback){ + if (callback.debug) { callback.debug("process_statement"); - const obj:string = y._object.id; - const ofun = find_function(obj,callback); // isp_report - const pred:string = y._predicate.id; - const pfun = find_function(pred,callback); // type - const subj:string = y._subject.id; - if (pfun) { - if (ofun) { - callback.debug("pfun"); - pfun(ofun, subj, callback); // type(isp_report, data - } else { - set_function(obj,missing); - } + } + } + const obj:string = y._object.id; + const ofun = find_function(obj,callback); // isp_report + const pred:string = y._predicate.id; + const pfun = find_function(pred,callback); // type + const subj:string = y._subject.id; + if (pfun) { + if (ofun) { + if (callback.debug) { + callback.debug("pfun"); } + pfun(ofun, subj, callback); // type(isp_report, data + } else { + set_function(obj,missing); + } } + } } diff --git a/rdf_callbacks.ts b/rdf_callbacks.ts index d0378ae..c31d087 100644 --- a/rdf_callbacks.ts +++ b/rdf_callbacks.ts @@ -1,7 +1,8 @@ -import { Functions } from "./functions.ts"; +import type { Functions } from "./functions.ts"; import { statement } from "./statement.ts"; import { isp_clinic_report } from "./clinic_report.ts"; import { isp_self } from "./introspector.ts"; +import type { _Introspetor,CallbackOutput } from "./introspector.ts"; import { rdf_type } from "./rdf_type.ts"; const functions: Functions = { @@ -11,12 +12,12 @@ const functions: Functions = { 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type': rdf_type } -export function find_function(x:string, callback:any):any { +export function find_function(x:string, _callback:Introspector):CallbackOutput { // skip callback for now return functions[x]; } -export type Callback = (x: any) => void; -export function set_function(x:string,y:Callback):any { +export type Callback = (x: string) => void; +export function set_function(x:string,y:Callback):Callback { return functions[x]=y; } diff --git a/rdf_type.ts b/rdf_type.ts index 08a7864..63dd235 100644 --- a/rdf_type.ts +++ b/rdf_type.ts @@ -1,14 +1,17 @@ -type TypeObjectCallback = (subject:string,callback:any) => string; -export function rdf_type(type_function: TypeObjectCallback, subj:string,callback:any):any { +import type { Introspector,CallbackOutput } from "./introspector.ts"; +type TypeObjectCallback = (subject:string,callback:Introspector) => string; +export function rdf_type(type_function: TypeObjectCallback, subj:string,callback:Introspector):CallbackOutput { //const obj = obj; //console.log("rdf_type type_obj: " + type_obj); // console.log("type_obj:" + typeof(type_obj) ); //console.log("rdf type subj:" + typeof(subj) ); - if (typeof(type_function)=="function") { - callback.debug("rdf_type"); - const instance = type_function(subj,callback); - //console.log("rdf_type instance:" + type_function + " result: "+ instance ); - return instance; - } + if (typeof(type_function)=="function") { + if(callback.debug){ + callback.debug("rdf_type"); + } + const instance = type_function(subj,callback); + //console.log("rdf_type instance:" + type_function + " result: "+ instance ); + return instance; + } } diff --git a/statement.ts b/statement.ts index c5437a6..dd66f10 100644 --- a/statement.ts +++ b/statement.ts @@ -2,6 +2,6 @@ interface Any { name:string; }; -export function statement(x:Any):string { +export function statement(_x:Any):string { return "fixme" } diff --git a/test_driver.ts b/test_driver.ts index d96c762..ead9143 100644 --- a/test_driver.ts +++ b/test_driver.ts @@ -1,20 +1,32 @@ -//const N3 = require('n3'); import * as N3 from "npm:n3@1.22.3" -import * as fs from 'node:fs'; -//const fs = require('node:fs'); - +//import * as fs from 'node:fs'; import { process_statement } from "./process_statements.ts"; -// (z:any,y:RdfObject) { +//import type { Callback } from "./introspector.ts"; + +import type { rdf_type } from "./rdf_type.ts"; +type Error=string; + +export function test_driver(callback:Introspector) { +// callback.enter_test_driver(); + const parser = new N3.Parser(); + // function chunk(chunk) { + // console.log(chunk.toString()); + // }; + // function end() { + // console.log("END"); + // } -export function test_driver(callback:any) { - callback.enter_test_driver(); - const parser = new N3.Parser(); - const rdfStream = fs.createReadStream('introspector.ttl'); - function wrapper(x:any,y:any){ - callback.wrapper_rdf(); -// console.log("wrapper1"); - process_statement(x,y,callback); - } - const quads = parser.parse(rdfStream, wrapper); - callback.leave_test_driver(); + + function wrapper(x:Error,y:rdf_type //,prefixes:any + ){ + //callback.wrapper_rdf(); + //console.log("wrapper1",x,y,prefixes); + process_statement(x,y,callback); + } + + const bytes = Deno.readFileSync("introspector.ttl"); + const decoder = new TextDecoder().decode(bytes); + const ret = parser.parse(decoder, wrapper); + console.log("finished",ret); + // rdfStream.close(); }