@graphty/graph-io 0.3.48 → 0.3.50
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/chunks/{approximations-C2riR4NT.js → approximations-BRXsll0T.js} +2 -2
- package/dist/chunks/{approximations-C2riR4NT.js.map → approximations-BRXsll0T.js.map} +1 -1
- package/dist/chunks/bends-BGXjv_U4.js +129 -0
- package/dist/chunks/bends-BGXjv_U4.js.map +1 -0
- package/dist/chunks/{block-Cu22ewuS.js → block-yl0f_qLO.js} +931 -164
- package/dist/chunks/block-yl0f_qLO.js.map +1 -0
- package/dist/chunks/choose-CczZJaX_.js +717 -0
- package/dist/chunks/choose-CczZJaX_.js.map +1 -0
- package/dist/chunks/{codes-CV_Bhcyi.js → codes-BE2xir2k.js} +6 -2
- package/dist/chunks/codes-BE2xir2k.js.map +1 -0
- package/dist/chunks/{constants-D0LqcsLJ.js → constants-CKkYLPtt.js} +2 -2
- package/dist/chunks/{constants-D0LqcsLJ.js.map → constants-CKkYLPtt.js.map} +1 -1
- package/dist/chunks/{context-cgmmOxZ2.js → context-DizmppHy.js} +5 -4
- package/dist/chunks/{context-cgmmOxZ2.js.map → context-DizmppHy.js.map} +1 -1
- package/dist/chunks/{convert-BcQ8_jMo.js → convert-Ct2zelbQ.js} +7 -2
- package/dist/chunks/convert-Ct2zelbQ.js.map +1 -0
- package/dist/chunks/{credentials-BiQsnMTb.js → credentials-CmvJXYeH.js} +67 -16
- package/dist/chunks/credentials-CmvJXYeH.js.map +1 -0
- package/dist/chunks/{cx-export-BEeF6ymo.js → cx-export-Bt6NoqTQ.js} +3 -3
- package/dist/chunks/{cx-export-BEeF6ymo.js.map → cx-export-Bt6NoqTQ.js.map} +1 -1
- package/dist/chunks/descriptor-B28U25x4.js +60 -0
- package/dist/chunks/descriptor-B28U25x4.js.map +1 -0
- package/dist/chunks/{descriptor-BJ-W0Jd-.js → descriptor-Dhez_Cew.js} +11 -2
- package/dist/chunks/descriptor-Dhez_Cew.js.map +1 -0
- package/dist/chunks/{emit-CD8xnY8s.js → emit-7Jkpg0yd.js} +1788 -133
- package/dist/chunks/emit-7Jkpg0yd.js.map +1 -0
- package/dist/chunks/{escape-DH2Egt-l.js → escape-CuCIzNMB.js} +8 -8
- package/dist/chunks/{escape-DH2Egt-l.js.map → escape-CuCIzNMB.js.map} +1 -1
- package/dist/chunks/{export-CZ7VRm4I.js → export-Cha4dRFz.js} +45 -387
- package/dist/chunks/export-Cha4dRFz.js.map +1 -0
- package/dist/chunks/{exporter-ChjL5fmP.js → exporter-1Ajud15J.js} +9 -8
- package/dist/chunks/{exporter-ChjL5fmP.js.map → exporter-1Ajud15J.js.map} +1 -1
- package/dist/chunks/{exporter-BIdaoIgh.js → exporter-B6yvL3wy.js} +7 -7
- package/dist/chunks/{exporter-BIdaoIgh.js.map → exporter-B6yvL3wy.js.map} +1 -1
- package/dist/chunks/{exporter-Dcw7Ldtq.js → exporter-BP6otMO6.js} +6 -6
- package/dist/chunks/{exporter-Dcw7Ldtq.js.map → exporter-BP6otMO6.js.map} +1 -1
- package/dist/chunks/{exporter-DtVU80Fa.js → exporter-CA5q8ROP.js} +9 -8
- package/dist/chunks/{exporter-DtVU80Fa.js.map → exporter-CA5q8ROP.js.map} +1 -1
- package/dist/chunks/{exporter-bxxjOrDZ.js → exporter-CQQZFJ2v.js} +1284 -156
- package/dist/chunks/exporter-CQQZFJ2v.js.map +1 -0
- package/dist/chunks/format-BXiAb-1h.js +408 -0
- package/dist/chunks/format-BXiAb-1h.js.map +1 -0
- package/dist/chunks/{generic-CP6YD34u.js → generic-Dc21MAdg.js} +387 -31
- package/dist/chunks/generic-Dc21MAdg.js.map +1 -0
- package/dist/chunks/{importer-B87_fmVx.js → importer-C6NVpCXp.js} +327 -84
- package/dist/chunks/importer-C6NVpCXp.js.map +1 -0
- package/dist/chunks/{importer-DPZDN40-.js → importer-CKFe4q54.js} +25 -17
- package/dist/chunks/importer-CKFe4q54.js.map +1 -0
- package/dist/chunks/{importer-Bji2MeWr.js → importer-CKbUbsJA.js} +13 -10
- package/dist/chunks/{importer-Bji2MeWr.js.map → importer-CKbUbsJA.js.map} +1 -1
- package/dist/chunks/{importer-CB_zV5_L.js → importer-ClCsdgTJ.js} +208 -1104
- package/dist/chunks/importer-ClCsdgTJ.js.map +1 -0
- package/dist/chunks/{importer-e3huMZbm.js → importer-CyVZTrf0.js} +14 -10
- package/dist/chunks/importer-CyVZTrf0.js.map +1 -0
- package/dist/chunks/{importer-CVT-JyDE.js → importer-DgG4v1Ms.js} +1537 -355
- package/dist/chunks/importer-DgG4v1Ms.js.map +1 -0
- package/dist/chunks/{importer-Cyy6UseH.js → importer-asFUrIsj.js} +66 -13
- package/dist/chunks/importer-asFUrIsj.js.map +1 -0
- package/dist/chunks/{input-Ccg9I22A.js → input-CAxt_aV-.js} +4 -4
- package/dist/chunks/{input-Ccg9I22A.js.map → input-CAxt_aV-.js.map} +1 -1
- package/dist/chunks/{json-elements-By172SVq.js → json-elements-Cq76WjnZ.js} +4 -4
- package/dist/chunks/{json-elements-By172SVq.js.map → json-elements-Cq76WjnZ.js.map} +1 -1
- package/dist/chunks/{lexicon-u2SI5xcx.js → lexicon-IVRq2Uoo.js} +282 -74
- package/dist/chunks/lexicon-IVRq2Uoo.js.map +1 -0
- package/dist/chunks/{ontology-export-BwgMyuF0.js → ontology-export-OMo91mb0.js} +4 -4
- package/dist/chunks/{ontology-export-BwgMyuF0.js.map → ontology-export-OMo91mb0.js.map} +1 -1
- package/dist/chunks/{records-Cgvxz-Vx.js → records-NJiYvekn.js} +2 -2
- package/dist/chunks/{records-Cgvxz-Vx.js.map → records-NJiYvekn.js.map} +1 -1
- package/dist/chunks/{report-CgdsL9Hb.js → report-CwMfYa9J.js} +23 -23
- package/dist/chunks/{report-CgdsL9Hb.js.map → report-CwMfYa9J.js.map} +1 -1
- package/dist/chunks/round-trip-Cy3_SHRZ.js +79 -0
- package/dist/chunks/round-trip-Cy3_SHRZ.js.map +1 -0
- package/dist/chunks/{sigv4-LkAzsLAu.js → sigv4-BXwVbza3.js} +5 -5
- package/dist/chunks/sigv4-BXwVbza3.js.map +1 -0
- package/dist/chunks/{styles-CaABMoO1.js → styles-CAVmBLgp.js} +1237 -138
- package/dist/chunks/styles-CAVmBLgp.js.map +1 -0
- package/dist/chunks/styles-CPczw1Jz.js +1928 -0
- package/dist/chunks/styles-CPczw1Jz.js.map +1 -0
- package/dist/chunks/styles-boK6Ln54.js +2847 -0
- package/dist/chunks/styles-boK6Ln54.js.map +1 -0
- package/dist/chunks/{styles-yed-Cs1nmrjn.js → styles-yed-XeFBQ6VS.js} +506 -175
- package/dist/chunks/styles-yed-XeFBQ6VS.js.map +1 -0
- package/dist/chunks/{text-BuKQVMz2.js → text-ystE2bYi.js} +2 -2
- package/dist/chunks/{text-BuKQVMz2.js.map → text-ystE2bYi.js.map} +1 -1
- package/dist/csv.js +7 -7
- package/dist/cx.js +2 -2
- package/dist/cx2.js +2 -2
- package/dist/cys.js +1 -1
- package/dist/dot.js +8 -4
- package/dist/dot.js.map +1 -1
- package/dist/gexf.js +42 -12
- package/dist/gexf.js.map +1 -1
- package/dist/gml.js +848 -194
- package/dist/gml.js.map +1 -1
- package/dist/graph-io.js +230 -193
- package/dist/graph-io.js.map +1 -1
- package/dist/graphml.js +3 -3
- package/dist/json.js +3 -2
- package/dist/neo4j.js +6 -6
- package/dist/obo.js +1 -1
- package/dist/pajek.js +1 -1
- package/dist/positions.js +45 -3
- package/dist/positions.js.map +1 -1
- package/dist/sources-cypher.js +141 -23
- package/dist/sources-cypher.js.map +1 -1
- package/dist/sources-ndex.js +2 -2
- package/dist/sources-rest.js +32 -6
- package/dist/sources-rest.js.map +1 -1
- package/dist/sources-sparql.d.ts +1 -0
- package/dist/sources-sparql.js +439 -0
- package/dist/sources-sparql.js.map +1 -0
- package/dist/src/formats/cx/importer.d.ts.map +1 -1
- package/dist/src/formats/cx/importer.js +5 -1
- package/dist/src/formats/cx/importer.js.map +1 -1
- package/dist/src/formats/cx/styles.d.ts +24 -1
- package/dist/src/formats/cx/styles.d.ts.map +1 -1
- package/dist/src/formats/cx/styles.js +117 -11
- package/dist/src/formats/cx/styles.js.map +1 -1
- package/dist/src/formats/cx2/importer.d.ts.map +1 -1
- package/dist/src/formats/cx2/importer.js +1 -0
- package/dist/src/formats/cx2/importer.js.map +1 -1
- package/dist/src/formats/cx2/styles.d.ts.map +1 -1
- package/dist/src/formats/cx2/styles.js +3 -1
- package/dist/src/formats/cx2/styles.js.map +1 -1
- package/dist/src/formats/cys/importer.d.ts.map +1 -1
- package/dist/src/formats/cys/importer.js +1 -0
- package/dist/src/formats/cys/importer.js.map +1 -1
- package/dist/src/formats/cys/styles.d.ts +2 -0
- package/dist/src/formats/cys/styles.d.ts.map +1 -1
- package/dist/src/formats/cys/styles.js +15 -7
- package/dist/src/formats/cys/styles.js.map +1 -1
- package/dist/src/formats/dot/drawing.d.ts +98 -0
- package/dist/src/formats/dot/drawing.d.ts.map +1 -0
- package/dist/src/formats/dot/drawing.js +734 -0
- package/dist/src/formats/dot/drawing.js.map +1 -0
- package/dist/src/formats/dot/exporter.d.ts.map +1 -1
- package/dist/src/formats/dot/exporter.js +34 -2
- package/dist/src/formats/dot/exporter.js.map +1 -1
- package/dist/src/formats/dot/importer.d.ts +6 -1
- package/dist/src/formats/dot/importer.d.ts.map +1 -1
- package/dist/src/formats/dot/importer.js +170 -33
- package/dist/src/formats/dot/importer.js.map +1 -1
- package/dist/src/formats/dot/index.d.ts +3 -1
- package/dist/src/formats/dot/index.d.ts.map +1 -1
- package/dist/src/formats/dot/index.js +2 -1
- package/dist/src/formats/dot/index.js.map +1 -1
- package/dist/src/formats/dot/label-places.d.ts +41 -0
- package/dist/src/formats/dot/label-places.d.ts.map +1 -0
- package/dist/src/formats/dot/label-places.js +185 -0
- package/dist/src/formats/dot/label-places.js.map +1 -0
- package/dist/src/formats/dot/names.d.ts +13 -0
- package/dist/src/formats/dot/names.d.ts.map +1 -1
- package/dist/src/formats/dot/names.js +13 -0
- package/dist/src/formats/dot/names.js.map +1 -1
- package/dist/src/formats/dot/record.d.ts +50 -0
- package/dist/src/formats/dot/record.d.ts.map +1 -0
- package/dist/src/formats/dot/record.js +275 -0
- package/dist/src/formats/dot/record.js.map +1 -0
- package/dist/src/formats/dot/styles.d.ts +72 -2
- package/dist/src/formats/dot/styles.d.ts.map +1 -1
- package/dist/src/formats/dot/styles.js +1500 -119
- package/dist/src/formats/dot/styles.js.map +1 -1
- package/dist/src/formats/gexf/dialog-metrics.d.ts +15 -0
- package/dist/src/formats/gexf/dialog-metrics.d.ts.map +1 -0
- package/dist/src/formats/gexf/dialog-metrics.js +59 -0
- package/dist/src/formats/gexf/dialog-metrics.js.map +1 -0
- package/dist/src/formats/gexf/importer.d.ts +7 -0
- package/dist/src/formats/gexf/importer.d.ts.map +1 -1
- package/dist/src/formats/gexf/importer.js +41 -5
- package/dist/src/formats/gexf/importer.js.map +1 -1
- package/dist/src/formats/gexf/preview.d.ts +77 -0
- package/dist/src/formats/gexf/preview.d.ts.map +1 -0
- package/dist/src/formats/gexf/preview.js +191 -0
- package/dist/src/formats/gexf/preview.js.map +1 -0
- package/dist/src/formats/gexf/schema.d.ts.map +1 -1
- package/dist/src/formats/gexf/schema.js +2 -1
- package/dist/src/formats/gexf/schema.js.map +1 -1
- package/dist/src/formats/gexf/styles.d.ts +58 -31
- package/dist/src/formats/gexf/styles.d.ts.map +1 -1
- package/dist/src/formats/gexf/styles.js +848 -225
- package/dist/src/formats/gexf/styles.js.map +1 -1
- package/dist/src/formats/gml/importer.d.ts +5 -2
- package/dist/src/formats/gml/importer.d.ts.map +1 -1
- package/dist/src/formats/gml/importer.js +258 -71
- package/dist/src/formats/gml/importer.js.map +1 -1
- package/dist/src/formats/gml/index.d.ts +1 -1
- package/dist/src/formats/gml/index.d.ts.map +1 -1
- package/dist/src/formats/gml/index.js +1 -1
- package/dist/src/formats/gml/index.js.map +1 -1
- package/dist/src/formats/gml/positions.d.ts +7 -0
- package/dist/src/formats/gml/positions.d.ts.map +1 -1
- package/dist/src/formats/gml/positions.js +29 -7
- package/dist/src/formats/gml/positions.js.map +1 -1
- package/dist/src/formats/gml/styles.d.ts.map +1 -1
- package/dist/src/formats/gml/styles.js +754 -102
- package/dist/src/formats/gml/styles.js.map +1 -1
- package/dist/src/formats/graphml/styles-plain.d.ts.map +1 -1
- package/dist/src/formats/graphml/styles-plain.js +6 -10
- package/dist/src/formats/graphml/styles-plain.js.map +1 -1
- package/dist/src/formats/graphml/styles-yed.d.ts +21 -15
- package/dist/src/formats/graphml/styles-yed.d.ts.map +1 -1
- package/dist/src/formats/graphml/styles-yed.js +695 -164
- package/dist/src/formats/graphml/styles-yed.js.map +1 -1
- package/dist/src/formats/graphml/styles-yfiles3.d.ts +1 -1
- package/dist/src/formats/graphml/styles-yfiles3.d.ts.map +1 -1
- package/dist/src/formats/graphml/styles-yfiles3.js +431 -64
- package/dist/src/formats/graphml/styles-yfiles3.js.map +1 -1
- package/dist/src/formats/graphml/yfiles.d.ts +3 -3
- package/dist/src/formats/graphml/yfiles.d.ts.map +1 -1
- package/dist/src/formats/graphml/yfiles.js +16 -6
- package/dist/src/formats/graphml/yfiles.js.map +1 -1
- package/dist/src/formats/json/dialect.d.ts +3 -2
- package/dist/src/formats/json/dialect.d.ts.map +1 -1
- package/dist/src/formats/json/dialect.js +39 -5
- package/dist/src/formats/json/dialect.js.map +1 -1
- package/dist/src/formats/json/importer.d.ts +13 -2
- package/dist/src/formats/json/importer.d.ts.map +1 -1
- package/dist/src/formats/json/importer.js +42 -6
- package/dist/src/formats/json/importer.js.map +1 -1
- package/dist/src/formats/json/index.d.ts +1 -1
- package/dist/src/formats/json/index.d.ts.map +1 -1
- package/dist/src/formats/json/index.js +1 -1
- package/dist/src/formats/json/index.js.map +1 -1
- package/dist/src/formats/json/positions.d.ts +5 -2
- package/dist/src/formats/json/positions.d.ts.map +1 -1
- package/dist/src/formats/json/positions.js +20 -4
- package/dist/src/formats/json/positions.js.map +1 -1
- package/dist/src/formats/json/styles.d.ts +12 -1
- package/dist/src/formats/json/styles.d.ts.map +1 -1
- package/dist/src/formats/json/styles.js +1843 -136
- package/dist/src/formats/json/styles.js.map +1 -1
- package/dist/src/formats/pajek/draw.d.ts +104 -0
- package/dist/src/formats/pajek/draw.d.ts.map +1 -0
- package/dist/src/formats/pajek/draw.js +382 -0
- package/dist/src/formats/pajek/draw.js.map +1 -0
- package/dist/src/formats/pajek/exporter.d.ts.map +1 -1
- package/dist/src/formats/pajek/exporter.js +70 -51
- package/dist/src/formats/pajek/exporter.js.map +1 -1
- package/dist/src/formats/pajek/importer.d.ts +9 -0
- package/dist/src/formats/pajek/importer.d.ts.map +1 -1
- package/dist/src/formats/pajek/importer.js +233 -102
- package/dist/src/formats/pajek/importer.js.map +1 -1
- package/dist/src/formats/pajek/index.d.ts +1 -0
- package/dist/src/formats/pajek/index.d.ts.map +1 -1
- package/dist/src/formats/pajek/index.js.map +1 -1
- package/dist/src/formats/pajek/styles.d.ts +15 -7
- package/dist/src/formats/pajek/styles.d.ts.map +1 -1
- package/dist/src/formats/pajek/styles.js +1395 -114
- package/dist/src/formats/pajek/styles.js.map +1 -1
- package/dist/src/formats/pajek/syntax.d.ts +10 -1
- package/dist/src/formats/pajek/syntax.d.ts.map +1 -1
- package/dist/src/formats/pajek/syntax.js +26 -2
- package/dist/src/formats/pajek/syntax.js.map +1 -1
- package/dist/src/formats/xgmml/emit.d.ts +1 -0
- package/dist/src/formats/xgmml/emit.d.ts.map +1 -1
- package/dist/src/formats/xgmml/emit.js +65 -5
- package/dist/src/formats/xgmml/emit.js.map +1 -1
- package/dist/src/formats/xgmml/styles.d.ts +23 -3
- package/dist/src/formats/xgmml/styles.d.ts.map +1 -1
- package/dist/src/formats/xgmml/styles.js +277 -60
- package/dist/src/formats/xgmml/styles.js.map +1 -1
- package/dist/src/index.d.ts +6 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +6 -5
- package/dist/src/index.js.map +1 -1
- package/dist/src/positions/convert.d.ts.map +1 -1
- package/dist/src/positions/convert.js +11 -1
- package/dist/src/positions/convert.js.map +1 -1
- package/dist/src/positions/extract.d.ts.map +1 -1
- package/dist/src/positions/extract.js +53 -1
- package/dist/src/positions/extract.js.map +1 -1
- package/dist/src/positions/index.d.ts +1 -1
- package/dist/src/positions/index.d.ts.map +1 -1
- package/dist/src/positions/types.d.ts +59 -0
- package/dist/src/positions/types.d.ts.map +1 -1
- package/dist/src/sources/builtins.d.ts +1 -1
- package/dist/src/sources/builtins.d.ts.map +1 -1
- package/dist/src/sources/builtins.js +8 -2
- package/dist/src/sources/builtins.js.map +1 -1
- package/dist/src/sources/context.d.ts.map +1 -1
- package/dist/src/sources/context.js +1 -0
- package/dist/src/sources/context.js.map +1 -1
- package/dist/src/sources/credentials.d.ts +50 -1
- package/dist/src/sources/credentials.d.ts.map +1 -1
- package/dist/src/sources/credentials.js +69 -0
- package/dist/src/sources/credentials.js.map +1 -1
- package/dist/src/sources/cypher/descriptor.d.ts.map +1 -1
- package/dist/src/sources/cypher/descriptor.js +5 -0
- package/dist/src/sources/cypher/descriptor.js.map +1 -1
- package/dist/src/sources/cypher/index.d.ts.map +1 -1
- package/dist/src/sources/cypher/index.js +125 -18
- package/dist/src/sources/cypher/index.js.map +1 -1
- package/dist/src/sources/cypher/params.d.ts +1 -1
- package/dist/src/sources/cypher/params.d.ts.map +1 -1
- package/dist/src/sources/cypher/query-builder.d.ts +17 -0
- package/dist/src/sources/cypher/query-builder.d.ts.map +1 -1
- package/dist/src/sources/cypher/query-builder.js +31 -0
- package/dist/src/sources/cypher/query-builder.js.map +1 -1
- package/dist/src/sources/ids.d.ts +5 -0
- package/dist/src/sources/ids.d.ts.map +1 -1
- package/dist/src/sources/ids.js +5 -0
- package/dist/src/sources/ids.js.map +1 -1
- package/dist/src/sources/params.d.ts +3 -0
- package/dist/src/sources/params.d.ts.map +1 -1
- package/dist/src/sources/rest/descriptor.d.ts.map +1 -1
- package/dist/src/sources/rest/descriptor.js +9 -0
- package/dist/src/sources/rest/descriptor.js.map +1 -1
- package/dist/src/sources/rest/openalex.d.ts +4 -2
- package/dist/src/sources/rest/openalex.d.ts.map +1 -1
- package/dist/src/sources/rest/openalex.js +4 -2
- package/dist/src/sources/rest/openalex.js.map +1 -1
- package/dist/src/sources/rest/source.d.ts.map +1 -1
- package/dist/src/sources/rest/source.js +38 -0
- package/dist/src/sources/rest/source.js.map +1 -1
- package/dist/src/sources/run.d.ts +2 -0
- package/dist/src/sources/run.d.ts.map +1 -1
- package/dist/src/sources/run.js +30 -3
- package/dist/src/sources/run.js.map +1 -1
- package/dist/src/sources/sigv4.d.ts +5 -3
- package/dist/src/sources/sigv4.d.ts.map +1 -1
- package/dist/src/sources/sigv4.js +6 -4
- package/dist/src/sources/sigv4.js.map +1 -1
- package/dist/src/sources/sparql/descriptor.d.ts +10 -0
- package/dist/src/sources/sparql/descriptor.d.ts.map +1 -0
- package/dist/src/sources/sparql/descriptor.js +64 -0
- package/dist/src/sources/sparql/descriptor.js.map +1 -0
- package/dist/src/sources/sparql/index.d.ts +28 -0
- package/dist/src/sources/sparql/index.d.ts.map +1 -0
- package/dist/src/sources/sparql/index.js +327 -0
- package/dist/src/sources/sparql/index.js.map +1 -0
- package/dist/src/sources/sparql/ntriples.d.ts +69 -0
- package/dist/src/sources/sparql/ntriples.d.ts.map +1 -0
- package/dist/src/sources/sparql/ntriples.js +180 -0
- package/dist/src/sources/sparql/ntriples.js.map +1 -0
- package/dist/src/sources/sparql/params.d.ts +27 -0
- package/dist/src/sources/sparql/params.d.ts.map +1 -0
- package/dist/src/sources/sparql/params.js +5 -0
- package/dist/src/sources/sparql/params.js.map +1 -0
- package/dist/src/sources/sparql/query.d.ts +73 -0
- package/dist/src/sources/sparql/query.d.ts.map +1 -0
- package/dist/src/sources/sparql/query.js +164 -0
- package/dist/src/sources/sparql/query.js.map +1 -0
- package/dist/src/sources/types.d.ts +60 -0
- package/dist/src/sources/types.d.ts.map +1 -1
- package/dist/src/styles/annotations.d.ts +61 -5
- package/dist/src/styles/annotations.d.ts.map +1 -1
- package/dist/src/styles/annotations.js +130 -22
- package/dist/src/styles/annotations.js.map +1 -1
- package/dist/src/styles/canon/bends.d.ts +46 -0
- package/dist/src/styles/canon/bends.d.ts.map +1 -1
- package/dist/src/styles/canon/bends.js +123 -0
- package/dist/src/styles/canon/bends.js.map +1 -1
- package/dist/src/styles/canon/color-tables.d.ts +6 -1
- package/dist/src/styles/canon/color-tables.d.ts.map +1 -1
- package/dist/src/styles/canon/color-tables.js +10 -4
- package/dist/src/styles/canon/color-tables.js.map +1 -1
- package/dist/src/styles/canon/color.d.ts +3 -1
- package/dist/src/styles/canon/color.d.ts.map +1 -1
- package/dist/src/styles/canon/color.js +103 -3
- package/dist/src/styles/canon/color.js.map +1 -1
- package/dist/src/styles/canon/enums.d.ts +2 -2
- package/dist/src/styles/canon/enums.d.ts.map +1 -1
- package/dist/src/styles/canon/enums.js +89 -7
- package/dist/src/styles/canon/enums.js.map +1 -1
- package/dist/src/styles/canon/graphviz.d.ts +12 -3
- package/dist/src/styles/canon/graphviz.d.ts.map +1 -1
- package/dist/src/styles/canon/graphviz.js +57 -9
- package/dist/src/styles/canon/graphviz.js.map +1 -1
- package/dist/src/styles/canon/number.d.ts +8 -0
- package/dist/src/styles/canon/number.d.ts.map +1 -1
- package/dist/src/styles/canon/number.js +18 -0
- package/dist/src/styles/canon/number.js.map +1 -1
- package/dist/src/styles/canon/text.d.ts +29 -2
- package/dist/src/styles/canon/text.d.ts.map +1 -1
- package/dist/src/styles/canon/text.js +156 -16
- package/dist/src/styles/canon/text.js.map +1 -1
- package/dist/src/styles/codes.d.ts +2 -0
- package/dist/src/styles/codes.d.ts.map +1 -1
- package/dist/src/styles/codes.js +2 -0
- package/dist/src/styles/codes.js.map +1 -1
- package/dist/src/styles/cyjs/cascade.d.ts.map +1 -1
- package/dist/src/styles/cyjs/cascade.js +1139 -79
- package/dist/src/styles/cyjs/cascade.js.map +1 -1
- package/dist/src/styles/cyjs/defaults-table.d.ts.map +1 -1
- package/dist/src/styles/cyjs/defaults-table.js +4 -0
- package/dist/src/styles/cyjs/defaults-table.js.map +1 -1
- package/dist/src/styles/cyjs/emit.d.ts.map +1 -1
- package/dist/src/styles/cyjs/emit.js +232 -10
- package/dist/src/styles/cyjs/emit.js.map +1 -1
- package/dist/src/styles/cyjs/face.d.ts +20 -0
- package/dist/src/styles/cyjs/face.d.ts.map +1 -0
- package/dist/src/styles/cyjs/face.js +332 -0
- package/dist/src/styles/cyjs/face.js.map +1 -0
- package/dist/src/styles/cyjs/mappers.d.ts +44 -1
- package/dist/src/styles/cyjs/mappers.d.ts.map +1 -1
- package/dist/src/styles/cyjs/mappers.js +475 -26
- package/dist/src/styles/cyjs/mappers.js.map +1 -1
- package/dist/src/styles/cyjs/routes.d.ts +53 -0
- package/dist/src/styles/cyjs/routes.d.ts.map +1 -0
- package/dist/src/styles/cyjs/routes.js +360 -0
- package/dist/src/styles/cyjs/routes.js.map +1 -0
- package/dist/src/styles/cytoscape/charts.d.ts +23 -0
- package/dist/src/styles/cytoscape/charts.d.ts.map +1 -0
- package/dist/src/styles/cytoscape/charts.js +560 -0
- package/dist/src/styles/cytoscape/charts.js.map +1 -0
- package/dist/src/styles/cytoscape/emit.d.ts.map +1 -1
- package/dist/src/styles/cytoscape/emit.js +156 -48
- package/dist/src/styles/cytoscape/emit.js.map +1 -1
- package/dist/src/styles/cytoscape/lexicon.d.ts +91 -3
- package/dist/src/styles/cytoscape/lexicon.d.ts.map +1 -1
- package/dist/src/styles/cytoscape/lexicon.js +387 -77
- package/dist/src/styles/cytoscape/lexicon.js.map +1 -1
- package/dist/src/styles/cytoscape/mappings.d.ts +30 -0
- package/dist/src/styles/cytoscape/mappings.d.ts.map +1 -1
- package/dist/src/styles/cytoscape/mappings.js +92 -0
- package/dist/src/styles/cytoscape/mappings.js.map +1 -1
- package/dist/src/styles/cytoscape/resolve.d.ts +42 -2
- package/dist/src/styles/cytoscape/resolve.d.ts.map +1 -1
- package/dist/src/styles/cytoscape/resolve.js +623 -17
- package/dist/src/styles/cytoscape/resolve.js.map +1 -1
- package/dist/src/styles/defaults.d.ts +46 -26
- package/dist/src/styles/defaults.d.ts.map +1 -1
- package/dist/src/styles/defaults.js +308 -71
- package/dist/src/styles/defaults.js.map +1 -1
- package/dist/src/styles/index.d.ts +4 -3
- package/dist/src/styles/index.d.ts.map +1 -1
- package/dist/src/styles/index.js +3 -2
- package/dist/src/styles/index.js.map +1 -1
- package/dist/src/styles/internal.d.ts +1 -0
- package/dist/src/styles/internal.d.ts.map +1 -1
- package/dist/src/styles/internal.js +1 -0
- package/dist/src/styles/internal.js.map +1 -1
- package/dist/src/styles/io/generic.d.ts.map +1 -1
- package/dist/src/styles/io/generic.js +56 -16
- package/dist/src/styles/io/generic.js.map +1 -1
- package/dist/src/styles/io/round-trip.d.ts +56 -0
- package/dist/src/styles/io/round-trip.d.ts.map +1 -0
- package/dist/src/styles/io/round-trip.js +138 -0
- package/dist/src/styles/io/round-trip.js.map +1 -0
- package/dist/src/styles/io/writer.d.ts.map +1 -1
- package/dist/src/styles/io/writer.js +6 -1
- package/dist/src/styles/io/writer.js.map +1 -1
- package/dist/src/styles/notes.d.ts.map +1 -1
- package/dist/src/styles/notes.js +1 -0
- package/dist/src/styles/notes.js.map +1 -1
- package/dist/src/styles/plan/features.d.ts +1 -1
- package/dist/src/styles/plan/features.d.ts.map +1 -1
- package/dist/src/styles/plan/features.js +22 -2
- package/dist/src/styles/plan/features.js.map +1 -1
- package/dist/src/styles/plan/index.d.ts +1 -1
- package/dist/src/styles/plan/index.d.ts.map +1 -1
- package/dist/src/styles/plan/index.js +1 -1
- package/dist/src/styles/plan/index.js.map +1 -1
- package/dist/src/styles/plan/plan.d.ts.map +1 -1
- package/dist/src/styles/plan/plan.js +61 -4
- package/dist/src/styles/plan/plan.js.map +1 -1
- package/dist/src/styles/plan/resolve.d.ts +11 -0
- package/dist/src/styles/plan/resolve.d.ts.map +1 -1
- package/dist/src/styles/plan/resolve.js +40 -4
- package/dist/src/styles/plan/resolve.js.map +1 -1
- package/dist/src/styles/slots.d.ts +14 -0
- package/dist/src/styles/slots.d.ts.map +1 -0
- package/dist/src/styles/slots.js +20 -0
- package/dist/src/styles/slots.js.map +1 -0
- package/dist/src/styles/types.d.ts +687 -6
- package/dist/src/styles/types.d.ts.map +1 -1
- package/dist/src/styles/vocabulary.d.ts +3 -2
- package/dist/src/styles/vocabulary.d.ts.map +1 -1
- package/dist/src/styles/vocabulary.js +224 -0
- package/dist/src/styles/vocabulary.js.map +1 -1
- package/dist/styles.js +30 -239
- package/dist/styles.js.map +1 -1
- package/dist/xgmml.js +3 -3
- package/package.json +27 -7
- package/src/formats/cx/importer.ts +6 -1
- package/src/formats/cx/styles.ts +143 -9
- package/src/formats/cx2/importer.ts +1 -0
- package/src/formats/cx2/styles.ts +3 -1
- package/src/formats/cys/importer.ts +1 -0
- package/src/formats/cys/styles.ts +27 -5
- package/src/formats/dot/drawing.ts +799 -0
- package/src/formats/dot/exporter.ts +37 -1
- package/src/formats/dot/importer.ts +192 -36
- package/src/formats/dot/index.ts +3 -1
- package/src/formats/dot/label-places.ts +241 -0
- package/src/formats/dot/names.ts +15 -0
- package/src/formats/dot/record.ts +336 -0
- package/src/formats/dot/styles.ts +1702 -149
- package/src/formats/gexf/dialog-metrics.ts +61 -0
- package/src/formats/gexf/importer.ts +50 -5
- package/src/formats/gexf/preview.ts +217 -0
- package/src/formats/gexf/schema.ts +2 -1
- package/src/formats/gexf/styles.ts +1099 -245
- package/src/formats/gml/importer.ts +291 -76
- package/src/formats/gml/index.ts +1 -1
- package/src/formats/gml/positions.ts +29 -7
- package/src/formats/gml/styles.ts +852 -110
- package/src/formats/graphml/styles-plain.ts +6 -15
- package/src/formats/graphml/styles-yed.ts +765 -176
- package/src/formats/graphml/styles-yfiles3.ts +487 -63
- package/src/formats/graphml/yfiles.ts +19 -6
- package/src/formats/json/dialect.ts +41 -5
- package/src/formats/json/importer.ts +59 -7
- package/src/formats/json/index.ts +1 -0
- package/src/formats/json/positions.ts +22 -5
- package/src/formats/json/styles.ts +2123 -171
- package/src/formats/pajek/draw.ts +469 -0
- package/src/formats/pajek/exporter.ts +81 -49
- package/src/formats/pajek/importer.ts +278 -103
- package/src/formats/pajek/index.ts +1 -0
- package/src/formats/pajek/styles.ts +1506 -133
- package/src/formats/pajek/syntax.ts +27 -2
- package/src/formats/xgmml/emit.ts +73 -5
- package/src/formats/xgmml/styles.ts +330 -71
- package/src/index.ts +12 -1
- package/src/positions/convert.ts +12 -1
- package/src/positions/extract.ts +55 -1
- package/src/positions/index.ts +1 -0
- package/src/positions/types.ts +60 -0
- package/src/sources/builtins.ts +8 -1
- package/src/sources/context.ts +1 -0
- package/src/sources/credentials.ts +90 -1
- package/src/sources/cypher/descriptor.ts +7 -1
- package/src/sources/cypher/index.ts +149 -18
- package/src/sources/cypher/params.ts +1 -1
- package/src/sources/cypher/query-builder.ts +33 -0
- package/src/sources/ids.ts +6 -0
- package/src/sources/params.ts +3 -0
- package/src/sources/rest/descriptor.ts +9 -0
- package/src/sources/rest/openalex.ts +4 -2
- package/src/sources/rest/source.ts +41 -0
- package/src/sources/run.ts +35 -3
- package/src/sources/sigv4.ts +6 -4
- package/src/sources/sparql/descriptor.ts +67 -0
- package/src/sources/sparql/index.ts +371 -0
- package/src/sources/sparql/ntriples.ts +219 -0
- package/src/sources/sparql/params.ts +28 -0
- package/src/sources/sparql/query.ts +216 -0
- package/src/sources/types.ts +68 -0
- package/src/styles/annotations.ts +201 -27
- package/src/styles/canon/bends.ts +137 -0
- package/src/styles/canon/color-tables.ts +10 -4
- package/src/styles/canon/color.ts +105 -3
- package/src/styles/canon/enums.ts +107 -8
- package/src/styles/canon/graphviz.ts +71 -10
- package/src/styles/canon/number.ts +19 -0
- package/src/styles/canon/text.ts +187 -16
- package/src/styles/codes.ts +2 -0
- package/src/styles/cyjs/cascade.ts +1303 -84
- package/src/styles/cyjs/defaults-table.ts +4 -0
- package/src/styles/cyjs/emit.ts +268 -14
- package/src/styles/cyjs/face.ts +372 -0
- package/src/styles/cyjs/mappers.ts +506 -27
- package/src/styles/cyjs/routes.ts +432 -0
- package/src/styles/cytoscape/charts.ts +684 -0
- package/src/styles/cytoscape/emit.ts +170 -48
- package/src/styles/cytoscape/lexicon.ts +431 -78
- package/src/styles/cytoscape/mappings.ts +108 -0
- package/src/styles/cytoscape/resolve.ts +741 -17
- package/src/styles/defaults.ts +417 -108
- package/src/styles/index.ts +5 -0
- package/src/styles/internal.ts +1 -0
- package/src/styles/io/generic.ts +79 -23
- package/src/styles/io/round-trip.ts +202 -0
- package/src/styles/io/writer.ts +6 -1
- package/src/styles/notes.ts +1 -0
- package/src/styles/plan/features.ts +23 -2
- package/src/styles/plan/index.ts +1 -1
- package/src/styles/plan/plan.ts +69 -5
- package/src/styles/plan/resolve.ts +47 -4
- package/src/styles/slots.ts +25 -0
- package/src/styles/types.ts +698 -5
- package/src/styles/vocabulary.ts +232 -2
- package/dist/chunks/block-Cu22ewuS.js.map +0 -1
- package/dist/chunks/choose-Cdx6Enl2.js +0 -57
- package/dist/chunks/choose-Cdx6Enl2.js.map +0 -1
- package/dist/chunks/codes-CV_Bhcyi.js.map +0 -1
- package/dist/chunks/convert-BcQ8_jMo.js.map +0 -1
- package/dist/chunks/credentials-BiQsnMTb.js.map +0 -1
- package/dist/chunks/descriptor-BJ-W0Jd-.js.map +0 -1
- package/dist/chunks/emit-CD8xnY8s.js.map +0 -1
- package/dist/chunks/export-CZ7VRm4I.js.map +0 -1
- package/dist/chunks/exporter-bxxjOrDZ.js.map +0 -1
- package/dist/chunks/format-BMS-1Nxb.js +0 -64
- package/dist/chunks/format-BMS-1Nxb.js.map +0 -1
- package/dist/chunks/generic-CP6YD34u.js.map +0 -1
- package/dist/chunks/importer-B87_fmVx.js.map +0 -1
- package/dist/chunks/importer-CB_zV5_L.js.map +0 -1
- package/dist/chunks/importer-CVT-JyDE.js.map +0 -1
- package/dist/chunks/importer-Cyy6UseH.js.map +0 -1
- package/dist/chunks/importer-DPZDN40-.js.map +0 -1
- package/dist/chunks/importer-e3huMZbm.js.map +0 -1
- package/dist/chunks/lexicon-u2SI5xcx.js.map +0 -1
- package/dist/chunks/sigv4-LkAzsLAu.js.map +0 -1
- package/dist/chunks/styles-CaABMoO1.js.map +0 -1
- package/dist/chunks/styles-P_gmFAOi.js +0 -770
- package/dist/chunks/styles-P_gmFAOi.js.map +0 -1
- package/dist/chunks/styles-yed-Cs1nmrjn.js.map +0 -1
- package/dist/chunks/writer-DvHTl36J.js +0 -449
- package/dist/chunks/writer-DvHTl36J.js.map +0 -1
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
function flipY(y) {
|
|
2
2
|
return y === 0 ? 0 : -y;
|
|
3
3
|
}
|
|
4
|
+
function yStretch(extra) {
|
|
5
|
+
return extra.pxPerUnit === void 0 || extra.pxPerUnitY === void 0 ? 1 : extra.pxPerUnitY / extra.pxPerUnit;
|
|
6
|
+
}
|
|
4
7
|
function toNeutral(p, extra, size, realZ) {
|
|
8
|
+
p[1] *= yStretch(extra);
|
|
5
9
|
if (extra.anchor === "top-left" && size !== null) {
|
|
6
10
|
p[0] += size[0] / 2;
|
|
7
11
|
p[1] += extra.yAxis === "down" ? size[1] / 2 : -size[1] / 2;
|
|
@@ -15,8 +19,9 @@ function toNeutral(p, extra, size, realZ) {
|
|
|
15
19
|
function toFilePositions(coords, extra, sizes) {
|
|
16
20
|
const out = new Float64Array(coords.length);
|
|
17
21
|
const down = extra.yAxis === "down";
|
|
22
|
+
const stretch = yStretch(extra);
|
|
18
23
|
for (let i = 0; i < coords.length; i += 3) {
|
|
19
|
-
let y = coords[i + 1];
|
|
24
|
+
let y = coords[i + 1] / stretch;
|
|
20
25
|
let z = coords[i + 2];
|
|
21
26
|
if (down) {
|
|
22
27
|
y = flipY(y);
|
|
@@ -56,4 +61,4 @@ export {
|
|
|
56
61
|
toNeutral as t,
|
|
57
62
|
writtenPositions as w
|
|
58
63
|
};
|
|
59
|
-
//# sourceMappingURL=convert-
|
|
64
|
+
//# sourceMappingURL=convert-Ct2zelbQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-Ct2zelbQ.js","sources":["../../src/positions/convert.ts"],"sourcesContent":["/**\n * The coordinate conversions between a file's spelling and the neutral convention (center, y up):\n * the y flip, the top-left anchor shift, and `toFilePositions()`, the inverse a writer uses. Format\n * modules import from here, so they never pull in the reader.\n */\n\nimport type { PositionColumnExtra } from \"./types.js\";\n\n/**\n * A y that grows downward as one that grows upward, and back: a negation that never yields -0.\n * @param y - the coordinate\n * @returns the flipped coordinate\n * @category Positions\n */\nexport function flipY(y: number): number {\n return y === 0 ? 0 : -y;\n}\n\n/**\n * How much longer a unit of y is than a unit of x, for a program that stretches its axes apart.\n * @param extra - how the file spells its coordinates\n * @returns `pxPerUnitY / pxPerUnit`, 1 when either is absent\n */\nfunction yStretch(extra: PositionColumnExtra): number {\n return extra.pxPerUnit === undefined || extra.pxPerUnitY === undefined ? 1 : extra.pxPerUnitY / extra.pxPerUnit;\n}\n\n/**\n * One coordinate from a file's spelling into the neutral convention, in place.\n * @param p - x, y, z as the file wrote them; becomes the node's center, y up\n * @param extra - how the file spells it\n * @param size - the node's width and height, for a top-left anchor; null when unknown\n * @param realZ - whether the file has a z that differs between nodes\n */\nexport function toNeutral(\n p: [number, number, number],\n extra: PositionColumnExtra,\n size: readonly [number, number] | null,\n realZ: boolean,\n): void {\n p[1] *= yStretch(extra);\n if (extra.anchor === \"top-left\" && size !== null) {\n p[0] += size[0] / 2;\n p[1] += extra.yAxis === \"down\" ? size[1] / 2 : -size[1] / 2;\n }\n p[2] = realZ ? p[2] - (extra.zOrigin ?? 0) : 0;\n if (extra.yAxis === \"down\") {\n // with a real z this turns the drawing 180 degrees about x, so a 3D shape is never mirrored\n p[1] = flipY(p[1]);\n p[2] = flipY(p[2]);\n }\n}\n\n/**\n * Neutral coordinates (center, y up, as `extractPositions()` returns them) back into a column\n * spelled as `extra` declares, for a writer: the y flip, Pajek's z origin and yEd's top-left corner\n * are undone. Rows that are NaN stay NaN.\n * @param coords - x, y, z per node\n * @param extra - the spelling of the column to write\n * @param sizes - each node's width and height, needed for a top-left anchor\n * @param sizes.width - widths by node index\n * @param sizes.height - heights by node index\n * @returns a new array, x, y, z per node in the file's spelling\n * @category Positions\n */\nexport function toFilePositions(\n coords: Float64Array,\n extra: PositionColumnExtra,\n sizes?: { width: Float64Array; height: Float64Array },\n): Float64Array {\n const out = new Float64Array(coords.length);\n const down = extra.yAxis === \"down\";\n const stretch = yStretch(extra);\n for (let i = 0; i < coords.length; i += 3) {\n let y = coords[i + 1] / stretch;\n let z = coords[i + 2];\n if (down) {\n y = flipY(y);\n z = flipY(z);\n }\n out[i] = coords[i];\n out[i + 1] = y;\n out[i + 2] = z === 0 && extra.sourceDims !== 3 ? 0 : z + (extra.zOrigin ?? 0);\n const row = i / 3;\n if (extra.anchor === \"top-left\" && sizes !== undefined) {\n out[i] -= sizes.width[row] / 2;\n out[i + 1] -= down ? sizes.height[row] / 2 : -sizes.height[row] / 2;\n }\n }\n return out;\n}\n\n/**\n * The median of some numbers.\n * @param values - the numbers, reordered in place\n * @returns the median, or null for none\n * @category Positions\n */\nexport function median(values: number[]): number | null {\n if (values.length === 0) {\n return null;\n }\n values.sort((a, b) => a - b);\n const mid = values.length >> 1;\n return values.length % 2 === 1 ? values[mid] : (values[mid - 1] + values[mid]) / 2;\n}\n\n/**\n * How each built-in writer that writes the position column as it stands spells a coordinate:\n * GML (y down, as yEd draws it) and Pajek (y down, z centered on 0.5). Every other built-in writer\n * either converts the neutral form itself (JSON, XGMML, CX, CX2, Cytoscape sessions, yEd graphics\n * in a styled GraphML) or writes a y-up format (GEXF, DOT).\n */\nconst WRITTEN_SPELLING: Readonly<Record<string, PositionColumnExtra>> = {\n gml: { yAxis: \"down\" },\n pajek: { yAxis: \"down\", zOrigin: 0.5 },\n};\n\n/**\n * Neutral coordinates (center, y up) as a built-in format's writer expects its position column, so\n * a graph whose positions are in the neutral form is written the way up its program draws it.\n * @example\n * ```ts\n * const column = writtenPositions(\"gml\", coords); // y flipped for GML\n * ```\n * @param format - the format being written\n * @param coords - x, y, z per node; NaN for a node with no position\n * @returns the coordinates to write (the same array when the format needs no conversion)\n * @category Positions\n */\nexport function writtenPositions(format: string, coords: Float64Array): Float64Array {\n const spelling = WRITTEN_SPELLING[format];\n return spelling === undefined ? coords : toFilePositions(coords, spelling);\n}\n"],"names":[],"mappings":"AAcO,SAAS,MAAM,GAAmB;AACrC,SAAO,MAAM,IAAI,IAAI,CAAC;AAC1B;AAOA,SAAS,SAAS,OAAoC;AAClD,SAAO,MAAM,cAAc,UAAa,MAAM,eAAe,SAAY,IAAI,MAAM,aAAa,MAAM;AAC1G;AASO,SAAS,UACZ,GACA,OACA,MACA,OACI;AACJ,IAAE,CAAC,KAAK,SAAS,KAAK;AACtB,MAAI,MAAM,WAAW,cAAc,SAAS,MAAM;AAC9C,MAAE,CAAC,KAAK,KAAK,CAAC,IAAI;AAClB,MAAE,CAAC,KAAK,MAAM,UAAU,SAAS,KAAK,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI;AAAA,EAC9D;AACA,IAAE,CAAC,IAAI,QAAQ,EAAE,CAAC,KAAK,MAAM,WAAW,KAAK;AAC7C,MAAI,MAAM,UAAU,QAAQ;AAExB,MAAE,CAAC,IAAI,MAAM,EAAE,CAAC,CAAC;AACjB,MAAE,CAAC,IAAI,MAAM,EAAE,CAAC,CAAC;AAAA,EACrB;AACJ;AAcO,SAAS,gBACZ,QACA,OACA,OACY;AACZ,QAAM,MAAM,IAAI,aAAa,OAAO,MAAM;AAC1C,QAAM,OAAO,MAAM,UAAU;AAC7B,QAAM,UAAU,SAAS,KAAK;AAC9B,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK,GAAG;AACvC,QAAI,IAAI,OAAO,IAAI,CAAC,IAAI;AACxB,QAAI,IAAI,OAAO,IAAI,CAAC;AACpB,QAAI,MAAM;AACN,UAAI,MAAM,CAAC;AACX,UAAI,MAAM,CAAC;AAAA,IACf;AACA,QAAI,CAAC,IAAI,OAAO,CAAC;AACjB,QAAI,IAAI,CAAC,IAAI;AACb,QAAI,IAAI,CAAC,IAAI,MAAM,KAAK,MAAM,eAAe,IAAI,IAAI,KAAK,MAAM,WAAW;AAC3E,UAAM,MAAM,IAAI;AAChB,QAAI,MAAM,WAAW,cAAc,UAAU,QAAW;AACpD,UAAI,CAAC,KAAK,MAAM,MAAM,GAAG,IAAI;AAC7B,UAAI,IAAI,CAAC,KAAK,OAAO,MAAM,OAAO,GAAG,IAAI,IAAI,CAAC,MAAM,OAAO,GAAG,IAAI;AAAA,IACtE;AAAA,EACJ;AACA,SAAO;AACX;AAQO,SAAS,OAAO,QAAiC;AACpD,MAAI,OAAO,WAAW,GAAG;AACrB,WAAO;AAAA,EACX;AACA,SAAO,KAAK,CAAC,GAAG,MAAM,IAAI,CAAC;AAC3B,QAAM,MAAM,OAAO,UAAU;AAC7B,SAAO,OAAO,SAAS,MAAM,IAAI,OAAO,GAAG,KAAK,OAAO,MAAM,CAAC,IAAI,OAAO,GAAG,KAAK;AACrF;AAQA,MAAM,mBAAkE;AAAA,EACpE,KAAK,EAAE,OAAO,OAAA;AAAA,EACd,OAAO,EAAE,OAAO,QAAQ,SAAS,IAAA;AACrC;AAcO,SAAS,iBAAiB,QAAgB,QAAoC;AACjF,QAAM,WAAW,iBAAiB,MAAM;AACxC,SAAO,aAAa,SAAY,SAAS,gBAAgB,QAAQ,QAAQ;AAC7E;"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { K as ImportReportBuilder } from "./report-
|
|
1
|
+
import { K as ImportReportBuilder } from "./report-CwMfYa9J.js";
|
|
2
2
|
const NDEX_SOURCE_ID = "ndex";
|
|
3
3
|
const CYPHER_SOURCE_ID = "cypher";
|
|
4
4
|
const NEO4J_SOURCE_ID = "neo4j";
|
|
5
5
|
const NEPTUNE_SOURCE_ID = "neptune";
|
|
6
6
|
const REST_SOURCE_ID = "rest";
|
|
7
7
|
const OPENALEX_SOURCE_ID = "openalex";
|
|
8
|
+
const SPARQL_SOURCE_ID = "sparql";
|
|
8
9
|
const SOURCE_ATTR_PREFIX = "_source.";
|
|
9
10
|
const SOURCE_STUB_ATTR = "_source.stub";
|
|
10
11
|
const SOURCE_ENTITY_ATTR = "_source.entity";
|
|
@@ -185,6 +186,34 @@ function base64(text) {
|
|
|
185
186
|
}
|
|
186
187
|
return btoa(binary);
|
|
187
188
|
}
|
|
189
|
+
function forSlot(slot, value, bind) {
|
|
190
|
+
if (typeof value !== "string") {
|
|
191
|
+
if (slot.kind === "basic") {
|
|
192
|
+
return new SourceCredential({ kind: "basic", username: value.username, password: value.password }, bind);
|
|
193
|
+
}
|
|
194
|
+
} else if (slot.kind === "bearer") {
|
|
195
|
+
return new SourceCredential({ kind: "bearer", token: value }, bind);
|
|
196
|
+
} else if (slot.kind === "api-key") {
|
|
197
|
+
const send = slot.send ?? { query: slot.name };
|
|
198
|
+
const header = "header" in send ? send.header : null;
|
|
199
|
+
const query = "query" in send ? send.query : null;
|
|
200
|
+
return new SourceCredential({ kind: "api-key", header, query, value }, bind);
|
|
201
|
+
}
|
|
202
|
+
return failAlone("E_SOURCE_PARAM", `a ${slot.kind} slot cannot take this value`, {
|
|
203
|
+
name: "credential",
|
|
204
|
+
reason: "type"
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
function credentialSlots(descriptor) {
|
|
208
|
+
if (descriptor?.credentials !== void 0) {
|
|
209
|
+
return descriptor.credentials;
|
|
210
|
+
}
|
|
211
|
+
const kind = descriptor?.auth?.[0];
|
|
212
|
+
if (kind === void 0 || descriptor?.authRequired === "none") {
|
|
213
|
+
return [];
|
|
214
|
+
}
|
|
215
|
+
return [{ name: "default", kind, required: descriptor?.authRequired === "required" }];
|
|
216
|
+
}
|
|
188
217
|
const credentials = Object.freeze({
|
|
189
218
|
/**
|
|
190
219
|
* An `Authorization: Bearer` token, or a function returning a fresh one per request.
|
|
@@ -236,11 +265,30 @@ const credentials = Object.freeze({
|
|
|
236
265
|
*/
|
|
237
266
|
custom(apply, kind, bind) {
|
|
238
267
|
return new SourceCredential({ kind: "custom", name: kind, apply }, bind);
|
|
239
|
-
}
|
|
268
|
+
},
|
|
269
|
+
/**
|
|
270
|
+
* The credential a source's slot describes (`credentialSlots(descriptor)`), from its plain
|
|
271
|
+
* value: an API key sent as the slot says, a bearer token, or a basic slot's user name and
|
|
272
|
+
* password.
|
|
273
|
+
* @example
|
|
274
|
+
* ```ts
|
|
275
|
+
* const [slot] = credentialSlots(openalex.descriptor); // api_key, sent as ?api_key=
|
|
276
|
+
* const credential = credentials.forSlot(slot, key);
|
|
277
|
+
* ```
|
|
278
|
+
* @param slot - the slot
|
|
279
|
+
* @param value - the key or token, or `{ username, password }` for a basic slot
|
|
280
|
+
* @param bind - the origins it may be sent to
|
|
281
|
+
* @returns the credential
|
|
282
|
+
*/
|
|
283
|
+
forSlot
|
|
240
284
|
});
|
|
241
285
|
function secretOf(credential) {
|
|
242
286
|
return SECRETS.get(credential);
|
|
243
287
|
}
|
|
288
|
+
function credentialQuery(credential) {
|
|
289
|
+
const secret = secretOf(credential);
|
|
290
|
+
return secret?.kind === "api-key" && secret.header === null ? secret.query ?? "api_key" : null;
|
|
291
|
+
}
|
|
244
292
|
async function applyCredential(credential, request) {
|
|
245
293
|
const secret = secretOf(credential);
|
|
246
294
|
if (secret === void 0) {
|
|
@@ -273,7 +321,7 @@ async function applyCredential(credential, request) {
|
|
|
273
321
|
return new Request(url, request);
|
|
274
322
|
}
|
|
275
323
|
case "aws-sigv4": {
|
|
276
|
-
const { signRequest } = await import("./sigv4-
|
|
324
|
+
const { signRequest } = await import("./sigv4-BXwVbza3.js");
|
|
277
325
|
return signRequest(request, secret.options);
|
|
278
326
|
}
|
|
279
327
|
case "custom":
|
|
@@ -323,25 +371,28 @@ export {
|
|
|
323
371
|
NDEX_SOURCE_ID as N,
|
|
324
372
|
OPENALEX_SOURCE_ID as O,
|
|
325
373
|
REST_SOURCE_ID as R,
|
|
326
|
-
|
|
374
|
+
SPARQL_SOURCE_ID as S,
|
|
327
375
|
applyCredential as a,
|
|
328
376
|
failAlone as b,
|
|
329
377
|
credentials as c,
|
|
330
378
|
defineSource as d,
|
|
331
|
-
|
|
379
|
+
SOURCE_ENTITY_ATTR as e,
|
|
332
380
|
failOn as f,
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
381
|
+
SOURCE_STUB_ATTR as g,
|
|
382
|
+
NEO4J_SOURCE_ID as h,
|
|
383
|
+
NEPTUNE_SOURCE_ID as i,
|
|
384
|
+
SOURCE_FORMAT_PREFIX as j,
|
|
385
|
+
checkParams as k,
|
|
386
|
+
credentialQuery as l,
|
|
387
|
+
checkLazySource as m,
|
|
388
|
+
checkSource as n,
|
|
341
389
|
originOf as o,
|
|
342
|
-
|
|
343
|
-
|
|
390
|
+
SOURCE_ATTR_PREFIX as p,
|
|
391
|
+
SOURCE_DEGREE_ATTR as q,
|
|
392
|
+
credentialSlots as r,
|
|
393
|
+
fromStorableCredential as s,
|
|
394
|
+
storableCredential as t,
|
|
344
395
|
unwrapCredential as u,
|
|
345
396
|
warnOn as w
|
|
346
397
|
};
|
|
347
|
-
//# sourceMappingURL=credentials-
|
|
398
|
+
//# sourceMappingURL=credentials-CmvJXYeH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials-CmvJXYeH.js","sources":["../../src/sources/ids.ts","../../src/sources/fail.ts","../../src/sources/define.ts","../../src/sources/credentials.ts"],"sourcesContent":["/**\n * The public names of network sources: one constant per built-in source id, and the reserved\n * `_source.` attribute names. Nothing else in graph-io spells them, so a rename is one edit here.\n *\n * Experimental: the ids and the `_source.` namespace await the owner's final word (design\n * section 22, items 4 and 5).\n */\n\n/**\n * The NDEx source (www.ndexbio.org). Experimental.\n * @category Network sources\n */\nexport const NDEX_SOURCE_ID = \"ndex\";\n\n/**\n * The generic Cypher source, for any openCypher server. Experimental.\n * @category Network sources\n */\nexport const CYPHER_SOURCE_ID = \"cypher\";\n\n/**\n * The Neo4j preset of the Cypher source. Experimental.\n * @category Network sources\n */\nexport const NEO4J_SOURCE_ID = \"neo4j\";\n\n/**\n * The Amazon Neptune preset of the Cypher source. Experimental.\n * @category Network sources\n */\nexport const NEPTUNE_SOURCE_ID = \"neptune\";\n\n/**\n * The generic REST mapping source. Experimental.\n * @category Network sources\n */\nexport const REST_SOURCE_ID = \"rest\";\n\n/**\n * The OpenAlex preset of the REST mapping source. Experimental.\n * @category Network sources\n */\nexport const OPENALEX_SOURCE_ID = \"openalex\";\n\n/**\n * The SPARQL source, for any SPARQL 1.1 endpoint. Experimental.\n * @category Network sources\n */\nexport const SPARQL_SOURCE_ID = \"sparql\";\n\n/**\n * The prefix of the reserved attribute namespace sources and graphty-element write facts under.\n * @category Network sources\n */\nexport const SOURCE_ATTR_PREFIX = \"_source.\";\n\n/**\n * Node attribute: true on a stub, a node known only by its id until it is hydrated or expanded.\n * @category Network sources\n */\nexport const SOURCE_STUB_ATTR = \"_source.stub\";\n\n/**\n * Node attribute: the entity a stub node is (a REST mapping's entity name).\n * @category Network sources\n */\nexport const SOURCE_ENTITY_ATTR = \"_source.entity\";\n\n/**\n * Node attribute: the node's degree at the source, when the source returns it at no extra cost\n * (the Cypher source's degree hint).\n * @category Network sources\n */\nexport const SOURCE_DEGREE_ATTR = \"_source.degree\";\n\n/**\n * The prefix of `ImportGraphResult.format` for a load from a source: `\"source:<id>\"`.\n * @category Network sources\n */\nexport const SOURCE_FORMAT_PREFIX = \"source:\";\n","/**\n * Raising a network source issue: one place that turns a code and its params into an ImportError\n * whose `issue.params` and `details` both carry the params, so callers branch on\n * `err.issue.code` and read `err.issue.params` as with every other graph-io failure.\n */\n\nimport { ImportReportBuilder } from \"../common/report.js\";\nimport { type IssueCategory } from \"../types.js\";\nimport { type SourceIssueCode } from \"./codes.js\";\n\n/** The category each code is filed under. */\nconst CATEGORY: Readonly<Partial<Record<SourceIssueCode, IssueCategory>>> = {\n E_SOURCE_PARAM: \"validation-error\",\n E_SOURCE_INVALID: \"validation-error\",\n E_SOURCE_RESPONSE: \"parse-error\",\n E_SOURCE_NOT_A_GRAPH: \"parse-error\",\n E_SOURCE_NOT_FOUND: \"missing-value\",\n E_SOURCE_UNKNOWN: \"missing-value\",\n};\n\n/**\n * Abort a load with a source error, carrying the load's report so far plus the error.\n * @param report - the load's report\n * @param code - the code\n * @param message - a plain-ASCII message, for logs\n * @param params - the issue's values\n * @returns never; it throws the ImportError\n */\nexport function failOn(\n report: ImportReportBuilder,\n code: SourceIssueCode,\n message: string,\n params: Readonly<Record<string, unknown>>,\n): never {\n // a fork, so a failure the runner turns into a warning (a later page's 401, a cap) leaves no\n // error in the load's own report; the ImportError carries everything recorded so far\n return report.fork().failWith(CATEGORY[code] ?? \"unsupported\", code, message, undefined, params, params);\n}\n\n/**\n * Raise a source error outside a load (registration, a credential factory).\n * @param code - the code\n * @param message - a plain-ASCII message, for logs\n * @param params - the issue's values\n * @param format - the report's format name\n */\nexport function failAlone(\n code: SourceIssueCode,\n message: string,\n params: Readonly<Record<string, unknown>>,\n format = \"source\",\n): never {\n failOn(new ImportReportBuilder(format, 0), code, message, params);\n}\n\n/**\n * Record a source warning on a report.\n * @param report - the report\n * @param code - the code\n * @param message - a plain-ASCII message, for logs\n * @param params - the issue's values\n */\nexport function warnOn(\n report: ImportReportBuilder,\n code: SourceIssueCode,\n message: string,\n params: Readonly<Record<string, unknown>>,\n): void {\n report.warning(\"unsupported\", code, message, undefined, params);\n}\n","/**\n * `defineSource` and the registration checks (design section 2): the id form, exactly one read\n * method, and the declared features against the methods present. Also the parameter checks every\n * load runs against the descriptor before any request.\n */\n\nimport { type ImportReportBuilder } from \"../common/report.js\";\nimport { failAlone, failOn } from \"./fail.js\";\nimport {\n type GraphSource,\n type LazySource,\n type SourceDescriptor,\n type SourceFeature,\n type SourceParamDescriptor,\n} from \"./types.js\";\n\n/** Lowercase letters, digits and single dashes between them. */\nconst ID_FORM = /^[a-z0-9]+(-[a-z0-9]+)*$/;\n\n/** The optional methods and the feature each one is. */\nconst FEATURE_METHODS: readonly (readonly [SourceFeature, \"expand\" | \"probe\" | \"list\" | \"validate\"])[] = [\n [\"expand\", \"expand\"],\n [\"probe\", \"probe\"],\n [\"list\", \"list\"],\n [\"validate\", \"validate\"],\n];\n\n/**\n * Refuse a malformed source.\n * @param id - the source id\n * @param reason - why\n * @param message - for logs\n */\nfunction invalid(id: string, reason: string, message: string): never {\n failAlone(\"E_SOURCE_INVALID\", message, { id, reason });\n}\n\n/**\n * Check a source id.\n * @param id - the id\n */\nfunction checkSourceId(id: unknown): asserts id is string {\n if (typeof id !== \"string\" || !ID_FORM.test(id)) {\n invalid(String(id), \"id\", `source id ${JSON.stringify(id)} must be lowercase letters, digits and dashes`);\n }\n}\n\n/**\n * The features a loaded source has, from its methods.\n * @param source - the source\n * @returns the features\n */\nfunction featuresOf(source: GraphSource<never>): readonly SourceFeature[] {\n return FEATURE_METHODS.filter(([, method]) => typeof source[method] === \"function\").map(([f]) => f);\n}\n\n/**\n * Check a loaded source: its id, exactly one read method, and its declared features.\n * @param source - the source\n * @param declared - features a lazy registration declared, if any\n */\nexport function checkSource(source: GraphSource<never>, declared?: SourceDescriptor): void {\n checkSourceId((source as { id?: unknown }).id);\n const reads = ([\"records\", \"file\", \"import\"] as const).filter((m) => typeof source[m] === \"function\");\n if (reads.length !== 1) {\n invalid(source.id, \"read-methods\", `source ${source.id} must have exactly one of records, file and import`);\n }\n const features = (declared ?? source.descriptor)?.features;\n if (features !== undefined) {\n const has = new Set(featuresOf(source));\n for (const f of features) {\n if (f !== \"page\" && !has.has(f)) {\n invalid(source.id, \"features\", `source ${source.id} declares ${f} but has no ${f} method`);\n }\n }\n }\n}\n\n/**\n * Check a lazy registration before its code is loaded.\n * @param source - the lazy source\n */\nexport function checkLazySource(source: LazySource): void {\n checkSourceId(source.id);\n if (typeof source.load !== \"function\" || typeof source.descriptor !== \"object\") {\n invalid(source.id, \"lazy\", `lazy source ${source.id} needs a descriptor and a load function`);\n }\n}\n\n/**\n * Define a network source: returns it unchanged, with its parameter type inferred, after the\n * registration checks (an id of lowercase letters, digits and dashes; exactly one of `records`,\n * `file` and `import`; declared features backed by methods). A malformed source throws an\n * ImportError whose `issue.code` is E_SOURCE_INVALID. Experimental.\n * @param source - the source\n * @returns the same source\n * @example\n * ```ts\n * const people = defineSource({\n * id: \"people\",\n * async records(params: { team: string }, ctx) {\n * const rows = await ctx.fetchJson<{ id: string; name: string }[]>(`/api/people?team=${params.team}`);\n * return { nodes: rows };\n * },\n * });\n * ```\n * @category Network sources\n */\nexport function defineSource<P>(source: GraphSource<P>): GraphSource<P> {\n checkSource(source);\n return source;\n}\n\n/**\n * Why a number or integer param is wrong, if it is.\n * @param p - the param's descriptor\n * @param value - the value given\n * @returns the reason, or null when it is fine\n */\nfunction numberProblem(p: SourceParamDescriptor, value: unknown): string | null {\n if (typeof value !== \"number\" || Number.isNaN(value) || (p.type === \"integer\" && !Number.isInteger(value))) {\n return \"type\";\n }\n if ((p.min !== undefined && value < p.min) || (p.max !== undefined && value > p.max)) {\n return \"range\";\n }\n return null;\n}\n\n/**\n * Why a URL param is wrong, if it is.\n * @param value - the value given\n * @returns the reason, or null when it is fine\n */\nfunction urlProblem(value: unknown): string | null {\n let url: URL;\n try {\n url = new URL(typeof value === \"string\" ? value : \"\");\n } catch {\n return \"type\";\n }\n return url.username !== \"\" || url.password !== \"\" ? \"credentials-in-url\" : null;\n}\n\n/**\n * Why a present param value is wrong for its descriptor, if it is.\n * @param p - the param's descriptor\n * @param value - the value given (not undefined or null)\n * @returns the reason, or null when it is fine\n */\nfunction paramProblem(p: SourceParamDescriptor, value: unknown): string | null {\n switch (p.type) {\n case \"integer\":\n case \"number\":\n return numberProblem(p, value);\n case \"boolean\":\n return typeof value === \"boolean\" ? null : \"type\";\n case \"enum\":\n return p.values !== undefined && !p.values.some((v) => v.value === value) ? \"enum\" : null;\n case \"url\":\n return urlProblem(value);\n default:\n return null;\n }\n}\n\n/**\n * Check params against a descriptor before any request: required ones present, numbers and\n * integers in range, booleans, enums, URLs (never with a user name or password in them).\n * @param params - the caller's params\n * @param descriptor - the source's descriptor\n * @param report - the load's report\n */\nexport function checkParams(\n params: Readonly<Record<string, unknown>>,\n descriptor: SourceDescriptor | undefined,\n report: ImportReportBuilder,\n): void {\n if (typeof params !== \"object\" || (params as unknown) === null) {\n failOn(report, \"E_SOURCE_PARAM\", \"params must be an object\", { name: \"params\", reason: \"type\" });\n }\n for (const p of descriptor?.params ?? []) {\n const value = params[p.name];\n const missing = value === undefined || value === null;\n let reason: string | null = null;\n if (!missing) {\n reason = paramProblem(p, value);\n } else if (p.required === true && p.default === undefined) {\n reason = \"required\";\n }\n if (reason !== null) {\n failOn(report, \"E_SOURCE_PARAM\", `parameter ${p.name}: ${reason}`, { name: p.name, reason });\n }\n }\n}\n","/**\n * Credentials (design section 6): objects made by factories, holding their secret where no code\n * can read it back. graph-io applies a credential inside `ctx.fetch`, only to the origins it is\n * bound to, and keeps nothing after a load settles.\n *\n * Experimental, with the source contract.\n */\n\nimport { failAlone } from \"./fail.js\";\nimport {\n type AwsCredentials,\n type Credential,\n type CredentialKind,\n type SourceCredentialSlot,\n type SourceDescriptor,\n} from \"./types.js\";\n\n/**\n * Where a credential may go: the load's endpoint origin by default. Experimental.\n * @category Network sources\n */\nexport interface CredentialBind {\n /** The origins (scheme, host and port) it may be sent to. */\n readonly origins?: readonly string[] | undefined;\n}\n\n/**\n * The options of `credentials.awsSigV4`. Experimental.\n * @category Network sources\n */\nexport interface AwsSigV4Options {\n /** The AWS region (\"us-east-1\"). */\n readonly region: string;\n /** The signing service: \"neptune-db\" (default) or \"neptune-graph\" for Neptune Analytics. */\n readonly service?: string | undefined;\n /** The credentials, or a function returning fresh ones per request. */\n readonly credentials: AwsCredentials | (() => Promise<AwsCredentials>);\n}\n\n/** What only graph-io's own code can read about a credential. */\ntype Secret =\n | { readonly kind: \"bearer\"; readonly token: string | (() => Promise<string>) }\n | { readonly kind: \"basic\"; readonly username: string; readonly password: string }\n | {\n readonly kind: \"api-key\";\n readonly header: string | null;\n readonly query: string | null;\n readonly value: string;\n }\n | { readonly kind: \"aws-sigv4\"; readonly options: AwsSigV4Options }\n | {\n readonly kind: \"custom\";\n readonly name: string;\n readonly apply: (request: Request) => Promise<Request> | Request;\n };\n\n/** The secrets, by credential; a WeakMap so nothing reachable from the object holds them. */\nconst SECRETS = new WeakMap<Credential, Secret>();\n\n/** The key Node's util.inspect looks up. */\nconst INSPECT = Symbol.for(\"nodejs.util.inspect.custom\");\n\n/**\n * The scheme, host and port of a URL. `URL.origin` is \"null\" for schemes such as bolt+s:, so this\n * is used everywhere instead.\n * @param url - the URL\n * @returns the origin string\n */\nexport function originOf(url: URL): string {\n return `${url.protocol}//${url.host}`;\n}\n\n/**\n * Normalize the origins a credential is bound to.\n * @param bind - the bind option\n * @returns the normalized origins\n */\nfunction bindOrigins(bind: CredentialBind | undefined): readonly string[] {\n return Object.freeze(\n (bind?.origins ?? []).map((o) => {\n let url: URL;\n try {\n url = new URL(o);\n } catch {\n return failAlone(\"E_SOURCE_PARAM\", `credential origin ${JSON.stringify(o)} is not a URL`, {\n name: \"origins\",\n reason: \"origin\",\n });\n }\n return originOf(url);\n }),\n );\n}\n\n/** The object every factory returns: kind and origins visible, the secret in SECRETS. */\nclass SourceCredential implements Credential {\n readonly kind: CredentialKind;\n readonly origins: readonly string[];\n readonly username: string | undefined;\n\n /**\n * Create one; only the factories do.\n * @param secret - the secret\n * @param bind - the origins it is bound to\n */\n constructor(secret: Secret, bind: CredentialBind | undefined) {\n this.kind = secret.kind === \"custom\" ? secret.name : secret.kind;\n this.origins = bindOrigins(bind);\n this.username = secret.kind === \"basic\" ? secret.username : undefined;\n SECRETS.set(this, secret);\n Object.freeze(this);\n }\n\n /**\n * What JSON.stringify writes: never the secret.\n * @returns kind, origins and a basic credential's user name\n */\n toJSON(): Record<string, unknown> {\n return this.username === undefined\n ? { kind: this.kind, origins: this.origins }\n : { kind: this.kind, origins: this.origins, username: this.username };\n }\n\n /**\n * What util.inspect and console.log show in Node: never the secret.\n * @returns the same as toJSON\n */\n [INSPECT](): Record<string, unknown> {\n return this.toJSON();\n }\n\n /**\n * What string conversion shows: never the secret.\n * @returns a description\n */\n toString(): string {\n return `[Credential ${this.kind}]`;\n }\n}\n\n/**\n * Base64 of a string's UTF-8 bytes.\n * @param text - the text\n * @returns base64\n */\nfunction base64(text: string): string {\n let binary = \"\";\n for (const b of new TextEncoder().encode(text)) {\n binary += String.fromCodePoint(b);\n }\n return btoa(binary);\n}\n\n/**\n * The plain value a slot's credential is made from: a key or a token, or a user name and password.\n * @category Network sources\n */\nexport type SlotValue =\n | string\n | {\n /** A basic slot's user name. */\n readonly username: string;\n /** A basic slot's password. */\n readonly password: string;\n };\n\n/**\n * The credential a slot describes, from its plain value.\n * @param slot - the slot\n * @param value - the key or token, or a basic slot's user name and password\n * @param bind - the origins it may be sent to\n * @returns the credential\n */\nfunction forSlot(slot: SourceCredentialSlot, value: SlotValue, bind?: CredentialBind): Credential {\n if (typeof value !== \"string\") {\n if (slot.kind === \"basic\") {\n return new SourceCredential({ kind: \"basic\", username: value.username, password: value.password }, bind);\n }\n } else if (slot.kind === \"bearer\") {\n return new SourceCredential({ kind: \"bearer\", token: value }, bind);\n } else if (slot.kind === \"api-key\") {\n const send = slot.send ?? { query: slot.name };\n const header = \"header\" in send ? send.header : null;\n const query = \"query\" in send ? send.query : null;\n return new SourceCredential({ kind: \"api-key\", header, query, value }, bind);\n }\n return failAlone(\"E_SOURCE_PARAM\", `a ${slot.kind} slot cannot take this value`, {\n name: \"credential\",\n reason: \"type\",\n });\n}\n\n/**\n * The credential slots a source takes: the ones its descriptor declares, else one slot `default`\n * of its first credential kind when it takes a credential (`auth`), else none. Experimental.\n * @param descriptor - the source's descriptor\n * @returns the slots\n * @category Network sources\n */\nexport function credentialSlots(descriptor: SourceDescriptor | undefined): readonly SourceCredentialSlot[] {\n if (descriptor?.credentials !== undefined) {\n return descriptor.credentials;\n }\n const kind = descriptor?.auth?.[0];\n if (kind === undefined || descriptor?.authRequired === \"none\") {\n return [];\n }\n return [{ name: \"default\", kind, required: descriptor?.authRequired === \"required\" }];\n}\n\n/**\n * The factories that make credentials. Pass the result as the `credential` option of a load; it is\n * sent only to the load's endpoint origin, or to `bind.origins` when you give them. Experimental.\n * @example\n * ```ts\n * await loadFromSource(\"people\", { team: \"core\" }, {\n * endpoint: \"https://example.com\",\n * credential: credentials.bearer(token),\n * });\n * ```\n * @category Network sources\n */\nexport const credentials = Object.freeze({\n /**\n * An `Authorization: Bearer` token, or a function returning a fresh one per request.\n * @param token - the token or a function returning it\n * @param bind - the origins it may be sent to\n * @returns the credential\n */\n bearer(token: string | (() => Promise<string>), bind?: CredentialBind): Credential {\n return new SourceCredential({ kind: \"bearer\", token }, bind);\n },\n /**\n * HTTP basic authentication (a database user and password).\n * @param username - the user name\n * @param password - the password\n * @param bind - the origins it may be sent to\n * @returns the credential\n */\n basic(username: string, password: string, bind?: CredentialBind): Credential {\n return new SourceCredential({ kind: \"basic\", username, password }, bind);\n },\n /**\n * An API key sent in a request header or a query parameter.\n * @param where - `{ header: \"X-Api-Key\" }` or `{ query: \"api_key\" }`\n * @param value - the key\n * @param bind - the origins it may be sent to\n * @returns the credential\n */\n apiKey(\n where: { readonly header: string } | { readonly query: string },\n value: string,\n bind?: CredentialBind,\n ): Credential {\n const header = \"header\" in where ? where.header : null;\n const query = \"query\" in where ? where.query : null;\n return new SourceCredential({ kind: \"api-key\", header, query, value }, bind);\n },\n /**\n * AWS Signature Version 4 (Amazon Neptune). The signer loads on first use.\n * @param options - region, service and the credentials or a provider of them\n * @param bind - the origins it may be sent to\n * @returns the credential\n */\n awsSigV4(options: AwsSigV4Options, bind?: CredentialBind): Credential {\n return new SourceCredential({ kind: \"aws-sigv4\", options }, bind);\n },\n /**\n * Anything else: a function that returns the request with its authentication added. The\n * request's origin must not change.\n * @param apply - adds the authentication\n * @param kind - what to call it in `credential.kind`\n * @param bind - the origins it may be sent to\n * @returns the credential\n */\n custom(apply: (request: Request) => Promise<Request> | Request, kind: string, bind?: CredentialBind): Credential {\n return new SourceCredential({ kind: \"custom\", name: kind, apply }, bind);\n },\n /**\n * The credential a source's slot describes (`credentialSlots(descriptor)`), from its plain\n * value: an API key sent as the slot says, a bearer token, or a basic slot's user name and\n * password.\n * @example\n * ```ts\n * const [slot] = credentialSlots(openalex.descriptor); // api_key, sent as ?api_key=\n * const credential = credentials.forSlot(slot, key);\n * ```\n * @param slot - the slot\n * @param value - the key or token, or `{ username, password }` for a basic slot\n * @param bind - the origins it may be sent to\n * @returns the credential\n */\n forSlot,\n});\n\n/**\n * The secret of a credential made by the factories, or undefined for any other object.\n * @param credential - the credential\n * @returns the secret\n */\nfunction secretOf(credential: Credential): Secret | undefined {\n return SECRETS.get(credential);\n}\n\n/**\n * Whether an object is a credential made by the `credentials` factories.\n * @param value - the value\n * @returns true for a factory-made credential\n */\nexport function isCredential(value: unknown): value is Credential {\n return typeof value === \"object\" && value !== null && secretOf(value as Credential) !== undefined;\n}\n\n/**\n * The request header a credential sets, for the browser checks; null for a query key or a custom one.\n * @param credential - the credential\n * @returns the header name, lowercase\n */\nexport function credentialHeader(credential: Credential): string | null {\n const secret = secretOf(credential);\n if (secret?.kind === \"api-key\") {\n return secret.header?.toLowerCase() ?? null;\n }\n return secret?.kind === \"bearer\" || secret?.kind === \"basic\" || secret?.kind === \"aws-sigv4\"\n ? \"authorization\"\n : null;\n}\n\n/**\n * The query parameter a credential is sent in, so a cursor can leave it out; null for one sent in\n * a header or not at all.\n * @param credential - the credential\n * @returns the parameter's name\n */\nexport function credentialQuery(credential: Credential): string | null {\n const secret = secretOf(credential);\n return secret?.kind === \"api-key\" && secret.header === null ? (secret.query ?? \"api_key\") : null;\n}\n\n/**\n * Add a credential to a request. Internal to graph-io: only `ctx.fetch` calls it.\n * @param credential - the credential\n * @param request - the request\n * @returns the request with its authentication\n */\nexport async function applyCredential(credential: Credential, request: Request): Promise<Request> {\n const secret = secretOf(credential);\n if (secret === undefined) {\n return failAlone(\"E_SOURCE_PARAM\", \"the credential was not made by the credentials factories\", {\n name: \"credential\",\n reason: \"type\",\n });\n }\n switch (secret.kind) {\n case \"bearer\": {\n const token = typeof secret.token === \"string\" ? secret.token : await secret.token();\n const headers = new Headers(request.headers);\n headers.set(\"Authorization\", `Bearer ${token}`);\n return new Request(request, { headers });\n }\n case \"basic\": {\n const headers = new Headers(request.headers);\n const pair = `${secret.username}:${secret.password}`;\n headers.set(\"Authorization\", `Basic ${base64(pair)}`);\n return new Request(request, { headers });\n }\n case \"api-key\": {\n if (secret.header !== null) {\n const headers = new Headers(request.headers);\n headers.set(secret.header, secret.value);\n return new Request(request, { headers });\n }\n const url = new URL(request.url);\n url.searchParams.set(secret.query ?? \"api_key\", secret.value);\n return new Request(url, request);\n }\n case \"aws-sigv4\": {\n const { signRequest } = await import(\"./sigv4.js\");\n return signRequest(request, secret.options);\n }\n case \"custom\":\n return secret.apply(request);\n default:\n return request;\n }\n}\n\n/**\n * The raw secret, for a transport that must hand it to a driver (Bolt). Internal to graph-io; the\n * caller applies the origin and TLS rules itself.\n * @param credential - the credential\n * @returns the kind and the values the driver needs\n */\nexport function unwrapCredential(\n credential: Credential,\n):\n | { readonly kind: \"basic\"; readonly username: string; readonly password: string }\n | { readonly kind: \"bearer\"; readonly token: string | (() => Promise<string>) }\n | { readonly kind: CredentialKind }\n | undefined {\n const secret = secretOf(credential);\n if (secret?.kind === \"basic\") {\n return { kind: \"basic\", username: secret.username, password: secret.password };\n }\n if (secret?.kind === \"bearer\") {\n return { kind: \"bearer\", token: secret.token };\n }\n return secret === undefined ? undefined : { kind: credential.kind };\n}\n\n/**\n * Whether a credential can be remembered: its secret is a plain value, not a function. A token\n * refresher, a custom credential and an AWS provider cannot.\n * @param credential - the credential\n * @returns true for basic, a bearer string token and an API key\n */\nexport function isStorableCredential(credential: Credential): boolean {\n const secret = secretOf(credential);\n return (\n secret?.kind === \"basic\" ||\n secret?.kind === \"api-key\" ||\n (secret?.kind === \"bearer\" && typeof secret.token === \"string\")\n );\n}\n\n/**\n * The plain parts of a credential that can be remembered. Experimental.\n * @category Network sources\n */\nexport type StorableCredential =\n | {\n /** A user name and password, sent as HTTP Basic authentication. */\n readonly kind: \"basic\";\n /** The user name. */\n readonly username: string;\n /** The password. */\n readonly password: string;\n }\n | {\n /** A bearer token, sent in the Authorization header. */\n readonly kind: \"bearer\";\n /** The token. */\n readonly token: string;\n }\n | {\n /** An API key, sent in a header or a query parameter. */\n readonly kind: \"api-key\";\n /** The header that carries the key, or null when a query parameter does. */\n readonly header: string | null;\n /** The query parameter that carries the key, or null when a header does. */\n readonly query: string | null;\n /** The key. */\n readonly value: string;\n };\n\n/**\n * The parts of a credential a credential store saves (graphty-element's `CredentialStore` is the\n * one caller), or null when it cannot be saved: a token function, an AWS provider or a custom\n * credential. The result HOLDS THE SECRET: never log it, and keep it only where you would keep the\n * password itself. `fromStorableCredential` makes the credential again. Experimental.\n * @param credential - a credential made by the `credentials` factories\n * @returns the parts, or null\n * @category Network sources\n */\nexport function storableCredential(credential: Credential): StorableCredential | null {\n const secret = secretOf(credential);\n switch (secret?.kind) {\n case \"basic\":\n return { kind: \"basic\", username: secret.username, password: secret.password };\n case \"api-key\":\n return { kind: \"api-key\", header: secret.header, query: secret.query, value: secret.value };\n case \"bearer\":\n return typeof secret.token === \"string\" ? { kind: \"bearer\", token: secret.token } : null;\n default:\n return null;\n }\n}\n\n/**\n * The credential `storableCredential` took apart, bound to the origins given. Experimental.\n * @param parts - what `storableCredential` returned\n * @param bind - the origins it may be sent to\n * @returns the credential\n * @category Network sources\n */\nexport function fromStorableCredential(parts: StorableCredential, bind?: CredentialBind): Credential {\n switch (parts.kind) {\n case \"basic\":\n return credentials.basic(parts.username, parts.password, bind);\n case \"bearer\":\n return credentials.bearer(parts.token, bind);\n default:\n return new SourceCredential(\n { kind: \"api-key\", header: parts.header, query: parts.query, value: parts.value },\n bind,\n );\n }\n}\n"],"names":[],"mappings":";AAYO,MAAM,iBAAiB;AAMvB,MAAM,mBAAmB;AAMzB,MAAM,kBAAkB;AAMxB,MAAM,oBAAoB;AAM1B,MAAM,iBAAiB;AAMvB,MAAM,qBAAqB;AAM3B,MAAM,mBAAmB;AAMzB,MAAM,qBAAqB;AAM3B,MAAM,mBAAmB;AAMzB,MAAM,qBAAqB;AAO3B,MAAM,qBAAqB;AAM3B,MAAM,uBAAuB;ACpEpC,MAAM,WAAsE;AAAA,EACxE,gBAAgB;AAAA,EAChB,kBAAkB;AAAA,EAClB,mBAAmB;AAAA,EACnB,sBAAsB;AAAA,EACtB,oBAAoB;AAAA,EACpB,kBAAkB;AACtB;AAUO,SAAS,OACZ,QACA,MACA,SACA,QACK;AAGL,SAAO,OAAO,KAAA,EAAO,SAAS,SAAS,IAAI,KAAK,eAAe,MAAM,SAAS,QAAW,QAAQ,MAAM;AAC3G;AASO,SAAS,UACZ,MACA,SACA,QACA,SAAS,UACJ;AACL,SAAO,IAAI,oBAAoB,QAAQ,CAAC,GAAG,MAAM,SAAS,MAAM;AACpE;AASO,SAAS,OACZ,QACA,MACA,SACA,QACI;AACJ,SAAO,QAAQ,eAAe,MAAM,SAAS,QAAW,MAAM;AAClE;ACpDA,MAAM,UAAU;AAGhB,MAAM,kBAAmG;AAAA,EACrG,CAAC,UAAU,QAAQ;AAAA,EACnB,CAAC,SAAS,OAAO;AAAA,EACjB,CAAC,QAAQ,MAAM;AAAA,EACf,CAAC,YAAY,UAAU;AAC3B;AAQA,SAAS,QAAQ,IAAY,QAAgB,SAAwB;AACjE,YAAU,oBAAoB,SAAS,EAAE,IAAI,QAAQ;AACzD;AAMA,SAAS,cAAc,IAAmC;AACtD,MAAI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AM,SAAS,SAAS,UAAU;AAClC,MAAI,QAAQ,SAAS,SAAS;AAC1B,WAAO,EAAE,MAAM,SAAS,UAAU,OAAO,UAAU,UAAU,OAAO,SAAA;AAAA,EACxE;AACA,MAAI,QAAQ,SAAS,UAAU;AAC3B,WAAO,EAAE,MAAM,UAAU,OAAO,OAAO,MAAA;AAAA,EAC3C;AACA,SAAO,WAAW,SAAY,SAAY,EAAE,MAAM,WAAW,KAAA;AACjE;AAwDO,SAAS,mBAAmB,YAAmD;AAClF,QAAM,SAAS,SAAS,UAAU;AAClC,UAAQ,QAAQ,MAAA;AAAA,IACZ,KAAK;AACD,aAAO,EAAE,MAAM,SAAS,UAAU,OAAO,UAAU,UAAU,OAAO,SAAA;AAAA,IACxE,KAAK;AACD,aAAO,EAAE,MAAM,WAAW,QAAQ,OAAO,QAAQ,OAAO,OAAO,OAAO,OAAO,OAAO,MAAA;AAAA,IACxF,KAAK;AACD,aAAO,OAAO,OAAO,UAAU,WAAW,EAAE,MAAM,UAAU,OAAO,OAAO,MAAA,IAAU;AAAA,IACxF;AACI,aAAO;AAAA,EAAA;AAEnB;AASO,SAAS,uBAAuB,OAA2B,MAAmC;AACjG,UAAQ,MAAM,MAAA;AAAA,IACV,KAAK;AACD,aAAO,YAAY,MAAM,MAAM,UAAU,MAAM,UAAU,IAAI;AAAA,IACjE,KAAK;AACD,aAAO,YAAY,OAAO,MAAM,OAAO,IAAI;AAAA,IAC/C;AACI,aAAO,IAAI;AAAA,QACP,EAAE,MAAM,WAAW,QAAQ,MAAM,QAAQ,OAAO,MAAM,OAAO,OAAO,MAAM,MAAA;AAAA,QAC1E;AAAA,MAAA;AAAA,EACJ;AAEZ;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GraphFormatError } from "@graphty/graph-format";
|
|
2
|
-
import { L as LOSS } from "./export-
|
|
3
|
-
import { p as plural, a as agree } from "./report-
|
|
2
|
+
import { L as LOSS } from "./export-Cha4dRFz.js";
|
|
3
|
+
import { p as plural, a as agree } from "./report-CwMfYa9J.js";
|
|
4
4
|
const RAW = `${String.fromCodePoint(0)}cx:`;
|
|
5
5
|
const RAW_JSON = /"\\u0000cx:(-?\d+)"/g;
|
|
6
6
|
const BIG_INTEGER_TEXT = /^-?[1-9]\d{15,}$/;
|
|
@@ -256,4 +256,4 @@ export {
|
|
|
256
256
|
planNodeIds as p,
|
|
257
257
|
stringify as s
|
|
258
258
|
};
|
|
259
|
-
//# sourceMappingURL=cx-export-
|
|
259
|
+
//# sourceMappingURL=cx-export-Bt6NoqTQ.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cx-export-BEeF6ymo.js","sources":["../../src/common/cx-export.ts"],"sourcesContent":["/**\n * The exporter machinery CX version 1 and CX2 share (design/graph-io/cytoscape-and-obo/design.md\n * sections 1.2 and 1.3): integer node ids (safe integers, or the digits of an integer beyond 2^53\n * written raw), sanitizeIds \"mangle\" renumbering, edge ids from the id role column, the declared\n * type of a column, the direction notes (every CX edge is directed) and the JSON writer that keeps\n * -0 and raw big integers.\n */\n\nimport { type Column, GraphFormatError, type GraphSnapshot, type NodeId } from \"@graphty/graph-format\";\n\nimport { type LossNote } from \"../types.js\";\nimport { type PairFolding } from \"./direction.js\";\nimport { LOSS } from \"./export.js\";\nimport { type ResolvedExportOptions } from \"./options.js\";\nimport { agree, plural } from \"./plural.js\";\n\n/**\n * Records a loss note.\n * @category Plugin helpers\n */\nexport type CxNoteFn = (code: string, message: string, column?: string | null, count?: number | null) => void;\n\n/**\n * The prefix of a string that stands for a raw number literal in the output: -0 (which\n * JSON.stringify writes as 0) and an integer id beyond 2^53 (kept as its digits).\n */\nconst RAW = `${String.fromCodePoint(0)}cx:`;\n\n/** A raw literal as JSON.stringify writes it, to be unquoted. */\nconst RAW_JSON = /\"\\\\u0000cx:(-?\\d+)\"/g;\n\n/** An integer literal beyond 2^53 as text: a CX id graph-io keeps as its digits. */\nconst BIG_INTEGER_TEXT = /^-?[1-9]\\d{15,}$/;\n\n/**\n * The node ids as written: the original, a renumbered one, or a raw big integer.\n * @category Plugin helpers\n */\nexport interface WrittenIds {\n /** How many ids were renumbered (sanitizeIds \"mangle\"). */\n readonly changed: number;\n /**\n * The written id of a node.\n * @param i - the node index\n * @returns a number, or a raw string for a big integer\n */\n idAt(i: number): NodeId;\n /**\n * Whether a node was renumbered.\n * @param i - the node index\n * @returns true when its original goes into graphty:originalId\n */\n isChanged(i: number): boolean;\n /**\n * The original id of a node.\n * @param i - the node index\n * @returns the snapshot's id\n */\n originalAt(i: number): NodeId;\n}\n\n/**\n * Whether an id can be written as a CX id unchanged: a safe integer, or the digits of an integer\n * beyond 2^53 (the CX importers read those back as the same digits).\n * @param id - the id\n * @returns true when writable\n */\nfunction writableId(id: NodeId): boolean {\n return typeof id === \"number\"\n ? Number.isSafeInteger(id)\n : BIG_INTEGER_TEXT.test(id) && !Number.isSafeInteger(Number(id));\n}\n\n/**\n * The written node ids; under \"error\" an id that is not writable throws E_INVALID_ID, under\n * \"mangle\" it gets the next unused integer.\n * @param snapshot - the snapshot\n * @param mode - the sanitizeIds option\n * @param format - the format's display name, for the message\n * @returns the ids\n */\nfunction writtenIds(snapshot: GraphSnapshot, mode: \"error\" | \"mangle\", format: string): WrittenIds {\n const { ids } = snapshot;\n const bad: number[] = [];\n const used = new Set<number>();\n for (let i = 0; i < ids.size; i++) {\n const id = ids.idOf(i);\n if (!writableId(id)) {\n bad.push(i);\n } else if (typeof id === \"number\") {\n used.add(id);\n }\n }\n if (bad.length > 0 && mode === \"error\") {\n const first = ids.idOf(bad[0]);\n throw new GraphFormatError(\n \"E_INVALID_ID\",\n `${bad.length} node id${plural(bad.length)} cannot be written as ${format} integers (first: ${JSON.stringify(first)} at index ${bad[0]}); pass sanitizeIds: \"mangle\" to rewrite them`,\n { reason: \"charset\", charset: \"integer\", count: bad.length, index: bad[0] },\n );\n }\n const renumbered = new Map<number, number>();\n let next = 0;\n for (const i of bad) {\n while (used.has(next)) {\n next++;\n }\n used.add(next);\n renumbered.set(i, next);\n }\n return {\n changed: bad.length,\n idAt: (i: number): NodeId => {\n const id = renumbered.get(i) ?? ids.idOf(i);\n return typeof id === \"string\" ? `${RAW}${id}` : id;\n },\n isChanged: (i: number): boolean => renumbered.has(i),\n originalAt: (i: number): NodeId => ids.idOf(i),\n };\n}\n\n/**\n * The `idCounter` of the node ids as written (the largest id plus one, NDEx's next free id).\n * @param ids - the written ids\n * @param count - the node count\n * @returns the counter: a number, or a raw big integer for stringify()\n * @category Plugin helpers\n */\nexport function nextNodeId(ids: WrittenIds, count: number): NodeId {\n let max = -1n;\n for (let i = 0; i < count; i++) {\n const id = ids.idAt(i);\n const value = typeof id === \"number\" ? BigInt(id) : BigInt(id.slice(RAW.length));\n if (value > max) {\n max = value;\n }\n }\n const next = max + 1n;\n return next <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(next) : `${RAW}${next.toString()}`;\n}\n\n/**\n * How many node ids are not writable unchanged.\n * @param snapshot - the snapshot\n * @returns the count\n */\nfunction unwritableIds(snapshot: GraphSnapshot): number {\n let count = 0;\n for (let i = 0; i < snapshot.ids.size; i++) {\n if (!writableId(snapshot.ids.idOf(i))) {\n count++;\n }\n }\n return count;\n}\n\n/**\n * The id notes and the written ids of a CX export: E_ID_CHARSET (export() throws) or\n * W_ID_MANGLED for the ids that are not integers.\n * @param snapshot - the snapshot\n * @param common - the resolved common options\n * @param format - the format's display name\n * @param attribute - the attribute the originals are kept in\n * @param note - records a note\n * @returns the ids, or the error export() throws\n * @category Plugin helpers\n */\nexport function planNodeIds(\n snapshot: GraphSnapshot,\n common: ResolvedExportOptions,\n format: string,\n attribute: string,\n note: CxNoteFn,\n): WrittenIds | GraphFormatError {\n const unwritable = unwritableIds(snapshot);\n if (unwritable > 0) {\n note(\n common.sanitizeIds === \"mangle\" ? LOSS.ID_MANGLED : LOSS.ID_CHARSET,\n common.sanitizeIds === \"mangle\"\n ? `${unwritable} node id${plural(unwritable)} ${agree(unwritable, \"is\", \"are\")} not integers, so they are renumbered; the original ids are written to the ${attribute} attribute, and an import with restoreMangledIds: true reads them back`\n : `${unwritable} node id${plural(unwritable)} ${agree(unwritable, \"is\", \"are\")} not integers, so the save fails unless sanitizeIds is \"mangle\"`,\n null,\n unwritable,\n );\n }\n try {\n return writtenIds(snapshot, common.sanitizeIds, format);\n } catch (err) {\n if (err instanceof GraphFormatError) {\n return err;\n }\n throw err;\n }\n}\n\n/**\n * The CX type of a scalar dtype.\n * @param dtype - the dtype\n * @param longOrigin - whether the source declared the column long\n * @returns the type text\n */\nfunction scalarType(dtype: string, longOrigin: boolean): string {\n switch (dtype) {\n case \"f64\":\n return longOrigin ? \"long\" : \"double\";\n case \"f32\":\n return \"double\";\n case \"i32\":\n case \"u8\":\n return \"integer\";\n case \"u32\":\n return \"long\";\n case \"bool\":\n return \"boolean\";\n default:\n return \"string\";\n }\n}\n\n/**\n * Whether every set value of an f64 column is integral (so a declared long stays long).\n * @param column - the column\n * @returns true when every set value is a safe integer\n */\nfunction allIntegral(column: Column): boolean {\n for (let i = 0; i < column.length; i++) {\n if (column.isSet(i) && !Number.isSafeInteger(column.value(i))) {\n return false;\n }\n }\n return true;\n}\n\n/**\n * The declared CX type of a column: string / double / long / integer / boolean or a list of one;\n * a json column (and a list of json items) is a string holding JSON text.\n * @param column - the column\n * @returns the type text\n * @category Plugin helpers\n */\nexport function declaredType(column: Column): string {\n const { meta } = column;\n const origin = meta.origin?.type ?? null;\n const longOrigin = origin !== null && origin.endsWith(\"long\") && (meta.dtype !== \"f64\" || allIntegral(column));\n if (meta.dtype === \"list\") {\n return meta.itemDtype === null || meta.itemDtype === \"json\"\n ? \"string\"\n : `list_of_${scalarType(meta.itemDtype, longOrigin)}`;\n }\n // a multi-component column (a color, a 3D vector) is written as a list of its components\n return meta.components > 1 ? `list_of_${scalarType(meta.dtype, false)}` : scalarType(meta.dtype, longOrigin);\n}\n\n/**\n * Count the positions with a non-finite x or y.\n * @param position - the position column\n * @returns the count\n * @category Plugin helpers\n */\nexport function nonFinitePositions(position: Column): number {\n let count = 0;\n for (let i = 0; i < position.length; i++) {\n if (position.isSet(i)) {\n const p = position.value(i) as ArrayLike<number>;\n if (!Number.isFinite(p[0]) || !Number.isFinite(p[1])) {\n count++;\n }\n }\n }\n return count;\n}\n\n/**\n * The edge ids to write: the id role column's values when they are distinct safe integers, next\n * unused integers for edges without one (W_EDGE_IDS_GENERATED). A generated id is never a\n * written node id either: CX keeps node and edge ids apart, but Cytoscape desktop numbers both\n * from one counter, and a reader with one id space (Cytoscape.js) would have to drop the edge's.\n * @param snapshot - the snapshot\n * @param note - records a note\n * @param nodeIds - the written node ids, which generated edge ids avoid\n * @returns one id per edge\n * @category Plugin helpers\n */\nexport function planEdgeIds(snapshot: GraphSnapshot, note: CxNoteFn, nodeIds: WrittenIds | null = null): number[] {\n const column = snapshot.edges.byRole(\"id\");\n const used = new Set<number>();\n let generated = 0;\n const ids: (number | null)[] = keptEdgeIds(column, snapshot.edgeCount, used);\n for (let i = 0; nodeIds !== null && i < snapshot.nodeCount; i++) {\n const id = nodeIds.idAt(i);\n if (typeof id === \"number\") {\n used.add(id);\n }\n }\n let next = 0;\n const out: number[] = [];\n for (let e = 0; e < snapshot.edgeCount; e++) {\n let id = ids[e];\n if (id === null) {\n while (used.has(next)) {\n next++;\n }\n id = next;\n used.add(next);\n generated++;\n }\n out.push(id);\n }\n if (column !== null && generated > 0) {\n note(\n LOSS.EDGE_IDS_GENERATED,\n `${generated} edge${plural(generated)} ${agree(generated, \"has\", \"have\")} no distinct integer id in \"${column.meta.name}\"; they are written with generated ids`,\n column.meta.name,\n generated,\n );\n }\n if (column !== null && column.dtype !== \"f64\") {\n note(\n LOSS.DTYPE,\n `edge id column \"${column.meta.name}\" is ${column.dtype}; CX edge ids are integers and read back as f64`,\n column.meta.name,\n snapshot.edgeCount - column.nullCount,\n );\n }\n return out;\n}\n\n/**\n * The edge ids an id column can keep: its distinct safe integers (numbers, or text that reads as one).\n * @param column - the edge id column, or null\n * @param edgeCount - the number of edges\n * @param used - receives the kept ids\n * @returns the kept id per edge, null where it cannot be kept\n */\nfunction keptEdgeIds(column: Column | null, edgeCount: number, used: Set<number>): (number | null)[] {\n const ids: (number | null)[] = new Array<number | null>(edgeCount).fill(null);\n if (column === null) {\n return ids;\n }\n for (let e = 0; e < edgeCount; e++) {\n const value = column.isSet(e) ? column.value(e) : undefined;\n const n = typeof value === \"number\" || typeof value === \"string\" ? Number(value) : Number.NaN;\n if (Number.isSafeInteger(n) && !used.has(n)) {\n ids[e] = n === 0 ? 0 : n;\n used.add(n);\n }\n }\n return ids;\n}\n\n/**\n * The direction notes: every CX edge is directed, so an undirected snapshot (or the undirected\n * pairs of a mixed one, folded under onMixedDirection) is written directed, and a mutual pair as\n * two edges without its mark.\n * @param snapshot - the snapshot\n * @param folding - the pair folding\n * @param common - the resolved common options\n * @param undirectedCode - the format's \"undirected written as directed\" code\n * @param note - records a note\n * @category Plugin helpers\n */\nexport function directionNotes(\n snapshot: GraphSnapshot,\n folding: PairFolding,\n common: ResolvedExportOptions,\n undirectedCode: string,\n note: CxNoteFn,\n): void {\n if (!snapshot.directed) {\n note(\n undirectedCode,\n `the snapshot is undirected; every edge is written as a directed edge (${snapshot.edgeCount} edge${plural(snapshot.edgeCount)})`,\n null,\n snapshot.edgeCount,\n );\n } else if (common.onMixedDirection !== \"error\") {\n let undirected = 0;\n for (let e = 0; e < snapshot.edgeCount; e++) {\n if (!folding.folded(e) && !folding.sourceDirected(e)) {\n undirected++;\n }\n }\n if (undirected > 0) {\n note(\n undirectedCode,\n `${undirected} undirected edge${plural(undirected)} ${agree(undirected, \"is\", \"are\")} written as one directed edge each (a pair folded to its primary); CX has no undirected edge`,\n null,\n undirected,\n );\n }\n }\n if (folding.mutualCount > 0) {\n note(\n LOSS.MUTUAL_EXPANDED,\n `${folding.mutualCount} mutual pair${plural(folding.mutualCount)} ${agree(folding.mutualCount, \"is\", \"are\")} written as two directed edges; the mutual mark is lost`,\n null,\n folding.mutualCount,\n );\n }\n}\n\n/**\n * The note recorder of a plan and its notes.\n * @returns the notes and the recorder\n * @category Plugin helpers\n */\nexport function noteList(): { notes: LossNote[]; note: CxNoteFn } {\n const notes: LossNote[] = [];\n const note: CxNoteFn = (code, message, column = null, count = null) => {\n notes.push(Object.freeze({ code, message, column, count }));\n };\n return { notes, note };\n}\n\n/**\n * The JSON text of a value, keeping -0 and writing the raw big-integer ids of idAt() as numbers.\n * @param value - the value\n * @returns the text\n * @category Plugin helpers\n */\nexport function stringify(value: unknown): string {\n const text = JSON.stringify(value, (_key, v: unknown) => (Object.is(v, -0) ? `${RAW}-0` : v));\n return text.includes(String.raw`\\u0000cx:`) ? text.replaceAll(RAW_JSON, \"$1\") : text;\n}\n\n/**\n * The text of one aspect block, element by element.\n * @param aspect - the aspect name\n * @param elements - the JSON texts of its elements\n * @yields the block's text\n * @returns nothing\n */\nexport function* aspectBlock(aspect: string, elements: Iterable<string>): Generator<string, void, undefined> {\n yield `{${JSON.stringify(aspect)}:[`;\n let first = true;\n for (const element of elements) {\n yield first ? `\\n${element}` : `,\\n${element}`;\n first = false;\n }\n yield \"]},\\n\";\n}\n"],"names":[],"mappings":";;;AA0BA,MAAM,MAAM,GAAG,OAAO,cAAc,CAAC,CAAC;AAGtC,MAAM,WAAW;AAGjB,MAAM,mBAAmB;AAmCzB,SAAS,WAAW,IAAqB;AACrC,SAAO,OAAO,OAAO,WACf,OAAO,cAAc,EAAE,IACvB,iBAAiB,KAAK,EAAE,KAAK,CAAC,OAAO,cAAc,OAAO,EAAE,CAAC;AACvE;AAUA,SAAS,WAAW,UAAyB,MAA0B,QAA4B;AAC/F,QAAM,EAAE,QAAQ;AAChB,QAAM,MAAgB,CAAA;AACtB,QAAM,2BAAW,IAAA;AACjB,WAAS,IAAI,GAAG,IAAI,IAAI,MAAM,KAAK;AAC/B,UAAM,KAAK,IAAI,KAAK,CAAC;AACrB,QAAI,CAAC,WAAW,EAAE,GAAG;AACjB,UAAI,KAAK,CAAC;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AACpF;AASO,UAAU,YAAY,QAAgB,UAAgE;AACzG,QAAM,IAAI,KAAK,UAAU,MAAM,CAAC;AAChC,MAAI,QAAQ;AACZ,aAAW,WAAW,UAAU;AAC5B,UAAM,QAAQ;AAAA,EAAK,OAAO,KAAK;AAAA,EAAM,OAAO;AAC5C,YAAQ;AAAA,EACZ;AACA,QAAM;AACV;"}
|
|
1
|
+
{"version":3,"file":"cx-export-Bt6NoqTQ.js","sources":["../../src/common/cx-export.ts"],"sourcesContent":["/**\n * The exporter machinery CX version 1 and CX2 share (design/graph-io/cytoscape-and-obo/design.md\n * sections 1.2 and 1.3): integer node ids (safe integers, or the digits of an integer beyond 2^53\n * written raw), sanitizeIds \"mangle\" renumbering, edge ids from the id role column, the declared\n * type of a column, the direction notes (every CX edge is directed) and the JSON writer that keeps\n * -0 and raw big integers.\n */\n\nimport { type Column, GraphFormatError, type GraphSnapshot, type NodeId } from \"@graphty/graph-format\";\n\nimport { type LossNote } from \"../types.js\";\nimport { type PairFolding } from \"./direction.js\";\nimport { LOSS } from \"./export.js\";\nimport { type ResolvedExportOptions } from \"./options.js\";\nimport { agree, plural } from \"./plural.js\";\n\n/**\n * Records a loss note.\n * @category Plugin helpers\n */\nexport type CxNoteFn = (code: string, message: string, column?: string | null, count?: number | null) => void;\n\n/**\n * The prefix of a string that stands for a raw number literal in the output: -0 (which\n * JSON.stringify writes as 0) and an integer id beyond 2^53 (kept as its digits).\n */\nconst RAW = `${String.fromCodePoint(0)}cx:`;\n\n/** A raw literal as JSON.stringify writes it, to be unquoted. */\nconst RAW_JSON = /\"\\\\u0000cx:(-?\\d+)\"/g;\n\n/** An integer literal beyond 2^53 as text: a CX id graph-io keeps as its digits. */\nconst BIG_INTEGER_TEXT = /^-?[1-9]\\d{15,}$/;\n\n/**\n * The node ids as written: the original, a renumbered one, or a raw big integer.\n * @category Plugin helpers\n */\nexport interface WrittenIds {\n /** How many ids were renumbered (sanitizeIds \"mangle\"). */\n readonly changed: number;\n /**\n * The written id of a node.\n * @param i - the node index\n * @returns a number, or a raw string for a big integer\n */\n idAt(i: number): NodeId;\n /**\n * Whether a node was renumbered.\n * @param i - the node index\n * @returns true when its original goes into graphty:originalId\n */\n isChanged(i: number): boolean;\n /**\n * The original id of a node.\n * @param i - the node index\n * @returns the snapshot's id\n */\n originalAt(i: number): NodeId;\n}\n\n/**\n * Whether an id can be written as a CX id unchanged: a safe integer, or the digits of an integer\n * beyond 2^53 (the CX importers read those back as the same digits).\n * @param id - the id\n * @returns true when writable\n */\nfunction writableId(id: NodeId): boolean {\n return typeof id === \"number\"\n ? Number.isSafeInteger(id)\n : BIG_INTEGER_TEXT.test(id) && !Number.isSafeInteger(Number(id));\n}\n\n/**\n * The written node ids; under \"error\" an id that is not writable throws E_INVALID_ID, under\n * \"mangle\" it gets the next unused integer.\n * @param snapshot - the snapshot\n * @param mode - the sanitizeIds option\n * @param format - the format's display name, for the message\n * @returns the ids\n */\nfunction writtenIds(snapshot: GraphSnapshot, mode: \"error\" | \"mangle\", format: string): WrittenIds {\n const { ids } = snapshot;\n const bad: number[] = [];\n const used = new Set<number>();\n for (let i = 0; i < ids.size; i++) {\n const id = ids.idOf(i);\n if (!writableId(id)) {\n bad.push(i);\n } else if (typeof id === \"number\") {\n used.add(id);\n }\n }\n if (bad.length > 0 && mode === \"error\") {\n const first = ids.idOf(bad[0]);\n throw new GraphFormatError(\n \"E_INVALID_ID\",\n `${bad.length} node id${plural(bad.length)} cannot be written as ${format} integers (first: ${JSON.stringify(first)} at index ${bad[0]}); pass sanitizeIds: \"mangle\" to rewrite them`,\n { reason: \"charset\", charset: \"integer\", count: bad.length, index: bad[0] },\n );\n }\n const renumbered = new Map<number, number>();\n let next = 0;\n for (const i of bad) {\n while (used.has(next)) {\n next++;\n }\n used.add(next);\n renumbered.set(i, next);\n }\n return {\n changed: bad.length,\n idAt: (i: number): NodeId => {\n const id = renumbered.get(i) ?? ids.idOf(i);\n return typeof id === \"string\" ? `${RAW}${id}` : id;\n },\n isChanged: (i: number): boolean => renumbered.has(i),\n originalAt: (i: number): NodeId => ids.idOf(i),\n };\n}\n\n/**\n * The `idCounter` of the node ids as written (the largest id plus one, NDEx's next free id).\n * @param ids - the written ids\n * @param count - the node count\n * @returns the counter: a number, or a raw big integer for stringify()\n * @category Plugin helpers\n */\nexport function nextNodeId(ids: WrittenIds, count: number): NodeId {\n let max = -1n;\n for (let i = 0; i < count; i++) {\n const id = ids.idAt(i);\n const value = typeof id === \"number\" ? BigInt(id) : BigInt(id.slice(RAW.length));\n if (value > max) {\n max = value;\n }\n }\n const next = max + 1n;\n return next <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(next) : `${RAW}${next.toString()}`;\n}\n\n/**\n * How many node ids are not writable unchanged.\n * @param snapshot - the snapshot\n * @returns the count\n */\nfunction unwritableIds(snapshot: GraphSnapshot): number {\n let count = 0;\n for (let i = 0; i < snapshot.ids.size; i++) {\n if (!writableId(snapshot.ids.idOf(i))) {\n count++;\n }\n }\n return count;\n}\n\n/**\n * The id notes and the written ids of a CX export: E_ID_CHARSET (export() throws) or\n * W_ID_MANGLED for the ids that are not integers.\n * @param snapshot - the snapshot\n * @param common - the resolved common options\n * @param format - the format's display name\n * @param attribute - the attribute the originals are kept in\n * @param note - records a note\n * @returns the ids, or the error export() throws\n * @category Plugin helpers\n */\nexport function planNodeIds(\n snapshot: GraphSnapshot,\n common: ResolvedExportOptions,\n format: string,\n attribute: string,\n note: CxNoteFn,\n): WrittenIds | GraphFormatError {\n const unwritable = unwritableIds(snapshot);\n if (unwritable > 0) {\n note(\n common.sanitizeIds === \"mangle\" ? LOSS.ID_MANGLED : LOSS.ID_CHARSET,\n common.sanitizeIds === \"mangle\"\n ? `${unwritable} node id${plural(unwritable)} ${agree(unwritable, \"is\", \"are\")} not integers, so they are renumbered; the original ids are written to the ${attribute} attribute, and an import with restoreMangledIds: true reads them back`\n : `${unwritable} node id${plural(unwritable)} ${agree(unwritable, \"is\", \"are\")} not integers, so the save fails unless sanitizeIds is \"mangle\"`,\n null,\n unwritable,\n );\n }\n try {\n return writtenIds(snapshot, common.sanitizeIds, format);\n } catch (err) {\n if (err instanceof GraphFormatError) {\n return err;\n }\n throw err;\n }\n}\n\n/**\n * The CX type of a scalar dtype.\n * @param dtype - the dtype\n * @param longOrigin - whether the source declared the column long\n * @returns the type text\n */\nfunction scalarType(dtype: string, longOrigin: boolean): string {\n switch (dtype) {\n case \"f64\":\n return longOrigin ? \"long\" : \"double\";\n case \"f32\":\n return \"double\";\n case \"i32\":\n case \"u8\":\n return \"integer\";\n case \"u32\":\n return \"long\";\n case \"bool\":\n return \"boolean\";\n default:\n return \"string\";\n }\n}\n\n/**\n * Whether every set value of an f64 column is integral (so a declared long stays long).\n * @param column - the column\n * @returns true when every set value is a safe integer\n */\nfunction allIntegral(column: Column): boolean {\n for (let i = 0; i < column.length; i++) {\n if (column.isSet(i) && !Number.isSafeInteger(column.value(i))) {\n return false;\n }\n }\n return true;\n}\n\n/**\n * The declared CX type of a column: string / double / long / integer / boolean or a list of one;\n * a json column (and a list of json items) is a string holding JSON text.\n * @param column - the column\n * @returns the type text\n * @category Plugin helpers\n */\nexport function declaredType(column: Column): string {\n const { meta } = column;\n const origin = meta.origin?.type ?? null;\n const longOrigin = origin !== null && origin.endsWith(\"long\") && (meta.dtype !== \"f64\" || allIntegral(column));\n if (meta.dtype === \"list\") {\n return meta.itemDtype === null || meta.itemDtype === \"json\"\n ? \"string\"\n : `list_of_${scalarType(meta.itemDtype, longOrigin)}`;\n }\n // a multi-component column (a color, a 3D vector) is written as a list of its components\n return meta.components > 1 ? `list_of_${scalarType(meta.dtype, false)}` : scalarType(meta.dtype, longOrigin);\n}\n\n/**\n * Count the positions with a non-finite x or y.\n * @param position - the position column\n * @returns the count\n * @category Plugin helpers\n */\nexport function nonFinitePositions(position: Column): number {\n let count = 0;\n for (let i = 0; i < position.length; i++) {\n if (position.isSet(i)) {\n const p = position.value(i) as ArrayLike<number>;\n if (!Number.isFinite(p[0]) || !Number.isFinite(p[1])) {\n count++;\n }\n }\n }\n return count;\n}\n\n/**\n * The edge ids to write: the id role column's values when they are distinct safe integers, next\n * unused integers for edges without one (W_EDGE_IDS_GENERATED). A generated id is never a\n * written node id either: CX keeps node and edge ids apart, but Cytoscape desktop numbers both\n * from one counter, and a reader with one id space (Cytoscape.js) would have to drop the edge's.\n * @param snapshot - the snapshot\n * @param note - records a note\n * @param nodeIds - the written node ids, which generated edge ids avoid\n * @returns one id per edge\n * @category Plugin helpers\n */\nexport function planEdgeIds(snapshot: GraphSnapshot, note: CxNoteFn, nodeIds: WrittenIds | null = null): number[] {\n const column = snapshot.edges.byRole(\"id\");\n const used = new Set<number>();\n let generated = 0;\n const ids: (number | null)[] = keptEdgeIds(column, snapshot.edgeCount, used);\n for (let i = 0; nodeIds !== null && i < snapshot.nodeCount; i++) {\n const id = nodeIds.idAt(i);\n if (typeof id === \"number\") {\n used.add(id);\n }\n }\n let next = 0;\n const out: number[] = [];\n for (let e = 0; e < snapshot.edgeCount; e++) {\n let id = ids[e];\n if (id === null) {\n while (used.has(next)) {\n next++;\n }\n id = next;\n used.add(next);\n generated++;\n }\n out.push(id);\n }\n if (column !== null && generated > 0) {\n note(\n LOSS.EDGE_IDS_GENERATED,\n `${generated} edge${plural(generated)} ${agree(generated, \"has\", \"have\")} no distinct integer id in \"${column.meta.name}\"; they are written with generated ids`,\n column.meta.name,\n generated,\n );\n }\n if (column !== null && column.dtype !== \"f64\") {\n note(\n LOSS.DTYPE,\n `edge id column \"${column.meta.name}\" is ${column.dtype}; CX edge ids are integers and read back as f64`,\n column.meta.name,\n snapshot.edgeCount - column.nullCount,\n );\n }\n return out;\n}\n\n/**\n * The edge ids an id column can keep: its distinct safe integers (numbers, or text that reads as one).\n * @param column - the edge id column, or null\n * @param edgeCount - the number of edges\n * @param used - receives the kept ids\n * @returns the kept id per edge, null where it cannot be kept\n */\nfunction keptEdgeIds(column: Column | null, edgeCount: number, used: Set<number>): (number | null)[] {\n const ids: (number | null)[] = new Array<number | null>(edgeCount).fill(null);\n if (column === null) {\n return ids;\n }\n for (let e = 0; e < edgeCount; e++) {\n const value = column.isSet(e) ? column.value(e) : undefined;\n const n = typeof value === \"number\" || typeof value === \"string\" ? Number(value) : Number.NaN;\n if (Number.isSafeInteger(n) && !used.has(n)) {\n ids[e] = n === 0 ? 0 : n;\n used.add(n);\n }\n }\n return ids;\n}\n\n/**\n * The direction notes: every CX edge is directed, so an undirected snapshot (or the undirected\n * pairs of a mixed one, folded under onMixedDirection) is written directed, and a mutual pair as\n * two edges without its mark.\n * @param snapshot - the snapshot\n * @param folding - the pair folding\n * @param common - the resolved common options\n * @param undirectedCode - the format's \"undirected written as directed\" code\n * @param note - records a note\n * @category Plugin helpers\n */\nexport function directionNotes(\n snapshot: GraphSnapshot,\n folding: PairFolding,\n common: ResolvedExportOptions,\n undirectedCode: string,\n note: CxNoteFn,\n): void {\n if (!snapshot.directed) {\n note(\n undirectedCode,\n `the snapshot is undirected; every edge is written as a directed edge (${snapshot.edgeCount} edge${plural(snapshot.edgeCount)})`,\n null,\n snapshot.edgeCount,\n );\n } else if (common.onMixedDirection !== \"error\") {\n let undirected = 0;\n for (let e = 0; e < snapshot.edgeCount; e++) {\n if (!folding.folded(e) && !folding.sourceDirected(e)) {\n undirected++;\n }\n }\n if (undirected > 0) {\n note(\n undirectedCode,\n `${undirected} undirected edge${plural(undirected)} ${agree(undirected, \"is\", \"are\")} written as one directed edge each (a pair folded to its primary); CX has no undirected edge`,\n null,\n undirected,\n );\n }\n }\n if (folding.mutualCount > 0) {\n note(\n LOSS.MUTUAL_EXPANDED,\n `${folding.mutualCount} mutual pair${plural(folding.mutualCount)} ${agree(folding.mutualCount, \"is\", \"are\")} written as two directed edges; the mutual mark is lost`,\n null,\n folding.mutualCount,\n );\n }\n}\n\n/**\n * The note recorder of a plan and its notes.\n * @returns the notes and the recorder\n * @category Plugin helpers\n */\nexport function noteList(): { notes: LossNote[]; note: CxNoteFn } {\n const notes: LossNote[] = [];\n const note: CxNoteFn = (code, message, column = null, count = null) => {\n notes.push(Object.freeze({ code, message, column, count }));\n };\n return { notes, note };\n}\n\n/**\n * The JSON text of a value, keeping -0 and writing the raw big-integer ids of idAt() as numbers.\n * @param value - the value\n * @returns the text\n * @category Plugin helpers\n */\nexport function stringify(value: unknown): string {\n const text = JSON.stringify(value, (_key, v: unknown) => (Object.is(v, -0) ? `${RAW}-0` : v));\n return text.includes(String.raw`\\u0000cx:`) ? text.replaceAll(RAW_JSON, \"$1\") : text;\n}\n\n/**\n * The text of one aspect block, element by element.\n * @param aspect - the aspect name\n * @param elements - the JSON texts of its elements\n * @yields the block's text\n * @returns nothing\n */\nexport function* aspectBlock(aspect: string, elements: Iterable<string>): Generator<string, void, undefined> {\n yield `{${JSON.stringify(aspect)}:[`;\n let first = true;\n for (const element of elements) {\n yield first ? `\\n${element}` : `,\\n${element}`;\n first = false;\n }\n yield \"]},\\n\";\n}\n"],"names":[],"mappings":";;;AA0BA,MAAM,MAAM,GAAG,OAAO,cAAc,CAAC,CAAC;AAGtC,MAAM,WAAW;AAGjB,MAAM,mBAAmB;AAmCzB,SAAS,WAAW,IAAqB;AACrC,SAAO,OAAO,OAAO,WACf,OAAO,cAAc,EAAE,IACvB,iBAAiB,KAAK,EAAE,KAAK,CAAC,OAAO,cAAc,OAAO,EAAE,CAAC;AACvE;AAUA,SAAS,WAAW,UAAyB,MAA0B,QAA4B;AAC/F,QAAM,EAAE,QAAQ;AAChB,QAAM,MAAgB,CAAA;AACtB,QAAM,2BAAW,IAAA;AACjB,WAAS,IAAI,GAAG,IAAI,IAAI,MAAM,KAAK;AAC/B,UAAM,KAAK,IAAI,KAAK,CAAC;AACrB,QAAI,CAAC,WAAW,EAAE,GAAG;AACjB,UAAI,KAAK,CAAC;AAAA,IACd,WAAW,OAAO,OAAO,UAAU;AAC/B,WAAK,IAAI,EAAE;AAAA,IACf;AAAA,EACJ;AACA,MAAI,IAAI,SAAS,KAAK,SAAS,SAAS;AACpC,UAAM,Q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AAQ;AAAA,EAAK,OAAO,KAAK;AAAA,EAAM,OAAO;AAC5C,YAAQ;AAAA,EACZ;AACA,QAAM;AACV;"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const WIKIDATA_ADVISORS = `PREFIX wd: <http://www.wikidata.org/entity/>
|
|
2
|
+
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
|
|
3
|
+
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
|
4
|
+
CONSTRUCT { ?person wdt:P184 ?advisor . ?person rdfs:label ?name . ?advisor rdfs:label ?advisorName . }
|
|
5
|
+
WHERE {
|
|
6
|
+
?person wdt:P166 wd:Q38104 ; wdt:P184 ?advisor ; rdfs:label ?name .
|
|
7
|
+
?advisor rdfs:label ?advisorName .
|
|
8
|
+
FILTER(lang(?name) = "en" && lang(?advisorName) = "en")
|
|
9
|
+
}`;
|
|
10
|
+
const SPARQL_DESCRIPTOR = Object.freeze({
|
|
11
|
+
plainName: "SPARQL endpoint",
|
|
12
|
+
kind: "sparql",
|
|
13
|
+
version: 1,
|
|
14
|
+
auth: ["basic", "bearer"],
|
|
15
|
+
authRequired: "optional",
|
|
16
|
+
features: ["expand", "probe", "validate", "page"],
|
|
17
|
+
params: [
|
|
18
|
+
{ name: "query", plainName: "Query", type: "query", language: "sparql" },
|
|
19
|
+
{
|
|
20
|
+
name: "mode",
|
|
21
|
+
plainName: "Mode",
|
|
22
|
+
type: "enum",
|
|
23
|
+
values: [
|
|
24
|
+
{ value: "query", label: "Query" },
|
|
25
|
+
{ value: "all", label: "Everything" },
|
|
26
|
+
{ value: "neighborhood", label: "Seed nodes" }
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
{ name: "ids", plainName: "Seed IRIs", type: "node-id" },
|
|
30
|
+
{ name: "language", plainName: "Language", type: "string", advanced: true },
|
|
31
|
+
{ name: "predicates", plainName: "Follow predicates", type: "string", advanced: true },
|
|
32
|
+
{
|
|
33
|
+
name: "pageSize",
|
|
34
|
+
plainName: "Page size",
|
|
35
|
+
type: "integer",
|
|
36
|
+
default: 1e3,
|
|
37
|
+
min: 1,
|
|
38
|
+
max: 1e4,
|
|
39
|
+
advanced: true
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
samples: [
|
|
43
|
+
{
|
|
44
|
+
id: "wikidata-physics-advisors",
|
|
45
|
+
plainName: "Wikidata: physics Nobel laureates and their advisors",
|
|
46
|
+
endpoint: "https://query.wikidata.org/sparql",
|
|
47
|
+
params: {
|
|
48
|
+
query: WIKIDATA_ADVISORS,
|
|
49
|
+
pageSize: 100,
|
|
50
|
+
language: "en",
|
|
51
|
+
predicates: ["http://www.wikidata.org/prop/direct/"]
|
|
52
|
+
// NOSONAR(S5332): an RDF namespace IRI, never fetched; Wikidata's IRIs are http
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
});
|
|
57
|
+
export {
|
|
58
|
+
SPARQL_DESCRIPTOR as S
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=descriptor-B28U25x4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"descriptor-B28U25x4.js","sources":["../../src/sources/sparql/descriptor.ts"],"sourcesContent":["/**\n * The SPARQL source's descriptor: catalog data, available without loading the source's code.\n */\n\nimport { type SourceDescriptor } from \"../types.js\";\n\n/** A small Wikidata query: physics Nobel laureates and their doctoral advisors. */\nconst WIKIDATA_ADVISORS = `PREFIX wd: <http://www.wikidata.org/entity/>\nPREFIX wdt: <http://www.wikidata.org/prop/direct/>\nPREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\nCONSTRUCT { ?person wdt:P184 ?advisor . ?person rdfs:label ?name . ?advisor rdfs:label ?advisorName . }\nWHERE {\n ?person wdt:P166 wd:Q38104 ; wdt:P184 ?advisor ; rdfs:label ?name .\n ?advisor rdfs:label ?advisorName .\n FILTER(lang(?name) = \"en\" && lang(?advisorName) = \"en\")\n}`;\n\n/**\n * The descriptor of the `sparql` source. Experimental.\n * @category Network sources\n */\nexport const SPARQL_DESCRIPTOR: SourceDescriptor = Object.freeze({\n plainName: \"SPARQL endpoint\",\n kind: \"sparql\",\n version: 1,\n auth: [\"basic\", \"bearer\"],\n authRequired: \"optional\",\n features: [\"expand\", \"probe\", \"validate\", \"page\"],\n params: [\n { name: \"query\", plainName: \"Query\", type: \"query\", language: \"sparql\" },\n {\n name: \"mode\",\n plainName: \"Mode\",\n type: \"enum\",\n values: [\n { value: \"query\", label: \"Query\" },\n { value: \"all\", label: \"Everything\" },\n { value: \"neighborhood\", label: \"Seed nodes\" },\n ],\n },\n { name: \"ids\", plainName: \"Seed IRIs\", type: \"node-id\" },\n { name: \"language\", plainName: \"Language\", type: \"string\", advanced: true },\n { name: \"predicates\", plainName: \"Follow predicates\", type: \"string\", advanced: true },\n {\n name: \"pageSize\",\n plainName: \"Page size\",\n type: \"integer\",\n default: 1000,\n min: 1,\n max: 10000,\n advanced: true,\n },\n ],\n samples: [\n {\n id: \"wikidata-physics-advisors\",\n plainName: \"Wikidata: physics Nobel laureates and their advisors\",\n endpoint: \"https://query.wikidata.org/sparql\",\n params: {\n query: WIKIDATA_ADVISORS,\n pageSize: 100,\n language: \"en\",\n predicates: [\"http://www.wikidata.org/prop/direct/\"], // NOSONAR(S5332): an RDF namespace IRI, never fetched; Wikidata's IRIs are http\n },\n },\n ],\n});\n"],"names":[],"mappings":"AAOA,MAAM,oBAAoB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAcnB,MAAM,oBAAsC,OAAO,OAAO;AAAA,EAC7D,WAAW;AAAA,EACX,MAAM;AAAA,EACN,SAAS;AAAA,EACT,MAAM,CAAC,SAAS,QAAQ;AAAA,EACxB,cAAc;AAAA,EACd,UAAU,CAAC,UAAU,SAAS,YAAY,MAAM;AAAA,EAChD,QAAQ;AAAA,IACJ,EAAE,MAAM,SAAS,WAAW,SAAS,MAAM,SAAS,UAAU,SAAA;AAAA,IAC9D;AAAA,MACI,MAAM;AAAA,MACN,WAAW;AAAA,MACX,MAAM;AAAA,MACN,QAAQ;AAAA,QACJ,EAAE,OAAO,SAAS,OAAO,QAAA;AAAA,QACzB,EAAE,OAAO,OAAO,OAAO,aAAA;AAAA,QACvB,EAAE,OAAO,gBAAgB,OAAO,aAAA;AAAA,MAAa;AAAA,IACjD;AAAA,IAEJ,EAAE,MAAM,OAAO,WAAW,aAAa,MAAM,UAAA;AAAA,IAC7C,EAAE,MAAM,YAAY,WAAW,YAAY,MAAM,UAAU,UAAU,KAAA;AAAA,IACrE,EAAE,MAAM,cAAc,WAAW,qBAAqB,MAAM,UAAU,UAAU,KAAA;AAAA,IAChF;AAAA,MACI,MAAM;AAAA,MACN,WAAW;AAAA,MACX,MAAM;AAAA,MACN,SAAS;AAAA,MACT,KAAK;AAAA,MACL,KAAK;AAAA,MACL,UAAU;AAAA,IAAA;AAAA,EACd;AAAA,EAEJ,SAAS;AAAA,IACL;AAAA,MACI,IAAI;AAAA,MACJ,WAAW;AAAA,MACX,UAAU;AAAA,MACV,QAAQ;AAAA,QACJ,OAAO;AAAA,QACP,UAAU;AAAA,QACV,UAAU;AAAA,QACV,YAAY,CAAC,sCAAsC;AAAA;AAAA,MAAA;AAAA,IACvD;AAAA,EACJ;AAER,CAAC;"}
|
|
@@ -78,6 +78,8 @@ const REST_DESCRIPTOR = Object.freeze({
|
|
|
78
78
|
version: 1,
|
|
79
79
|
auth: ["bearer", "api-key"],
|
|
80
80
|
authRequired: "optional",
|
|
81
|
+
// ponytail: a mapping without `expand` or paging cannot do either; per-mapping features when a form needs them
|
|
82
|
+
features: ["expand", "probe", "validate", "page"],
|
|
81
83
|
params: [{ name: "mapping", plainName: "Mapping", type: "text", required: true }],
|
|
82
84
|
samples: [
|
|
83
85
|
{
|
|
@@ -103,7 +105,13 @@ const OPENALEX_DESCRIPTOR = Object.freeze({
|
|
|
103
105
|
defaultEndpoint: "https://api.openalex.org",
|
|
104
106
|
auth: ["api-key"],
|
|
105
107
|
authRequired: "optional",
|
|
108
|
+
// OpenAlex documents its key as the api_key query parameter
|
|
109
|
+
credentials: [
|
|
110
|
+
{ name: "api_key", kind: "api-key", required: false, plainName: "API key", send: { query: "api_key" } }
|
|
111
|
+
],
|
|
112
|
+
apiKey: { query: "api_key" },
|
|
106
113
|
rateLimit: { requests: 10, perMs: 1e3 },
|
|
114
|
+
features: ["expand", "probe", "validate", "page"],
|
|
107
115
|
params: [
|
|
108
116
|
{ name: "work", plainName: "Work", type: "string" },
|
|
109
117
|
{ name: "author", plainName: "Author", type: "string" },
|
|
@@ -124,7 +132,8 @@ const OPENALEX_DESCRIPTOR = Object.freeze({
|
|
|
124
132
|
id: "openalex-watts-strogatz",
|
|
125
133
|
plainName: "Watts-Strogatz paper's citations",
|
|
126
134
|
params: { work: "W2112090702" },
|
|
127
|
-
whole: false
|
|
135
|
+
whole: false,
|
|
136
|
+
firstPage: 200
|
|
128
137
|
}
|
|
129
138
|
]
|
|
130
139
|
});
|
|
@@ -134,4 +143,4 @@ export {
|
|
|
134
143
|
REST_DESCRIPTOR as R,
|
|
135
144
|
STRING_MAPPING as S
|
|
136
145
|
};
|
|
137
|
-
//# sourceMappingURL=descriptor-
|
|
146
|
+
//# sourceMappingURL=descriptor-Dhez_Cew.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"descriptor-Dhez_Cew.js","sources":["../../src/sources/rest/samples/deps-dev.ts","../../src/sources/rest/samples/string.ts","../../src/sources/rest/descriptor.ts"],"sourcesContent":["/**\n * A sample mapping: the resolved dependency graph of one package version from deps.dev\n * (https://deps.dev). The body already holds a node array and an edge array whose ends are node\n * positions, so the body is a container and `#` gives each package its position as its id.\n * Catalog data for the `rest` source's samples.\n */\n\nimport { type RestMapping } from \"../params.js\";\n\n/** The deps.dev dependencies mapping: `system` (npm, pypi, ...), `package` and `version`. */\nexport const DEPS_DEV_MAPPING: RestMapping = Object.freeze<RestMapping>({\n version: 1,\n endpoint: \"https://api.deps.dev\",\n load: \"dependencies\",\n directed: true,\n requests: {\n dependencies: {\n path: \"/v3/systems/{system}/packages/{package}/versions/{version}:dependencies\",\n records: \".\",\n entity: \"graph\",\n },\n },\n entities: {\n graph: {\n id: \"nodes\",\n node: false,\n edges: [\n {\n each: \"edges[]\",\n from: \"fromNode\",\n to: \"toNode\",\n type: \"depends_on\",\n entity: \"package\",\n fields: { requirement: \"requirement\" },\n },\n ],\n embedded: [{ at: \"nodes[]\", entity: \"package\" }],\n },\n package: {\n id: \"#\",\n fields: {\n name: \"versionKey.name\",\n version: \"versionKey.version\",\n system: \"versionKey.system\",\n relation: \"relation\",\n },\n },\n },\n});\n","/**\n * A sample mapping: STRING's functional partners of a protein (https://string-db.org). Each\n * interaction record names both proteins, so both are embedded nodes and the record itself is only\n * the edge. Catalog data for the `rest` source's samples.\n */\n\nimport { type RestMapping } from \"../params.js\";\n\n/** The STRING network mapping: `identifiers`, `species` (NCBI taxon) and `add_nodes`. */\nexport const STRING_MAPPING: RestMapping = Object.freeze<RestMapping>({\n version: 1,\n endpoint: \"https://string-db.org\",\n load: \"network\",\n directed: false,\n requests: {\n network: {\n path: \"/api/json/network\",\n query: { identifiers: \"{identifiers}\", species: \"{species}\", add_nodes: \"{add_nodes}\" },\n records: \".\",\n entity: \"interaction\",\n },\n },\n entities: {\n interaction: {\n id: \"stringId_A\",\n node: false,\n edges: [\n {\n from: \"stringId_A\",\n to: \"stringId_B\",\n type: \"interacts_with\",\n entity: \"protein-b\",\n fields: { score: \"score\" },\n },\n ],\n embedded: [\n { at: \".\", entity: \"protein-a\" },\n { at: \".\", entity: \"protein-b\" },\n ],\n },\n \"protein-a\": { id: \"stringId_A\", label: \"protein\", fields: { name: \"preferredName_A\" } },\n \"protein-b\": { id: \"stringId_B\", label: \"protein\", fields: { name: \"preferredName_B\" } },\n },\n});\n","/**\n * The descriptors of the REST mapping source and its `openalex` preset: catalog data, available\n * without loading the sources' code.\n */\n\nimport { type SourceDescriptor } from \"../types.js\";\nimport { DEPS_DEV_MAPPING } from \"./samples/deps-dev.js\";\nimport { STRING_MAPPING } from \"./samples/string.js\";\n\n/**\n * The descriptor of the generic `rest` source. Experimental.\n * @category Network sources\n */\nexport const REST_DESCRIPTOR: SourceDescriptor = Object.freeze({\n plainName: \"REST API\",\n kind: \"rest\",\n version: 1,\n auth: [\"bearer\", \"api-key\"],\n authRequired: \"optional\",\n // ponytail: a mapping without `expand` or paging cannot do either; per-mapping features when a form needs them\n features: [\"expand\", \"probe\", \"validate\", \"page\"],\n params: [{ name: \"mapping\", plainName: \"Mapping\", type: \"text\", required: true }],\n samples: [\n {\n id: \"string-tp53\",\n plainName: \"STRING: TP53's functional partners\",\n params: { mapping: STRING_MAPPING, identifiers: \"TP53\", species: \"9606\", add_nodes: \"20\" },\n endpoint: STRING_MAPPING.endpoint,\n counts: { nodes: 21, edges: 113 },\n },\n {\n id: \"deps-dev-webpack\",\n plainName: \"deps.dev: webpack 5.90.0\",\n params: { mapping: DEPS_DEV_MAPPING, system: \"npm\", package: \"webpack\", version: \"5.90.0\" },\n endpoint: DEPS_DEV_MAPPING.endpoint,\n counts: { nodes: 84, edges: 121 },\n },\n ],\n});\n\n/**\n * The descriptor of the `openalex` preset. Experimental.\n * @category Network sources\n */\nexport const OPENALEX_DESCRIPTOR: SourceDescriptor = Object.freeze({\n plainName: \"OpenAlex\",\n kind: \"rest\",\n version: 1,\n defaultEndpoint: \"https://api.openalex.org\",\n auth: [\"api-key\"],\n authRequired: \"optional\",\n // OpenAlex documents its key as the api_key query parameter\n credentials: [\n { name: \"api_key\", kind: \"api-key\", required: false, plainName: \"API key\", send: { query: \"api_key\" } },\n ],\n apiKey: { query: \"api_key\" },\n rateLimit: { requests: 10, perMs: 1000 },\n features: [\"expand\", \"probe\", \"validate\", \"page\"],\n params: [\n { name: \"work\", plainName: \"Work\", type: \"string\" },\n { name: \"author\", plainName: \"Author\", type: \"string\" },\n {\n name: \"graph\",\n plainName: \"Graph\",\n type: \"enum\",\n default: \"citation\",\n values: [\n { value: \"citation\", label: \"Citations\" },\n { value: \"coauthorship\", label: \"Co-authors\" },\n ],\n },\n { name: \"include\", plainName: \"Include\", type: \"string\", advanced: true },\n ],\n samples: [\n {\n id: \"openalex-watts-strogatz\",\n plainName: \"Watts-Strogatz paper's citations\",\n params: { work: \"W2112090702\" },\n whole: false,\n firstPage: 200,\n },\n ],\n});\n"],"names":[],"mappings":"AAUO,MAAM,mBAAgC,OAAO,OAAoB;AAAA,EACpE,SAAS;AAAA,EACT,UAAU;AAAA,EACV,MAAM;AAAA,EACN,UAAU;AAAA,EACV,UAAU;AAAA,IACN,cAAc;AAAA,MACV,MAAM;AAAA,MACN,SAAS;AAAA,MACT,QAAQ;AAAA,IAAA;AAAA,EACZ;AAAA,EAEJ,UAAU;AAAA,IACN,OAAO;AAAA,MACH,IAAI;AAAA,MACJ,MAAM;AAAA,MACN,OAAO;AAAA,QACH;AAAA,UACI,MAAM;AAAA,UACN,MAAM;AAAA,UACN,IAAI;AAAA,UACJ,MAAM;AAAA,UACN,QAAQ;AAAA,UACR,QAAQ,EAAE,aAAa,cAAA;AAAA,QAAc;AAAA,MACzC;AAAA,MAEJ,UAAU,CAAC,EAAE,IAAI,WAAW,QAAQ,WAAW;AAAA,IAAA;AAAA,IAEnD,SAAS;AAAA,MACL,IAAI;AAAA,MACJ,QAAQ;AAAA,QACJ,MAAM;AAAA,QACN,SAAS;AAAA,QACT,QAAQ;AAAA,QACR,UAAU;AAAA,MAAA;AAAA,IACd;AAAA,EACJ;AAER,CAAC;ACvCM,MAAM,iBAA8B,OAAO,OAAoB;AAAA,EAClE,SAAS;AAAA,EACT,UAAU;AAAA,EACV,MAAM;AAAA,EACN,UAAU;AAAA,EACV,UAAU;AAAA,IACN,SAAS;AAAA,MACL,MAAM;AAAA,MACN,OAAO,EAAE,aAAa,iBAAiB,SAAS,aAAa,WAAW,cAAA;AAAA,MACxE,SAAS;AAAA,MACT,QAAQ;AAAA,IAAA;AAAA,EACZ;AAAA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