Removed unused variable.

Removed unused variable.

import module namespace http-client = "http://zorba.io/modules/http-client";
import module namespace request = "http://www.28msec.com/modules/http-request";
import module namespace response = "http://www.28msec.com/modules/http-response";

declare %an:nondeterministic function local:test-spreadsheet($expected as integer, $params as string) as atomic
{
    let $actual as integer := count(parse-json(http-client:get("http://" || request:server-name() || ":" || request:server-port() || "/v1/_queries/public/api/spreadsheet-for-component.jq?_method=POST" || $params).body.content).TableSet[].TableCells.Facts[][].Value)
    return if ($actual eq $expected) then true else "false [Actual="||$actual||", Expected="||$expected ||"]"
};

declare %an:sequential function local:check($o as object) as object
{
    if (not(every $k in (keys($o) ! $o.$$) satisfies ($k instance of boolean and $k)))
    then {
            response:status-code(500);
            $o
    } else
            $o
};

local:check({
    cocacola: local:test-spreadsheet(1, "&ticker=ko"),
    tickerrole: local:test-spreadsheet(60, "&ticker=ko&networkIdentifier=http://www.thecocacolacompany.com/role/ConsolidatedStatementsOfIncome"),
    tickerconcept: local:test-spreadsheet(76, "&ticker=ko&fiscalYear=2013&concept=us-gaap:Assets"),
    tickerfyfprole: local:test-spreadsheet(70, "&ticker=ko&fiscalYear=2012&fiscalPeriod=Q1&networkIdentifier=http://www.thecoca-colacompany.com/role/CondensedConsolidatedBalanceSheets")
})

import module namespace http-client = "http://zorba.io/modules/http-client";
import module namespace request = "http://www.28msec.com/modules/http-request";
import module namespace response = "http://www.28msec.com/modules/http-response";

declare %an:nondeterministic function local:test-spreadsheet($expected as integer, $params as string) as atomic
{
    let $actual as integer := count(parse-json(http-client:get("http://" || request:server-name() || ":" || request:server-port() || "/v1/_queries/public/api/spreadsheet-for-component.jq?_method=POST" || $params).body.content).TableSet[].TableCells.Facts[][].Value)
    return if ($actual eq $expected) then true else "false [Actual="||$actual||", Expected="||$expected ||"]"
};

declare %an:sequential function local:check($o as object) as object
{
    if (not(every $k in (keys($o) ! $o.$$) satisfies ($k instance of boolean and $k)))
    then {
            response:status-code(500);
            $o
    } else
            $o
};

let $db := request:param-values("db", "all-sec-filings")
return local:check({
    cocacola: local:test-spreadsheet(1, "&ticker=ko"),
    tickerrole: local:test-spreadsheet(60, "&ticker=ko&networkIdentifier=http://www.thecocacolacompany.com/role/ConsolidatedStatementsOfIncome"),
    tickerconcept: local:test-spreadsheet(76, "&ticker=ko&fiscalYear=2013&concept=us-gaap:Assets"),
    tickerfyfprole: local:test-spreadsheet(70, "&ticker=ko&fiscalYear=2012&fiscalPeriod=Q1&networkIdentifier=http://www.thecoca-colacompany.com/role/CondensedConsolidatedBalanceSheets")
})


Added bootstrap for report-elements.jq api endpoint

The endpoint is supposed to be used for type-ahead functionality first. It will later allow users to retrieve information about report-elements of a filing.

import module namespace companies = "http://xbrl.io/modules/bizql/profiles/sec/companies";
import module namespace sec-fiscal = "http://xbrl.io/modules/bizql/profiles/sec/fiscal/core";
import module namespace core = "http://xbrl.io/modules/bizql/profiles/sec/core";
import module namespace response = "http://www.28msec.com/modules/http-response";
import module namespace request = "http://www.28msec.com/modules/http-request";
import module namespace session = "http://apps.28.io/session";
import module namespace archives = "http://xbrl.io/modules/bizql/archives";
import module namespace entities = "http://xbrl.io/modules/bizql/entities";

import module namespace mongo = "http://www.28msec.com/modules/mongodb";
import module namespace credentials = "http://www.28msec.com/modules/credentials";

import module namespace csv = "http://zorba.io/modules/json-csv";

declare namespace concepts = "http://www.28msec.com/modules/bizql/concepts";

declare function local:filings(
    $ciks,
    $tags,
    $tickers,
    $sics,
    $fp,
    $fy)
{
    let $entities := (
        companies:companies($ciks),
        companies:companies-for-tags($tags),
        companies:companies-for-tickers($tickers),
        companies:companies-for-SIC($sics)
    )
    for $entity in $entities
    for $fy in distinct-values(
                for $fy in $fy
                return
                    switch ($fy)
                    case "LATEST" return
                        for $p in $fp
                        return
                            if ($p eq "FY")
                            then sec-fiscal:latest-reported-fiscal-period($entity, "10-K").year
                            else sec-fiscal:latest-reported-fiscal-period($entity, "10-Q").year
                    case "ALL" return (2010 to 2015) (: temporary solution until next release :)
                    default return $fy
                )
    for $fp in $fp
    return sec-fiscal:filings-for-entities-and-fiscal-periods-and-years($entity, $fp, $fy ! ($$ cast as integer))
};

