@redocly/openapi-docs 3.24.0-next.4 → 3.24.0-next.6

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.
Files changed (33) hide show
  1. package/dist/redocly-openapi-docs.min.AiChatProvider-C_OmERaa.js +32 -0
  2. package/dist/redocly-openapi-docs.min.AiChatSqliteDBStorage-C5E-x8f4.js +1 -0
  3. package/dist/redocly-openapi-docs.min.AiPanel-Z2Zw-OOK.js +754 -0
  4. package/dist/redocly-openapi-docs.min.HistorySqliteDBStorage-DYnaxLim.js +1 -0
  5. package/dist/redocly-openapi-docs.min.SqliteDBStorage-B6uym4Oj.js +14 -0
  6. package/dist/redocly-openapi-docs.min.StepContextSqliteDBStorage-DTB5U2yh.js +1 -0
  7. package/dist/redocly-openapi-docs.min.ai-chat-mappers-y6k4QA37.js +1 -0
  8. package/dist/redocly-openapi-docs.min.ai-message-parts.schema-C7fjQhYX.js +1 -0
  9. package/dist/redocly-openapi-docs.min.external-resolver-6xHVd9y7.js +2 -0
  10. package/dist/redocly-openapi-docs.min.history.schema-DzAAX18S.js +1 -0
  11. package/dist/redocly-openapi-docs.min.index-B2kW1MJX.js +1 -0
  12. package/dist/redocly-openapi-docs.min.index-D5tgmAoY.js +1 -0
  13. package/dist/redocly-openapi-docs.min.index-DHNqz_Gi.js +7694 -0
  14. package/dist/redocly-openapi-docs.min.index-DkqHu0CX.js +1 -0
  15. package/dist/redocly-openapi-docs.min.indexes-Bp4ld5gB.js +1 -0
  16. package/dist/redocly-openapi-docs.min.js +1 -21007
  17. package/dist/redocly-openapi-docs.min.lint-CmpdR_qH.js +181 -0
  18. package/dist/redocly-openapi-docs.min.lint-graphql-CAO-eUMC.js +3 -0
  19. package/dist/redocly-openapi-docs.min.respect-run-DjAvzRiR.js +78 -0
  20. package/dist/redocly-openapi-docs.min.standalone-C6JXws-S.js +12087 -0
  21. package/dist/redocly-openapi-docs.min.step-context.schema-DEgzIgw0.js +1 -0
  22. package/dist/redocly-openapi-docs.min.tauri-path-DySEV5MH.js +1 -0
  23. package/dist/redocly-openapi-docs.min.useAiChatQueries-CYikEfuU.js +358 -0
  24. package/lib/components/Callbacks/CallbackSummary.js +1 -1
  25. package/lib/components/Callbacks/CallbacksList.js +1 -1
  26. package/lib/components/Schema/ArraySchema.js +1 -1
  27. package/lib/components/Schema/Schema.js +1 -1
  28. package/lib/components/Schema/SubSchema.js +1 -1
  29. package/lib/components/Schema/types.d.ts +2 -0
  30. package/lib/models/field.js +1 -1
  31. package/lib/models/schema.js +2 -2
  32. package/lib/services/OpenAPIParser.js +1 -1
  33. package/package.json +7 -7
