@cognite/cli 1.7.0 → 1.8.0-alpha.sdk-gen
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/_templates/agents/create/README_TEMPLATE.md +66 -0
- package/_templates/app/new/config/vitest.config.ts.ejs.t +3 -2
- package/_templates/app/new/root/.npmrc.ejs.t +1 -1
- package/_templates/app/new/root/AGENTS.md.ejs.t +62 -12
- package/_templates/app/new/root/SPEC.md.ejs.t +17 -15
- package/_templates/app/new/root/app.json.ejs.t +1 -0
- package/_templates/app/new/root/manifest.json.ejs.t +6 -1
- package/_templates/app/new/root/package.json.ejs.t +4 -1
- package/_templates/app/new/src/App.test.tsx.ejs.t +32 -2
- package/_templates/app/new/src/App.tsx.ejs.t +54 -5
- package/_templates/app/new/src/main.tsx.ejs.t +0 -70
- package/dist/chunk-ATR2SGLU.js +1 -0
- package/dist/chunk-M3FWAJ4N.js +12 -0
- package/dist/chunk-PZ2YS5FR.js +1 -0
- package/dist/cli/cli.js +241 -101
- package/dist/deploy/index.d.ts +37 -10
- package/dist/deploy/index.js +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/sdk-runtime/index.d.ts +371 -0
- package/dist/sdk-runtime/index.js +1 -0
- package/package.json +18 -4
- package/dist/chunk-74X2P7OO.js +0 -12
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as c}from"./chunk-ATR2SGLU.js";function A(e){return{space:e.space,externalId:e.externalId,version:e.version}}c(A,"toSharedViewId");function Ee(e){switch(e){case"text":return"String";case"boolean":return"Boolean";case"int32":case"int64":return"Int";case"float32":case"float64":return"Float";case"timestamp":return"DateTime";case"date":return"Date";case"json":return"JSON";case"timeseries":return"CogniteTimeSeriesReference";case"file":return"CogniteFileReference";case"sequence":return"CogniteSequenceReference";case"enum":return"String";default:return"String"}}c(Ee,"dmsTypeToGraphQL");function ie(e){if(!("source"in e)){if(e.type?.type==="direct")return e.type.list?e.type.source?{kind:"directRelationList",targetView:A(e.type.source)}:{kind:"scalar",isList:!1,graphqlType:"JSON"}:e.type.source?{kind:"directRelation",targetView:A(e.type.source)}:{kind:"scalar",isList:!1,graphqlType:"JSON"};if(e.type?.type==="enum"){let t=e.type,n={};if(typeof t=="object"&&t!==null&&"values"in t){let i=t.values;if(typeof i=="object"&&i!==null)for(let[r,s]of Object.entries(i))n[r]={name:typeof s=="object"&&s!==null&&"name"in s?String(s.name):void 0}}return{kind:"enum",values:Object.keys(n),valueNames:Object.fromEntries(Object.entries(n).map(([i,r])=>[i,r.name??i]))}}return{kind:"scalar",isList:e.type!==void 0&&"list"in e.type&&e.type.list===!0,graphqlType:e.type?.type?Ee(e.type.type):"String"}}if("through"in e)return{kind:e.connectionType==="single_reverse_direct_relation"?"reverseDirect":"reverseList",sourceView:A(e.source),throughProperty:e.through.identifier};if(e.connectionType==="single_edge_connection"||e.connectionType==="multi_edge_connection"){let t=e.direction==="inwards"?"inwards":"outwards";return{kind:"edge",targetView:A(e.source),direction:t}}return{kind:"scalar"}}c(ie,"parsePropertyDescriptor");function oe(e,t,n){let i=e.property(t,n);return i?i.kind==="directRelation"?!1:i.kind==="directRelationList"?!0:i.kind==="scalar"&&i.graphqlType==="JSON":!0}c(oe,"isListThroughProperty");function x(e){return e.usedFor!=="edge"}c(x,"isNodeOrAll");function se(e){let t=new Set;return e.filter(n=>t.has(n.externalId)?!1:(t.add(n.externalId),!0))}c(se,"dedupeByExternalId");function ae(e){return Object.entries(e.properties).map(([t,n])=>[t,ie(n),n.description])}c(ae,"parsedProperties");async function ce(e,t){let i=(await t.dataModels.retrieve([{space:e.space,externalId:e.dataModelExternalId,version:e.dataModelVersion}],{inlineViews:!1})).items[0];if(!i)throw new Error(`Data model ${e.space}/${e.dataModelExternalId}/${e.dataModelVersion} not found`);if(!i.views?.length)throw new Error(`Data model ${e.space}/${e.dataModelExternalId}/${e.dataModelVersion} has no views`);let r=i.views.map(o=>({space:o.space,externalId:o.externalId,version:o.version}));return(await t.views.retrieve(r,{includeInheritedProperties:!0})).items}c(ce,"fetchViews");function le(e){let t=e.filter(x),n=new Map,i=new Map;for(let r of t){let s=new Map;for(let[a,p]of ae(r))s.set(a,p);let o={view:{space:r.space,externalId:r.externalId,version:r.version},properties:s};n.set(`${r.space}:${r.externalId}`,o),i.set(r.externalId,o)}return{view(r){let s=n.get(`${r.space}:${r.externalId}`)??i.get(r.externalId);if(!s)throw new Error(`SchemaKnowledge: no view for "${r.space}:${r.externalId}"`);return s},property(r,s){return(n.get(`${r.space}:${r.externalId}`)??i.get(r.externalId))?.properties.get(s)}}}c(le,"buildSchemaKnowledge");function pe(){return{initialBatchLimit:1e3,maxBatchLimit:5e3,searchLimit:1e3,inFilterChunkSize:100,reverseListChunkSize:1e3,previewLimit:3,nestedDetailLimit:5,enableRemoveNotConnected:!1,max408Retries:3,max429Retries:5,retryBaseDelayMs:500,maxConcurrentRequests:4,maxNestingDepth:2,maxTotalItems:1e4,maxFilterDepth:16}}c(pe,"defaultPlannerConfig");var K=class K extends Error{constructor(t){super(t),this.name="PlannerValidationError"}};c(K,"PlannerValidationError");var m=K;var Me={avg:c(e=>({avg:{property:e.property}}),"avg"),sum:c(e=>({sum:{property:e.property}}),"sum"),min:c(e=>({min:{property:e.property}}),"min"),max:c(e=>({max:{property:e.property}}),"max"),count:c(e=>({count:{property:e.property??"externalId"}}),"count"),histogram:c(e=>({histogram:{property:e.property,interval:e.interval}}),"histogram")};function ue(e){let t=Me[e.function];if(!t)throw new m(`Unknown aggregation function '${e.function}'`);if(e.function!=="count"&&!e.property)throw new m(`Property is required for '${e.function}' aggregation`);if(e.function==="histogram"&&e.interval===void 0)throw new m("Interval is required for 'histogram' aggregation");return t(e)}c(ue,"toAggregationDefinition");function de(e){return e.flatMap(t=>t.aggregates.map(n=>{if(n.aggregate==="histogram"){let{aggregate:o,property:a,buckets:p}=n;return{aggregate:o,property:a??null,value:null,buckets:p,group:t.group??null}}let{aggregate:i,property:r,value:s}=n;return{aggregate:i,property:r??null,value:s??null,buckets:null,group:t.group??null}}))}c(de,"flattenAggregateItems");function U(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}c(U,"isRecord");function P(e){return typeof e=="string"||typeof e=="number"}c(P,"isScalar");var _e={space:["node","space"],externalId:["node","externalId"]};function Fe(e,t){return _e[t]??[e.space,`${e.externalId}/${e.version}`,t]}c(Fe,"propRef");var Oe={exists:c((e,t)=>typeof t!="boolean"?void 0:t?{exists:{property:e}}:{not:{exists:{property:e}}},"exists"),eq:c((e,t)=>({equals:{property:e,value:t}}),"eq"),in:c((e,t)=>Array.isArray(t)?{in:{property:e,values:t}}:void 0,"in"),isNull:c((e,t)=>typeof t!="boolean"?void 0:t?{not:{exists:{property:e}}}:{exists:{property:e}},"isNull"),prefix:c((e,t)=>typeof t=="string"?{prefix:{property:e,value:t}}:void 0,"prefix"),gte:c((e,t)=>P(t)?{range:{property:e,gte:t}}:void 0,"gte"),gt:c((e,t)=>P(t)?{range:{property:e,gt:t}}:void 0,"gt"),lte:c((e,t)=>P(t)?{range:{property:e,lte:t}}:void 0,"lte"),lt:c((e,t)=>P(t)?{range:{property:e,lt:t}}:void 0,"lt"),containsAny:c((e,t)=>Array.isArray(t)?{containsAny:{property:e,values:t}}:void 0,"containsAny"),containsAll:c((e,t)=>Array.isArray(t)?{containsAll:{property:e,values:t}}:void 0,"containsAll"),overlaps:c((e,t)=>Array.isArray(t)?{containsAny:{property:e,values:t}}:void 0,"overlaps")};function qe(e,t,n,i,r,s){let o=Fe(n,e),a=Object.entries(t).flatMap(([p,l])=>{if(l==null)return[];if(p==="nested"&&i&&U(l)){let d=i.property(n,e);if(d?.kind==="directRelation"){let f={type:"view",...d.targetView},g=b(l,f,i,r+1,s);if(g)return[{nested:{scope:[n.space,`${n.externalId}/${n.version}`,e],filter:g}}]}return[]}let u=Oe[p]?.(o,l);return u?[u]:[]});if(a.length!==0)return a.length===1?a[0]:{and:a}}c(qe,"translatePropertyFilter");function $e(e){if(e.length!==0)return e.length===1?e[0]:{and:e}}c($e,"collapse");function fe(e,t,n,i=16){return b(e,t,n,0,i)}c(fe,"buildFilter");function b(e,t,n,i,r){if(i>r)throw new m(`Filter nesting depth ${i} exceeds maximum ${r}. Reduce _and/_or/_not/nested nesting.`);if(!U(e))return;let s=Object.entries(e).flatMap(([o,a])=>{if(a==null)return[];if(o==="_not"){let p=b(a,t,n,i+1,r);return p?[{not:p}]:[]}if(o==="hasData"&&typeof a=="boolean"&&a)return[{hasData:[{type:"view",space:t.space,externalId:t.externalId,version:t.version}]}];if(o==="matchAll"&&typeof a=="boolean"&&a)return[{matchAll:{}}];if((o==="_and"||o==="_or")&&Array.isArray(a)){let p=a.flatMap(l=>{let u=b(l,t,n,i+1,r);return u?[u]:[]});return p.length>0?[o==="_and"?{and:p}:{or:p}]:[]}if(U(a)){let p=qe(o,a,t,n,i,r);return p?[p]:[]}return[]});return $e(s)}c(b,"buildFilterImpl");function ge(e,t){if(!(!e||e.length===0))return e.map(n=>({property:{view:t,property:n.field},direction:n.direction??"ascending",nullsFirst:n.nullsFirst}))}c(ge,"parseSortArg");var Qe=new Set(["space","externalId"]);function j(e,t){let n;try{n=t.view(e).properties}catch{return[]}let i=[];for(let[r,s]of n)(s.kind==="scalar"||s.kind==="enum"||s.kind==="directRelationList")&&!Qe.has(r)&&i.push(r);return i}c(j,"scalarNames");function me(e){switch(e.kind){case"directRelation":case"directRelationList":case"edge":return e.targetView;case"reverseDirect":case"reverseList":return e.sourceView;default:return}}c(me,"connectionTargetView");function Be(e,t,n){if(t==="count"||t==="aggregate")return{scalars:[],connections:new Map};let i=t==="query"||t==="search",r=j(e,n),s=new Map;for(let[o,a]of n.view(e).properties)if(a.kind==="directRelation"||a.kind==="reverseDirect"){let p=j(a.kind==="directRelation"?a.targetView:a.sourceView,n),l=i?["name","description"].filter(u=>p.includes(u)):p;s.set(o,{select:{scalars:l,connections:new Map}})}else!i&&(a.kind==="reverseList"||a.kind==="edge")&&s.set(o,{select:{scalars:[],connections:new Map}});return{scalars:r,connections:s}}c(Be,"buildDefaultSelection");function ye(e,t,n){let i=t.select?[...t.select]:j(e,n),r=new Map;if(t.with)for(let[s,o]of Object.entries(t.with)){let a=n.property(e,s),p=a&&me(a);if(!p)throw new m(`Connection "${s}" does not exist on view ${e.externalId}`);r.set(s,{limit:o.limit,select:ye(p,o,n)})}return{scalars:i,connections:r}}c(ye,"buildWithTree");function C(e,t,n,i){let r=Be(e,t,i);if(!n||!n.select&&!n.with)return r;let s=n.select?[...n.select]:r.scalars,a=n.select&&t==="getById"?new Map:new Map(r.connections);if(n.with)for(let[p,l]of Object.entries(n.with)){let u=i.property(e,p),d=u&&me(u);if(!d)throw new m(`Connection "${p}" does not exist on view ${e.externalId}`);a.set(p,{limit:l.limit,select:ye(d,l,i)})}return{scalars:s,connections:a}}c(C,"toSelectionTree");function H(e,t,n){let i=new Map;for(let o of e.filter(x))i.set(o.externalId,{type:"view",space:o.space,externalId:o.externalId,version:o.version});function r(o){let a=i.get(o);if(!a)throw new m(`Unknown view "${o}"`);return a}c(r,"resolveView");let s=c((o,a)=>fe(a,o,t,n.maxFilterDepth),"filterFor");return{async query(o,a={}){let p=r(o);return await n.query({view:p,select:C(p,"query",a,t),filter:s(p,a.filter),sort:ge(a.sort,p),cursor:a.cursor,limit:a.limit})},async getById(o,a){let p=r(o),l={and:[{equals:{property:["node","space"],value:a.space}},{equals:{property:["node","externalId"],value:a.externalId}}]},{items:u}=await n.query({view:p,select:C(p,"getById",a,t),filter:l,limit:1});return u[0]??null},async count(o,a={}){let p=r(o);return n.count({view:p,filter:s(p,a.filter)})},async search(o,a={}){let p=r(o);return await n.search({view:p,query:a.query,limit:a.limit,filter:s(p,a.filter),sort:a.sort,select:C(p,"search",a,t),properties:a.properties})},async aggregate(o,a={}){let p=r(o),{items:l}=await n.aggregate({view:p,filter:s(p,a.filter),aggregates:(a.aggregates??[{function:"count"}]).map(ue),groupBy:a.groupBy,query:a.query});return de(l)}}}c(H,"createSdkDispatcher");import{CogniteError as je}from"@cognite/sdk";function Ke(e){let t=e.property.view;return{property:[t.space,`${t.externalId}/${t.version}`,e.property.property],direction:e.direction,nullsFirst:e.nullsFirst??!1}}c(Ke,"compileSortClause");function Ue(e,t){let n=new Set,i=new Map(e.map(r=>[r.name,r]));for(let r of e){if(r.queryable)continue;let s=r.from;if(!s||s in t)continue;let o=i.get(s);o?.view&&(t[s]={sources:[{source:o.view,properties:["*"]}]},n.add(s))}return n}c(Ue,"injectPhantomSelects");function z(e,t,n){let i={},r={};for(let l of e){if(!l.queryable)continue;if(l.kind==="edgeIntermediate"){let f={edges:{from:l.from,direction:l.direction,maxDistance:1},limit:Math.min(l.limit,n)};l.filter&&(f.edges.filter=l.filter),l.limitEach!=null&&(f.edges.limitEach=l.limitEach),i[l.name]=f,r[l.name]={sources:[]};continue}let u={filter:l.filter};l.from&&(u.from=l.from),l.chainTo?u.chainTo=l.chainTo:l.through?(u.through={view:l.through.view,identifier:l.through.property},u.direction=l.direction):l.direction&&(u.direction=l.direction);let d={limit:Math.min(l.limit,n),nodes:u};l.sort&&l.sort.length>0&&(d.sort=l.sort.map(Ke)),i[l.name]=d,r[l.name]={sources:[{source:l.view,properties:l.select}]}}let s=Ue(e,r),o={with:i,select:r},a={},p=!1;for(let l of e){if(!l.queryable||l.kind==="edgeIntermediate")continue;let u=t.get(l.name);u!=null&&(a[l.name]=u,p=!0)}return p&&(o.cursors=a),{query:o,tempSelectSteps:s}}c(z,"compileQuery");function G(e,t){let n=[];for(let i=0;i<e.length;i+=t)n.push(e.slice(i,i+t));return n}c(G,"chunkArray");function He(e){let t=e.through;return[t.view.space,`${t.view.externalId}/${t.view.version}`,t.property]}c(He,"throughPropertyPath");function ze(e,t){let n=e.filter,i={containsAny:{property:He(e),values:t}};return n?{and:[n,i]}:i}c(ze,"containsAnyParentFilter");var X=class X{constructor(t,n){this.dms=t;this.config=n}async run(t,n,i){let{response:r,tempSelectSteps:s,batchLimit:o}=await this.queryWithRetry(t,n,i),a={},p=new Map;for(let[l,u]of Object.entries(r.items))a[l]=u,p.set(l,r.nextCursor[l]??null);return await this.fetchReverseLists(t,a),{batch:a,nextCursors:p,tempSelectSteps:s,batchLimit:o}}async fetchConnections(t,n){await this.fetchReverseLists(t,n),await this.fetchQueryableConnections(t,n),await this.fetchEdgeConnections(t,n)}async queryWithRetry(t,n,i){let r=i,s=0;for(;;){let{query:o,tempSelectSteps:a}=z(t,n,r);try{return{response:await this.dms.query({with:o.with,select:o.select,cursors:o.cursors}),tempSelectSteps:a,batchLimit:r}}catch(p){if(p instanceof je&&p.status===408){if(s>=this.config.max408Retries)throw p;s++,r=Math.max(1,Math.floor(r/2))}else throw p}}}async fetchReverseLists(t,n){let i=t.filter(r=>!r.queryable&&r.from&&r.kind==="reverseList");for(let r of i){let s=n[r.from]??[];if(s.length===0){n[r.name]=[];continue}let o=s.map(l=>({space:l.space,externalId:l.externalId})),a=G(o,this.config.reverseListChunkSize),p=await Promise.all(a.map(async l=>{let u=[],d;do{let f={limit:r.limit,nodes:{filter:ze(r,l)}},g=await this.dms.query({with:{[r.name]:f},select:{[r.name]:{sources:[{source:r.view,properties:r.select}]}},...d?{cursors:{[r.name]:d}}:{}});u.push(...g.items[r.name]??[]),d=g.nextCursor?.[r.name]??void 0}while(d);return u}));n[r.name]=p.flat()}}async fetchQueryableConnections(t,n){let i=t.filter(r=>r.queryable&&r.from&&(r.kind==="directRelation"||r.kind==="reverseDirect"));for(let r of i){let s=n[r.from]??[];if(s.length===0){n[r.name]=[];continue}if(r.kind==="directRelation"){let o=r.through,a=`${o.view.externalId}/${o.view.version}`,p=[],l=new Set;for(let f of s){let g=f.properties?.[o.view.space]?.[a]?.[o.property];if(g&&typeof g=="object"&&"space"in g&&"externalId"in g&&typeof g.space=="string"&&typeof g.externalId=="string"){let y=`${g.space}:${g.externalId}`;l.has(y)||(l.add(y),p.push({space:g.space,externalId:g.externalId}))}}if(p.length===0){n[r.name]=[];continue}let u=G(p,this.config.inFilterChunkSize),d=await Promise.all(u.map(f=>this.dms.retrieve({items:f.map(g=>({instanceType:"node",...g})),sources:[{source:r.view}]})));n[r.name]=d.flatMap(f=>f.items)}else{let o=s.map(d=>({space:d.space,externalId:d.externalId})),a=r.through,p=[a.view.space,`${a.view.externalId}/${a.view.version}`,a.property],l=G(o,this.config.inFilterChunkSize),u=[];for(let d of l){let f=r.limit-u.length;if(f<=0)break;let g=await this.dms.search({view:r.view,filter:{in:{property:p,values:d}},limit:f});u.push(...g.items)}n[r.name]=u}}}async fetchEdgeConnections(t,n){let i=t.filter(r=>r.kind==="edgeIntermediate"&&r.from);for(let r of i){let s=n[r.from]??[],o=t.find(f=>f.kind==="edge"&&f.from===r.name);if(!o)continue;if(s.length===0){n[r.name]=[],n[o.name]=[];continue}let a=`${r.from}__edge_root`,p={nodes:{filter:{or:s.map(f=>({and:[{equals:{property:["node","space"],value:f.space}},{equals:{property:["node","externalId"],value:f.externalId}}]}))}},limit:s.length},l={edges:{from:a,direction:r.direction,maxDistance:1},limit:r.limit};r.filter&&(l.edges.filter=r.filter),r.limitEach!=null&&(l.edges.limitEach=r.limitEach);let u={nodes:{from:r.name,chainTo:o.chainTo},limit:o.limit};o.filter&&(u.nodes.filter=o.filter);let d=await this.dms.query({with:{[a]:p,[r.name]:l,[o.name]:u},select:{[a]:{sources:[]},[r.name]:{sources:[]},[o.name]:{sources:[{source:o.view,properties:o.select}]}}});n[r.name]=d.items[r.name]??[],n[o.name]=d.items[o.name]??[]}}};c(X,"QueryExecutor");var R=X;var Ge={endCursor:null,hasNextPage:!1};function Se(e){return{items:e,pageInfo:Ge}}c(Se,"wrapConnection");function V(e){if(!e||typeof e!="object"||!("space"in e)||!("externalId"in e))return!1;let{space:t,externalId:n}=e;return typeof t=="string"&&typeof n=="string"}c(V,"isDmsRef");function Xe(e,t){if(V(e))return e;if(typeof e!="object"||e===null||!("externalId"in e))return;let{externalId:n}=e;if(typeof n!="string")return;let i="space"in e&&typeof e.space=="string"?e.space:t;return i?{space:i,externalId:n}:void 0}c(Xe,"resolveParentRef");function We(e,t,n){if(V(e)){t(e);return}if(Array.isArray(e))for(let i of e){let r=Xe(i,n);r&&t(r)}}c(We,"forEachParentRef");var Ye=/^[a-z]{2,3}(-[a-zA-Z0-9]{2,4})?$/;function N(e){if(!e||typeof e!="object"||Array.isArray(e)||V(e))return e;let t=Object.entries(e);return t.length===0||!t.every(n=>typeof n[1]=="string"&&Ye.test(n[0]))?e:t.find(([n])=>n==="en")?.[1]??t[0][1]}c(N,"coerceTextWithLocale");function we(e,t){let n=`${t.externalId}/${t.version}`,i=e.properties?.[t.space]?.[n]??{},r={};for(let[s,o]of Object.entries(i))r[s]=N(o);return{...r,space:e.space,externalId:e.externalId}}c(we,"extractViewProperties");function L(e,t,n,i){if(t.length===0)return;let r=[...n.values()].filter(o=>o.from===e.name&&o.fieldName),s=[...n.values()].filter(o=>o.kind==="edge"&&o.fieldName&&o.from!=null&&n.get(o.from)?.from===e.name);for(let o of[...r,...s]){let a=(i[o.name]??[]).map(p=>we(p,o.view));if(o.kind==="directRelation"){let p=new Map;for(let l of a)p.set(`${l.space}:${l.externalId}`,l);for(let l of t){let u=l[o.fieldName];l[o.fieldName]=V(u)?p.get(`${u.space}:${u.externalId}`)??null:null}L(o,a,n,i)}else if(o.kind==="reverseDirect"||o.kind==="reverseList"){let p=o.through.property,l=new Map;for(let u of t)l.set(`${u.space}:${u.externalId}`,[]);for(let u of a){let d=u[p];d!=null?We(d,f=>{l.get(`${f.space}:${f.externalId}`)?.push(u)},u.space):t.length===1&&l.get(`${t[0].space}:${t[0].externalId}`)?.push(u)}for(let u of t){let d=l.get(`${u.space}:${u.externalId}`)??[];u[o.fieldName]=o.kind==="reverseList"?Se(d):d}L(o,a,n,i)}else if(o.kind==="edge"){let p=i[o.from]??[],l=new Map;for(let d of p){if(d.instanceType!=="edge")continue;let{startNode:f,endNode:g}=d;if(!f||!g)continue;let y=o.chainTo==="destination"?f:g,h=o.chainTo==="destination"?g:f,S=`${y.space}:${y.externalId}`,w=`${h.space}:${h.externalId}`,ne=l.get(S)??[];ne.push(w),l.set(S,ne)}let u=new Map;for(let d of a)u.set(`${d.space}:${d.externalId}`,d);for(let d of t){let f=`${d.space}:${d.externalId}`,y=(l.get(f)??[]).map(h=>u.get(h)).filter(h=>h!==void 0);d[o.fieldName]=Se(y)}L(o,a,n,i)}}}c(L,"nestChildrenForStep");function Je(e,t,n){let i=e.find(s=>!s.from);if(!i)return n;let r=new Map(e.map(s=>[s.name,s]));return L(i,n,r,t),n}c(Je,"nestChildren");function M(e,t){let n=e.find(r=>!r.from);if(!n)return[];let i=(t[n.name]??[]).map(r=>we(r,n.view));return Je(e,t,i)}c(M,"unpack");function W(e,t){for(let n of e)delete t[n]}c(W,"stripTempSelects");function Y(e){let t={};for(let[n,i]of e)i!=null&&(t[n]=i);return Object.keys(t).length===0?null:btoa(JSON.stringify(t))}c(Y,"encodeCursors");function Ze(e){if(e===null||typeof e!="object"||Array.isArray(e))return!1;for(let t of Object.values(e))if(typeof t!="string")return!1;return!0}c(Ze,"isStringRecord");function J(e){if(!e)return new Map;let t;try{t=JSON.parse(atob(e))}catch{throw new m("Invalid pagination cursor \u2014 the value is malformed or has been modified by the client.")}if(!Ze(t))throw new m("Invalid pagination cursor \u2014 expected a JSON object of {stepName: string}.");return new Map(Object.entries(t))}c(J,"decodeCursors");import{CogniteError as et}from"@cognite/sdk";function xe(){return{max429Retries:5,retryBaseDelayMs:500,maxConcurrentRequests:4}}c(xe,"defaultRetryConfig");function tt(e){return new Promise(t=>setTimeout(t,e))}c(tt,"sleep");var ee=class ee{constructor(t){this.queue=[];this.count=t}acquire(){return this.count>0?(this.count--,Promise.resolve()):new Promise(t=>this.queue.push(t))}release(){let t=this.queue.shift();t?t():this.count++}};c(ee,"Semaphore");var Z=ee,te=class te{constructor(t,n=xe()){this.inner=t;this.config=n;this.semaphore=new Z(n.maxConcurrentRequests)}query(t){return this.withRetry(()=>this.inner.query(t))}search(t){return this.withRetry(()=>this.inner.search(t))}aggregate(t){return this.withRetry(()=>this.inner.aggregate(t))}retrieve(t){return this.withRetry(()=>this.inner.retrieve(t))}sync(t){return this.withRetry(()=>this.inner.sync(t))}upsert(t){return this.inner.upsert(t)}delete(t){return this.inner.delete(t)}inspect(t){return this.inner.inspect(t)}async withRetry(t){let n=0;for(;;){await this.semaphore.acquire();let i=!1;try{return await t()}catch(r){if(r instanceof et&&r.status===429){if(n>=this.config.max429Retries)throw r;n++,this.semaphore.release(),i=!0,await tt(this.config.retryBaseDelayMs*2**(n-1))}else throw r}finally{i||this.semaphore.release()}}}};c(te,"RetryingDmsClient");var I=te;function F(e){return e.connections.size===0?0:1+Math.max(...[...e.connections.values()].map(t=>F(t.select)))}c(F,"selectionDepth");function rt(e,t,n){for(let i of t.scalars)if(i!=="*"&&!n.property(e,i))throw new m(`Property "${i}" does not exist on view ${e.externalId}/${e.version}`);for(let[i]of t.connections)if(!n.property(e,i))throw new m(`Connection "${i}" does not exist on view ${e.externalId}/${e.version}`)}c(rt,"validateSelection");function E(e){return{hasData:[e]}}c(E,"hasDataFilter");function nt(e,t){let n=E(t);return e?{and:[e,n]}:n}c(nt,"scopedFilter");function it(e,t,n,i,r){return{name:"0",kind:"root",view:e,filter:nt(t,e),sort:n&&n.length>0?n:void 0,select:i.length>0?i:["*"],limit:r,queryable:!0}}c(it,"makeRootStep");function ot(e,t,n,i,r,s){return{name:e,from:t.name,kind:"directRelation",view:i,through:{view:t.view,property:n},direction:"outwards",filter:E(i),select:r.length>0?r:["*"],limit:s,queryable:!0,fieldName:n}}c(ot,"makeDirectRelationStep");function st(e,t,n,i,r,s,o){return{name:e,from:t.name,kind:"reverseDirect",view:i,through:{view:i,property:r},direction:"inwards",filter:E(i),select:s.length>0?s:["*"],limit:o,queryable:!0,fieldName:n}}c(st,"makeReverseDirectStep");function at(e,t,n,i,r,s,o,a){return{name:e,from:t.name,kind:"reverseList",view:i,through:{view:i,property:r},direction:"inwards",filter:E(i),select:s.length>0?s:["*"],limit:o,queryable:!a,fieldName:n}}c(at,"makeReverseListStep");function ct(e,t,n,i,r,s,o,a){let p={name:e,from:n.name,kind:"edgeIntermediate",view:r,direction:s,filter:void 0,select:[],limit:a,limitEach:a,queryable:!0},l={name:t,from:e,kind:"edge",view:r,filter:E(r),select:o.length>0?o:["*"],limit:a,queryable:!0,fieldName:i,chainTo:s==="outwards"?"destination":"source"};return[p,l]}c(ct,"makeEdgeSteps");function _(e){return{type:"view",space:e.space,externalId:e.externalId,version:e.version}}c(_,"toRef");function Re(e,t){return e.length===0||e.includes("*")||e.includes(t)?e:[...e,t]}c(Re,"withThroughProperty");function lt(e,t){return e.includes("*")||e.includes(t)?e:[...e,t]}c(lt,"withDirectRelationRef");function k(e,t,n,i,r,s){let o=0;for(let[a,p]of n.connections){let l=r.property(t,a);if(!l)continue;o++;let u=p.limit??i,d=p.select.scalars,f=p.select,g=`${e.name}_${o}`;if(l.kind==="directRelation"){e.select=lt(e.select,a);let y=_(l.targetView),h=ot(g,e,a,y,d,u);s.push(h),k(h,y,f,i,r,s)}else if(l.kind==="reverseDirect"){let y=_(l.sourceView),h=Re(d,l.throughProperty),S=st(g,e,a,y,l.throughProperty,h,u);s.push(S),k(S,y,f,i,r,s)}else if(l.kind==="reverseList"){let y=_(l.sourceView),h=Re(d,l.throughProperty),S=oe(r,l.sourceView,l.throughProperty),w=at(g,e,a,y,l.throughProperty,h,u,S);s.push(w),k(w,y,f,i,r,s)}else if(l.kind==="edge"){let y=_(l.targetView),h=`${e.name}_${o}_e`,[S,w]=ct(h,g,e,a,y,l.direction,d,u);s.push(S,w),k(w,y,f,i,r,s)}}}c(k,"addConnectionSteps");function O(e,t,n,i,r,s,o){s&&rt(e,t,s);let a=it(e,n,i,t.scalars,r),p=[a];return s&&k(a,e,t,o??r,s,p),p}c(O,"buildSteps");var pt="5c4d853e7c3b77b1eb4468d5329b278c",ut="https://api.mixpanel.com/track",dt="flows-typed-ts-sdk";var D={ClientCreated:"Flows.SDK.ClientCreated",OperationExecuted:"Flows.SDK.OperationExecuted"};function ft(e){return typeof e=="object"&&e!==null}c(ft,"isRecord");function Ie(){let e=globalThis;return ft(e)?e:{}}c(Ie,"defaultEnv");function gt(e=Ie()){return e.COGNITE_TELEMETRY_DISABLED==="1"||e.DO_NOT_TRACK==="1"}c(gt,"isSdkTelemetryDisabled");function mt(e){return{track(t,n,i){let r=JSON.stringify([{event:t,properties:{token:e,...n}}]),s=new URLSearchParams({data:r});fetch(ut,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:s.toString(),keepalive:!0}).then(()=>i(),()=>i())}}}c(mt,"fetchInit");var yt={track:c(()=>{},"track"),flush:c(async()=>{},"flush"),register:c(()=>{},"register")};function ht(e={}){let t=e.env??Ie();if(gt(t))return yt;let n=e.init??mt,i,r=new Set,s={};function o(){return i||(i=n(pt)),i}return c(o,"getClient"),{register(a){s={...s,...a}},track(a,p){let l=o(),u={...s,...p,applicationId:dt},d=c(()=>{},"finish"),f=new Promise(g=>{d=g});r.add(f);try{l.track(a,u,d)}catch{d()}f.finally(()=>r.delete(f))},async flush(a=2e3){if(r.size===0)return;let p,l=new Promise(u=>{p=setTimeout(u,a),p.unref?.()});try{await Promise.race([Promise.allSettled([...r]),l])}finally{p!==void 0&&clearTimeout(p)}}}}c(ht,"createSdkTelemetry");var T=ht();var re=class re{get schemaKnowledge(){return this.schema}get maxFilterDepth(){return this.config.maxFilterDepth}constructor(t,n,i,r=T){this.schema=n,this.config={...pe(),...i},this.telemetry=r,this.dms=new I(t,{max429Retries:this.config.max429Retries,retryBaseDelayMs:this.config.retryBaseDelayMs,maxConcurrentRequests:this.config.maxConcurrentRequests}),this.executor=new R(this.dms,{max408Retries:this.config.max408Retries,inFilterChunkSize:this.config.inFilterChunkSize,reverseListChunkSize:this.config.reverseListChunkSize})}async trackOperation(t,n,i){let r=performance.now();try{let s=await i();return this.telemetry.track(D.OperationExecuted,{operationType:t,viewExternalId:n.externalId,success:!0,durationMs:Math.round(performance.now()-r)}),s}catch(s){throw this.telemetry.track(D.OperationExecuted,{operationType:t,viewExternalId:n.externalId,success:!1,durationMs:Math.round(performance.now()-r)}),s}}async _queryPage(t){let n=F(t.select);if(n>this.config.maxNestingDepth)throw new m(`Query nesting depth ${n} exceeds the maximum of ${this.config.maxNestingDepth} enforced by the Data Modeling service. Reduce connection depth.`);let i=t.limit??this.config.initialBatchLimit,r=O(t.view,t.select,t.filter,t.sort,i,this.schema,this.config.previewLimit);if(r.length===0)return{items:[],pageInfo:{endCursor:null,hasNextPage:!1}};let s=new Map(J(t.cursor)),o=Math.min(this.config.initialBatchLimit,this.config.maxBatchLimit),{batch:a,nextCursors:p,tempSelectSteps:l}=await this.executor.run(r,s,o);W(l,a);let u=M(r,a),d=r[0],f=p.get(d.name)??null,g=Y(p),y=f!=null;return{items:u,pageInfo:{endCursor:g,hasNextPage:y}}}async query(t){return this.trackOperation("query",t.view,()=>this._queryPage(t))}async queryAll(t,n){let i=n??this.config.maxTotalItems,r=[],s,o=!0;for(;o;){let a=await this._queryPage({...t,cursor:s});if(r.push(...a.items),o=a.pageInfo.hasNextPage,s=a.pageInfo.endCursor??void 0,r.length>=i){if(n===void 0&&o)throw new m(`listAll reached the hard ceiling of ${i} items. Pass an explicit maxTotal to acknowledge this or raise maxTotalItems in config.`);break}}return r}async search(t){return this.trackOperation("search",t.view,async()=>{let n=t.limit??this.config.searchLimit,i=await this.dms.search({view:t.view,query:t.query,filter:t.filter,sort:t.sort,limit:n,properties:t.properties?[...t.properties]:void 0}),r=O(t.view,t.select,void 0,void 0,n,this.schema,this.config.previewLimit),s={0:i.items};return await this.executor.fetchConnections(r,s),{items:M(r,s),pageInfo:{endCursor:null,hasNextPage:!1}}})}async retrieve(t,n){return this.trackOperation("retrieve",n,async()=>{if(t.length===0)return[];let i=await this.dms.retrieve({items:t.map(s=>({instanceType:"node",space:s.space,externalId:s.externalId})),sources:[{source:n}]}),r=`${n.externalId}/${n.version}`;return i.items.map(s=>{let o=s.properties?.[n.space]?.[r]??{},a={};for(let[p,l]of Object.entries(o))a[p]=N(l);return{...a,space:s.space,externalId:s.externalId}})})}async count(t){return this.trackOperation("count",t.view,async()=>{let i=(await this.dms.aggregate({view:t.view,filter:t.filter,aggregates:[{count:{property:"externalId"}}]})).items[0]?.aggregates[0];return(i?.aggregate!=="histogram"?i?.value:void 0)??0})}async aggregate(t){return this.trackOperation("aggregate",t.view,async()=>({items:(await this.dms.aggregate({view:t.view,filter:t.filter,aggregates:t.aggregates,groupBy:t.groupBy,query:t.query})).items}))}async*queryPages(t){let n,i=!0;for(;i;){let r=await this._queryPage({...t,cursor:n});yield r,i=r.pageInfo.hasNextPage,n=r.pageInfo.endCursor??void 0}}};c(re,"QueryRunner");var v=re;async function St(e,t,n=T){let i=await ce(e,t);return ke(i,t,n)}c(St,"createSdkRuntime");function ke(e,t,n=T){let i=se(e),r=le(i),s=new v(t.instances,r,void 0,n),o=H(i,r,s);return n.register({project:t.project}),n.track(D.ClientCreated,{viewCount:i.filter(x).length}),{runner:s,dispatcher:o}}c(ke,"createSdkRuntimeFromViews");export{H as a,St as b,ke as c};
|