declare function local:concepts-for-archives($aids)
{
    let $conn :=
      let $credentials := credentials:credentials("MongoDB", "xbrl")
      return
        try {
            mongo:connect($credentials)
        } catch mongo:* {
            error(QName("concepts:CONNECTION-FAILED"), $err:description)
        }
    for $aid in $aids
    return
        mongo:find($conn, "concepts",
        {
            "Archive": $aid
        })
};

let $format      := lower-case((request:param-values("format"), substring-after(request:path(), ".jq."))[1])
let $ciks        := distinct-values(companies:eid(request:param-values("cik")))
let $tags        := distinct-values(request:param-values("tag") ! upper-case($$))
let $tickers     := distinct-values(request:param-values("ticker"))
let $sics        := distinct-values(request:param-values("sic"))
let $fiscalYears := distinct-values(
                        for $y in request:param-values("fiscalYear", "LATEST")
                        return
                            if ($y eq "LATEST" or $y eq "ALL")
                            then $y
                            else if ($y castable as integer)
                            then $y cast as integer
                            else ()
                    )
let $fiscalPeriods := distinct-values(let $fp := request:param-values("fiscalPeriod", "FY")
                      return
                        if (($fp ! lower-case($$)) = "all")
                        then ("Q1", "Q2", "Q3", "Q4", "FY")
                        else $fp)
let $aids        := archives:aid(request:param-values("aid"))
let $archives    := (
                        local:filings($ciks, $tags, $tickers, $sics, $fiscalPeriods, $fiscalYears),
                        archives:archives($aids)
                    )
let $entities    := entities:entities($archives.Entity)
let $onlyNames   := let $o := request:param-values("onlyNames")[1] return if (exists($o)) then ($o cast as boolean) else false
return
    if (session:only-dow30($entities) or session:valid())
        then {
            let $concepts := let $concepts := local:concepts-for-archives($archives._id)
                             return if ($onlyNames) then distinct-values($concepts.Name) else $concepts
            return
            switch ($format)
            case "xml" return {
                response:serialization-parameters({"omit-xml-declaration" : false, indent : true });
                ()
            }
            case "text" case "csv" return {
                response:content-type("text/csv");
                response:header("Content-Disposition", "attachment; filename=facts.csv");
                ()
            }
            case "excel" return {
                response:content-type("application/vnd.ms-excel");
                response:header("Content-Disposition", "attachment; filename=fact.csv");
                ()
            }
            default return {
                response:content-type("application/json");
                response:serialization-parameters({"indent" : true});
                {|
                    session:comment("json"),
                    { Concepts : [ $concepts ] }
                |}
            }
        }
        else {
            response:status-code(401);
            session:error("accessing filings of an entity that is not in the DOW30", $format)
        }

error: pathspec 'queries/public/api/report-elements.jq' did not match any file(s) known to git


Add new test project

Add new test project

error: pathspec 'tests/test_project/public/foo.jq' did not match any file(s) known to git


Create rxnfilter.jq

Create rxnfilter.jq

# Require jq > 1.4
# Takes open.fda.gov drug event JSON and transforms into compact flat linear records suitable for Perl recs-tocsv

#start from the .results array
.results

#Creates new object with .safetyreportid string and .patient.reaction array
|map(with_entries(select(.key == "safetyreportid")) + (.patient.reaction[]))

#Iterates through array of objects to return a stream of objects instead of a single array
|.[]

error: pathspec 'rxnfilter.jq' did not match any file(s) known to git


:pencil: Add tests.

:pencil: Add tests.

import module namespace response = "http://www.28msec.com/modules/http-response";
import module namespace test = "http://apps.28.io/test";
import module namespace config = "http://apps.28.io/config";
import module namespace backend = "http://apps.28.io/backend";