@@ -0,0 +1 @@
1
+ import{h as i}from"./redocly-openapi-docs.min.history.schema-DzAAX18S.js";import{s as n,e as a,d as o}from"./redocly-openapi-docs.min.indexes-Bp4ld5gB.js";function d(e){return n`count(${n.raw("*")})`.mapWith(Number)}function c(e){if(!e.step)throw new Error(`Invalid step history record: missing step data for id ${e.id}`);return{id:e.id,date:e.date,type:"step",step:e.step,response:e.response??null,statusCode:e.statusCode??null}}function u(e){if(!e.workflowId||!e.collectionId||!e.workflow||!e.workflowResult||e.success===null)throw new Error(`Invalid workflow history record: missing required fields for id ${e.id}`);return{id:e.id,date:e.date,type:"workflow",workflowId:e.workflowId,collectionId:e.collectionId,workflow:e.workflow,workflowResult:e.workflowResult,success:e.success,durationMs:e.durationMs??null}}function f(e){return{id:e.id,date:e.date,type:"step",step:e.step,response:e.response,statusCode:e.statusCode}}function p(e){return{id:e.id,date:e.date,type:"workflow",workflowId:e.workflowId,collectionId:e.collectionId,workflow:e.workflow,workflowResult:e.workflowResult,success:e.success,durationMs:e.durationMs}}function l(e){return e.type==="workflow"?u(e):c(e)}function h(e){return e.type==="workflow"?p(e):f(e)}class y{constructor(t){this.sqliteDB=t}sqliteDB;get db(){return this.sqliteDB.db}selectAll(){return this.db.select().from(i)}async initialize(){await this.sqliteDB.initialize()}async read(t){await this.initialize();const s=this.selectAll();return(t?.type?await s.where(a(i.type,t.type)).orderBy(o(i.date)):await s.orderBy(o(i.date))).map(l)}async addItem(t){await this.initialize();const s=h(t);await this.db.insert(i).values(s)}async updateItem(t,s){await this.initialize();const{id:r,type:k,...w}=s;await this.db.update(i).set(w).where(a(i.id,t))}async deleteItem(t){await this.initialize(),await this.db.delete(i).where(a(i.id,t))}async clear(){await this.initialize(),await this.db.delete(i)}async getById(t){await this.initialize();const s=await this.selectAll().where(a(i.id,t)).limit(1);return s.length===0?null:l(s[0])}async getRecent(t,s){await this.initialize();const r=this.selectAll();return(s?.type?await r.where(a(i.type,s.type)).orderBy(o(i.date)).limit(t):await r.orderBy(o(i.date)).limit(t)).map(l)}async count(t){return await this.initialize(),(t?.type?await this.db.select({value:d()}).from(i).where(a(i.type,t.type)):await this.db.select({value:d()}).from(i))[0]?.value||0}}export{y as HistorySqliteDBStorage};
@@ -0,0 +1,14 @@
1
+ import{aK as ve}from"./redocly-openapi-docs.min.index-DHNqz_Gi.js";import{h as We}from"./redocly-openapi-docs.min.history.schema-DzAAX18S.js";import{s as Ve}from"./redocly-openapi-docs.min.step-context.schema-DEgzIgw0.js";import{b as z,c as G,a as H}from"./redocly-openapi-docs.min.ai-message-parts.schema-C7fjQhYX.js";import{c as f,T as m,i as h,g as W,s as n,o as Ue,n as Ye,f as Ge,h as He,j as Ze,k as Xe,m as et,p as tt,q as st,l as it,r as rt,t as nt,u as at,v as ot,w as lt,x as ct,y as ht,z as ut,e as qe,A as dt,b as ce,d as ft,a as mt,C as O,S as y,V as A,B as E,D as he,E as R,F as V,G as Z,H as ue,P as Ce,I as pt,J as de,K as fe,L as gt,W as Ne,M as Qe,N as yt,O as X,Q as Te}from"./redocly-openapi-docs.min.indexes-Bp4ld5gB.js";class bt{static[f]="ConsoleLogWriter";write(e){console.log(e)}}class wt{static[f]="DefaultLogger";writer;constructor(e){this.writer=e?.writer??new bt}logQuery(e,t){const s=t.map(r=>{try{return JSON.stringify(r)}catch{return String(r)}}),i=s.length?` -- params: [${s.join(", ")}]`:"";this.writer.write(`Query: ${e}${i}`)}}class St{static[f]="NoopLogger";logQuery(){}}const Le=Symbol.for("drizzle:PgInlineForeignKeys"),xe=Symbol.for("drizzle:EnableRLS");class $t extends m{static[f]="PgTable";static Symbol=Object.assign({},m.Symbol,{InlineForeignKeys:Le,EnableRLS:xe});[Le]=[];[xe]=!1;[m.Symbol.ExtraConfigBuilder]=void 0;[m.Symbol.ExtraConfigColumns]={}}class vt{static[f]="PgPrimaryKeyBuilder";columns;name;constructor(e,t){this.columns=e,this.name=t}build(e){return new qt(e,this.columns,this.name)}}class qt{constructor(e,t,s){this.table=e,this.columns=t,this.name=s}static[f]="PgPrimaryKey";columns;name;getName(){return this.name??`${this.table[$t.Symbol.Name]}_${this.columns.map(e=>e.name).join("_")}_pk`}}class Oe{constructor(e,t,s){this.sourceTable=e,this.referencedTable=t,this.relationName=s,this.referencedTableName=t[m.Symbol.Name]}static[f]="Relation";referencedTableName;fieldName}class Be{constructor(e,t){this.table=e,this.config=t}static[f]="Relations"}class D extends Oe{constructor(e,t,s,i){super(e,t,s?.relationName),this.config=s,this.isNullable=i}static[f]="One";withFieldName(e){const t=new D(this.sourceTable,this.referencedTable,this.config,this.isNullable);return t.fieldName=e,t}}class ne extends Oe{constructor(e,t,s){super(e,t,s?.relationName),this.config=s}static[f]="Many";withFieldName(e){const t=new ne(this.sourceTable,this.referencedTable,this.config);return t.fieldName=e,t}}function Ct(){return{and:ce,between:dt,eq:qe,exists:ut,gt:ht,gte:ct,ilike:lt,inArray:ot,isNull:at,isNotNull:nt,like:rt,lt:it,lte:st,ne:tt,not:et,notBetween:Xe,notExists:Ze,notLike:He,notIlike:Ge,notInArray:Ye,or:Ue,sql:n}}function Nt(){return{sql:n,asc:mt,desc:ft}}function Qt(l,e){Object.keys(l).length===1&&"default"in l&&!h(l.default,m)&&(l=l.default);const t={},s={},i={};for(const[r,a]of Object.entries(l))if(h(a,m)){const o=W(a),c=s[o];t[o]=r,i[r]={tsName:r,dbName:a[m.Symbol.Name],schema:a[m.Symbol.Schema],columns:a[m.Symbol.Columns],relations:c?.relations??{},primaryKey:c?.primaryKey??[]};for(const d of Object.values(a[m.Symbol.Columns]))d.primary&&i[r].primaryKey.push(d);const u=a[m.Symbol.ExtraConfigBuilder]?.(a[m.Symbol.ExtraConfigColumns]);if(u)for(const d of Object.values(u))h(d,vt)&&i[r].primaryKey.push(...d.columns)}else if(h(a,Be)){const o=W(a.table),c=t[o],u=a.config(e(a.table));let d;for(const[g,N]of Object.entries(u))if(c){const Q=i[c];Q.relations[g]=N}else o in s||(s[o]={relations:{},primaryKey:d}),s[o].relations[g]=N}return{tables:i,tableNamesMap:t}}function me(l,e){return new Be(l,t=>Object.fromEntries(Object.entries(e(t)).map(([s,i])=>[s,i.withFieldName(s)])))}function Tt(l){return function(e,t){return new D(l,e,t,t?.fields.reduce((s,i)=>s&&i.notNull,!0)??!1)}}function Lt(l){return function(e,t){return new ne(l,e,t)}}function xt(l,e,t){if(h(t,D)&&t.config)return{fields:t.config.fields,references:t.config.references};const s=e[W(t.referencedTable)];if(!s)throw new Error(`Table "${t.referencedTable[m.Symbol.Name]}" not found in schema`);const i=l[s];if(!i)throw new Error(`Table "${s}" not found in schema`);const r=t.sourceTable,a=e[W(r)];if(!a)throw new Error(`Table "${r[m.Symbol.Name]}" not found in schema`);const o=[];for(const c of Object.values(i.relations))(t.relationName&&t!==c&&c.relationName===t.relationName||!t.relationName&&c.referencedTable===t.sourceTable)&&o.push(c);if(o.length>1)throw t.relationName?new Error(`There are multiple relations with name "${t.relationName}" in table "${s}"`):new Error(`There are multiple relations between "${s}" and "${t.sourceTable[m.Symbol.Name]}". Please specify relation name`);if(o[0]&&h(o[0],D)&&o[0].config)return{fields:o[0].config.references,references:o[0].config.fields};throw new Error(`There is not enough information to infer relation "${a}.${t.fieldName}"`)}function Ot(l){return{one:Tt(l),many:Lt(l)}}function pe(l,e,t,s,i=r=>r){const r={};for(const[a,o]of s.entries())if(o.isJson){const c=e.relations[o.tsKey],u=t[a],d=typeof u=="string"?JSON.parse(u):u;r[o.tsKey]=h(c,D)?d&&pe(l,l[o.relationTableTsKey],d,o.selection,i):d.map(g=>pe(l,l[o.relationTableTsKey],g,o.selection,i))}else{const c=i(t[a]),u=o.field;let d;h(u,O)?d=u:h(u,y)?d=u.decoder:d=u.sql.decoder,r[o.tsKey]=c===null?null:d.mapFromDriverValue(c)}return r}class ee{constructor(e){this.table=e}static[f]="ColumnAliasProxyHandler";get(e,t){return t==="table"?this.table:e[t]}}class ge{constructor(e,t){this.alias=e,this.replaceOriginalName=t}static[f]="TableAliasProxyHandler";get(e,t){if(t===m.Symbol.IsAlias)return!0;if(t===m.Symbol.Name)return this.alias;if(this.replaceOriginalName&&t===m.Symbol.OriginalName)return this.alias;if(t===A)return{...e[A],name:this.alias,isAlias:!0};if(t===m.Symbol.Columns){const i=e[m.Symbol.Columns];if(!i)return i;const r={};return Object.keys(i).map(a=>{r[a]=new Proxy(i[a],new ee(new Proxy(e,this)))}),r}const s=e[t];return h(s,O)?new Proxy(s,new ee(new Proxy(e,this))):s}}function ye(l,e){return new Proxy(l,new ge(e,!1))}function P(l,e){return new Proxy(l,new ee(new Proxy(l.table,new ge(e,!1))))}function je(l,e){return new y.Aliased(te(l.sql,e),l.fieldAlias)}function te(l,e){return n.join(l.queryChunks.map(t=>h(t,O)?P(t,e):h(t,y)?te(t,e):h(t,y.Aliased)?je(t,e):t))}class T{static[f]="SelectionProxyHandler";config;constructor(e){this.config={...e}}get(e,t){if(t==="_")return{...e._,selectedFields:new Proxy(e._.selectedFields,this)};if(t===A)return{...e[A],selectedFields:new Proxy(e[A].selectedFields,this)};if(typeof t=="symbol")return e[t];const s=(h(e,E)?e._.selectedFields:h(e,he)?e[A].selectedFields:e)[t];if(h(s,y.Aliased)){if(this.config.sqlAliasedBehavior==="sql"&&!s.isSelectionField)return s.sql;const i=s.clone();return i.isSelectionField=!0,i}if(h(s,y)){if(this.config.sqlBehavior==="sql")return s;throw new Error(`You tried to reference "${t}" field from a subquery, which is a raw SQL field, but it doesn't have an alias declared. Please add an alias to the field using ".as('alias')" method.`)}return h(s,O)?this.config.alias?new Proxy(s,new ee(new Proxy(s.table,new ge(this.config.alias,this.config.replaceOriginalName??!1)))):s:typeof s!="object"||s===null?s:new Proxy(s,new T(this.config))}}class K{static[f]="QueryPromise";[Symbol.toStringTag]="QueryPromise";catch(e){return this.then(void 0,e)}finally(e){return this.then(t=>(e?.(),t),t=>{throw e?.(),t})}then(e,t){return this.execute().then(e,t)}}function k(l){return h(l,R)?[`${l[m.Symbol.BaseName]}`]:h(l,E)?l._.usedTables??[]:h(l,y)?l.usedTables??[]:[]}class Ae extends K{constructor(e,t,s,i){super(),this.table=e,this.session=t,this.dialect=s,this.config={table:e,withList:i}}static[f]="SQLiteDelete";config;where(e){return this.config.where=e,this}orderBy(...e){if(typeof e[0]=="function"){const t=e[0](new Proxy(this.config.table[m.Symbol.Columns],new T({sqlAliasedBehavior:"alias",sqlBehavior:"sql"}))),s=Array.isArray(t)?t:[t];this.config.orderBy=s}else{const t=e;this.config.orderBy=t}return this}limit(e){return this.config.limit=e,this}returning(e=this.table[R.Symbol.Columns]){return this.config.returning=V(e),this}getSQL(){return this.dialect.buildDeleteQuery(this.config)}toSQL(){const{typings:e,...t}=this.dialect.sqlToQuery(this.getSQL());return t}_prepare(e=!0){return this.session[e?"prepareOneTimeQuery":"prepareQuery"](this.dialect.sqlToQuery(this.getSQL()),this.config.returning,this.config.returning?"all":"run",!0,void 0,{type:"delete",tables:k(this.config.table)})}prepare(){return this._prepare(!1)}run=e=>this._prepare().run(e);all=e=>this._prepare().all(e);get=e=>this._prepare().get(e);values=e=>this._prepare().values(e);async execute(e){return this._prepare().execute(e)}$dynamic(){return this}}function Bt(l){return(l.replace(/['\u2019]/g,"").match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g)??[]).map(e=>e.toLowerCase()).join("_")}function jt(l){return(l.replace(/['\u2019]/g,"").match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g)??[]).reduce((e,t,s)=>{const i=s===0?t.toLowerCase():`${t[0].toUpperCase()}${t.slice(1)}`;return e+i},"")}function At(l){return l}class Rt{static[f]="CasingCache";cache={};cachedTables={};convert;constructor(e){this.convert=e==="snake_case"?Bt:e==="camelCase"?jt:At}getColumnCasing(e){if(!e.keyAsName)return e.name;const t=e.table[m.Symbol.Schema]??"public",s=e.table[m.Symbol.OriginalName],i=`${t}.${s}.${e.name}`;return this.cache[i]||this.cacheTable(e.table),this.cache[i]}cacheTable(e){const t=e[m.Symbol.Schema]??"public",s=e[m.Symbol.OriginalName],i=`${t}.${s}`;if(!this.cachedTables[i]){for(const r of Object.values(e[m.Symbol.Columns])){const a=`${i}.${r.name}`;this.cache[a]=this.convert(r.name)}this.cachedTables[i]=!0}}clearCache(){this.cache={},this.cachedTables={}}}class be extends Error{static[f]="DrizzleError";constructor({message:e,cause:t}){super(e),this.name="DrizzleError",this.cause=t}}class I extends Error{constructor(e,t,s){super(`Failed query: ${e}
2
+ params: ${t}`),this.query=e,this.params=t,this.cause=s,Error.captureStackTrace(this,I),s&&(this.cause=s)}}class Mt extends be{static[f]="TransactionRollbackError";constructor(){super({message:"Rollback"})}}class we extends he{static[f]="SQLiteViewBase"}class se{static[f]="SQLiteDialect";casing;constructor(e){this.casing=new Rt(e?.casing)}escapeName(e){return`"${e.replace(/"/g,'""')}"`}escapeParam(e){return"?"}escapeString(e){return`'${e.replace(/'/g,"''")}'`}buildWithCTE(e){if(!e?.length)return;const t=[n`with `];for(const[s,i]of e.entries())t.push(n`${n.identifier(i._.alias)} as (${i._.sql})`),s<e.length-1&&t.push(n`, `);return t.push(n` `),n.join(t)}buildDeleteQuery({table:e,where:t,returning:s,withList:i,limit:r,orderBy:a}){const o=this.buildWithCTE(i),c=s?n` returning ${this.buildSelection(s,{isSingleTable:!0})}`:void 0,u=t?n` where ${t}`:void 0,d=this.buildOrderBy(a),g=this.buildLimit(r);return n`${o}delete from ${e}${u}${c}${d}${g}`}buildUpdateSet(e,t){const s=e[m.Symbol.Columns],i=Object.keys(s).filter(a=>t[a]!==void 0||s[a]?.onUpdateFn!==void 0),r=i.length;return n.join(i.flatMap((a,o)=>{const c=s[a],u=c.onUpdateFn?.(),d=t[a]??(h(u,y)?u:n.param(u,c)),g=n`${n.identifier(this.casing.getColumnCasing(c))} = ${d}`;return o<r-1?[g,n.raw(", ")]:[g]}))}buildUpdateQuery({table:e,set:t,where:s,returning:i,withList:r,joins:a,from:o,limit:c,orderBy:u}){const d=this.buildWithCTE(r),g=this.buildUpdateSet(e,t),N=o&&n.join([n.raw(" from "),this.buildFromTable(o)]),Q=this.buildJoins(a),q=i?n` returning ${this.buildSelection(i,{isSingleTable:!0})}`:void 0,w=s?n` where ${s}`:void 0,$=this.buildOrderBy(u),S=this.buildLimit(c);return n`${d}update ${e} set ${g}${N}${Q}${w}${q}${$}${S}`}buildSelection(e,{isSingleTable:t=!1}={}){const s=e.length,i=e.flatMap(({field:r},a)=>{const o=[];if(h(r,y.Aliased)&&r.isSelectionField)o.push(n.identifier(r.fieldAlias));else if(h(r,y.Aliased)||h(r,y)){const c=h(r,y.Aliased)?r.sql:r;t?o.push(new y(c.queryChunks.map(u=>h(u,O)?n.identifier(this.casing.getColumnCasing(u)):u))):o.push(c),h(r,y.Aliased)&&o.push(n` as ${n.identifier(r.fieldAlias)}`)}else if(h(r,O)){const c=r.table[m.Symbol.Name];r.columnType==="SQLiteNumericBigInt"?t?o.push(n`cast(${n.identifier(this.casing.getColumnCasing(r))} as text)`):o.push(n`cast(${n.identifier(c)}.${n.identifier(this.casing.getColumnCasing(r))} as text)`):t?o.push(n.identifier(this.casing.getColumnCasing(r))):o.push(n`${n.identifier(c)}.${n.identifier(this.casing.getColumnCasing(r))}`)}else if(h(r,E)){const c=Object.entries(r._.selectedFields);if(c.length===1){const u=c[0][1],d=h(u,y)?u.decoder:h(u,O)?{mapFromDriverValue:g=>u.mapFromDriverValue(g)}:u.sql.decoder;d&&(r._.sql.decoder=d)}o.push(r)}return a<s-1&&o.push(n`, `),o});return n.join(i)}buildJoins(e){if(!e||e.length===0)return;const t=[];if(e)for(const[s,i]of e.entries()){s===0&&t.push(n` `);const r=i.table,a=i.on?n` on ${i.on}`:void 0;if(h(r,R)){const o=r[R.Symbol.Name],c=r[R.Symbol.Schema],u=r[R.Symbol.OriginalName],d=o===u?void 0:i.alias;t.push(n`${n.raw(i.joinType)} join ${c?n`${n.identifier(c)}.`:void 0}${n.identifier(u)}${d&&n` ${n.identifier(d)}`}${a}`)}else t.push(n`${n.raw(i.joinType)} join ${r}${a}`);s<e.length-1&&t.push(n` `)}return n.join(t)}buildLimit(e){return typeof e=="object"||typeof e=="number"&&e>=0?n` limit ${e}`:void 0}buildOrderBy(e){const t=[];if(e)for(const[s,i]of e.entries())t.push(i),s<e.length-1&&t.push(n`, `);return t.length>0?n` order by ${n.join(t)}`:void 0}buildFromTable(e){return h(e,m)&&e[m.Symbol.IsAlias]?n`${n`${n.identifier(e[m.Symbol.Schema]??"")}.`.if(e[m.Symbol.Schema])}${n.identifier(e[m.Symbol.OriginalName])} ${n.identifier(e[m.Symbol.Name])}`:e}buildSelectQuery({withList:e,fields:t,fieldsFlat:s,where:i,having:r,table:a,joins:o,orderBy:c,groupBy:u,limit:d,offset:g,distinct:N,setOperators:Q}){const q=s??V(t);for(const B of q)if(h(B.field,O)&&Z(B.field.table)!==(h(a,E)?a._.alias:h(a,we)?a[A].name:h(a,y)?void 0:Z(a))&&!(j=>o?.some(({alias:Y})=>Y===(j[m.Symbol.IsAlias]?Z(j):j[m.Symbol.BaseName])))(B.field.table)){const j=Z(B.field.table);throw new Error(`Your "${B.path.join("->")}" field references a column "${j}"."${B.field.name}", but the table "${j}" is not part of the query! Did you forget to join it?`)}const w=!o||o.length===0,$=this.buildWithCTE(e),S=N?n` distinct`:void 0,L=this.buildSelection(q,{isSingleTable:w}),v=this.buildFromTable(a),C=this.buildJoins(o),M=i?n` where ${i}`:void 0,x=r?n` having ${r}`:void 0,p=[];if(u)for(const[B,j]of u.entries())p.push(j),B<u.length-1&&p.push(n`, `);const b=p.length>0?n` group by ${n.join(p)}`:void 0,_=this.buildOrderBy(c),U=this.buildLimit(d),le=g?n` offset ${g}`:void 0,J=n`${$}select${S} ${L} from ${v}${C}${M}${b}${x}${_}${U}${le}`;return Q.length>0?this.buildSetOperations(J,Q):J}buildSetOperations(e,t){const[s,...i]=t;if(!s)throw new Error("Cannot pass undefined values to any set operator");return i.length===0?this.buildSetOperationQuery({leftSelect:e,setOperator:s}):this.buildSetOperations(this.buildSetOperationQuery({leftSelect:e,setOperator:s}),i)}buildSetOperationQuery({leftSelect:e,setOperator:{type:t,isAll:s,rightSelect:i,limit:r,orderBy:a,offset:o}}){const c=n`${e.getSQL()} `,u=n`${i.getSQL()}`;let d;if(a&&a.length>0){const q=[];for(const w of a)if(h(w,ue))q.push(n.identifier(w.name));else if(h(w,y)){for(let $=0;$<w.queryChunks.length;$++){const S=w.queryChunks[$];h(S,ue)&&(w.queryChunks[$]=n.identifier(this.casing.getColumnCasing(S)))}q.push(n`${w}`)}else q.push(n`${w}`);d=n` order by ${n.join(q,n`, `)}`}const g=typeof r=="object"||typeof r=="number"&&r>=0?n` limit ${r}`:void 0,N=n.raw(`${t} ${s?"all ":""}`),Q=o?n` offset ${o}`:void 0;return n`${c}${N}${u}${d}${g}${Q}`}buildInsertQuery({table:e,values:t,onConflict:s,returning:i,withList:r,select:a}){const o=[],c=e[m.Symbol.Columns],u=Object.entries(c).filter(([w,$])=>!$.shouldDisableInsert()),d=u.map(([,w])=>n.identifier(this.casing.getColumnCasing(w)));if(a){const w=t;h(w,y)?o.push(w):o.push(w.getSQL())}else{const w=t;o.push(n.raw("values "));for(const[$,S]of w.entries()){const L=[];for(const[v,C]of u){const M=S[v];if(M===void 0||h(M,Ce)&&M.value===void 0){let x;if(C.default!==null&&C.default!==void 0)x=h(C.default,y)?C.default:n.param(C.default,C);else if(C.defaultFn!==void 0){const p=C.defaultFn();x=h(p,y)?p:n.param(p,C)}else if(!C.default&&C.onUpdateFn!==void 0){const p=C.onUpdateFn();x=h(p,y)?p:n.param(p,C)}else x=n`null`;L.push(x)}else L.push(M)}o.push(L),$<w.length-1&&o.push(n`, `)}}const g=this.buildWithCTE(r),N=n.join(o),Q=i?n` returning ${this.buildSelection(i,{isSingleTable:!0})}`:void 0,q=s?.length?n.join(s):void 0;return n`${g}insert into ${e} ${d} ${N}${q}${Q}`}sqlToQuery(e,t){return e.toQuery({casing:this.casing,escapeName:this.escapeName,escapeParam:this.escapeParam,escapeString:this.escapeString,invokeSource:t})}buildRelationalQuery({fullSchema:e,schema:t,tableNamesMap:s,table:i,tableConfig:r,queryConfig:a,tableAlias:o,nestedQueryRelation:c,joinOn:u}){let d=[],g,N,Q=[],q;const w=[];if(a===!0)d=Object.entries(r.columns).map(([S,L])=>({dbKey:L.name,tsKey:S,field:P(L,o),relationTableTsKey:void 0,isJson:!1,selection:[]}));else{const S=Object.fromEntries(Object.entries(r.columns).map(([p,b])=>[p,P(b,o)]));if(a.where){const p=typeof a.where=="function"?a.where(S,Ct()):a.where;q=p&&te(p,o)}const L=[];let v=[];if(a.columns){let p=!1;for(const[b,_]of Object.entries(a.columns))_!==void 0&&b in r.columns&&(!p&&_===!0&&(p=!0),v.push(b));v.length>0&&(v=p?v.filter(b=>a.columns?.[b]===!0):Object.keys(r.columns).filter(b=>!v.includes(b)))}else v=Object.keys(r.columns);for(const p of v){const b=r.columns[p];L.push({tsKey:p,value:b})}let C=[];a.with&&(C=Object.entries(a.with).filter(p=>!!p[1]).map(([p,b])=>({tsKey:p,queryConfig:b,relation:r.relations[p]})));let M;if(a.extras){M=typeof a.extras=="function"?a.extras(S,{sql:n}):a.extras;for(const[p,b]of Object.entries(M))L.push({tsKey:p,value:je(b,o)})}for(const{tsKey:p,value:b}of L)d.push({dbKey:h(b,y.Aliased)?b.fieldAlias:r.columns[p].name,tsKey:p,field:h(b,O)?P(b,o):b,relationTableTsKey:void 0,isJson:!1,selection:[]});let x=typeof a.orderBy=="function"?a.orderBy(S,Nt()):a.orderBy??[];Array.isArray(x)||(x=[x]),Q=x.map(p=>h(p,O)?P(p,o):te(p,o)),g=a.limit,N=a.offset;for(const{tsKey:p,queryConfig:b,relation:_}of C){const U=xt(t,s,_),le=W(_.referencedTable),J=s[le],B=`${o}_${p}`,j=ce(...U.fields.map((Je,ze)=>qe(P(U.references[ze],B),P(Je,o)))),Y=this.buildRelationalQuery({fullSchema:e,schema:t,tableNamesMap:s,table:e[J],tableConfig:t[J],queryConfig:h(_,D)?b===!0?{limit:1}:{...b,limit:1}:b,tableAlias:B,joinOn:j,nestedQueryRelation:_}),De=n`(${Y.sql})`.as(p);d.push({dbKey:p,tsKey:p,field:De,relationTableTsKey:J,isJson:!0,selection:Y.selection})}}if(d.length===0)throw new be({message:`No fields selected for table "${r.tsName}" ("${o}"). You need to have at least one item in "columns", "with" or "extras". If you need to select all columns, omit the "columns" key or set it to undefined.`});let $;if(q=ce(u,q),c){let S=n`json_array(${n.join(d.map(({field:v})=>h(v,ue)?n.identifier(this.casing.getColumnCasing(v)):h(v,y.Aliased)?v.sql:v),n`, `)})`;h(c,ne)&&(S=n`coalesce(json_group_array(${S}), json_array())`);const L=[{dbKey:"data",tsKey:"data",field:S.as("data"),isJson:!0,relationTableTsKey:r.tsName,selection:d}];g!==void 0||N!==void 0||Q.length>0?($=this.buildSelectQuery({table:ye(i,o),fields:{},fieldsFlat:[{path:[],field:n.raw("*")}],where:q,limit:g,offset:N,orderBy:Q,setOperators:[]}),q=void 0,g=void 0,N=void 0,Q=void 0):$=ye(i,o),$=this.buildSelectQuery({table:h($,R)?$:new E($,{},o),fields:{},fieldsFlat:L.map(({field:v})=>({path:[],field:h(v,O)?P(v,o):v})),joins:w,where:q,limit:g,offset:N,orderBy:Q,setOperators:[]})}else $=this.buildSelectQuery({table:ye(i,o),fields:{},fieldsFlat:d.map(({field:S})=>({path:[],field:h(S,O)?P(S,o):S})),joins:w,where:q,limit:g,offset:N,orderBy:Q,setOperators:[]});return{tableTsKey:r.tsName,sql:$,selection:d}}}class _t extends se{static[f]="SQLiteSyncDialect";migrate(e,t,s){const i=s===void 0||typeof s=="string"?"__drizzle_migrations":s.migrationsTable??"__drizzle_migrations",r=n`
3
+ CREATE TABLE IF NOT EXISTS ${n.identifier(i)} (
4
+ id SERIAL PRIMARY KEY,
5
+ hash text NOT NULL,
6
+ created_at numeric
7
+ )
8
+ `;t.run(r);const a=t.values(n`SELECT id, hash, created_at FROM ${n.identifier(i)} ORDER BY created_at DESC LIMIT 1`)[0]??void 0;t.run(n`BEGIN`);try{for(const o of e)if(!a||Number(a[2])<o.folderMillis){for(const c of o.sql)t.run(n.raw(c));t.run(n`INSERT INTO ${n.identifier(i)} ("hash", "created_at") VALUES(${o.hash}, ${o.folderMillis})`)}t.run(n`COMMIT`)}catch(o){throw t.run(n`ROLLBACK`),o}}}class Et extends se{static[f]="SQLiteAsyncDialect";async migrate(e,t,s){const i=s===void 0||typeof s=="string"?"__drizzle_migrations":s.migrationsTable??"__drizzle_migrations",r=n`
9
+ CREATE TABLE IF NOT EXISTS ${n.identifier(i)} (
10
+ id SERIAL PRIMARY KEY,
11
+ hash text NOT NULL,
12
+ created_at numeric
13
+ )
14
+ `;await t.run(r);const a=(await t.values(n`SELECT id, hash, created_at FROM ${n.identifier(i)} ORDER BY created_at DESC LIMIT 1`))[0]??void 0;await t.transaction(async o=>{for(const c of e)if(!a||Number(a[2])<c.folderMillis){for(const u of c.sql)await o.run(n.raw(u));await o.run(n`INSERT INTO ${n.identifier(i)} ("hash", "created_at") VALUES(${c.hash}, ${c.folderMillis})`)}})}}class Pt{static[f]="TypedQueryBuilder";getSelectedFields(){return this._.selectedFields}}class F{static[f]="SQLiteSelectBuilder";fields;session;dialect;withList;distinct;constructor(e){this.fields=e.fields,this.session=e.session,this.dialect=e.dialect,this.withList=e.withList,this.distinct=e.distinct}from(e){const t=!!this.fields;let s;return this.fields?s=this.fields:h(e,E)?s=Object.fromEntries(Object.keys(e._.selectedFields).map(i=>[i,e[i]])):h(e,we)?s=e[A].selectedFields:h(e,y)?s={}:s=pt(e),new Re({table:e,fields:s,isPartialSelect:t,session:this.session,dialect:this.dialect,withList:this.withList,distinct:this.distinct})}}class Ft extends Pt{static[f]="SQLiteSelectQueryBuilder";_;config;joinsNotNullableMap;tableName;isPartialSelect;session;dialect;cacheConfig=void 0;usedTables=new Set;constructor({table:e,fields:t,isPartialSelect:s,session:i,dialect:r,withList:a,distinct:o}){super(),this.config={withList:a,table:e,fields:{...t},distinct:o,setOperators:[]},this.isPartialSelect=s,this.session=i,this.dialect=r,this._={selectedFields:t,config:this.config},this.tableName=de(e),this.joinsNotNullableMap=typeof this.tableName=="string"?{[this.tableName]:!0}:{};for(const c of k(e))this.usedTables.add(c)}getUsedTables(){return[...this.usedTables]}createJoin(e){return(t,s)=>{const i=this.tableName,r=de(t);for(const a of k(t))this.usedTables.add(a);if(typeof r=="string"&&this.config.joins?.some(a=>a.alias===r))throw new Error(`Alias "${r}" is already used in this query`);if(!this.isPartialSelect&&(Object.keys(this.joinsNotNullableMap).length===1&&typeof i=="string"&&(this.config.fields={[i]:this.config.fields}),typeof r=="string"&&!h(t,y))){const a=h(t,E)?t._.selectedFields:h(t,he)?t[A].selectedFields:t[m.Symbol.Columns];this.config.fields[r]=a}if(typeof s=="function"&&(s=s(new Proxy(this.config.fields,new T({sqlAliasedBehavior:"sql",sqlBehavior:"sql"})))),this.config.joins||(this.config.joins=[]),this.config.joins.push({on:s,table:t,joinType:e,alias:r}),typeof r=="string")switch(e){case"left":{this.joinsNotNullableMap[r]=!1;break}case"right":{this.joinsNotNullableMap=Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([a])=>[a,!1])),this.joinsNotNullableMap[r]=!0;break}case"cross":case"inner":{this.joinsNotNullableMap[r]=!0;break}case"full":{this.joinsNotNullableMap=Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([a])=>[a,!1])),this.joinsNotNullableMap[r]=!1;break}}return this}}leftJoin=this.createJoin("left");rightJoin=this.createJoin("right");innerJoin=this.createJoin("inner");fullJoin=this.createJoin("full");crossJoin=this.createJoin("cross");createSetOperator(e,t){return s=>{const i=typeof s=="function"?s(It()):s;if(!fe(this.getSelectedFields(),i.getSelectedFields()))throw new Error("Set operator error (union / intersect / except): selected fields are not the same or are in a different order");return this.config.setOperators.push({type:e,isAll:t,rightSelect:i}),this}}union=this.createSetOperator("union",!1);unionAll=this.createSetOperator("union",!0);intersect=this.createSetOperator("intersect",!1);except=this.createSetOperator("except",!1);addSetOperators(e){return this.config.setOperators.push(...e),this}where(e){return typeof e=="function"&&(e=e(new Proxy(this.config.fields,new T({sqlAliasedBehavior:"sql",sqlBehavior:"sql"})))),this.config.where=e,this}having(e){return typeof e=="function"&&(e=e(new Proxy(this.config.fields,new T({sqlAliasedBehavior:"sql",sqlBehavior:"sql"})))),this.config.having=e,this}groupBy(...e){if(typeof e[0]=="function"){const t=e[0](new Proxy(this.config.fields,new T({sqlAliasedBehavior:"alias",sqlBehavior:"sql"})));this.config.groupBy=Array.isArray(t)?t:[t]}else this.config.groupBy=e;return this}orderBy(...e){if(typeof e[0]=="function"){const t=e[0](new Proxy(this.config.fields,new T({sqlAliasedBehavior:"alias",sqlBehavior:"sql"}))),s=Array.isArray(t)?t:[t];this.config.setOperators.length>0?this.config.setOperators.at(-1).orderBy=s:this.config.orderBy=s}else{const t=e;this.config.setOperators.length>0?this.config.setOperators.at(-1).orderBy=t:this.config.orderBy=t}return this}limit(e){return this.config.setOperators.length>0?this.config.setOperators.at(-1).limit=e:this.config.limit=e,this}offset(e){return this.config.setOperators.length>0?this.config.setOperators.at(-1).offset=e:this.config.offset=e,this}getSQL(){return this.dialect.buildSelectQuery(this.config)}toSQL(){const{typings:e,...t}=this.dialect.sqlToQuery(this.getSQL());return t}as(e){const t=[];if(t.push(...k(this.config.table)),this.config.joins)for(const s of this.config.joins)t.push(...k(s.table));return new Proxy(new E(this.getSQL(),this.config.fields,e,!1,[...new Set(t)]),new T({alias:e,sqlAliasedBehavior:"alias",sqlBehavior:"error"}))}getSelectedFields(){return new Proxy(this.config.fields,new T({alias:this.tableName,sqlAliasedBehavior:"alias",sqlBehavior:"error"}))}$dynamic(){return this}}class Re extends Ft{static[f]="SQLiteSelect";_prepare(e=!0){if(!this.session)throw new Error("Cannot execute a query on a query builder. Please use a database instance instead.");const t=V(this.config.fields),s=this.session[e?"prepareOneTimeQuery":"prepareQuery"](this.dialect.sqlToQuery(this.getSQL()),t,"all",!0,void 0,{type:"select",tables:[...this.usedTables]},this.cacheConfig);return s.joinsNotNullableMap=this.joinsNotNullableMap,s}$withCache(e){return this.cacheConfig=e===void 0?{config:{},enable:!0,autoInvalidate:!0}:e===!1?{enable:!1}:{enable:!0,autoInvalidate:!0,...e},this}prepare(){return this._prepare(!1)}run=e=>this._prepare().run(e);all=e=>this._prepare().all(e);get=e=>this._prepare().get(e);values=e=>this._prepare().values(e);async execute(){return this.all()}}gt(Re,[K]);function ie(l,e){return(t,s,...i)=>{const r=[s,...i].map(a=>({type:l,isAll:e,rightSelect:a}));for(const a of r)if(!fe(t.getSelectedFields(),a.rightSelect.getSelectedFields()))throw new Error("Set operator error (union / intersect / except): selected fields are not the same or are in a different order");return t.addSetOperators(r)}}const It=()=>({union:Kt,unionAll:kt,intersect:Dt,except:Jt}),Kt=ie("union",!1),kt=ie("union",!0),Dt=ie("intersect",!1),Jt=ie("except",!1);class Me{static[f]="SQLiteQueryBuilder";dialect;dialectConfig;constructor(e){this.dialect=h(e,se)?e:void 0,this.dialectConfig=h(e,se)?void 0:e}$with=(e,t)=>{const s=this;return{as:i=>(typeof i=="function"&&(i=i(s)),new Proxy(new Ne(i.getSQL(),t??("getSelectedFields"in i?i.getSelectedFields()??{}:{}),e,!0),new T({alias:e,sqlAliasedBehavior:"alias",sqlBehavior:"error"})))}};with(...e){const t=this;function s(r){return new F({fields:r??void 0,session:void 0,dialect:t.getDialect(),withList:e})}function i(r){return new F({fields:r??void 0,session:void 0,dialect:t.getDialect(),withList:e,distinct:!0})}return{select:s,selectDistinct:i}}select(e){return new F({fields:e??void 0,session:void 0,dialect:this.getDialect()})}selectDistinct(e){return new F({fields:e??void 0,session:void 0,dialect:this.getDialect(),distinct:!0})}getDialect(){return this.dialect||(this.dialect=new _t(this.dialectConfig)),this.dialect}}class _e{constructor(e,t,s,i){this.table=e,this.session=t,this.dialect=s,this.withList=i}static[f]="SQLiteInsertBuilder";values(e){if(e=Array.isArray(e)?e:[e],e.length===0)throw new Error("values() must be called with at least one value");const t=e.map(s=>{const i={},r=this.table[m.Symbol.Columns];for(const a of Object.keys(s)){const o=s[a];i[a]=h(o,y)?o:new Ce(o,r[a])}return i});return new Ee(this.table,t,this.session,this.dialect,this.withList)}select(e){const t=typeof e=="function"?e(new Me):e;if(!h(t,y)&&!fe(this.table[yt],t._.selectedFields))throw new Error("Insert select error: selected fields are not the same or are in a different order compared to the table definition");return new Ee(this.table,t,this.session,this.dialect,this.withList,!0)}}class Ee extends K{constructor(e,t,s,i,r,a){super(),this.session=s,this.dialect=i,this.config={table:e,values:t,withList:r,select:a}}static[f]="SQLiteInsert";config;returning(e=this.config.table[R.Symbol.Columns]){return this.config.returning=V(e),this}onConflictDoNothing(e={}){if(this.config.onConflict||(this.config.onConflict=[]),e.target===void 0)this.config.onConflict.push(n` on conflict do nothing`);else{const t=Array.isArray(e.target)?n`${e.target}`:n`${[e.target]}`,s=e.where?n` where ${e.where}`:n``;this.config.onConflict.push(n` on conflict ${t} do nothing${s}`)}return this}onConflictDoUpdate(e){if(e.where&&(e.targetWhere||e.setWhere))throw new Error('You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.');this.config.onConflict||(this.config.onConflict=[]);const t=e.where?n` where ${e.where}`:void 0,s=e.targetWhere?n` where ${e.targetWhere}`:void 0,i=e.setWhere?n` where ${e.setWhere}`:void 0,r=Array.isArray(e.target)?n`${e.target}`:n`${[e.target]}`,a=this.dialect.buildUpdateSet(this.config.table,Qe(this.config.table,e.set));return this.config.onConflict.push(n` on conflict ${r}${s} do update set ${a}${t}${i}`),this}getSQL(){return this.dialect.buildInsertQuery(this.config)}toSQL(){const{typings:e,...t}=this.dialect.sqlToQuery(this.getSQL());return t}_prepare(e=!0){return this.session[e?"prepareOneTimeQuery":"prepareQuery"](this.dialect.sqlToQuery(this.getSQL()),this.config.returning,this.config.returning?"all":"run",!0,void 0,{type:"insert",tables:k(this.config.table)})}prepare(){return this._prepare(!1)}run=e=>this._prepare().run(e);all=e=>this._prepare().all(e);get=e=>this._prepare().get(e);values=e=>this._prepare().values(e);async execute(){return this.config.returning?this.all():this.run()}$dynamic(){return this}}class Pe{constructor(e,t,s,i){this.table=e,this.session=t,this.dialect=s,this.withList=i}static[f]="SQLiteUpdateBuilder";set(e){return new zt(this.table,Qe(this.table,e),this.session,this.dialect,this.withList)}}class zt extends K{constructor(e,t,s,i,r){super(),this.session=s,this.dialect=i,this.config={set:t,table:e,withList:r,joins:[]}}static[f]="SQLiteUpdate";config;from(e){return this.config.from=e,this}createJoin(e){return(t,s)=>{const i=de(t);if(typeof i=="string"&&this.config.joins.some(r=>r.alias===i))throw new Error(`Alias "${i}" is already used in this query`);if(typeof s=="function"){const r=this.config.from?h(t,R)?t[m.Symbol.Columns]:h(t,E)?t._.selectedFields:h(t,we)?t[A].selectedFields:void 0:void 0;s=s(new Proxy(this.config.table[m.Symbol.Columns],new T({sqlAliasedBehavior:"sql",sqlBehavior:"sql"})),r&&new Proxy(r,new T({sqlAliasedBehavior:"sql",sqlBehavior:"sql"})))}return this.config.joins.push({on:s,table:t,joinType:e,alias:i}),this}}leftJoin=this.createJoin("left");rightJoin=this.createJoin("right");innerJoin=this.createJoin("inner");fullJoin=this.createJoin("full");where(e){return this.config.where=e,this}orderBy(...e){if(typeof e[0]=="function"){const t=e[0](new Proxy(this.config.table[m.Symbol.Columns],new T({sqlAliasedBehavior:"alias",sqlBehavior:"sql"}))),s=Array.isArray(t)?t:[t];this.config.orderBy=s}else{const t=e;this.config.orderBy=t}return this}limit(e){return this.config.limit=e,this}returning(e=this.config.table[R.Symbol.Columns]){return this.config.returning=V(e),this}getSQL(){return this.dialect.buildUpdateQuery(this.config)}toSQL(){const{typings:e,...t}=this.dialect.sqlToQuery(this.getSQL());return t}_prepare(e=!0){return this.session[e?"prepareOneTimeQuery":"prepareQuery"](this.dialect.sqlToQuery(this.getSQL()),this.config.returning,this.config.returning?"all":"run",!0,void 0,{type:"insert",tables:k(this.config.table)})}prepare(){return this._prepare(!1)}run=e=>this._prepare().run(e);all=e=>this._prepare().all(e);get=e=>this._prepare().get(e);values=e=>this._prepare().values(e);async execute(){return this.config.returning?this.all():this.run()}$dynamic(){return this}}class ae extends y{constructor(e){super(ae.buildEmbeddedCount(e.source,e.filters).queryChunks),this.params=e,this.session=e.session,this.sql=ae.buildCount(e.source,e.filters)}sql;static[f]="SQLiteCountBuilderAsync";[Symbol.toStringTag]="SQLiteCountBuilderAsync";session;static buildEmbeddedCount(e,t){return n`(select count(*) from ${e}${n.raw(" where ").if(t)}${t})`}static buildCount(e,t){return n`select count(*) from ${e}${n.raw(" where ").if(t)}${t}`}then(e,t){return Promise.resolve(this.session.count(this.sql)).then(e,t)}catch(e){return this.then(void 0,e)}finally(e){return this.then(t=>(e?.(),t),t=>{throw e?.(),t})}}class Wt{constructor(e,t,s,i,r,a,o,c){this.mode=e,this.fullSchema=t,this.schema=s,this.tableNamesMap=i,this.table=r,this.tableConfig=a,this.dialect=o,this.session=c}static[f]="SQLiteAsyncRelationalQueryBuilder";findMany(e){return this.mode==="sync"?new Fe(this.fullSchema,this.schema,this.tableNamesMap,this.table,this.tableConfig,this.dialect,this.session,e||{},"many"):new Se(this.fullSchema,this.schema,this.tableNamesMap,this.table,this.tableConfig,this.dialect,this.session,e||{},"many")}findFirst(e){return this.mode==="sync"?new Fe(this.fullSchema,this.schema,this.tableNamesMap,this.table,this.tableConfig,this.dialect,this.session,e?{...e,limit:1}:{limit:1},"first"):new Se(this.fullSchema,this.schema,this.tableNamesMap,this.table,this.tableConfig,this.dialect,this.session,e?{...e,limit:1}:{limit:1},"first")}}class Se extends K{constructor(e,t,s,i,r,a,o,c,u){super(),this.fullSchema=e,this.schema=t,this.tableNamesMap=s,this.table=i,this.tableConfig=r,this.dialect=a,this.session=o,this.config=c,this.mode=u}static[f]="SQLiteAsyncRelationalQuery";mode;getSQL(){return this.dialect.buildRelationalQuery({fullSchema:this.fullSchema,schema:this.schema,tableNamesMap:this.tableNamesMap,table:this.table,tableConfig:this.tableConfig,queryConfig:this.config,tableAlias:this.tableConfig.tsName}).sql}_prepare(e=!1){const{query:t,builtQuery:s}=this._toSQL();return this.session[e?"prepareOneTimeQuery":"prepareQuery"](s,void 0,this.mode==="first"?"get":"all",!0,(i,r)=>{const a=i.map(o=>pe(this.schema,this.tableConfig,o,t.selection,r));return this.mode==="first"?a[0]:a})}prepare(){return this._prepare(!1)}_toSQL(){const e=this.dialect.buildRelationalQuery({fullSchema:this.fullSchema,schema:this.schema,tableNamesMap:this.tableNamesMap,table:this.table,tableConfig:this.tableConfig,queryConfig:this.config,tableAlias:this.tableConfig.tsName}),t=this.dialect.sqlToQuery(e.sql);return{query:e,builtQuery:t}}toSQL(){return this._toSQL().builtQuery}executeRaw(){return this.mode==="first"?this._prepare(!1).get():this._prepare(!1).all()}async execute(){return this.executeRaw()}}class Fe extends Se{static[f]="SQLiteSyncRelationalQuery";sync(){return this.executeRaw()}}class re extends K{constructor(e,t,s,i,r){super(),this.execute=e,this.getSQL=t,this.dialect=i,this.mapBatchResult=r,this.config={action:s}}static[f]="SQLiteRaw";config;getQuery(){return{...this.dialect.sqlToQuery(this.getSQL()),method:this.config.action}}mapResult(e,t){return t?this.mapBatchResult(e):e}_prepare(){return this}isResponseInArrayMode(){return!1}}class Ie{constructor(e,t,s,i){this.resultKind=e,this.dialect=t,this.session=s,this._=i?{schema:i.schema,fullSchema:i.fullSchema,tableNamesMap:i.tableNamesMap}:{schema:void 0,fullSchema:{},tableNamesMap:{}},this.query={};const r=this.query;if(this._.schema)for(const[a,o]of Object.entries(this._.schema))r[a]=new Wt(e,i.fullSchema,this._.schema,this._.tableNamesMap,i.fullSchema[a],o,t,s);this.$cache={invalidate:async a=>{}}}static[f]="BaseSQLiteDatabase";query;$with=(e,t)=>{const s=this;return{as:i=>(typeof i=="function"&&(i=i(new Me(s.dialect))),new Proxy(new Ne(i.getSQL(),t??("getSelectedFields"in i?i.getSelectedFields()??{}:{}),e,!0),new T({alias:e,sqlAliasedBehavior:"alias",sqlBehavior:"error"})))}};$count(e,t){return new ae({source:e,filters:t,session:this.session})}with(...e){const t=this;function s(c){return new F({fields:c??void 0,session:t.session,dialect:t.dialect,withList:e})}function i(c){return new F({fields:c??void 0,session:t.session,dialect:t.dialect,withList:e,distinct:!0})}function r(c){return new Pe(c,t.session,t.dialect,e)}function a(c){return new _e(c,t.session,t.dialect,e)}function o(c){return new Ae(c,t.session,t.dialect,e)}return{select:s,selectDistinct:i,update:r,insert:a,delete:o}}select(e){return new F({fields:e??void 0,session:this.session,dialect:this.dialect})}selectDistinct(e){return new F({fields:e??void 0,session:this.session,dialect:this.dialect,distinct:!0})}update(e){return new Pe(e,this.session,this.dialect)}$cache;insert(e){return new _e(e,this.session,this.dialect)}delete(e){return new Ae(e,this.session,this.dialect)}run(e){const t=typeof e=="string"?n.raw(e):e.getSQL();return this.resultKind==="async"?new re(async()=>this.session.run(t),()=>t,"run",this.dialect,this.session.extractRawRunValueFromBatchResult.bind(this.session)):this.session.run(t)}all(e){const t=typeof e=="string"?n.raw(e):e.getSQL();return this.resultKind==="async"?new re(async()=>this.session.all(t),()=>t,"all",this.dialect,this.session.extractRawAllValueFromBatchResult.bind(this.session)):this.session.all(t)}get(e){const t=typeof e=="string"?n.raw(e):e.getSQL();return this.resultKind==="async"?new re(async()=>this.session.get(t),()=>t,"get",this.dialect,this.session.extractRawGetValueFromBatchResult.bind(this.session)):this.session.get(t)}values(e){const t=typeof e=="string"?n.raw(e):e.getSQL();return this.resultKind==="async"?new re(async()=>this.session.values(t),()=>t,"values",this.dialect,this.session.extractRawValuesValueFromBatchResult.bind(this.session)):this.session.values(t)}transaction(e,t){return this.session.transaction(e,t)}}class Vt{static[f]="Cache"}class Ke extends Vt{strategy(){return"all"}static[f]="NoopCache";async get(e){}async put(e,t,s,i){}async onMutate(e){}}async function ke(l,e){const t=`${l}-${JSON.stringify(e)}`,s=new TextEncoder().encode(t),i=await crypto.subtle.digest("SHA-256",s);return[...new Uint8Array(i)].map(r=>r.toString(16).padStart(2,"0")).join("")}class Ut extends K{constructor(e){super(),this.resultCb=e}static[f]="ExecuteResultSync";async execute(){return this.resultCb()}sync(){return this.resultCb()}}class Yt{constructor(e,t,s,i,r,a){this.mode=e,this.executeMethod=t,this.query=s,this.cache=i,this.queryMetadata=r,this.cacheConfig=a,i&&i.strategy()==="all"&&a===void 0&&(this.cacheConfig={enable:!0,autoInvalidate:!0}),this.cacheConfig?.enable||(this.cacheConfig=void 0)}static[f]="PreparedQuery";joinsNotNullableMap;async queryWithCache(e,t,s){if(this.cache===void 0||h(this.cache,Ke)||this.queryMetadata===void 0)try{return await s()}catch(i){throw new I(e,t,i)}if(this.cacheConfig&&!this.cacheConfig.enable)try{return await s()}catch(i){throw new I(e,t,i)}if((this.queryMetadata.type==="insert"||this.queryMetadata.type==="update"||this.queryMetadata.type==="delete")&&this.queryMetadata.tables.length>0)try{const[i]=await Promise.all([s(),this.cache.onMutate({tables:this.queryMetadata.tables})]);return i}catch(i){throw new I(e,t,i)}if(!this.cacheConfig)try{return await s()}catch(i){throw new I(e,t,i)}if(this.queryMetadata.type==="select"){const i=await this.cache.get(this.cacheConfig.tag??await ke(e,t),this.queryMetadata.tables,this.cacheConfig.tag!==void 0,this.cacheConfig.autoInvalidate);if(i===void 0){let r;try{r=await s()}catch(a){throw new I(e,t,a)}return await this.cache.put(this.cacheConfig.tag??await ke(e,t),r,this.cacheConfig.autoInvalidate?this.queryMetadata.tables:[],this.cacheConfig.tag!==void 0,this.cacheConfig.config),r}return i}try{return await s()}catch(i){throw new I(e,t,i)}}getQuery(){return this.query}mapRunResult(e,t){return e}mapAllResult(e,t){throw new Error("Not implemented")}mapGetResult(e,t){throw new Error("Not implemented")}execute(e){return this.mode==="async"?this[this.executeMethod](e):new Ut(()=>this[this.executeMethod](e))}mapResult(e,t){switch(this.executeMethod){case"run":return this.mapRunResult(e,t);case"all":return this.mapAllResult(e,t);case"get":return this.mapGetResult(e,t)}}}class Gt{constructor(e){this.dialect=e}static[f]="SQLiteSession";prepareOneTimeQuery(e,t,s,i,r,a,o){return this.prepareQuery(e,t,s,i,r,a,o)}run(e){const t=this.dialect.sqlToQuery(e);try{return this.prepareOneTimeQuery(t,void 0,"run",!1).run()}catch(s){throw new be({cause:s,message:`Failed to run the query '${t.sql}'`})}}extractRawRunValueFromBatchResult(e){return e}all(e){return this.prepareOneTimeQuery(this.dialect.sqlToQuery(e),void 0,"run",!1).all()}extractRawAllValueFromBatchResult(e){throw new Error("Not implemented")}get(e){return this.prepareOneTimeQuery(this.dialect.sqlToQuery(e),void 0,"run",!1).get()}extractRawGetValueFromBatchResult(e){throw new Error("Not implemented")}values(e){return this.prepareOneTimeQuery(this.dialect.sqlToQuery(e),void 0,"run",!1).values()}async count(e){return(await this.values(e))[0][0]}extractRawValuesValueFromBatchResult(e){throw new Error("Not implemented")}}class Ht extends Ie{constructor(e,t,s,i,r=0){super(e,t,s,i),this.schema=i,this.nestedIndex=r}static[f]="SQLiteTransaction";rollback(){throw new Mt}}class Zt extends Gt{constructor(e,t,s,i,r={}){super(t),this.client=e,this.schema=s,this.batchCLient=i,this.logger=r.logger??new St,this.cache=r.cache??new Ke}static[f]="SQLiteRemoteSession";logger;cache;prepareQuery(e,t,s,i,r,a,o){return new Xt(this.client,e,this.logger,this.cache,a,o,t,s,i,r)}async batch(e){const t=[],s=[];for(const i of e){const r=i._prepare(),a=r.getQuery();t.push(r),s.push({sql:a.sql,params:a.params,method:a.method})}return(await this.batchCLient(s)).map((i,r)=>t[r].mapResult(i,!0))}async transaction(e,t){const s=new $e("async",this.dialect,this,this.schema);await this.run(n.raw(`begin${t?.behavior?" "+t.behavior:""}`));try{const i=await e(s);return await this.run(n`commit`),i}catch(i){throw await this.run(n`rollback`),i}}extractRawAllValueFromBatchResult(e){return e.rows}extractRawGetValueFromBatchResult(e){return e.rows[0]}extractRawValuesValueFromBatchResult(e){return e.rows}}class $e extends Ht{static[f]="SQLiteProxyTransaction";async transaction(e){const t=`sp${this.nestedIndex}`,s=new $e("async",this.dialect,this.session,this.schema,this.nestedIndex+1);await this.session.run(n.raw(`savepoint ${t}`));try{const i=await e(s);return await this.session.run(n.raw(`release savepoint ${t}`)),i}catch(i){throw await this.session.run(n.raw(`rollback to savepoint ${t}`)),i}}}class Xt extends Yt{constructor(e,t,s,i,r,a,o,c,u,d){super("async",c,t,i,r,a),this.client=e,this.logger=s,this.fields=o,this._isResponseInArrayMode=u,this.customResultMapper=d,this.customResultMapper=d,this.method=c}static[f]="SQLiteProxyPreparedQuery";method;getQuery(){return{...this.query,method:this.method}}async run(e){const t=X(this.query.params,e??{});return this.logger.logQuery(this.query.sql,t),await this.queryWithCache(this.query.sql,t,async()=>await this.client(this.query.sql,t,"run"))}mapAllResult(e,t){return t&&(e=e.rows),!this.fields&&!this.customResultMapper?e:this.customResultMapper?this.customResultMapper(e):e.map(s=>Te(this.fields,s,this.joinsNotNullableMap))}async all(e){const{query:t,logger:s,client:i}=this,r=X(t.params,e??{});s.logQuery(t.sql,r);const{rows:a}=await this.queryWithCache(t.sql,r,async()=>await i(t.sql,r,"all"));return this.mapAllResult(a)}async get(e){const{query:t,logger:s,client:i}=this,r=X(t.params,e??{});s.logQuery(t.sql,r);const a=await this.queryWithCache(t.sql,r,async()=>await i(t.sql,r,"get"));return this.mapGetResult(a.rows)}mapGetResult(e,t){t&&(e=e.rows);const s=e;if(!this.fields&&!this.customResultMapper)return s;if(s)return this.customResultMapper?this.customResultMapper([e]):Te(this.fields,s,this.joinsNotNullableMap)}async values(e){const t=X(this.query.params,e??{});return this.logger.logQuery(this.query.sql,t),(await this.queryWithCache(this.query.sql,t,async()=>await this.client(this.query.sql,t,"values"))).rows}isResponseInArrayMode(){return this._isResponseInArrayMode}}class es extends Ie{static[f]="SqliteRemoteDatabase";async batch(e){return this.session.batch(e)}}function ts(l,e,t){const s=new Et({casing:t?.casing});let i,r,a,o={};e&&(typeof e=="function"?(a=e,o={}):(a=void 0,o=e),o.logger===!0?i=new wt:o.logger!==!1&&(i=o.logger,r=o.cache));let c;if(o.schema){const g=Qt(o.schema,Ot);c={fullSchema:o.schema,schema:g.tables,tableNamesMap:g.tableNamesMap}}const u=new Zt(l,s,c,a,{logger:i,cache:r}),d=new es("async",s,u,c);return d.$cache=r,d.$cache&&(d.$cache.invalidate=r?.onMutate),d}const ss=me(G,({many:l})=>({messages:l(z)})),is=me(z,({one:l,many:e})=>({chat:l(G,{fields:[z.aiChatId],references:[G.id]}),parts:e(H)})),rs=me(H,({one:l})=>({message:l(z,{fields:[H.aiMessageId],references:[z.id]})})),ns=Object.freeze(Object.defineProperty({__proto__:null,aiChats:G,aiChatsRelations:ss,aiMessageParts:H,aiMessagePartsRelations:rs,aiMessages:z,aiMessagesRelations:is,history:We,stepContext:Ve},Symbol.toStringTag,{value:"Module"}));function as(l){return l.map(e=>e===""?null:e)}class oe{constructor(e){this.dbPath=e,this.db=ts(async(t,s,i)=>{try{const r=(await ve("db_query",{params:{sql:t,params:s||[]}})).rows||[];if(r.length===0&&i==="get")return{};const a=r.map(as);return{rows:i==="get"?a[0]:a}}catch(r){throw console.error("SQLite proxy error:",r),r}},{schema:ns})}dbPath;static instances=new Map;initPromise=null;db;static getInstance(e){let t=this.instances.get(e);return t||(t=new oe(e),this.instances.set(e,t)),t}async initialize(){if(this.initPromise)return this.initPromise;this.initPromise=ve("db_init",{dbPath:this.dbPath});try{await this.initPromise}catch(e){throw this.initPromise=null,e}}async close(){oe.instances.delete(this.dbPath)}}export{oe as SqliteDBStorage};
@@ -0,0 +1 @@
1
+ import{s as t}from"./redocly-openapi-docs.min.step-context.schema-DEgzIgw0.js";import{b as l,e as o,d,l as u}from"./redocly-openapi-docs.min.indexes-Bp4ld5gB.js";function r(e){return{id:e.id,collectionId:e.collectionId,workflowId:e.workflowId,stepId:e.stepId,request:e.request??null,response:e.response??null,outputs:e.outputs??{},date:e.date}}function c(e){return{id:e.id,collectionId:e.collectionId,workflowId:e.workflowId,stepId:e.stepId,request:e.request,response:e.response,outputs:e.outputs,date:e.date}}class w{constructor(i){this.sqliteDB=i}sqliteDB;get db(){return this.sqliteDB.db}async initialize(){await this.sqliteDB.initialize()}async upsert(i){await this.initialize();const s=c(i);await this.db.insert(t).values(s).onConflictDoUpdate({target:[t.collectionId,t.workflowId,t.stepId],set:{request:s.request,response:s.response,outputs:s.outputs,date:s.date}})}async getByWorkflow(i,s){return await this.initialize(),(await this.db.select().from(t).where(l(o(t.collectionId,i),o(t.workflowId,s))).orderBy(d(t.date))).map(r)}async getByKey(i,s,n){await this.initialize();const a=await this.db.select().from(t).where(l(o(t.collectionId,i),o(t.workflowId,s),o(t.stepId,n))).limit(1);return a.length===0?null:r(a[0])}async pruneOlderThan(i){await this.initialize(),await this.db.delete(t).where(u(t.date,i))}async clear(){await this.initialize(),await this.db.delete(t)}}export{w as StepContextSqliteDBStorage};
@@ -0,0 +1 @@
1
+ import{Q as i}from"./redocly-openapi-docs.min.standalone-C6JXws-S.js";import{R as u,Q as n}from"./redocly-openapi-docs.min.index-DHNqz_Gi.js";function m(){return`aichat_${i()}`}function l(){return`aimsg_${i()}`}function c(){return`aimpt_${i()}`}function f(t){return{id:t.id,title:t.title??void 0,modelConfig:t.modelConfig,messages:t.messages.map(p),createdAt:new Date(t.createdAt),updatedAt:new Date(t.updatedAt)}}function p(t){return{id:t.uiId,role:t.role,metadata:t.metadata,parts:t.parts.map(g)}}function g(t){return t.self}function I(t){const a=t.id;return{id:a,title:t.title,modelConfig:t.modelConfig,messages:t.messages.map((e,r)=>d(a,r,e))}}function d(t,a,e,r=l()){return{id:r,uiId:e.id,role:e.role,metadata:e.metadata,aiChatId:t,indexWithinInsertBatch:a,parts:e.parts.map((o,s)=>C(r,s,o))}}function C(t,a,e){return{id:c(),text:e.type==="text"?e.text:null,index:a,self:e,aiMessageId:t}}function h(t){return{id:t.id,title:t.title,modelConfig:v(t.model),messages:t.messages.map(x)}}function v(t){switch(t.provider){case n.OPENAI:case n.ANTHROPIC:case n.GEMINI:return{provider:t.provider,modelId:t.modelId};case u:return{provider:t.provider,baseUrl:t.baseUrl};default:throw new Error("Cannot create model config")}}function x(t){return{...t,parts:t.parts.filter(a=>a.type!=="file")}}export{I as a,h as b,f as c,d,m as g};
@@ -0,0 +1 @@
1
+ import{s as n,R as s,U as t,X as e,Y as i,Z as o}from"./redocly-openapi-docs.min.indexes-Bp4ld5gB.js";const d=n`(cast(round(unixepoch('subsec') * 1000) as integer))`,_=s("ai_chats",{id:e("id").primaryKey().$type().notNull(),modelConfig:e("model_config",{mode:"json"}).$type().notNull(),title:e("title"),createdAt:t("created_at").notNull().default(d),updatedAt:t("updated_at").notNull().default(d)},a=>({idx_ai_chats_created_at:i("idx_ai_chats_created_at").on(a.createdAt),idx_ai_chats_updated_at:i("idx_ai_chats_updated_at").on(a.updatedAt)})),l=s("ai_messages",{id:e("id").primaryKey().$type().notNull(),uiId:e("ui_id").notNull(),indexWithinInsertBatch:t("index_within_insert_batch").notNull(),role:e("role",{enum:["system","user","assistant"]}).notNull(),metadata:e("metadata",{mode:"json"}),aiChatId:e("ai_chat_id").notNull().references(()=>_.id,{onDelete:"cascade"}),createdAt:t("created_at").notNull().default(d),updatedAt:t("updated_at").notNull().default(d)},a=>({idx_ai_messages_chat_timeline:i("idx_ai_messages_chat_timeline").on(a.aiChatId,a.createdAt,a.indexWithinInsertBatch),idx_ai_messages_id_ui_id:i("idx_ai_messages_id_ui_id").on(a.id,a.uiId)})),u=s("ai_message_parts",{id:e("id").primaryKey().$type().notNull(),index:t("index").notNull(),text:e("text"),self:e("self",{mode:"json"}).$type().notNull(),aiMessageId:e("ai_message_id").notNull().references(()=>l.id,{onDelete:"cascade"}),createdAt:t("created_at").notNull().default(d),updatedAt:t("updated_at").notNull().default(d)},a=>({idx_ai_message_parts_message_sort:o("idx_ai_message_parts_message_sort").on(a.aiMessageId,a.index)}));export{u as a,l as b,_ as c};
@@ -0,0 +1,2 @@
1
+ import{aR as r,a5 as n,aS as i,aT as c,aU as l}from"./redocly-openapi-docs.min.index-DHNqz_Gi.js";import{aG as f,ap as s,bi as d,b1 as o}from"./redocly-openapi-docs.min.standalone-C6JXws-S.js";class w extends f{constructor(){super()}resolveExternalRef(e,a){return r(a)?a:e&&r(e)?new URL(a,e).href:e?s.resolve(s.dirname(e),a):a}async loadExternalRef(e){if(r(e)){const{body:a,mimeType:t}=await d(e,{...this.config.http,customFetch:n});return new o(e,a,t)}else{if(!await i(e))throw new Error(`File not found at ${e}.`);try{throw await c(e),new Error(`Expected a file but received a folder at ${e}.`)}catch(t){if(t instanceof Error&&t.message.includes("Expected a file but received a folder"))throw t}const a=await l(e);return new o(e,a.replace(/\r\n/g,`
2
+ `))}}}export{w as ExternalResolver};
@@ -0,0 +1 @@
1
+ import{R as d,U as e,X as o,Y as s}from"./redocly-openapi-docs.min.indexes-Bp4ld5gB.js";const l=d("history",{id:o("id").primaryKey().notNull(),date:e("date").notNull(),type:o("type").$type().notNull().default("step"),step:o("step",{mode:"json"}).$type(),response:o("response",{mode:"json"}).$type(),statusCode:e("status_code"),workflowId:o("workflow_id"),collectionId:o("collection_id"),workflow:o("workflow",{mode:"json"}).$type(),workflowResult:o("workflow_result",{mode:"json"}).$type(),success:e("success",{mode:"boolean"}),durationMs:e("duration_ms")},t=>({date_idx:s("date_idx").on(t.date),type_idx:s("type_idx").on(t.type),workflow_idx:s("workflow_idx").on(t.workflowId)}));export{l as h};
@@ -0,0 +1 @@
1
+ import{aA as T,x as m,aB as v,aC as O,aD as I,aE as A,aF as w,aG as h,aH as C,aI as b,aJ as G}from"./redocly-openapi-docs.min.standalone-C6JXws-S.js";import{aK as B,aL as M,aM as J,aN as Y,aO as W,aP as q,aQ as H,aR as K,aS as Q,aT as X,aU as Z,aV as ee,aW as se,aX as ae,aY as te,aZ as re,a_ as ne,a$ as oe,b0 as ie,b1 as le,b2 as ce,b3 as me,b4 as ue,b5 as pe,b6 as ye,b7 as fe,b8 as de,b9 as ge,ba as he,bb as ve,bc as be,bd as Ee,be as Re,bf as Se,bg as Te,bh as Oe,bi as Ie,bj as Ae,bk as we,bl as Ce,bm as xe,bn as De}from"./redocly-openapi-docs.min.standalone-C6JXws-S.js";import{g as x,t as D,A as Pe,c as E,l as R,S as je,C as ke,u as Ne}from"./redocly-openapi-docs.min.lint-CmpdR_qH.js";import{a as Fe,b as ze,d as _e,e as $e,f as Le,h as Ue,i as Ve,j as Ge,k as Be,m as Me,n as Je,o as Ye,p as We,q as qe,r as He,s as Ke,v as Qe,w as Xe,x as Ze,y as es,z as ss,B as as,D as ts,s as rs,E as ns}from"./redocly-openapi-docs.min.lint-CmpdR_qH.js";function os(e){return(T.extname(e)===".yaml"||T.extname(e)===".yml")&&!1}function is(e){return m(e)&&!v(e)}async function ls(e){return new Promise(s=>setTimeout(s,e))}const S="type",P=["api-description","api-operation","data-schema"];function j(e,s){const{ctx:a}=x("EntityFileDefault",s),{ctx:t,discriminatorResolver:r}=x("EntityFile",e);return{entityTypes:{...a,...t,EntityFileArray:{properties:{},items:n=>{if(m(n)){const i=n[S];if(!i)return"Entity";const o=r?.(n,i);if(o&&typeof o=="string")return o}return"Entity"}}},discriminatorResolver:r}}const cs=e=>({ExternalDocs:{leave(){e.externalDocs.total++}},ref:{enter(s){e.refs.items.add(s.$ref)}},Tag:{leave(s){e.tags.items.add(s.name)}},Link:{leave(s){e.links.items.add(s.operationId)}},WebhooksMap:{Operation:{leave(s){if(e.webhooks.total++,s.tags)for(const a of s.tags)e.tags.items.add(a)}}},Paths:{PathItem:{leave(){e.pathItems.total++},Operation:{leave(s){if(e.operations.total++,s.tags)for(const a of s.tags)e.tags.items.add(a)}},Parameter:{leave(s){e.parameters.items.add(s.name)}}}},NamedSchemas:{Schema:{leave(){e.schemas.total++}}},Root:{leave(){e.parameters.total=e.parameters.items.size,e.refs.total=e.refs.items.size,e.links.total=e.links.items.size,e.tags.total=e.tags.items.size}}}),ms=e=>({ExternalDocs:{leave(){e.externalDocs.total++}},ref:{enter(s){e.refs.items.add(s.$ref)}},Tag:{leave(s){e.tags.items.add(s.name)}},ChannelMap:{Channel:{leave(){e.channels.total++},Operation:{leave(s){if(e.operations.total++,s.tags)for(const a of s.tags)e.tags.items.add(a)}},Parameter:{leave(s){s.name&&e.parameters.items.add(s.name)}}}},NamedSchemas:{Schema:{leave(){e.schemas.total++}}},Root:{leave(){e.parameters.total=e.parameters.items.size,e.refs.total=e.refs.items.size,e.tags.total=e.tags.items.size}}}),us=e=>({ExternalDocs:{leave(){e.externalDocs.total++}},ref:{enter(s){e.refs.items.add(s.$ref)}},Tag:{leave(s){e.tags.items.add(s.name)}},NamedChannels:{Channel:{leave(){e.channels.total++},Parameter:{leave(s){s.name&&e.parameters.items.add(s.name)}}}},NamedOperations:{Operation:{leave(s){if(e.operations.total++,s.tags)for(const a of s.tags)e.tags.items.add(a)}}},NamedSchemas:{Schema:{leave(){e.schemas.total++}}},Root:{leave(){e.parameters.total=e.parameters.items.size,e.refs.total=e.refs.items.size,e.tags.total=e.tags.items.size}}}),ps=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,k=2,N=150,ys=()=>({any(e,{report:s,location:a}){if(m(e)&&"key"in e){const t=e.key;if(typeof t!="string"){s({message:"Entity `key` must be a string.",location:a.child(["key"])});return}t.length<k&&s({message:`Entity 'key' must be at least ${k} characters long.`,location:a.child(["key"])}),t.length>N&&s({message:`Entity 'key' must not exceed ${N} characters.`,location:a.child(["key"])}),ps.test(t)||s({message:"Entity `key` must contain only lowercase letters, numbers, and hyphens, and cannot start or end with a hyphen.",location:a.child(["key"])})}}});function F(e,s){const a=s.split("-").map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join("")+e;return Object.values(D).includes(a)?a:e}function fs(e,s){const a={};for(const[t,r]of Object.entries(s))if(z(t,r)){if(r.severity==="off")continue;a[t]={...vs(e,t,r)}}else a[t]=r;return a}function ds(e){const s={},a={};for(const[t,r]of Object.entries(e))if(z(t,r)){const n=r;hs(n)?s[t]=n:a[t]=n}else a[t]=r;return{entityRules:s,apiRules:a}}function gs(e,s,a){if(!m(a.parsed)||!m(a.parsed.components))return null;const t=a.parsed.components,r="schemas"in t?t.schemas:void 0;if(!r||!(e in r))return null;const n=r[e];try{const i=JSON.parse(s);if(O(n,i))return n}catch{return null}return null}function z(e,s){return e.startsWith("rule/")&&m(s)}function hs(e){return Object.values(D).some(s=>e.subject.type===s)}function vs(e,s,a){const t=F(a.subject.type,e),r=a.where?.map(n=>({...n,subject:{...n.subject,type:F(n.subject.type,e)}}));return{assertionId:s,subject:{...a.subject,type:t},assertions:a.assertions,...r&&{where:r},...a.message&&{message:a.message},...a.severity&&{severity:a.severity}}}async function _(e){const{document:s,entitySchema:a,entityDefaultSchema:t,severity:r,externalRefResolver:n=new h,assertionConfig:i={}}=e,o={problems:[],specVersion:"entity",visitorsData:{}},{entityTypes:u,discriminatorResolver:p}=j(a,t),l=I(u);let c=l.Entity;if(Array.isArray(s.parsed))c=l.EntityFileArray;else if(m(s.parsed)){const d=s.parsed[S];if(!d)c=l.Entity;else{const g=p?.(s.parsed,d);g&&typeof g=="string"&&l[g]&&(c=l[g])}}const y=Pe(i),f=Array.isArray(y)?y.map(d=>({severity:r||"error",ruleId:"entity assertions",visitor:d})):[{severity:r||"error",ruleId:"entity assertions",visitor:y}],L=[{severity:r||"error",ruleId:"entity struct",visitor:je()},{severity:r||"error",ruleId:"entity no-unresolved-refs",visitor:G()},{severity:r||"error",ruleId:"entity key-valid",visitor:ys()},...f],U=A(L,l),V=await w({rootDocument:s,rootType:c,externalRefResolver:n});return C({document:s,rootType:c,normalizedVisitors:U,resolvedRefMap:V,ctx:o}),o.problems}async function bs(e,s,a){if(!s.rules)throw new Error(`Scorecard level "${s.name}" has no rules defined.`);const t=new h,r=b(JSON.stringify(e,null,2),"entity"),n=r.parsed[S],i=fs(n||"unknown",s.rules),{entityRules:o,apiRules:u}=ds(i),p=await _({document:r,entitySchema:Ne,entityDefaultSchema:ke,externalRefResolver:t,assertionConfig:o});if(P.includes(e.type)){if(Object.keys(u).length===0)return p;if(!a)throw new Error(`Document is required for entity type "${e.type}". Provide the source API document to lint API rules.`);if(e.type==="data-schema"&&e.metadata?.schema){Object.values(u).forEach(f=>{if(m(f)&&m(f.subject)&&f.subject.type!=="Schema")throw new Error(`API rules for "data-schema" entity must target Schema subject, but found "${f.subject.type}".`)});const c=gs(e.title,e.metadata.schema,a);if(!c)throw new Error(`Schema "${e.title}" not found in the document. Ensure the schema exists in components.schemas.`);const y=await $({schema:c,schemaKey:e.title,config:await E({rules:u}),specType:e.metadata.specType,sourceDocument:a,externalRefResolver:t});return[...p,...y]}const l=await R({document:a,externalRefResolver:t,config:await E({rules:u})});return[...p,...l]}else if(!v(u))throw new Error(`API rules are not supported for entity type "${e.type}". Only ${P.join(", ")} support API rules.`);return p}async function $(e){const{schema:s,schemaKey:a,config:t,sourceDocument:r,specType:n,externalRefResolver:i=new h(t.resolve)}=e,o=r.parsed,u=o[n],p=o.info,l=b(JSON.stringify({[n]:u,info:p,components:{schemas:{[a]:s}}},null,2),r?.source.absoluteRef||`schema:${a}`);return(await R({document:l,config:t,externalRefResolver:i})).filter(c=>c.location.some(y=>y.pointer?.includes(`/components/schemas/${a}`)))}class Es extends Error{}export{B as Arazzo1Types,M as Arazzo1_1Types,J as AsyncApi2Types,Y as AsyncApi3Types,h as BaseResolver,W as CONFIG_BUNDLER_VISITOR_ID,q as CONFIG_FILE_NAME,H as Config,Fe as ConfigTypes,ze as ConfigValidationError,K as DEFAULT_CONFIG,Q as DEFAULT_PROJECT_PLUGIN_PATHS,Es as HandledError,X as IGNORE_BANNER,Z as IGNORE_FILE,ee as Oas2Types,se as Oas3Types,ae as Oas3_1Types,te as Oas3_2Types,re as OpenRpcTypes,ne as Overlay1Types,oe as PLUGINS_COLLECTOR_VISITOR_ID,ie as ResolveError,le as Source,ms as StatsAsync2,us as StatsAsync3,cs as StatsOAS,ce as YamlParseError,_e as bundle,me as bundleDocument,$e as bundleFromString,Le as clearPluginsCache,E as createConfig,Ue as createConfigTypes,j as createEntityTypes,O as dequal,ue as detectSpec,os as doesYamlFileExist,pe as escapePointerFragment,Ve as findConfig,Ge as formatProblems,Be as getAstNodeByPointer,Me as getCodeframe,ye as getDir,Je as getLineColLocation,fe as getMajorSpecVersion,Ye as getPluginCacheVersion,We as getTotals,de as getTypes,ge as isAbsoluteUrl,he as isBrowser,v as isEmptyObject,ve as isMappingRef,qe as isNotEmptyArray,is as isNotEmptyObject,m as isPlainObject,be as isRef,Ee as isString,Re as isSupportedExtension,Se as isTruthy,He as keysOf,Ke as lint,Qe as lintConfig,R as lintDocument,_ as lintEntityFile,bs as lintEntityWithScorecardLevel,Xe as lintFromString,$ as lintSchema,Ze as loadConfig,es as loadIgnoreConfig,ss as logger,b as makeDocumentFromString,Te as mapTypeToComponent,I as normalizeTypes,A as normalizeVisitors,Oe as parseYaml,ls as pause,as as pluralize,Ie as readFileFromUrl,Ae as regexFromString,w as resolveDocument,we as resolvePath,ts as resolvePlugins,Ce as slash,xe as stringifyYaml,De as unescapePointerFragment,rs as validate,C as walkDocument,ns as xmlEscape};
@@ -0,0 +1 @@
1
+ import{aJ as t}from"./redocly-openapi-docs.min.index-DHNqz_Gi.js";async function a(o={}){return typeof o=="object"&&Object.freeze(o),await t("plugin:dialog|open",{options:o})}export{a as open};