declare variable $local:expected as object :=
    {
      "byconcept" : [ "1001000 - Statement - Consolidated Statements Of Operations", "1002000 - Statement - Consolidated Statements of Comprehensive Income", "1004000 - Statement - Consolidated Statements Of Cash Flows", "2401402 - Disclosure - Summary Of Business Segment Data (Details)", "2405403 - Disclosure - Earnings Per Share (Schedule Of Weighted-Average Number Of Shares Outstanding Used To Compute Earnings Per Share) (Details)", "2424403 - Disclosure - Quarterly Financial Data (Schedule Of Quarterly Financial Data) (Details)", "1002000 - Statement - Consolidated Statements of Income", "1003000 - Statement - Consolidated Statements of Comprehensive Income", "1005000 - Statement - Consolidated Statements of Changes in Stockholders' Equity", "1006000 - Statement - Consolidated Statements of Cash Flows", "2429403 - Disclosure - Earnings Per Share (Details)", "2438402 - Disclosure - International Operations (Details)", "2440402 - Disclosure - Parent Company - Statements of Income (Details)", "2440404 - Disclosure - Parent Company - Statements of Cash Flows (Details2)", "1001000 - Statement - CONSOLIDATED STATEMENTS OF INCOME", "1005000 - Statement - CONSOLIDATED STATEMENTS OF SHAREOWNERS' EQUITY", "1001000 - Statement - Consolidated Income Statements", "000100 - Statement - Consolidated Statement Of Income", "041101 - Disclosure - Earnings Per Share (Details)", "041702 - Disclosure - Disclosures About Segments And Related Information (Schedule Of Segments And Related Information) (Details)", "100020 - Statement - Statement of Earnings", "100030 - Statement - Statement of Comprehensive Income", "100040 - Statement - Statement of Changes in Shareowners' Equity", "100060 - Statement - Statement of Cash Flows", "401500 - Disclosure - Shareowners' Equity (Details)", "402800 - Disclosure - Quarterly Information (unaudited) (Details)", "1001000 - Statement - Consolidated Statements of Income", "1004000 - Statement - Consolidated Statements of Cash Flows", "1005000 - Statement - Consolidated Statements of Stockholders' Equity", "1001000 - Statement - Consolidated Statement of Income", "1002000 - Statement - Consolidated Statement of Comprehensive Income", "1004000 - Statement - Consolidated Statement of Cash Flows", "1005000 - Statement - Consolidated Statement of Shareholders Equity", "2414402 - Disclosure - Quarterly Results (Detail)", "1001000 - Statement - CONSOLIDATED STATEMENTS OF EARNINGS", "2418402 - Disclosure - EARNINGS PER SHARE (DETAILS)", "2447402 - Disclosure - QUARTERLY RESULTS (UNAUDITED) (DETAILS)", "1005000 - Statement - Consolidated Statement of Equity", "2404402 - Disclosure - Summarized Financial Data - Chevron U.S.A. Inc. (Details)", "2405402 - Disclosure - Summarized Financial Data - Chevron Transport Corporation (Details)", "2410402 - Disclosure - Operating Segments and Geographic Data (Details)", "2427402 - Disclosure - Earnings Per Share (Details)", "1001000 - Statement - Consolidated Statement of Operations", "2404402 - Disclosure - Earnings Per Share (Details)", "2410403 - Disclosure - Equity (Changes in Noncontrolling Interests) (Details)", "2420404 - Disclosure - Segment Financial Data (Selected Quarterly Financial Data) (Details)", "2421402 - Disclosure - Selected Quarterly Financial Data - Unaudited (Details)", "1001000 - Statement - Consolidated Statements Of Income (Audited)", "1002000 - Statement - Consolidated Statements Of Comprehensive Income (Audited)", "2415402 - Disclosure - Quarterly Financial Data (Unaudited) (Quarterly Financial Data) (Details)", "1002000 - Statement - Consolidated Statements of Earnings", "1004000 - Statement - Consolidated Statements of Equity", "2419402 - Disclosure - Selected Quarterly Financial Data (Unaudited) (Details)", "1004000 - Statement - Consolidated Statement of Equity", "2420402 - Disclosure - Earnings Per Share - Calculations of Earnings Per Share (Detail)", "1001000 - Statement - Consolidated Statements Of Income", "1005000 - Statement - Consolidated Statements of Shareholders' Equity", "1002000 - Statement - Consolidated Statements Of Earnings", "1004000 - Statement - Consolidated Statements of Stockholders' Equity", "1005000 - Statement - Consolidated Statements Of Cash Flows", "2415402 - Disclosure - Quarterly Financial Data (Unaudited) (Details)", "1003000 - Statement - Consolidated Statements of Operations", "1005000 - Statement - Consolidated Statements of Changes in Shareholders' Equity", "2429403 - Disclosure - Quarterly Financial Data Quarterly Financial Data (Unaudited) (Details)", "2430405 - Disclosure - Schedule I Condensed Income Statement (Details)", "000100 - Statement - Consolidated Statements Of Income", "000400 - Statement - Consolidated Statements Of Changes In Stockholders' Equity", "041801 - Disclosure - Quarterly Financial Information (Unaudited) (Quarterly Financial Results) (Details)", "1003000 - Statement - Consolidated Statements Of Operations", "1004000 - Statement - Consolidated Statements of Comprehensive Income", "1006000 - Statement - Consolidated Statements Of Equity", "2420402 - Disclosure - Net Income per Share (Calculation Of Basic And Diluted Net Income Per Share) (Detail)", "2475402 - Disclosure - Quarterly Financial Summary (Detail)", "000011 - Statement - Consolidated Statement of Income", "004010 - Disclosure - Significant Accounting Policies (Details)", "004170 - Disclosure - Quarterly Data (Unaudited) (Details)", "1003 - Statement - Income Statements", "1004 - Statement - Comprehensive Income Statements", "1008 - Statement - Cash Flows Statements", "1009 - Statement - Stockholders' Equity Statements", "1055 - Disclosure - Basic and Diluted Earnings Per Share (Detail)", "1121 - Disclosure - Quarterly Information (Unaudited) (Detail)", "010020 - Statement - Consolidated Statements of Income", "010035 - Statement - Consolidated Statements of Comprehensive Income", "010060 - Statement - Consolidated Statements of Cash Flows", "010080 - Statement - Consolidated Statements of Shareholders' Equity", "042600 - Disclosure - Parent Company (Details)", "042620 - Disclosure - Parent Company (Details 2)", "042700 - Disclosure - Quarterly Financial Data (Unaudited) (Details)", "1003 - Statement - Consolidated Statements of Income", "1008 - Statement - Consolidated Statements of Changes in Equity", "1118 - Disclosure - Schedule of Quarterly Financial Information (Detail)", "0110 - Statement - Consolidated Statements of Earnings", "0120 - Statement - Consolidated Statements of Comprehensive Income", "0140 - Statement - Consolidated Statements of Changes in Shareholders' Equity", "0150 - Statement - Consolidated Statements of Cash Flows", "0625 - Disclosure - Business Segments (Details)", "0630 - Disclosure - Parent Company (Details)", "06302 - Disclosure - Parent Company (Details 2)", "1002000 - Statement - CONSOLIDATED STATEMENTS OF OPERATIONS", "1004000 - Statement - CONSOLIDATED STATEMENTS OF CHANGES IN EQUITY", "2436402 - Disclosure - Basic and Diluted Earnings Per Share (Detail)" ]
    };

declare %an:nondeterministic function local:test-sections($expected as integer, $params as object) as item
{
    let $endpoint := "sections"
    let $request := test:invoke($endpoint, $params)
    let $actual as integer := count($request[2].Sections[])
    let $status as integer := $request[1]
    return test:assert-eq($expected, $actual, $status, test:url($endpoint, $params))
};

declare %an:sequential function local:test-sections-result($expected as array, $params as object) as item
{
    let $endpoint := "sections"
    let $request := test:invoke($endpoint, $params)
    let $actual as array := [ distinct-values($request[2].Sections[].Section) ]
    let $status as integer := $request[1]
    return test:assert-eq-array($expected, $actual, $status, test:url($endpoint, $params))
};

declare %an:nondeterministic function local:test-generic-components($expected as integer, $params as object) as item
{
    let $endpoint := "sections"
    let $request := test:invoke($endpoint, $params)
    let $actual as integer := count($request[2].Sections[])
    let $status as integer := $request[1]
    return test:assert-eq($expected, $actual, $status, test:url($endpoint, $params))
};

declare %an:sequential function local:check($o as object) as object
{
    if (not(every $k in (keys($o) ! $o.$$) satisfies ($k instance of boolean and $k)))
    then {
            response:status-code(500);
            $o
    } else
            $o
};

local:check({
    cocacola: local:test-sections(94, {
        ticker:"ko",
        fiscalYear: "2013",
        fiscalPeriod: "FY"
    }),
    cocacola-implied: local:test-sections(55, {
        ticker:"ko",
        fiscalYear: "2013",
        fiscalPeriod: "FY",
        hypercube: "xbrl28:ImpliedTable"
    }),
    cocacolaincome: local:test-sections(1, {
        ticker:"ko",
        section:"http://www.thecocacolacompany.com/role/ConsolidatedStatementsOfIncome",
        fiscalYear: "2013",
        fiscalPeriod: "FY"
    }),
    cocacolaincome-q4: local:test-sections(1, {
        ticker:"ko",
        section:"http://www.thecocacolacompany.com/role/ConsolidatedStatementsOfIncome",
        fiscalYear: "2013",
        fiscalPeriod: "Q4"
    }),
    byconcept: local:test-sections-result($local:expected.byconcept, {
        tag:"DOW30",
        concept:"us-gaap:NetIncomeLoss",
        fiscalYear: "2013",
        fiscalPeriod: "FY"
    }),
    byfyfp: local:test-sections(1, {
        ticker:"ko",
        fiscalYear:"2012",
        fiscalPeriod:"Q1",
        section:"http://www.thecoca-colacompany.com/role/CondensedConsolidatedBalanceSheets"
    }),
    byfyfplowercase: local:test-sections(1, {
        ticker:"ko",
        fiscalYear:"2012",
        fiscalPeriod:"q2",
        section: "http://www.thecoca-colacompany.com/role/CondensedConsolidatedBalanceSheets"
    }),
    generic: local:test-generic-components(1, {
      profile-name: "generic",
      aid: "0000021344-14-000008",
      section: "http://www.thecocacolacompany.com/role/DocumentAndEntityInformationDocument"
    }),
    generic-aid: local:test-generic-components(95, {
      profile-name: "generic",
      aid: "0000021344-14-000008"
    }),
    generic-aid-with-tables: if(test:is-dow30()) then true else local:test-generic-components(72, {
      profile-name: "generic",
      aid: "0001214659-13-001731"
    }),
    platinumre: if(test:is-dow30()) then true else test:invoke-and-assert-deep-equal(
      "sections",
      {aid:"0001171500-15-000007"},
      function($b as item*) as item* { count($b.Components[]) },
      76
    ),
    example1: test:invoke-and-assert-deep-equal(
      "sections",
      {aid:"0000021344-13-000039"},
      function($b as item*) as item* { [ trim($b.Sections[], ("ReportElements", "Components", "ValidationErrors")) ] },
      test:get-expected-result("secxbrl/sections-expected1.jq"),
      { NoArrayOrder: true }
    ),
    example2: test:invoke-and-assert-deep-equal(
      "sections",
      {
        ticker:"ko",
        fiscalYear: "2013",
        fiscalPeriod: "FY"
      },
      function($b as item*) as item* {
        [ trim(
          $b.Sections[],
          ("ReportElements", "Components", "ValidationErrors")
        ) ]
      },
      test:get-expected-result("secxbrl/sections-expected2.jq"),
      { NoArrayOrder: true }
    ),
    url: test:invoke-and-assert-deep-equal(
      "sections",
      {aid:"0000021344-13-000039"},
      function($b as item*) as item* {
        project(
          $b.Sections[]
            [$$.SectionURI = "http://www.thecoca-colacompany.com/role/DocumentAndEntityInformation"],
          ("ReportElements", "Components")
        )
      },
      {
        "ReportElements" : backend:url("report-elements", {
            token: $config:test-token,
            aid: "0000021344-13-000039",
            format: "json",
            section: "http://www.thecoca-colacompany.com/role/DocumentAndEntityInformation",
            profile-name: "sec"
            }),
        "Components" : backend:url("components", {
            token: $config:test-token,
            aid: "0000021344-13-000039",
            format: "json",
            section: "http://www.thecoca-colacompany.com/role/DocumentAndEntityInformation",
            profile-name: "sec"
            })
      },
      { NoArrayOrder: true }
    )
})

error: pathspec 'queries/public/test/secxbrl/sections.jq' did not match any file(s) known to git


:white_check_mark: add test for non existing entity error.

import module namespace response = "http://www.28msec.com/modules/http-response";
import module namespace test = "http://apps.28.io/test";

declare %an:nondeterministic function local:test-non-existing-entity() as item
{
    let $endpoint := "facts"
    let $params := {
        concept: [ "tse-ed-t:DividendPerShare" ],
        eid: "http://www.example.or.jp/doesntexist 666",
        fiscalYear: 2013
    }
    let $res as item* := test:invoke($endpoint, $params)
    let $status as integer := $res[1]
    let $errorCode as string? := $res[2].code
    return if($status eq 500 and $errorCode eq "ENTITY_NOT_FOUND") then true else {
        url: test:url($endpoint, $params),
        unexpectedResponse: $res[2],
        expected: "Error code: 500 - ENTITY_NOT_FOUND"
    }
};

test:check-all-success({
    entityNotFound: local:test-non-existing-entity()
})

error: pathspec 'queries/public/test/edinet/facts.jq' did not match any file(s) known to git


minor improvement

minor improvement

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/ekho/jq-tools.git/'


fixed tests (no dei facts in qtd, therefore no Tradingsymbol).

import module namespace response = "http://www.28msec.com/modules/http-response";
import module namespace test = "http://apps.28.io/test";

declare %an:nondeterministic function local:test-spreadsheet($expected as integer, $params as object) as item
{
    let $endpoint := "spreadsheet-for-report"
    let $request := test:invoke($endpoint, $params)
    let $actual as integer := count($request[2].TableSet[].TableCells.Facts[][].Value)
    let $status as integer := $request[1]
    return test:assert-eq($expected, $actual, $status, test:url($endpoint, $params))
};

declare %an:nondeterministic function local:test-report-does-not-exist($params as object) as item
{
    let $endpoint := "spreadsheet-for-report"
    let $request := test:invoke($endpoint, $params)
    let $status as integer := $request[1]
    return if ($status eq 404) then true else { url: test:url($endpoint, $params), unexpectedResponse: $request[2] }
};

declare %an:sequential function local:check($o as object) as object
{
    if (not(every $k in (keys($o) ! $o.$$) satisfies ($k instance of boolean and $k)))
    then {
            response:status-code(500);
            $o
    } else
            $o
};

local:check({
    cocacola: local:test-spreadsheet(96, {
        report:"FundamentalAccountingConcepts",
        ticker:"ko",
        fiscalYear:"2013",
        fiscalPeriod:"Q1"}),
    tickerrole: local:test-spreadsheet(96, {
        report:"FundamentalAccountingConcepts",
        ticker:"ko",
        fiscalYear:"2012",
        fiscalPeriod:"Q1"}),
    tickerconcept: local:test-spreadsheet(384, {
        report:"FundamentalAccountingConcepts",
        ticker:"ko",
        fiscalYear:"2012",
        fiscalPeriod:"ALL",
        fiscalPeriodType:["instant", "YTD"]
    }),
    tickerconcept-qtd: local:test-spreadsheet(196, {
        report:"FundamentalAccountingConcepts",
        ticker:"ko",
        fiscalYear:"2012",
        fiscalPeriod:"ALL",
        fiscalPeriodType:["instant", "QTD"]
    }),
    tickerfyfprole: local:test-spreadsheet(193, {
        report:"FundamentalAccountingConcepts",
        ticker:["ko","wmt"],
        fiscalYear:"2013",
        fiscalPeriod:"FY",
        fiscalPeriodType:["instant", "YTD"],
        eliminate:"true"}),
    reportDoesntExist: local:test-report-does-not-exist({
        report:"report-not-found",
        ticker:"MSFT",
        fiscalYear:"ALL",
        fiscalPeriod:"FY"})
})

import module namespace response = "http://www.28msec.com/modules/http-response";
import module namespace test = "http://apps.28.io/test";

declare %an:nondeterministic function local:test-spreadsheet($expected as integer, $params as object) as item
{
    let $endpoint := "spreadsheet-for-report"
    let $request := test:invoke($endpoint, $params)
    let $actual as integer := count($request[2].TableSet[].TableCells.Facts[][].Value)
    let $status as integer := $request[1]
    return test:assert-eq($expected, $actual, $status, test:url($endpoint, $params))
};

declare %an:nondeterministic function local:test-report-does-not-exist($params as object) as item
{
    let $endpoint := "spreadsheet-for-report"
    let $request := test:invoke($endpoint, $params)
    let $status as integer := $request[1]
    return if ($status eq 404) then true else { url: test:url($endpoint, $params), unexpectedResponse: $request[2] }
};

declare %an:sequential function local:check($o as object) as object
{
    if (not(every $k in (keys($o) ! $o.$$) satisfies ($k instance of boolean and $k)))
    then {
            response:status-code(500);
            $o
    } else
            $o
};

local:check({
    cocacola: local:test-spreadsheet(96, {
        report:"FundamentalAccountingConcepts",
        ticker:"ko",
        fiscalYear:"2013",
        fiscalPeriod:"Q1"}),
    tickerrole: local:test-spreadsheet(96, {
        report:"FundamentalAccountingConcepts",
        ticker:"ko",
        fiscalYear:"2012",
        fiscalPeriod:"Q1"}),
    tickerconcept: local:test-spreadsheet(384, {
        report:"FundamentalAccountingConcepts",
        ticker:"ko",
        fiscalYear:"2012",
        fiscalPeriod:"ALL",
        fiscalPeriodType:["instant", "YTD"]
    }),
    tickerconcept-qtd: local:test-spreadsheet(200, {
        report:"FundamentalAccountingConcepts",
        ticker:"ko",
        fiscalYear:"2012",
        fiscalPeriod:"ALL",
        fiscalPeriodType:["instant", "QTD"]
    }),
    tickerfyfprole: local:test-spreadsheet(193, {
        report:"FundamentalAccountingConcepts",
        ticker:["ko","wmt"],
        fiscalYear:"2013",
        fiscalPeriod:"FY",
        fiscalPeriodType:["instant", "YTD"],
        eliminate:"true"}),
    reportDoesntExist: local:test-report-does-not-exist({
        report:"report-not-found",
        ticker:"MSFT",
        fiscalYear:"ALL",
        fiscalPeriod:"FY"})
})


Key counter functionality

Key counter functionality

import "joelpurra/jq-object-sorting" as ObjectSorting;

# Create a new key counter object.
# Yes, it's as simple as an empty object.
def create:
	{};

# Increment a single key by a certain count.
def incrementBy(obj; value):
	obj as $obj
	| value as $value
	| .[$obj] = ((.[$obj] // 0) + $value);

def increment(obj):
	obj as $obj
	| incrementBy($obj; 1);

def decrement(obj):
	obj as $obj
	| incrementBy($obj; -1);

# Add two key counter objects together.
# Keys that exist in both have their counts added.
# Keys that exist in only one of the objects are kept.
def add(obj):
	. as $keyCounterObject
	| obj
	| to_entries
	| reduce .[] as $item
	(
		$keyCounterObject;
		incrementBy($item.key; $item.value)
	);

# Use the values in an array as keys to increment.
def incrementByArray(arr):
	. as $keyCounterObject
	| arr as $arr
	| reduce $arr[] as $item
	(
		$keyCounterObject;
		increment($item)
	);

# Get values with a minimum count.
def minimum(n):
	n as $n
	| with_entries(
		select(.value >= $n)
	);

def minimumTwo:
	minimum(2);

# Get top counts.
def top(n):
	n as $n
	# TODO: Use a stable primarily value (desc), secondarily key (asc) sort.
	| ObjectSorting::byValueDesc
	| to_entries
	| .[0:$n]
	| from_entries;

def topTen:
	top(10);

error: pathspec 'jq/main.jq' did not match any file(s) known to git


Module to support jq 1.4.

Module to support jq 1.4.

def flatten: reduce .[] as $i ([]; if $i | type == "array" then . + ($i | flatten) else . + [$i] end);

error: pathspec 'lib/flatten.jq' did not match any file(s) known to git


added facs export query

added facs export query

jsoniq version "1.0";

declare variable $id := "FundamentalAccountingConcepts";
declare variable $report := find("reports",{ "_id" :  $id });
declare variable $desc :=
  "Documentation about the fundamental accounting concepts defined in this report can be found at http://fundamentalaccountingconcepts.wikispaces.com/home";
declare variable $acl :=
    [
       {
          "Type": "Group",
          "Grantee": "http://28.io/groups/AllUsers",
          "Permission": "READ"
       }
    ];
declare variable $def :=
    [ {
        "ModelKind" : "DefinitionModel",
        "Labels" : [ "Fundamental Accounting Concepts" ],
        "Parameters" : {

        },
        "Breakdowns" : {
          "x" : [ {
            "BreakdownLabels" : [ "Reporting Entity Breakdown" ],
            "BreakdownTrees" : [ {
              "Kind" : "Rule",
              "Abstract" : true,
              "Labels" : [ "Reporting Entity [Axis]" ],
              "Children" : [ {
                "Kind" : "Aspect",
                "Aspect" : "xbrl:Entity"
              } ]
            } ]
          }, {
            "BreakdownLabels" : [ "Fiscal Year Breakdown" ],
            "BreakdownTrees" : [ {
              "Kind" : "Rule",
              "Abstract" : true,
              "Labels" : [ "Fiscal Year [Axis]" ],
              "Children" : [ {
                "Kind" : "Aspect",
                "Aspect" : "sec:FiscalYear"
              } ]
            } ]
          }, {
            "BreakdownLabels" : [ "Fiscal Period Breakdown" ],
            "BreakdownTrees" : [ {
              "Kind" : "Rule",
              "Abstract" : true,
              "Labels" : [ "Fiscal Period [Axis]" ],
              "Children" : [ {
                "Kind" : "Aspect",
                "Aspect" : "sec:FiscalPeriod"
              } ]
            } ]
          } ],
          "y" : [ {
            "BreakdownLabels" : [ "Breakdown on concepts" ],
            "BreakdownTrees" : [ {
              "Kind" : "ConceptRelationship",
              "LinkName" : "link:presentationLink",
              "LinkRole" : "http://xbrl.io/fundamental-accounting-concepts",
              "ArcName" : "link:presentationArc",
              "ArcRole" : "http://www.xbrl.org/2003/arcrole/parent-child",
              "RelationshipSource" : "fac:FundamentalAccountingConceptsLineItems",
              "FormulaAxis" : "descendant",
              "Generations" : 0
            } ]
          } ]
        },
        "TableFilters" : {

        }
      }
    ];

declare function local:convert($item as item)
{
    typeswitch($item)
    case $object as object return {|
        for $key in keys($object)
        return
            switch($key)
            (:case "To" return { $key : [ (values($object.$key)) ! (local:convert($$)) ] }:)
            case "children" return ()
            case "expanded" return ()
            case "$$hashKey" return ()
            default return { $key : local:convert($object.$key) }
    |}
    case $array as array return [ ($array[]) ! (local:convert($$)) ]
    default return $item
};

if($id eq "FundamentalAccountingConcepts")
then
    {
        replace value of json $report.Hypercubes."xbrl:DefaultHypercube".Aspects."xbrl:Entity" with
            {
              "Name": "xbrl:Entity",
              "Label": "Reporting Entity",
              "Kind": "TypedDimension",
              "Type": "string",
              "DomainRestriction": {
                "Name": "xbrl:EntityDomain",
                "Label": "Entity Domain",
                "Enumeration": [ "http://www.sec.gov/CIK 0001403161","http://www.sec.gov/CIK 0000004962","http://www.sec.gov/CIK 0000019617","http://www.sec.gov/CIK 0000030554","http://www.sec.gov/CIK 0000034088","http://www.sec.gov/CIK 0000040545","http://www.sec.gov/CIK 0000066740","http://www.sec.gov/CIK 0000078003","http://www.sec.gov/CIK 0000080424","http://www.sec.gov/CIK 0000093410","http://www.sec.gov/CIK 0000101829","http://www.sec.gov/CIK 0000310158","http://www.sec.gov/CIK 0000320187","http://www.sec.gov/CIK 0000354950","http://www.sec.gov/CIK 0000732712","http://www.sec.gov/CIK 0000732717","http://www.sec.gov/CIK 0000789019","http://www.sec.gov/CIK 0000858877","http://www.sec.gov/CIK 0000886982","http://www.sec.gov/CIK 0001001039","http://www.sec.gov/CIK 0000012927","http://www.sec.gov/CIK 0000018230","http://www.sec.gov/CIK 0000021344","http://www.sec.gov/CIK 0000050863","http://www.sec.gov/CIK 0000051143","http://www.sec.gov/CIK 0000063908","http://www.sec.gov/CIK 0000086312","http://www.sec.gov/CIK 0000104169","http://www.sec.gov/CIK 0000200406","http://www.sec.gov/CIK 0000731766" ]
              }
            };
        replace value of json $report.Hypercubes."xbrl:DefaultHypercube".Aspects."sec:FiscalYear" with
            {
              "Name": "sec:FiscalYear",
              "Label": "Fiscal Year",
              "Kind": "TypedDimension",
              "Type": "integer",
              "DomainRestriction": {
                "Name": "sec:FiscalYearDomain",
                "Label": "Fiscal Year Domain",
                "Enumeration": [ 2013 ]
              }
            };
        replace value of json $report.Hypercubes."xbrl:DefaultHypercube".Aspects."sec:FiscalPeriod" with
            {
              "Name": "sec:FiscalPeriod",
              "Label": "Fiscal Period",
              "Kind": "TypedDimension",
              "Type": "string",
              "DomainRestriction": {
                "Name": "sec:FiscalPeriodDomain",
                "Label": "Fiscal Period Domain",
                "Enumeration": [ "FY" ]
              }
            };
    }
else ();

(: remove archives filter :)
for $arch in $report.Hypercubes."xbrl:DefaultHypercube".Aspects."sec:Archive"
where exists($arch.DomainRestriction)
return
    replace value of json $report.Hypercubes."xbrl:DefaultHypercube".Aspects."sec:Archive" with
    {
        "Name": "sec:Archive",
        "Label": "Archive ID"
    };

for $rule in $report.Rules[]
for $f in $rule.Formulae[]
where $f.Prereq or $f.Body or exists($f.valid) or exists($f.active)
return
    {
        if($f.Prereq)
        then delete json $f.Prereq;
        else ();
        if($f.Body)
        then delete json $f.Body;
        else ();
        if(exists($f.active))
        then delete json $f.active;
        else ();
        if(exists($f.valid))
        then delete json $f.valid;
        else ();
    }

local:convert(
    { "_id": $id,
      Archive: null,
      Label: "Fundamental Accounting Concepts",
      Description: $desc,
      Prefix: "fac",
      Role: "http://xbrl.io/fundamental-accounting-concepts",
      Owner: "admin@28.io",
      ACL: $acl,
      LastModified: string(current-dateTime()),
      Networks: $report.Networks,
      Hypercubes: $report.Hypercubes,
      DefinitionModels: $def,
      Rules: $report.Rules,
      Filters: {
        cik: [  ],
        tag: [ "DOW30" ],
        fiscalYear : [ 2013 ],
        fiscalPeriod : [ "FY" ],
        sic : [  ]
      }
    }
)

error: pathspec 'queries/public/export/fac.jq' did not match any file(s) known to git


:new: add missing references module.

:new: add missing references module.

jsoniq version "1.0";
(:
 : Copyright 2015 28msec Inc.
 :)

(:~
 :
This module provides functionality for XBRL references.

 :
 : @author Dennis Knochenwefel
 :)
module namespace references = "http://28.io/modules/xbrl/references";

import module namespace concepts = "http://28.io/modules/xbrl/concepts";
import module namespace entities = "http://28.io/modules/xbrl/entities";

declare namespace xbrli = "http://www.xbrl.org/2003/instance";
declare namespace xlink = "http://www.w3.org/1999/xlink";

declare namespace ver = "http://zorba.io/options/versioning";
declare option ver:module-version "1.0";

(:~
 : The standard reference role.
 :)
declare variable $references:STANDARD_REFERENCE_ROLE as xs:string :=
    "http://www.xbrl.org/2003/role/reference";

declare %private function references:to-element(
    $namespaces as object?,
    $element-name as string,
    $value as string?) as element()
{
  let $prefix as string := tokenize($element-name, ":")[1]
  let $namespace as string := $namespaces.$prefix
  return
    element { fn:QName($namespace, $element-name) } { $value }
};

(:~
 :
Transforms concept references into XBRL referenceLink.

 :
 : @param $concepts the concepts to transform.
 :
 : @return the referenceLink element to be put into a linkbase.
 :)
declare function references:to-xbrl(
    $archive as object,
    $concepts as object*,
    $taxonomyName as string) as element()
{
  <link:referenceLink xmlns:link="http://www.xbrl.org/2003/linkbase" xlink:type="extended" xlink:role="http://www.xbrl.org/2003/role/link">
  {
    for $concept as object in $concepts
    where not $concept.Name = $concepts:BUILT_IN_REPORT_ELEMENTS
    where exists($concept.References[])
    group by $concept.Name
    let $id as string := replace($concept.Name[1], ":", "_")
    let $references as object* :=
      for $references in $concept.References[]
      let $role as string := ($references.Role, $references:STANDARD_REFERENCE_ROLE)[1]
      let $part as string := $references.Part
      group by $role, $part
      return $references[1]
    return
      (
        <link:loc xlink:type="locator" xlink:href="{$taxonomyName}.xsd#{$id}" xlink:label="{$id}" />,
        for $references in $references
        let $role as string := ($references.Role, $references:STANDARD_REFERENCE_ROLE)[1]
        group by $role
        let $labelID as string := $id || "_ref"
        return (
              <link:reference xlink:role="{$role}"
                     xlink:label="{$labelID}"
                     xlink:type="resource">{
                 for $reference in $references
                 let $part as string := $reference.Part
                 let $value as string? := ($reference.Value)[$$ instance of string][1]
                 return
                  references:to-element($archive.Namespaces, $part, $value)
              }</link:reference>,
              <link:referenceArc xlink:type="arc"
                        xlink:arcrole="http://www.xbrl.org/2003/arcrole/concept-reference"
                        xlink:from="{$id}"
                        xlink:to="{$labelID}" />
          )

      )
  }</link:referenceLink>
};

error: pathspec 'queries/modules/io/28/modules/xbrl/references.jq' did not match any file(s) known to git