@opengis/fcore 0.0.1-beta.25 → 0.0.1-beta.27

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 (142) hide show
  1. package/dist/config.js +1 -1
  2. package/dist/context.js +1 -1
  3. package/dist/errors.js +1 -1
  4. package/dist/fastify.js +1 -1
  5. package/dist/fcore.js +1 -1
  6. package/dist/migrations/cli.js +1 -1
  7. package/dist/migrations/runner.js +1 -1
  8. package/dist/modules/auth/adduser-cli.js +1 -1
  9. package/dist/modules/auth/passwd-cli.js +1 -1
  10. package/dist/modules/auth/permission-cli.js +1 -1
  11. package/dist/modules/auth/route.d.ts.map +1 -1
  12. package/dist/modules/auth/route.js +1 -1
  13. package/dist/modules/auth/schema.js +1 -1
  14. package/dist/modules/auth/services/change-password.js +1 -1
  15. package/dist/modules/auth/services/get-current-user.d.ts +2 -0
  16. package/dist/modules/auth/services/get-current-user.d.ts.map +1 -1
  17. package/dist/modules/auth/services/get-current-user.js +1 -1
  18. package/dist/modules/auth/services/registration.js +1 -1
  19. package/dist/modules/auth/services/verify-two-factor.js +1 -1
  20. package/dist/modules/file/mime.js +1 -1
  21. package/dist/modules/file/route.js +1 -1
  22. package/dist/modules/file/schema.js +1 -1
  23. package/dist/modules/file/services/get-file.js +1 -1
  24. package/dist/modules/file/services/resize-file.js +1 -1
  25. package/dist/modules/file/services/upload-file.js +1 -1
  26. package/dist/modules/resource/route.d.ts.map +1 -1
  27. package/dist/modules/resource/route.js +1 -1
  28. package/dist/modules/resource/schema.d.ts +13 -0
  29. package/dist/modules/resource/schema.d.ts.map +1 -1
  30. package/dist/modules/resource/schema.js +1 -1
  31. package/dist/modules/resource/services/add-note.js +1 -1
  32. package/dist/modules/resource/services/add-resource-file.js +1 -1
  33. package/dist/modules/resource/services/create-resource-relation.js +1 -1
  34. package/dist/modules/resource/services/create-resource.js +1 -1
  35. package/dist/modules/resource/services/delete-resource-relation.js +1 -1
  36. package/dist/modules/resource/services/delete-resource.js +1 -1
  37. package/dist/modules/resource/services/export-resource.js +1 -1
  38. package/dist/modules/resource/services/generate-resource-code.d.ts +16 -0
  39. package/dist/modules/resource/services/generate-resource-code.d.ts.map +1 -0
  40. package/dist/modules/resource/services/generate-resource-code.js +1 -0
  41. package/dist/modules/resource/services/get-resource-schema.d.ts +6 -0
  42. package/dist/modules/resource/services/get-resource-schema.d.ts.map +1 -0
  43. package/dist/modules/resource/services/get-resource-schema.js +1 -0
  44. package/dist/modules/resource/services/get-resource.js +1 -1
  45. package/dist/modules/resource/services/list-resource-as-user.d.ts +8 -0
  46. package/dist/modules/resource/services/list-resource-as-user.d.ts.map +1 -0
  47. package/dist/modules/resource/services/list-resource-as-user.js +1 -0
  48. package/dist/modules/resource/services/list-resource-list.d.ts +20 -0
  49. package/dist/modules/resource/services/list-resource-list.d.ts.map +1 -0
  50. package/dist/modules/resource/services/list-resource-list.js +1 -0
  51. package/dist/modules/resource/services/list-resource-relation.js +1 -1
  52. package/dist/modules/resource/services/list-resources.d.ts.map +1 -1
  53. package/dist/modules/resource/services/list-resources.js +1 -1
  54. package/dist/modules/resource/services/search-resource.js +1 -1
  55. package/dist/modules/resource/services/suggest-resource.js +1 -1
  56. package/dist/modules/resource/services/update-resource-relation.js +1 -1
  57. package/dist/modules/resource/services/update-resource.js +1 -1
  58. package/dist/modules/resource/services/upload-resource-file.js +1 -1
  59. package/dist/modules/system/route.d.ts.map +1 -1
  60. package/dist/modules/system/route.js +1 -1
  61. package/dist/modules/system/schema.d.ts +22 -0
  62. package/dist/modules/system/schema.d.ts.map +1 -1
  63. package/dist/modules/system/schema.js +1 -1
  64. package/dist/modules/system/services/check-system.js +1 -1
  65. package/dist/modules/system/services/get-access.js +1 -1
  66. package/dist/modules/system/services/get-api-list.js +1 -1
  67. package/dist/modules/system/services/get-audit-log.js +1 -1
  68. package/dist/modules/system/services/get-dictionary.js +1 -1
  69. package/dist/modules/system/services/get-resource-access.d.ts +23 -0
  70. package/dist/modules/system/services/get-resource-access.d.ts.map +1 -0
  71. package/dist/modules/system/services/get-resource-access.js +1 -0
  72. package/dist/modules/system/services/get-resource-scopes.d.ts +16 -0
  73. package/dist/modules/system/services/get-resource-scopes.d.ts.map +1 -0
  74. package/dist/modules/system/services/get-resource-scopes.js +1 -0
  75. package/dist/modules/system/services/get-system-log.js +1 -1
  76. package/dist/modules/system/services/get-system-settings.js +1 -1
  77. package/dist/modules/system/services/list-dictionaries.js +1 -1
  78. package/dist/modules/system/services/set-access.d.ts +1 -0
  79. package/dist/modules/system/services/set-access.d.ts.map +1 -1
  80. package/dist/modules/system/services/set-access.js +1 -1
  81. package/dist/modules/system/services/set-resource-access.d.ts +18 -0
  82. package/dist/modules/system/services/set-resource-access.d.ts.map +1 -0
  83. package/dist/modules/system/services/set-resource-access.js +1 -0
  84. package/dist/modules/system/services/set-resource-scopes.d.ts +10 -0
  85. package/dist/modules/system/services/set-resource-scopes.d.ts.map +1 -0
  86. package/dist/modules/system/services/set-resource-scopes.js +1 -0
  87. package/dist/modules/system/services/update-dictionary.js +1 -1
  88. package/dist/modules/system/services/update-system-settings.js +1 -1
  89. package/dist/modules/utils/require-admin.js +1 -1
  90. package/dist/modules/utils/safe-user.js +1 -1
  91. package/dist/modules/utils/unsupported.js +1 -1
  92. package/dist/plugins/audit/audit.js +1 -1
  93. package/dist/plugins/audit/services/write-audit.js +1 -1
  94. package/dist/plugins/auth/get-user-permissions.js +1 -1
  95. package/dist/plugins/auth/index.js +1 -1
  96. package/dist/plugins/auth/verifyUser.js +1 -1
  97. package/dist/plugins/dictionary.js +1 -1
  98. package/dist/plugins/file.js +1 -1
  99. package/dist/plugins/jwt.js +1 -1
  100. package/dist/plugins/logger/index.js +1 -1
  101. package/dist/plugins/logger/transport.js +1 -1
  102. package/dist/plugins/pg.js +1 -1
  103. package/dist/plugins/redis.js +1 -1
  104. package/dist/plugins/resource/resource.d.ts +1 -1
  105. package/dist/plugins/resource/resource.d.ts.map +1 -1
  106. package/dist/plugins/resource/resource.js +1 -1
  107. package/dist/plugins/resource/resource.registry.d.ts +3 -2
  108. package/dist/plugins/resource/resource.registry.d.ts.map +1 -1
  109. package/dist/plugins/resource/resource.registry.js +1 -1
  110. package/dist/plugins/resource/resource.types.d.ts +23 -4
  111. package/dist/plugins/resource/resource.types.d.ts.map +1 -1
  112. package/dist/plugins/resource/services/add-dictionary-lookup-data.js +1 -1
  113. package/dist/plugins/resource/services/add-file-token.js +1 -1
  114. package/dist/plugins/resource/services/add-table-lookup-data.js +1 -1
  115. package/dist/plugins/resource/services/create-relation.js +1 -1
  116. package/dist/plugins/resource/services/create.js +1 -1
  117. package/dist/plugins/resource/services/delete-relation.js +1 -1
  118. package/dist/plugins/resource/services/delete.js +1 -1
  119. package/dist/plugins/resource/services/find-one.d.ts.map +1 -1
  120. package/dist/plugins/resource/services/find-one.js +1 -1
  121. package/dist/plugins/resource/services/find-relation.js +1 -1
  122. package/dist/plugins/resource/services/find.d.ts.map +1 -1
  123. package/dist/plugins/resource/services/find.js +1 -1
  124. package/dist/plugins/resource/services/get-table-columns.js +1 -1
  125. package/dist/plugins/resource/services/update-relation.js +1 -1
  126. package/dist/plugins/resource/services/update.js +1 -1
  127. package/dist/plugins/resource/utils/auto-index.js +1 -1
  128. package/dist/plugins/resource/utils/fields.js +1 -1
  129. package/dist/plugins/resource/utils/filters.js +1 -1
  130. package/dist/plugins/resource/utils/permissions.js +1 -1
  131. package/dist/plugins/resource/utils/scope.d.ts +10 -0
  132. package/dist/plugins/resource/utils/scope.d.ts.map +1 -0
  133. package/dist/plugins/resource/utils/scope.js +1 -0
  134. package/dist/plugins/resource/utils/sort.js +1 -1
  135. package/dist/plugins/resource/utils/sql.js +1 -1
  136. package/dist/plugins/resource/utils/summary.d.ts +5 -1
  137. package/dist/plugins/resource/utils/summary.d.ts.map +1 -1
  138. package/dist/plugins/resource/utils/summary.js +1 -1
  139. package/dist/shared/getIP.js +1 -1
  140. package/migrations/20260929120000_allow_user_only_role_scopes.sql +2 -0
  141. package/migrations/20260929_role_scope.sql +32 -0
  142. package/package.json +2 -2
@@ -1 +1 @@
1
- import{ValidationError}from'../../../errors.js';import{assertOperation}from'../utils/permissions.js';import{qt,qi,readableFields}from'../utils/sql.js';function f(){const E=['get','type','table','key','=$1','include','rows'];f=function(){return E;};return f();}import{addDictionaryLookupData}from'./add-dictionary-lookup-data.js';import{addTableLookupData}from'./add-table-lookup-data.js';import{addFileToken}from'./add-file-token.js';import{createFindRelation}from'./find-relation.js';function Y(w,y){w=w-0x1ba;const d=f();let Z=d[w];return Z;}export function createFindOne(w,y){return async function d({name:Z,id:M,query:query={},user:H}){const U=Y,Q=Date['now'](),s=y[U(0x1ba)](Z);assertOperation(s,'read',H);if(s['fields'][s['key']]?.[U(0x1bb)]==='integer'&&!Number['isInteger'](Number(M)))throw new ValidationError('Invalid\x20id:\x20'+M+'\x20name:'+Z);const j=s['joins']?.['map'](i=>i['sql']+'\x20')['join']('\x20')||'',n=s['where']?'\x20AND\x20('+s['where']+')':'',t=await w['pg']['query']('SELECT\x20'+readableFields(s)['join'](',\x20')+'\x20FROM\x20'+qt(s[U(0x1bc)])+'\x20t\x20'+j+'\x20WHERE\x20'+qi(s[U(0x1bd)])+U(0x1be)+n+'\x20LIMIT\x201',[M]),K=t['rows'][0x0];if(!K)return null;await addDictionaryLookupData([K],s['fields'],w['dictionary']),await addTableLookupData([K],s['fields'],w['pg']),addFileToken([K],s['fields'],w['file']);const T=Array['isArray'](query['include'])?query[U(0x1bf)]:query['include']?.['split'](',')??[],h=createFindRelation(w,y);for(const i of T){K[i]=await h({'name':Z,'id':M,'relation':i,'query':query,'user':H})['then'](G=>G[U(0x1c0)]??[]);}return K['time']=Date['now']()-Q,K;};}
1
+ import{ValidationError}from'../../../errors.js';import{assertOperation}from'../utils/permissions.js';function Q(){const m=['now','get','key','isInteger','Invalid\x20id:\x20','where','\x20AND\x20(','SELECT\x20','join','\x20t\x20','\x20LIMIT\x201','fields','isArray','include','rows','relations','one'];Q=function(){return m;};return Q();}import{qt,qi,readableFields}from'../utils/sql.js';import{addDictionaryLookupData}from'./add-dictionary-lookup-data.js';import{addTableLookupData}from'./add-table-lookup-data.js';function k(h,n){h=h-0xb8;const B=Q();let G=B[h];return G;}import{addFileToken}from'./add-file-token.js';import{createFindRelation}from'./find-relation.js';export function createFindOne(h,n){return async function B({name:G,id:f,query:query={},user:j}){const t=k,Z=Date[t(0xb8)](),e=n[t(0xb9)](G);assertOperation(e,'read',j);if(e['fields'][e[t(0xba)]]?.['type']==='integer'&&!Number[t(0xbb)](Number(f)))throw new ValidationError(t(0xbc)+f+'\x20name:'+G);const b=e['joins']?.['map'](p=>p['sql']+'\x20')['join']('\x20')||'',P=e[t(0xbd)]?t(0xbe)+e[t(0xbd)]+')':'',u=await h['pg']['query'](t(0xbf)+readableFields(e)[t(0xc0)](',\x20')+'\x20FROM\x20'+qt(e['table'])+t(0xc1)+b+'\x20WHERE\x20'+qi(e[t(0xba)])+'=$1'+P+t(0xc2),[f]),X=u['rows'][0x0];if(!X)return null;await addDictionaryLookupData([X],e[t(0xc3)],h['dictionary']),await addTableLookupData([X],e['fields'],h['pg']),addFileToken([X],e['fields'],h['file']);const H=(query['include']==='all'?Object['keys'](e['relations']||{}):null)||(Array[t(0xc4)](query['include'])?query['include']:query[t(0xc5)]?.['split'](',')??[]),i=createFindRelation(h,n);for(const p of H){X[p]=await i({'name':G,'id':f,'relation':p,'query':query,'user':j})['then'](z=>z[t(0xc6)]??[])['then'](z=>e[t(0xc7)]?.[p]?.['type']===t(0xc8)?z[0x0]??null:z);}return X['time']=Date['now']()-Z,X;};}
@@ -1 +1 @@
1
- import{UnsupportedError,ValidationError}from'../../../errors.js';function f(){const r=['now','capabilities','Generic\x20Resource\x20relation\x20\x22','notes','length','rows','files','file','\x22\x20requires\x20a\x20project/provider\x20implementation','fields','scope','map','join','\x20j\x20ON\x20j.','junctionLocalKey','where\x20','\x20=\x20(SELECT\x20','key','where','joins','\x20FROM\x20','dictionary'];f=function(){return r;};return f();}import{qi,qt}from'../utils/sql.js';import{addDictionaryLookupData}from'./add-dictionary-lookup-data.js';import{addTableLookupData}from'./add-table-lookup-data.js';function Y(w,y){w=w-0x1a1;const d=f();let Z=d[w];return Z;}import{addFileToken}from'./add-file-token.js';import{autoIndex}from'../utils/auto-index.js';export function createFindRelation(w,y){return async function d({name:Z,id:M,relation:H,query:query={}}){const o=Y,Q=Date[o(0x1a1)](),s=Math['min'](Math['max'](query['limit']??0x14,0x1),0xc8),j=Math['max'](query['offset']??0x0,0x0);if(!Number['isFinite'](s)||!Number['isFinite'](j))throw new ValidationError('Invalid\x20pagination');const n=y['get'](Z),t=n['relations']?.[H];if(['notes','files']['includes'](H)&&!n[o(0x1a2)]?.['includes'](H))throw new UnsupportedError(o(0x1a3)+H+'\x22\x20requires\x20a\x20capabilities\x20\x22'+H+'\x22');if(H===o(0x1a4)){const A=await w['pg']['query']('SELECT\x20*\x20FROM\x20admin.notes\x20WHERE\x20resource\x20=\x20$1\x20AND\x20resource_id\x20=\x20$2\x20ORDER\x20BY\x20created_at\x20DESC',[Z,String(M)]);return{'total':A['rows'][o(0x1a5)],'time':Date['now']()-Q,'rows':A[o(0x1a6)]};}if(H===o(0x1a7)){const c=await w['pg']['query']('SELECT\x20*\x20FROM\x20admin.files\x20WHERE\x20resource\x20=\x20$1\x20AND\x20resource_id\x20=\x20$2\x20ORDER\x20BY\x20created_at\x20DESC',[Z,String(M)]);return addFileToken(c['rows'],{'file_path':{'type':o(0x1a8)}},w['file']),{'total':c['rows']['length'],'time':Date[o(0x1a1)]()-Q,'rows':c['rows']};}if(!t?.['resource'])throw new UnsupportedError('Generic\x20Resource\x20relation\x20\x22'+H+o(0x1a9));const K=y['get'](t['resource']),T=K?.['key']??'id',h=K?.['table'],i=Object['keys'](K?.[o(0x1aa)]??{})['filter'](x=>K?.['fields'][x]?.['read']&&K?.[o(0x1aa)][x]?.[o(0x1ab)]!=='item')[o(0x1ac)](qi)['join'](',\x20'),G=t['fields']?.[o(0x1ad)](',\x20')||i||'*';t['foreignKey']&&autoIndex(h,t['foreignKey'],'btree',w['pg']);const U=t['junctionTable']?'JOIN\x20'+qt(t['junctionTable'])+o(0x1ae)+qi(t['junctionForeignKey'])+'\x20=\x20t.'+(t['junctionTargetKey']||qi(T))+'\x20WHERE\x20'+qi(t[o(0x1af)])+'\x20=\x20$1\x20':o(0x1b0)+(t['foreignKey']||qi(T))+o(0x1b1)+qi(t['localKey']||n[o(0x1b2)])+'\x20FROM\x20'+qt(n['table'])+'\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20'+qi(n['key'])+'\x20=\x20$1\x20LIMIT\x201\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20)\x20'+(t['where']?'AND\x20('+t[o(0x1b3)]+')':''),E=K[o(0x1b4)]?.['map'](x=>x['sql']+'\x20')['join']('\x20')||'',e='SELECT\x20'+G+o(0x1b5)+qt(h)+'\x20t\x20'+E+'\x20'+U+'\x20LIMIT\x20$2\x20OFFSET\x20$3',l=await w['pg']['query'](e,[M,s,j]);return K&&(await addDictionaryLookupData(l['rows'],K['fields'],w[o(0x1b6)]),await addTableLookupData(l['rows'],K['fields'],w['pg']),addFileToken(l[o(0x1a6)],K[o(0x1aa)],w['file'])),{'limit':s,'offset':j,'total':l['rows']['length'],'time':Date['now']()-Q,'rows':l['rows']??null};};}
1
+ function k(h,n){h=h-0x16a;const B=Q();let G=B[h];return G;}import{UnsupportedError,ValidationError}from'../../../errors.js';import{qi,qt}from'../utils/sql.js';function Q(){const V=['min','limit','relations','Generic\x20Resource\x20relation\x20\x22','query','length','files','rows','file','scope','join','\x20=\x20$1\x20','localKey','key','\x20=\x20$1\x20LIMIT\x201\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20)\x20','where','joins','\x20LIMIT\x20$2\x20OFFSET\x20$3','fields'];Q=function(){return V;};return Q();}import{addDictionaryLookupData}from'./add-dictionary-lookup-data.js';import{addTableLookupData}from'./add-table-lookup-data.js';import{addFileToken}from'./add-file-token.js';import{autoIndex}from'../utils/auto-index.js';export function createFindRelation(h,n){return async function B({name:G,id:f,relation:j,query:query={}}){const W=k,Z=Date['now'](),e=Math[W(0x16a)](Math['max'](query[W(0x16b)]??0x14,0x1),0xc8),b=Math['max'](query['offset']??0x0,0x0);if(!Number['isFinite'](e)||!Number['isFinite'](b))throw new ValidationError('Invalid\x20pagination');const P=n['get'](G),u=P[W(0x16c)]?.[j];if(['notes','files']['includes'](j)&&!P['capabilities']?.['includes'](j))throw new UnsupportedError(W(0x16d)+j+'\x22\x20requires\x20a\x20capabilities\x20\x22'+j+'\x22');if(j==='notes'){const O=await h['pg'][W(0x16e)]('SELECT\x20*\x20FROM\x20admin.notes\x20WHERE\x20resource\x20=\x20$1\x20AND\x20resource_id\x20=\x20$2\x20ORDER\x20BY\x20created_at\x20DESC',[G,String(f)]);return{'total':O['rows'][W(0x16f)],'time':Date['now']()-Z,'rows':O['rows']};}if(j===W(0x170)){const T=await h['pg']['query']('SELECT\x20*\x20FROM\x20admin.files\x20WHERE\x20resource\x20=\x20$1\x20AND\x20resource_id\x20=\x20$2\x20ORDER\x20BY\x20created_at\x20DESC',[G,String(f)]);return addFileToken(T[W(0x171)],{'file_path':{'type':W(0x172)}},h['file']),{'total':T['rows']['length'],'time':Date['now']()-Z,'rows':T['rows']};}if(!u?.['resource'])throw new UnsupportedError('Generic\x20Resource\x20relation\x20\x22'+j+'\x22\x20requires\x20a\x20project/provider\x20implementation');const X=n['get'](u['resource']),H=X?.['key']??'id',i=X?.['table'],p=Object['keys'](X?.['fields']??{})['filter'](d=>X?.['fields'][d]?.['read']&&X?.['fields'][d]?.[W(0x173)]!=='item')['map'](qi)[W(0x174)](',\x20'),z=u['fields']?.[W(0x174)](',\x20')||p||'*';u['foreignKey']&&autoIndex(i,u['foreignKey'],'btree',h['pg']);const t=u['junctionTable']?'JOIN\x20'+qt(u['junctionTable'])+'\x20j\x20ON\x20j.'+qi(u['junctionForeignKey'])+'\x20=\x20t.'+(u['junctionTargetKey']||qi(H))+'\x20WHERE\x20'+qi(u['junctionLocalKey'])+W(0x175):'where\x20'+(u['foreignKey']||qi(H))+'\x20=\x20(SELECT\x20'+qi(u[W(0x176)]||P['key'])+'\x20FROM\x20'+qt(P['table'])+'\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20'+qi(P[W(0x177)])+W(0x178)+(u[W(0x179)]?'AND\x20('+u['where']+')':''),m=X[W(0x17a)]?.['map'](d=>d['sql']+'\x20')['join']('\x20')||'',A='SELECT\x20'+z+'\x20FROM\x20'+qt(i)+'\x20t\x20'+m+'\x20'+t+W(0x17b),U=await h['pg']['query'](A,[f,e,b]);return X&&(await addDictionaryLookupData(U[W(0x171)],X['fields'],h['dictionary']),await addTableLookupData(U['rows'],X[W(0x17c)],h['pg']),addFileToken(U['rows'],X[W(0x17c)],h['file'])),{'limit':e,'offset':b,'total':U['rows']['length'],'time':Date['now']()-Z,'rows':U[W(0x171)]??null};};}
@@ -1 +1 @@
1
- {"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../../../../src/plugins/resource/services/find.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,oBAAoB,EACpB,kBAAkB,EAClB,aAAa,EACb,YAAY,EACb,MAAM,sBAAsB,CAAC;AAK9B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAOhE,wBAAgB,UAAU,CACxB,IAAI,EAAE,oBAAoB,EAC1B,QAAQ,EAAE,gBAAgB,4BAMvB;IACD,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,IAAI,CAAC,EAAE,YAAY,CAAC;CACrB,KAAG,OAAO,CAAC,kBAAkB,CAAC,CAyEhC"}
1
+ {"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../../../../src/plugins/resource/services/find.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,oBAAoB,EACpB,kBAAkB,EAClB,aAAa,EACb,YAAY,EACb,MAAM,sBAAsB,CAAC;AAK9B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAQhE,wBAAgB,UAAU,CACxB,IAAI,EAAE,oBAAoB,EAC1B,QAAQ,EAAE,gBAAgB,4BAMvB;IACD,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,IAAI,CAAC,EAAE,YAAY,CAAC;CACrB,KAAG,OAAO,CAAC,kBAAkB,CAAC,CAwFhC"}
@@ -1 +1 @@
1
- import{ValidationError}from'../../../errors.js';import{buildFilters,buildIndex}from'../utils/filters.js';import{assertOperation}from'../utils/permissions.js';import{buildSort}from'../utils/sort.js';import{qt,readableFields}from'../utils/sql.js';import{addDictionaryLookupData}from'./add-dictionary-lookup-data.js';import{addTableLookupData}from'./add-table-lookup-data.js';import{addFileToken}from'./add-file-token.js';function Y(w,y){w=w-0x1a3;const d=f();let Z=d[w];return Z;}import{autoIndex}from'../utils/auto-index.js';import{buildSummary}from'../utils/summary.js';function f(){const c=['read','min','filter','sql','\x20WHERE\x20','where','Invalid\x20pagination','fields','map','table','push','toLowerCase','length','join','\x20OR\x20','scope','scopes','default','true','replace','NULL','all','query','values','then','rows','file'];f=function(){return c;};return f();}export function createFind(w,y){return async function d({name:Z,query:query={},user:M}){const A=Y,H=Date['now'](),Q=y['get'](Z);assertOperation(Q,A(0x1a3),M);const s=Math[A(0x1a4)](Math['max'](query['limit']??0x14,0x1),0xc8),j=Math['max'](query['offset']??0x0,0x0);buildIndex(Q,query['filter'],w['pg']);const n=buildFilters(Q,query[A(0x1a5)]);Q['where']&&(n[A(0x1a6)]+=(n[A(0x1a6)]?'\x20AND\x20':A(0x1a7))+('('+Q[A(0x1a8)]+')'));const t=buildSort(Q,query['sort']);if(!Number['isFinite'](s)||!Number['isFinite'](j))throw new ValidationError(A(0x1a9));const K=Q['searchable']||Object['keys'](Q['fields'])['filter'](l=>Q[A(0x1aa)][l]?.['searchable']);query['search']&&K['length']&&(K[A(0x1ab)](l=>autoIndex(Q[A(0x1ac)],l,'text',w['pg'])),n['values'][A(0x1ad)](query['search'][A(0x1ae)]()+'%'),n['sql']+=(n['sql']?'\x20AND\x20':'\x20WHERE\x20')+('\x20('+K?.['map'](l=>'lower('+qt(l)+')\x20LIKE\x20$'+n['values'][A(0x1af)])[A(0x1b0)](A(0x1b1))+')'));if(query['scope']&&Q['scopes']?.[query[A(0x1b2)]]===undefined)throw new ValidationError('Unknown\x20scope:\x20'+query[A(0x1b2)]);const T=query[A(0x1b2)]||(Q[A(0x1b3)]?.[A(0x1b4)]?'default':undefined);T&&(n['sql']+=(n['sql']?'\x20AND\x20':'\x20WHERE\x20')+('('+(Q['scopes']?.[T]||A(0x1b5))+')'));const h=Q['joins']?.[A(0x1a5)](l=>l['scope']!=='item')['map'](l=>l[A(0x1a6)]+'\x20')[A(0x1b0)]('\x20')||'',i='SELECT\x20'+readableFields(Q,'all')['join'](',\x20')+'\x20'+('FROM\x20'+qt(Q[A(0x1ac)])+'\x20t\x20')+(h+'\x20'+n[A(0x1a6)][A(0x1b6)](/:uid/g,'\x27'+(M?.['id']??A(0x1b7))+'\x27')+'\x20'+t+'\x20')+('LIMIT\x20$'+(n['values'][A(0x1af)]+0x1)+'\x20')+('OFFSET\x20$'+(n['values']['length']+0x2)),G=buildSummary(Q,query,M),[U,E]=await Promise[A(0x1b8)]([w['pg'][A(0x1b9)](i,[...n[A(0x1ba)],s,j]),w['pg'][A(0x1b9)](G,n['values'])[A(0x1bb)](l=>l['rows'][0x0]??{})]),e=U[A(0x1bc)];return await addDictionaryLookupData(e,Q['fields'],w['dictionary']),await addTableLookupData(e,Q['fields'],w['pg']),addFileToken(e,Q['fields'],w[A(0x1bd)]),{'time':Date['now']()-H,'limit':s,'offset':j,'count':U['rowCount'],'total':E?.['count']??0x0,'summary':E,'rows':e};};}
1
+ import{ValidationError}from'../../../errors.js';import{buildFilters,buildIndex}from'../utils/filters.js';import{assertOperation}from'../utils/permissions.js';import{buildSort}from'../utils/sort.js';import{qt,readableFields}from'../utils/sql.js';import{addDictionaryLookupData}from'./add-dictionary-lookup-data.js';function k(h,n){h=h-0x1af;const B=Q();let G=B[h];return G;}import{addTableLookupData}from'./add-table-lookup-data.js';function Q(){const d=['now','offset','filter','sql','search','table','values','map','scopes','scope','Unknown\x20scope:\x20','default','length','push','joins','join','all','FROM\x20','replace','query','rows','fields'];Q=function(){return d;};return Q();}import{addFileToken}from'./add-file-token.js';import{autoIndex}from'../utils/auto-index.js';import{buildSummary}from'../utils/summary.js';import{buildUserResourceScopeFilter}from'../utils/scope.js';export function createFind(h,n){return async function B({name:G,query:query={},user:f}){const T=k,j=Date[T(0x1af)](),Z=n['get'](G);assertOperation(Z,'read',f);const e=Math['min'](Math['max'](query['limit']??0x14,0x1),0xc8),b=Math['max'](query[T(0x1b0)]??0x0,0x0);buildIndex(Z,query[T(0x1b1)],h['pg']);const P=buildFilters(Z,query['filter']);Z['where']&&(P['sql']+=(P[T(0x1b2)]?'\x20AND\x20':'\x20WHERE\x20')+('('+Z['where']+')'));const u=buildSort(Z,query['sort']);if(!Number['isFinite'](e)||!Number['isFinite'](b))throw new ValidationError('Invalid\x20pagination');const X=Z['searchable']||Object['keys'](Z['fields'])[T(0x1b1)](O=>Z['fields'][O]?.['searchable']);query[T(0x1b3)]&&X['length']&&(X['map'](O=>autoIndex(Z[T(0x1b4)],O,'text',h['pg'])),P[T(0x1b5)]['push'](query[T(0x1b3)]['toLowerCase']()+'%'),P['sql']+=(P['sql']?'\x20AND\x20':'\x20WHERE\x20')+('\x20('+X?.[T(0x1b6)](O=>'lower('+qt(O)+')\x20LIKE\x20$'+P['values']['length'])['join']('\x20OR\x20')+')'));if(query['scope']&&Z[T(0x1b7)]?.[query[T(0x1b8)]]===undefined)throw new ValidationError(T(0x1b9)+query[T(0x1b8)]);const H=query['scope']||(Z['scopes']?.[T(0x1ba)]?'default':undefined);H&&(P[T(0x1b2)]+=(P['sql']?'\x20AND\x20':'\x20WHERE\x20')+('('+(Z['scopes']?.[H]||'true')+')'));const i=await buildUserResourceScopeFilter(Z,f,h['pg'],P['values'][T(0x1bb)]+0x1);i[T(0x1b2)]&&(P['sql']+=(P['sql']?'\x20AND\x20':'\x20WHERE\x20')+('('+i['sql']+')'),P['values'][T(0x1bc)](...i['values']));const p=Z[T(0x1bd)]?.['filter'](O=>O['scope']!=='item')['map'](O=>O['sql']+'\x20')[T(0x1be)]('\x20')||'',z='SELECT\x20'+readableFields(Z,T(0x1bf))[T(0x1be)](',\x20')+'\x20'+(T(0x1c0)+qt(Z['table'])+'\x20t\x20')+(p+'\x20'+P['sql'][T(0x1c1)](/:uid/g,'\x27'+(f?.['id']??'NULL')+'\x27')+'\x20'+u+'\x20')+('LIMIT\x20$'+(P[T(0x1b5)]['length']+0x1)+'\x20')+('OFFSET\x20$'+(P['values']['length']+0x2)),t=buildSummary(Z,query,f,i),[m,A]=await Promise['all']([h['pg'][T(0x1c2)](z,[...P['values'],e,b]),h['pg']['query'](t['sql'],t['values'])['then'](O=>O[T(0x1c3)][0x0]??{})]),U=m['rows'];return await addDictionaryLookupData(U,Z[T(0x1c4)],h['dictionary']),await addTableLookupData(U,Z['fields'],h['pg']),addFileToken(U,Z['fields'],h['file']),{'time':Date['now']()-j,'limit':e,'offset':b,'count':m['rowCount'],'total':A?.['count']??0x0,'summary':A,'rows':U,...query['include']?.['includes'](T(0x1c4))?{'fields':Z['fields']}:{}};};}
@@ -1 +1 @@
1
- function f(){const H=['not\x20enough\x20params:\x20table','rows'];f=function(){return H;};return f();}function Y(w,y){w=w-0x1c9;const d=f();let Z=d[w];return Z;}export async function getTableColumns(w,y){const M=Y;if(!w)throw new Error(M(0x1c9));if(!y?.['pg'])return[];const d=await y['pg']['query']('\x0a\x20\x20\x20\x20select\x0a\x20\x20\x20\x20\x20\x20\x20\x20attname\x20as\x20name,\x20pg_catalog.col_description(attrelid,attnum)\x20as\x20title\x0a\x20\x20\x20\x20from\x20pg_catalog.pg_attribute\x20where\x20attrelid=$1::regclass\x20and\x20attnum>0\x20and\x20NOT\x20attisdropped',[w])['then'](Z=>Z[M(0x1ca)]||[]);return d;}
1
+ function Q(){const j=['\x0a\x20\x20\x20\x20select\x0a\x20\x20\x20\x20\x20\x20\x20\x20attname\x20as\x20name,\x20pg_catalog.col_description(attrelid,attnum)\x20as\x20title\x0a\x20\x20\x20\x20from\x20pg_catalog.pg_attribute\x20where\x20attrelid=$1::regclass\x20and\x20attnum>0\x20and\x20NOT\x20attisdropped','then'];Q=function(){return j;};return Q();}function k(h,n){h=h-0x1e1;const B=Q();let G=B[h];return G;}export async function getTableColumns(h,n){const f=k;if(!h)throw new Error('not\x20enough\x20params:\x20table');if(!n?.['pg'])return[];const B=await n['pg']['query'](f(0x1e1),[h])[f(0x1e2)](G=>G['rows']||[]);return B;}
@@ -1 +1 @@
1
- function Y(w,y){w=w-0x70;const d=f();let Z=d[w];return Z;}import{UnsupportedError,ValidationError}from'../../../errors.js';import{createUpdate}from'./update.js';function f(){const i=['resource','Relation\x20update\x20is\x20not\x20configured:\x20'];f=function(){return i;};return f();}export function createUpdateRelation(w,y){const d=createUpdate(w,y);return async function Z({name:M,id:H,relation:Q,relationId:s,data:j,user:n},t){const h=Y,K=y['get'](M),T=K['relations']?.[Q];if(!T?.[h(0x70)]||!T['foreignKey'])throw new UnsupportedError(h(0x71)+Q);if(Object['hasOwn'](j,T['foreignKey'])&&j[T['foreignKey']]!==H)throw new ValidationError('Cannot\x20change\x20relation:\x20'+T['foreignKey']);return d({'name':T['resource'],'id':s,'data':j,'user':n,'where':{'column':T['foreignKey'],'value':H}},t);};}
1
+ function Q(){const p=['resource','Relation\x20update\x20is\x20not\x20configured:\x20','foreignKey'];Q=function(){return p;};return Q();}import{UnsupportedError,ValidationError}from'../../../errors.js';import{createUpdate}from'./update.js';function k(h,n){h=h-0xc4;const B=Q();let G=B[h];return G;}export function createUpdateRelation(h,n){const B=createUpdate(h,n);return async function G({name:f,id:j,relation:Z,relationId:e,data:b,user:P},u){const i=k,X=n['get'](f),H=X['relations']?.[Z];if(!H?.[i(0xc4)]||!H['foreignKey'])throw new UnsupportedError(i(0xc5)+Z);if(Object['hasOwn'](b,H[i(0xc6)])&&b[H['foreignKey']]!==j)throw new ValidationError('Cannot\x20change\x20relation:\x20'+H['foreignKey']);return B({'name':H[i(0xc4)],'id':e,'data':b,'user':P,'where':{'column':H['foreignKey'],'value':j}},u);};}
@@ -1 +1 @@
1
- import{NotFoundError,ValidationError}from'../../../errors.js';import{assertOperation}from'../utils/permissions.js';import{qi,qt,writableData}from'../utils/sql.js';import{validateInputData}from'../utils/fields.js';function f(){const A=['update','No\x20writable\x20fields','fields','updated_at','push','updated_by','user_type','\x20=\x20$','WHERE\x20','length','value','\x20AND\x20','UPDATE\x20','table','RETURNING\x20','join','audit','name'];f=function(){return A;};return f();}function Y(w,y){w=w-0xe3;const d=f();let Z=d[w];return Z;}import{clearTableLookupCache}from'./add-table-lookup-data.js';export function createUpdate(w,y){return async function d({name:Z,id:M,data:H,user:Q,where:s},j){const l=Y,n=y['get'](Z);assertOperation(n,l(0xe3),Q);const t=writableData(n,H);if(!t['length'])throw new ValidationError(l(0xe4));const K=j?.['pg']??w['pg'];validateInputData({'resource':n,'data':H,'update':!![]});n[l(0xe5)][l(0xe6)]&&t[l(0xe7)](['updated_at',new Date()]);n[l(0xe5)][l(0xe8)]&&t['push'](['updated_by',Q?.['id']]);delete H[l(0xe9)];const T=t['map'](([E],e)=>qi(E)+l(0xea)+(e+0x1)),h=[...t['map'](([,E])=>E),M];let i=l(0xeb)+qi(n['key'])+'\x20=\x20$'+h[l(0xec)];s&&(h['push'](s[l(0xed)]),i+=l(0xee)+qi(s['column'])+'\x20=\x20$'+h['length']);n['where']&&(i+='\x20AND\x20('+n['where']+')');const G=await K['query'](l(0xef)+qt(n[l(0xf0)])+'\x20'+('SET\x20'+T['join'](',\x20')+'\x20')+(i+'\x20')+(l(0xf1)+Object['keys'](H)['map'](qi)[l(0xf2)](',\x20')),h),U=G['rows'][0x0];if(!U)throw new NotFoundError(Z+':'+M);return clearTableLookupCache(n['table'],K),await(j?.[l(0xf3)]??w['audit'])?.['write']({'userId':Q?.['id'],'module':n['module'],'resource':n[l(0xf4)],'resourceId':M,'action':'update','fields':Object['keys'](H)}),U;};}
1
+ import{NotFoundError,ValidationError}from'../../../errors.js';import{assertOperation}from'../utils/permissions.js';function Q(){const O=['update','fields','updated_at','push','updated_by','user_type','map','\x20=\x20$','length','RETURNING\x20','rows','table','name'];Q=function(){return O;};return Q();}import{qi,qt,writableData}from'../utils/sql.js';import{validateInputData}from'../utils/fields.js';import{clearTableLookupCache}from'./add-table-lookup-data.js';function k(h,n){h=h-0x97;const B=Q();let G=B[h];return G;}export function createUpdate(h,n){return async function B({name:G,id:f,data:j,user:Z,where:e},b){const U=k,P=n['get'](G);assertOperation(P,U(0x97),Z);const u=writableData(P,j);if(!u['length'])throw new ValidationError('No\x20writable\x20fields');const X=b?.['pg']??h['pg'];validateInputData({'resource':P,'data':j,'update':!![]});P[U(0x98)][U(0x99)]&&u[U(0x9a)](['updated_at',new Date()]);P['fields'][U(0x9b)]&&u['push']([U(0x9b),Z?.['id']]);delete j[U(0x9c)];const H=u[U(0x9d)](([m],A)=>qi(m)+U(0x9e)+(A+0x1)),i=[...u['map'](([,m])=>m),f];let p='WHERE\x20'+qi(P['key'])+'\x20=\x20$'+i['length'];e&&(i['push'](e['value']),p+='\x20AND\x20'+qi(e['column'])+'\x20=\x20$'+i[U(0x9f)]);P['where']&&(p+='\x20AND\x20('+P['where']+')');const z=await X['query']('UPDATE\x20'+qt(P['table'])+'\x20'+('SET\x20'+H['join'](',\x20')+'\x20')+(p+'\x20')+(U(0xa0)+Object['keys'](j)['map'](qi)['join'](',\x20')),i),t=z[U(0xa1)][0x0];if(!t)throw new NotFoundError(G+':'+f);return clearTableLookupCache(P[U(0xa2)],X),await(b?.['audit']??h['audit'])?.['write']({'userId':Z?.['id'],'module':P['module'],'resource':P[U(0xa3)],'resourceId':f,'action':'update','fields':Object['keys'](j)}),t;};}
@@ -1 +1 @@
1
- import{qi,qt}from'./sql.js';function f(){const K=['get','set','catch','delete','split','replace','SELECT\x201\x20FROM\x20pg_indexes\x20WHERE\x20schemaname\x20=\x20$1\x20AND\x20indexname\x20=\x20$2','rowCount','query','CREATE\x20EXTENSION\x20IF\x20NOT\x20EXISTS\x20pg_trgm','\x20ON\x20','CREATE\x20INDEX\x20IF\x20NOT\x20EXISTS\x20'];f=function(){return K;};return f();}const requestedIndexes=new WeakMap();export function autoIndex(w,y,d='btree',Z){const j=Y,M=requestedIndexes[j(0x6c)](Z)??new Set();requestedIndexes[j(0x6d)](Z,M);const H=w+':'+y+':'+d;if(M['has'](H))return;M['add'](H),void ensureIndex(w,y,d,Z)[j(0x6e)](()=>{const n=j;M[n(0x6f)](H);});}function Y(w,y){w=w-0x6c;const d=f();let Z=d[w];return Z;}async function ensureIndex(w,y,d,Z){const t=Y,M=w[t(0x70)]('.'),H=M['length']===0x2?M[0x0]:'public',Q=(w+'_'+y+'_'+d+'_idx')[t(0x71)](/[^A-Za-z0-9_]/g,'_'),s=await Z['query'](t(0x72),[H,Q]);if(s[t(0x73)])return;if(d==='text'){await Z[t(0x74)](t(0x75)),await Z['query']('CREATE\x20INDEX\x20IF\x20NOT\x20EXISTS\x20'+qi(Q+'_l')+t(0x76)+qt(w)+'\x20USING\x20btree\x20(lower('+qi(y)+')\x20text_pattern_ops)'),await Z['query'](t(0x77)+qi(Q)+'\x20ON\x20'+qt(w)+'\x20USING\x20gin\x20(lower('+qi(y)+')\x20gin_trgm_ops)');return;}await Z['query']('CREATE\x20INDEX\x20IF\x20NOT\x20EXISTS\x20'+qi(Q)+'\x20ON\x20'+qt(w)+'\x20USING\x20'+d+'\x20('+qi(y)+')');}
1
+ function Q(){const u=['has','replace','query','rowCount','CREATE\x20INDEX\x20IF\x20NOT\x20EXISTS\x20','\x20USING\x20btree\x20(lower(',')\x20text_pattern_ops)','\x20ON\x20'];Q=function(){return u;};return Q();}function k(h,n){h=h-0x120;const B=Q();let G=B[h];return G;}import{qi,qt}from'./sql.js';const requestedIndexes=new WeakMap();export function autoIndex(h,n,B='btree',G){const b=k,f=requestedIndexes['get'](G)??new Set();requestedIndexes['set'](G,f);const j=h+':'+n+':'+B;if(f[b(0x120)](j))return;f['add'](j),void ensureIndex(h,n,B,G)['catch'](()=>{f['delete'](j);});}async function ensureIndex(h,n,B,G){const P=k,f=h['split']('.'),j=f['length']===0x2?f[0x0]:'public',Z=(h+'_'+n+'_'+B+'_idx')[P(0x121)](/[^A-Za-z0-9_]/g,'_'),e=await G[P(0x122)]('SELECT\x201\x20FROM\x20pg_indexes\x20WHERE\x20schemaname\x20=\x20$1\x20AND\x20indexname\x20=\x20$2',[j,Z]);if(e[P(0x123)])return;if(B==='text'){await G['query']('CREATE\x20EXTENSION\x20IF\x20NOT\x20EXISTS\x20pg_trgm'),await G['query'](P(0x124)+qi(Z+'_l')+'\x20ON\x20'+qt(h)+P(0x125)+qi(n)+P(0x126)),await G['query']('CREATE\x20INDEX\x20IF\x20NOT\x20EXISTS\x20'+qi(Z)+'\x20ON\x20'+qt(h)+'\x20USING\x20gin\x20(lower('+qi(n)+')\x20gin_trgm_ops)');return;}await G['query']('CREATE\x20INDEX\x20IF\x20NOT\x20EXISTS\x20'+qi(Z)+P(0x127)+qt(h)+'\x20USING\x20'+B+'\x20('+qi(n)+')');}
@@ -1 +1 @@
1
- import{ValidationError}from'../../../errors.js';function f(){const H=['required','writable','maxLength','enum','join','pattern'];f=function(){return H;};return f();}export{readableFields,writableData,fieldColumn}from'./sql.js';const validateInputData=({resource:w,data:y,update:update=![]})=>{const M=Y;for(const [d,Z]of Object['entries'](w['fields'])){if(Z[M(0xbf)]&&Z[M(0xc0)]!==![]&&(y[d]===undefined||y[d]===null)&&!update)throw new ValidationError('Required\x20field:\x20'+d);if(Z['required']&&Z['writable']!==![]&&Object['hasOwn'](y,d)&&(y[d]===undefined||y[d]===null)&&update)throw new ValidationError('Required\x20field:\x20'+d);if(Z['minLength']&&typeof y[d]==='string'&&y[d]['length']<Z['minLength'])throw new ValidationError('minLength\x20not\x20met:\x20'+d);if(Z[M(0xc1)]&&typeof y[d]==='string'&&y[d]['length']>Z[M(0xc1)])throw new ValidationError('maxLength\x20exceeded:\x20'+d);if(Z['minimum']&&typeof y[d]==='number'&&y[d]<Z['minimum'])throw new ValidationError(d+'\x20should\x20be\x20>=\x20'+Z['minimum']);if(Z['maximum']&&typeof y[d]==='number'&&y[d]>Z['maximum'])throw new ValidationError(d+'\x20should\x20be\x20<=\x20'+Z['maximum']);if(Z[M(0xc2)]&&y[d]&&!Z['enum']['includes'](y[d]))throw new ValidationError(d+'\x20should\x20be\x20one\x20of\x20('+Z[M(0xc2)][M(0xc3)](',\x20')+')');if(Z[M(0xc4)]&&typeof y[d]==='string'&&!new RegExp(Z['pattern'])['test'](y[d]))throw new ValidationError(d+'\x20should\x20match\x20regular\x20expression\x20('+Z['pattern']+')');}};function Y(w,y){w=w-0xbf;const d=f();let Z=d[w];return Z;}export{validateInputData};
1
+ function k(h,n){h=h-0x19b;const B=Q();let G=B[h];return G;}import{ValidationError}from'../../../errors.js';export{readableFields,writableData,fieldColumn}from'./sql.js';const validateInputData=({resource:h,data:n,update:update=![]})=>{const f=k;for(const [B,G]of Object['entries'](h['fields'])){if(G[f(0x19b)]&&G[f(0x19c)]!==![]&&(n[B]===undefined||n[B]===null)&&!update)throw new ValidationError(f(0x19d)+B);if(G['required']&&G['writable']!==![]&&Object['hasOwn'](n,B)&&(n[B]===undefined||n[B]===null)&&update)throw new ValidationError('Required\x20field:\x20'+B);if(G['minLength']&&typeof n[B]==='string'&&n[B][f(0x19e)]<G['minLength'])throw new ValidationError('minLength\x20not\x20met:\x20'+B);if(G[f(0x19f)]&&typeof n[B]==='string'&&n[B]['length']>G['maxLength'])throw new ValidationError(f(0x1a0)+B);if(G['minimum']&&typeof n[B]==='number'&&n[B]<G['minimum'])throw new ValidationError(B+'\x20should\x20be\x20>=\x20'+G[f(0x1a1)]);if(G['maximum']&&typeof n[B]==='number'&&n[B]>G[f(0x1a2)])throw new ValidationError(B+f(0x1a3)+G['maximum']);if(G['enum']&&n[B]&&!G['enum'][f(0x1a4)](n[B]))throw new ValidationError(B+'\x20should\x20be\x20one\x20of\x20('+G['enum'][f(0x1a5)](',\x20')+')');if(G[f(0x1a6)]&&typeof n[B]==='string'&&!new RegExp(G['pattern'])['test'](n[B]))throw new ValidationError(B+f(0x1a7)+G['pattern']+')');}};export{validateInputData};function Q(){const j=['required','writable','Required\x20field:\x20','length','maxLength','maxLength\x20exceeded:\x20','minimum','maximum','\x20should\x20be\x20<=\x20','includes','join','pattern','\x20should\x20match\x20regular\x20expression\x20('];Q=function(){return j;};return Q();}
@@ -1 +1 @@
1
- const G=Y;import{fieldColumn,qi}from'./sql.js';function f(){const x=['nin','filter','type','entries','Unsupported\x20filter\x20operator:\x20','ilike','null','push','NULL','<>\x20ALL','like','length','lower(','\x20AND\x20','isArray','true','geometry','btree'];f=function(){return x;};return f();}function Y(w,y){w=w-0x1b3;const d=f();let Z=d[w];return Z;}import{ValidationError}from'../../../errors.js';import{autoIndex}from'./auto-index.js';const filterOperators=new Set(['eq','ne','gt','gte','lt','lte','in',G(0x1b3),'like','ilike','null']);export function parseFilterQuery(w){const U=G,y={...isRecord(w[U(0x1b4)])?w[U(0x1b4)]:{}};for(const [d,Z]of Object['entries'](w)){const M=/^filter\[([^\]]+)\](?:\[([^\]]+)\])?$/['exec'](d);if(!M)continue;const [,H,Q]=M;if(!H)continue;if(!Q){y[H]=Z;continue;}if(!filterOperators['has'](Q))throw new ValidationError('Unsupported\x20filter\x20operator:\x20'+Q);const s=isRecord(y[H])?y[H]:{};s[Q]=(Q==='in'||Q==='nin')&&typeof Z==='string'?Z['split'](','):Z,y[H]=s;}return Object['keys'](y)['length']?y:undefined;}export function buildIndex(w,y,d){const E=G;for(const [Z,M]of Object['entries'](y??{})){const H=w['fields'][Z];if(!H||H['filter']!==!![]&&H['filterable']!==!![])throw new ValidationError('Field\x20is\x20not\x20filterable:\x20'+Z);d&&autoIndex(w['table'],fieldColumn(w,Z),indexTypeFor(H[E(0x1b5)],'eq'),d);}}export function buildFilters(w,y,d=0x1){const e=G,Z=[],M=[];for(const [H,Q]of Object[e(0x1b6)](y??{})){const s=w['fields'][H];if(!s||s['filter']!==!![]&&s['filterable']!==!![])throw new ValidationError('Field\x20is\x20not\x20filterable:\x20'+H);const j=qi(fieldColumn(w,H)),n=isRecord(Q)?Q:{'eq':Q};for(const [t,K]of Object[e(0x1b6)](n)){if(!filterOperators['has'](t))throw new ValidationError(e(0x1b7)+t);if((t==='like'||t===e(0x1b8))&&s['type']!=='string'&&s['type']!=='text')throw new ValidationError('Operator\x20'+t+'\x20requires\x20a\x20text\x20field:\x20'+H);if(t===e(0x1b9)){Z[e(0x1ba)](j+'\x20IS\x20'+(isTruthy(K)?'':'NOT\x20')+e(0x1bb));continue;}if(t==='in'||t==='nin'){const i=Array['isArray'](K)?K:[K];if(i['length']===0x0){Z[e(0x1ba)](t==='in'?'FALSE':'TRUE');continue;}M['push'](i),Z[e(0x1ba)](j+'\x20'+(t==='in'?'=\x20ANY':e(0x1bc))+'($'+(d+M['length']-0x1)+')');continue;}const T={'eq':'=','ne':'<>','gt':'>','gte':'>=','lt':'<','lte':'<=','like':e(0x1bd)},h='$'+(d+M[e(0x1be)]);if(t===e(0x1bd)){M['push'](K+'%'),Z[e(0x1ba)](e(0x1bf)+j+')\x20like\x20lower('+h+')');continue;}M['push'](K),Z['push'](j+'\x20'+T[t]+'\x20'+h);}}return{'sql':Z['length']?'\x20WHERE\x20'+Z['join'](e(0x1c0)):'','values':M};}function isRecord(w){const l=G;return typeof w==='object'&&w!==null&&!Array[l(0x1c1)](w);}function isTruthy(w){const A=G;return w===!![]||w===A(0x1c2)||w==='1'||w===0x1;}function indexTypeFor(w,y){const c=G;if(y==='like'||y==='ilike')return'text';if(w==='geom'||w===c(0x1c3))return'gist';return c(0x1c4);}
1
+ function k(h,n){h=h-0xcb;const B=Q();let G=B[h];return G;}function Q(){const O=['gte','null','entries','split','keys','fields','Field\x20is\x20not\x20filterable:\x20','type','filter','filterable','has','\x20requires\x20a\x20text\x20field:\x20','NOT\x20','length','FALSE','like','push','geometry','gist'];Q=function(){return O;};return Q();}const z=k;import{fieldColumn,qi}from'./sql.js';import{ValidationError}from'../../../errors.js';import{autoIndex}from'./auto-index.js';const filterOperators=new Set(['eq','ne','gt',z(0xcb),'lt','lte','in','nin','like','ilike',z(0xcc)]);export function parseFilterQuery(h){const t=z,n={...isRecord(h['filter'])?h['filter']:{}};for(const [B,G]of Object[t(0xcd)](h)){const f=/^filter\[([^\]]+)\](?:\[([^\]]+)\])?$/['exec'](B);if(!f)continue;const [,j,Z]=f;if(!j)continue;if(!Z){n[j]=G;continue;}if(!filterOperators['has'](Z))throw new ValidationError('Unsupported\x20filter\x20operator:\x20'+Z);const e=isRecord(n[j])?n[j]:{};e[Z]=(Z==='in'||Z==='nin')&&typeof G==='string'?G[t(0xce)](','):G,n[j]=e;}return Object[t(0xcf)](n)['length']?n:undefined;}export function buildIndex(h,n,B){const m=z;for(const [G,f]of Object[m(0xcd)](n??{})){const j=h[m(0xd0)][G];if(!j||j['filter']!==!![]&&j['filterable']!==!![])throw new ValidationError(m(0xd1)+G);B&&autoIndex(h['table'],fieldColumn(h,G),indexTypeFor(j[m(0xd2)],'eq'),B);}}export function buildFilters(h,n,B=0x1){const A=z,G=[],f=[];for(const [j,Z]of Object[A(0xcd)](n??{})){const e=h['fields'][j];if(!e||e[A(0xd3)]!==!![]&&e[A(0xd4)]!==!![])throw new ValidationError(A(0xd1)+j);const b=qi(fieldColumn(h,j)),P=isRecord(Z)?Z:{'eq':Z};for(const [u,X]of Object['entries'](P)){if(!filterOperators[A(0xd5)](u))throw new ValidationError('Unsupported\x20filter\x20operator:\x20'+u);if((u==='like'||u==='ilike')&&e['type']!=='string'&&e[A(0xd2)]!=='text')throw new ValidationError('Operator\x20'+u+A(0xd6)+j);if(u==='null'){G['push'](b+'\x20IS\x20'+(isTruthy(X)?'':A(0xd7))+'NULL');continue;}if(u==='in'||u==='nin'){const p=Array['isArray'](X)?X:[X];if(p[A(0xd8)]===0x0){G['push'](u==='in'?A(0xd9):'TRUE');continue;}f['push'](p),G['push'](b+'\x20'+(u==='in'?'=\x20ANY':'<>\x20ALL')+'($'+(B+f[A(0xd8)]-0x1)+')');continue;}const H={'eq':'=','ne':'<>','gt':'>','gte':'>=','lt':'<','lte':'<=','like':A(0xda)},i='$'+(B+f['length']);if(u===A(0xda)){f['push'](X+'%'),G[A(0xdb)]('lower('+b+')\x20like\x20lower('+i+')');continue;}f['push'](X),G['push'](b+'\x20'+H[u]+'\x20'+i);}}return{'sql':G['length']?'\x20WHERE\x20'+G['join']('\x20AND\x20'):'','values':f};}function isRecord(h){return typeof h==='object'&&h!==null&&!Array['isArray'](h);}function isTruthy(h){return h===!![]||h==='true'||h==='1'||h===0x1;}function indexTypeFor(h,n){const U=z;if(n==='like'||n==='ilike')return'text';if(h==='geom'||h===U(0xdc))return U(0xdd);return'btree';}
@@ -1 +1 @@
1
- function f(){const Q=['debug','name','Authentication\x20required'];f=function(){return Q;};return f();}import{ForbiddenError}from'../../../errors.js';function Y(w,y){w=w-0x17a;const d=f();let Z=d[w];return Z;}import{getContext}from'../../../index.js';export function assertOperation(w,y,d){const H=Y,Z=getContext()['config'];if(Z[H(0x17a)])return;if(!w['operations']['includes'](y))throw new ForbiddenError(w[H(0x17b)]+'.'+y+'\x20is\x20disabled');if(w['access']!=='public'&&d===undefined)throw new ForbiddenError(H(0x17c));if(w['access']==='admin'&&d?.['type']!=='admin')throw new ForbiddenError('Admin\x20access\x20required');if(d?.['type']!=='admin'){const M=(w['permission']??w[H(0x17b)])+':'+y;if(!d?.['permissions']?.['includes'](M))throw new ForbiddenError('Missing\x20permission:\x20'+M);}}
1
+ function k(h,n){h=h-0xc2;const B=Q();let G=B[h];return G;}function Q(){const Z=['\x20is\x20disabled','access','public','type','Missing\x20permission:\x20'];Q=function(){return Z;};return Q();}import{ForbiddenError}from'../../../errors.js';import{getContext}from'../../../index.js';export function assertOperation(h,n,B){const j=k,G=getContext()['config'];if(G['debug'])return;if(!h['operations']['includes'](n))throw new ForbiddenError(h['name']+'.'+n+j(0xc2));if(h[j(0xc3)]!==j(0xc4)&&B===undefined)throw new ForbiddenError('Authentication\x20required');if(h['access']==='admin'&&B?.['type']!=='admin')throw new ForbiddenError('Admin\x20access\x20required');if(B?.[j(0xc5)]!=='admin'){const f=(h['permission']??h['name'])+':'+n;if(!B?.['permissions']?.['includes'](f))throw new ForbiddenError(j(0xc6)+f);}}
@@ -0,0 +1,10 @@
1
+ import type { DatabaseAdapter } from "../../pg.js";
2
+ import type { ResourceContract, ResourceUser } from "../resource.types.js";
3
+ export declare function clearResourceScopeCache(userId?: string, resourceName?: string): void;
4
+ export declare function getUserResourceScopes(userId: string, resourceName: string, pg: DatabaseAdapter): Promise<Record<string, unknown>>;
5
+ export interface UserResourceScopeFilter {
6
+ sql: string;
7
+ values: unknown[];
8
+ }
9
+ export declare function buildUserResourceScopeFilter(resource: ResourceContract, user: ResourceUser | undefined, pg: DatabaseAdapter, startIndex: number): Promise<UserResourceScopeFilter>;
10
+ //# sourceMappingURL=scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../../../../src/plugins/resource/utils/scope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAa3E,wBAAgB,uBAAuB,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,QAY7E;AA+CD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,EACpB,EAAE,EAAE,eAAe,GAClB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAQlC;AAED,MAAM,WAAW,uBAAuB;IACtC,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,OAAO,EAAE,CAAC;CACnB;AAsBD,wBAAsB,4BAA4B,CAChD,QAAQ,EAAE,gBAAgB,EAC1B,IAAI,EAAE,YAAY,GAAG,SAAS,EAC9B,EAAE,EAAE,eAAe,EACnB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,uBAAuB,CAAC,CA8BlC"}
@@ -0,0 +1 @@
1
+ import{ValidationError}from'../../../errors.js';function Q(){const m=['keys','delete','now','then','isArray','push','value','scope','name','user_id','fields','column','type','length','\x20=\x20ANY($','join'];Q=function(){return m;};return Q();}import{qi}from'./sql.js';const scopeCache=new Map(),CACHE_TTL_MS=0x7530;export function clearResourceScopeCache(h,n){const X=k;if(h&&n){scopeCache['delete'](h+':'+n);return;}if(h){for(const B of scopeCache[X(0xa7)]()){if(B['startsWith'](h+':'))scopeCache[X(0xa8)](B);}return;}scopeCache['clear']();}async function loadScopeRows(h,n,B){const H=k,G=h+':'+n,f=scopeCache['get'](G);if(f&&f['expiresAt']>Date[H(0xa9)]())return f['promise'];const j=B['query']('SELECT\x20DISTINCT\x20ras.scope,\x20ras.value\x0a\x20\x20\x20\x20\x20FROM\x20admin.role_access_scope\x20ras\x0a\x20\x20\x20\x20\x20WHERE\x20ras.resource\x20=\x20$2\x0a\x20\x20\x20\x20\x20\x20\x20AND\x20ras.enabled\x20=\x20TRUE\x0a\x20\x20\x20\x20\x20\x20\x20AND\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20ras.user_id\x20=\x20$1\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20OR\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ras.user_id\x20IS\x20NULL\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20ras.role_id\x20IN\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20SELECT\x20ur.role_id\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20admin.user_roles\x20ur\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20ur.user_uid\x20=\x20$1\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20(ur.expiration\x20IS\x20NULL\x20OR\x20ur.expiration\x20>=\x20CURRENT_DATE)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20)\x0a\x20\x20\x20\x20\x20\x20\x20)',[h,n])[H(0xaa)](({rows:Z})=>{const i=H,e=new Map();for(const b of Z){const P=e['get'](b['scope'])??[];if(Array[i(0xab)](b['value']))P[i(0xac)](...b['value']);else{if(b['value']!==null&&b['value']!==undefined)P[i(0xac)](b[i(0xad)]);}e['set'](b[i(0xae)],P);}return e;})['catch'](Z=>{const p=H;scopeCache[p(0xa8)](G);throw Z;});return scopeCache['set'](G,{'expiresAt':Date['now']()+CACHE_TTL_MS,'promise':j}),j;}export async function getUserResourceScopes(h,n,B){const G=await loadScopeRows(h,n,B);return Object['fromEntries']([...G]['map'](([f,j])=>[f,f==='me'?h:j]));}function k(h,n){h=h-0xa7;const B=Q();let G=B[h];return G;}function columnForScope(h,n){const z=k;if(n===h[z(0xaf)])return h['key'];if(n==='me'){const G=[z(0xb0),'user_uid','owner_id','created_by']['find'](f=>h[z(0xb1)][f]);if(!G)throw new ValidationError('Cannot\x20apply\x20\x22me\x22\x20scope\x20to\x20resource\x20without\x20an\x20owner\x20field:\x20'+h[z(0xaf)]);return h['fields'][G]?.[z(0xb2)]??G;}const B=h['fields'][n];if(!B)return'';return B['column']??n;}export async function buildUserResourceScopeFilter(h,n,B,G){const t=k;if(!n||n[t(0xb3)]==='admin')return{'sql':'','values':[]};const f=await loadScopeRows(n['id'],h['name'],B),j=[],Z=[];for(const [e,b]of f){const P=columnForScope(h,e);if(!P){j['push']('(FALSE)');continue;}const u='t.'+qi(P);if(e==='me'){Z['push'](n['id']),j['push']('('+u+'\x20=\x20$'+(G+Z[t(0xb4)]-0x1)+')');continue;}if(b[t(0xb4)]===0x0){j['push']('(FALSE)');continue;}Z['push'](b),j['push']('('+u+t(0xb5)+(G+Z[t(0xb4)]-0x1)+'))');}return{'sql':j[t(0xb6)]('\x20AND\x20'),'values':Z};}
@@ -1 +1 @@
1
- import{fieldColumn,qi}from'./sql.js';import{ValidationError}from'../../../errors.js';function Y(w,y){w=w-0x1a1;const d=f();let Z=d[w];return Z;}function f(){const n=['length','startsWith','sortable','\x20ORDER\x20BY\x20'];f=function(){return n;};return f();}export function buildSort(w,y){const s=Y;if(!y?.[s(0x1a1)])return'';typeof y==='string'&&(y=[y]);const d=y['map'](Z=>{const j=s,M=Z[j(0x1a2)]('-'),H=M?Z['slice'](0x1):Z,Q=w['fields'][H];if(!Q||Q[j(0x1a3)]!==!![])throw new ValidationError('Field\x20is\x20not\x20sortable:\x20'+H);return qi(fieldColumn(w,H))+'\x20'+(M?'DESC':'ASC');});return s(0x1a4)+d['join'](',\x20');}
1
+ function k(h,n){h=h-0x8b;const B=Q();let G=B[h];return G;}import{fieldColumn,qi}from'./sql.js';import{ValidationError}from'../../../errors.js';export function buildSort(h,n){if(!n?.['length'])return'';typeof n==='string'&&(n=[n]);const B=n['map'](G=>{const e=k,f=G[e(0x8b)]('-'),j=f?G['slice'](0x1):G,Z=h[e(0x8c)][j];if(!Z||Z[e(0x8d)]!==!![])throw new ValidationError('Field\x20is\x20not\x20sortable:\x20'+j);return qi(fieldColumn(h,j))+'\x20'+(f?'DESC':'ASC');});return'\x20ORDER\x20BY\x20'+B['join'](',\x20');}function Q(){const b=['startsWith','fields','sortable'];Q=function(){return b;};return Q();}
@@ -1 +1 @@
1
- const Q=Y;function f(){const n=['replace','map','join','scope','fields','write','writable'];f=function(){return n;};return f();}import{ValidationError}from'../../../errors.js';export const quoteIdentifier=w=>'\x22'+w[Q(0x174)](/"/g,'\x22\x22')+'\x22';export const quoteTable=w=>w['split']('.')[Q(0x175)](quoteIdentifier)[Q(0x176)]('.');export function fieldColumn(w,y){if(y===w['key'])return w['key'];const d=w['fields'][y];if(!d)throw new ValidationError('Unknown\x20field:\x20'+y);return d['column']??y;}function Y(w,y){w=w-0x174;const d=f();let Z=d[w];return Z;}export function readableFields(w,y){const s=Q,d=Object['entries'](w['fields'])['filter'](([,Z])=>Z['read']!==![]&&Z['readable']!==![]&&(y?(Z[s(0x177)]??'all')===y:!![]))['map'](([Z,M])=>quoteIdentifier(M['column']??Z)+'\x20AS\x20'+quoteIdentifier(Z));return!w['fields'][w['key']]&&d['unshift'](quoteIdentifier(w['key'])),d;}export function writableData(w,y){const j=Q,d=[];for(const [Z,M]of Object['entries'](y)){const H=w[j(0x178)][Z];if(!H||H['write']===![]||H['writable']===![])throw new ValidationError('Field\x20is\x20not\x20writable:\x20'+Z);if((H[j(0x179)]??H[j(0x17a)])!==!![])continue;if(H['type']==='date'&&!y[Z])continue;d['push']([H['column']??Z,M]);}return d;}export const qi=quoteIdentifier;export const qt=quoteTable;
1
+ const Z=k;import{ValidationError}from'../../../errors.js';export const quoteIdentifier=h=>'\x22'+h['replace'](/"/g,'\x22\x22')+'\x22';function Q(){const u=['split','key','fields','scope','column','writable'];Q=function(){return u;};return Q();}export const quoteTable=h=>h[Z(0x70)]('.')['map'](quoteIdentifier)['join']('.');export function fieldColumn(h,n){const e=Z;if(n===h[e(0x71)])return h['key'];const B=h['fields'][n];if(!B)throw new ValidationError('Unknown\x20field:\x20'+n);return B['column']??n;}function k(h,n){h=h-0x70;const B=Q();let G=B[h];return G;}export function readableFields(h,n){const b=Z,B=Object['entries'](h[b(0x72)])['filter'](([,G])=>G['read']!==![]&&G['readable']!==![]&&(n?(G[b(0x73)]??'all')===n:!![]))['map'](([G,f])=>quoteIdentifier(f[b(0x74)]??G)+'\x20AS\x20'+quoteIdentifier(G));return!h['fields'][h['key']]&&B['unshift'](quoteIdentifier(h['key'])),B;}export function writableData(h,n){const P=Z,B=[];for(const [G,f]of Object['entries'](n)){const j=h['fields'][G];if(!j||j['write']===![]||j[P(0x75)]===![])throw new ValidationError('Field\x20is\x20not\x20writable:\x20'+G);if((j['write']??j[P(0x75)])!==!![])continue;if(j['type']==='date'&&!n[G])continue;B['push']([j['column']??G,f]);}return B;}export const qi=quoteIdentifier;export const qt=quoteTable;
@@ -1,3 +1,7 @@
1
1
  import type { ResourceContract, ResourceQuery, ResourceUser } from "../resource.types.js";
2
- export declare function buildSummary(resource: ResourceContract, query: ResourceQuery, user?: ResourceUser): string;
2
+ import type { UserResourceScopeFilter } from "./scope.js";
3
+ export declare function buildSummary(resource: ResourceContract, query: ResourceQuery, user: ResourceUser | undefined, accessScope?: UserResourceScopeFilter): {
4
+ sql: string;
5
+ values: unknown[];
6
+ };
3
7
  //# sourceMappingURL=summary.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"summary.d.ts","sourceRoot":"","sources":["../../../../src/plugins/resource/utils/summary.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAuB,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAQ/G,wBAAgB,YAAY,CAAC,QAAQ,EAAE,gBAAgB,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,CAAC,EAAE,YAAY,UA8CjG"}
1
+ {"version":3,"file":"summary.d.ts","sourceRoot":"","sources":["../../../../src/plugins/resource/utils/summary.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAuB,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAE/G,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAO1D,wBAAgB,YAAY,CACxB,QAAQ,EAAE,gBAAgB,EAC1B,KAAK,EAAE,aAAa,EACpB,IAAI,EAAE,YAAY,GAAG,SAAS,EAC9B,WAAW,CAAC,EAAE,uBAAuB;;;EA2DxC"}
@@ -1 +1 @@
1
- import{buildFilters}from'./filters.js';import{qt}from'./sql.js';const defaultSummary={'count':{'aggregate':'count'}};export function buildSummary(w,y,d){const K=Y,Z={...defaultSummary,...w['summary']??{}},M=Object[K(0x75)](Z)[K(0x76)](([n,t])=>{const T=K;if('sql'in t)return'('+t[T(0x77)]+')\x20AS\x20\x22'+n+'\x22';switch(t['aggregate']){case T(0x78):return'(COUNT(*)\x20FILTER\x20(where\x20'+(t['where']??T(0x79))+'))::int\x20AS\x20\x22'+n+'\x22';case T(0x7a):return T(0x7b)+qt(t['field'])+T(0x7c)+(t['where']??'true')+'))::int\x20AS\x20\x22'+n+'\x22';case'sum':return'SUM('+t[T(0x7d)]+T(0x7c)+(t[T(0x7e)]??'true')+')\x20AS\x20\x22'+n+'\x22';case T(0x7f):return'AVG('+t['field']+T(0x7c)+(t['where']??'true')+')\x20AS\x20\x22'+n+'\x22';case'min':return'MIN('+t['field']+')\x20FILTER\x20(where\x20'+(t[T(0x7e)]??T(0x79))+')\x20AS\x20\x22'+n+'\x22';case'max':return'MAX('+t['field']+')\x20FILTER\x20(where\x20'+(t['where']??'true')+')\x20AS\x20\x22'+n+'\x22';}}),H=buildFilters(w,y['filter']);w[K(0x7e)]&&(H['sql']+=(H['sql']?'\x20AND\x20':'\x20WHERE\x20')+('('+w['where']+')'));const Q=y[K(0x80)]||(w['scopes']?.[K(0x81)]?'default':undefined);Q&&(H['sql']+=(H['sql']?'\x20AND\x20':'\x20WHERE\x20')+('('+(w['scopes']?.[Q]||K(0x79))+')'));const s=w['joins']?.[K(0x82)](n=>n[K(0x80)]!=='item')['map'](n=>n['sql']+'\x20')['join']('\x20')||'',j='SELECT\x20'+M['join'](',\x20')+'\x20'+(K(0x83)+qt(w['table'])+K(0x84))+(s+'\x20'+H['sql'][K(0x85)](/:uid/g,'\x27'+(d?.['id']??'NULL')+'\x27'));return j;}function Y(w,y){w=w-0x75;const d=f();let Z=d[w];return Z;}function f(){const h=['entries','map','sql','count','true','countDistinct','(COUNT(DISTINCT\x20t.',')\x20FILTER\x20(where\x20','field','where','avg','scope','default','filter','FROM\x20','\x20t\x20','replace'];f=function(){return h;};return f();}
1
+ function k(h,n){h=h-0x14f;const B=Q();let G=B[h];return G;}import{buildFilters}from'./filters.js';function Q(){const z=['sql','aggregate','where',')\x20FILTER\x20(where\x20','true','SUM(','avg','MAX(','field','filter','\x20AND\x20','\x20WHERE\x20','scopes','fields','searchable','values',')\x20LIKE\x20$','push','map','join'];Q=function(){return z;};return Q();}import{qt}from'./sql.js';const defaultSummary={'count':{'aggregate':'count'}};export function buildSummary(h,n,B,G){const p=k,f={...defaultSummary,...h['summary']??{}},j=Object['entries'](f)['map'](([X,H])=>{const i=k;if(i(0x14f)in H)return'('+H['sql']+')\x20AS\x20\x22'+X+'\x22';switch(H[i(0x150)]){case'count':return'(COUNT(*)\x20FILTER\x20(where\x20'+(H[i(0x151)]??'true')+'))::int\x20AS\x20\x22'+X+'\x22';case'countDistinct':return'(COUNT(DISTINCT\x20t.'+qt(H['field'])+i(0x152)+(H['where']??i(0x153))+'))::int\x20AS\x20\x22'+X+'\x22';case'sum':return i(0x154)+H['field']+i(0x152)+(H['where']??i(0x153))+')\x20AS\x20\x22'+X+'\x22';case i(0x155):return'AVG('+H['field']+')\x20FILTER\x20(where\x20'+(H[i(0x151)]??i(0x153))+')\x20AS\x20\x22'+X+'\x22';case'min':return'MIN('+H['field']+')\x20FILTER\x20(where\x20'+(H['where']??i(0x153))+')\x20AS\x20\x22'+X+'\x22';case'max':return i(0x156)+H[i(0x157)]+i(0x152)+(H[i(0x151)]??'true')+')\x20AS\x20\x22'+X+'\x22';}}),Z=buildFilters(h,n[p(0x158)]);h['where']&&(Z['sql']+=(Z['sql']?'\x20AND\x20':'\x20WHERE\x20')+('('+h['where']+')'));const e=n['scope']||(h['scopes']?.['default']?'default':undefined);e&&(Z['sql']+=(Z['sql']?p(0x159):p(0x15a))+('('+(h[p(0x15b)]?.[e]||'true')+')'));const b=h['searchable']||Object['keys'](h[p(0x15c)])[p(0x158)](X=>h['fields'][X]?.[p(0x15d)]);n['search']&&b['length']&&(Z[p(0x15e)]['push'](n['search']['toLowerCase']()+'%'),Z['sql']+=(Z[p(0x14f)]?'\x20AND\x20':p(0x15a))+('\x20('+b['map'](X=>'lower('+qt(X)+p(0x15f)+Z['values']['length'])['join']('\x20OR\x20')+')'));G?.['sql']&&(Z['sql']+=(Z[p(0x14f)]?'\x20AND\x20':'\x20WHERE\x20')+('('+G[p(0x14f)]+')'),Z[p(0x15e)][p(0x160)](...G['values']));const P=h['joins']?.['filter'](X=>X['scope']!=='item')[p(0x161)](X=>X['sql']+'\x20')['join']('\x20')||'',u='SELECT\x20'+j[p(0x162)](',\x20')+'\x20'+('FROM\x20'+qt(h['table'])+'\x20t\x20')+(P+'\x20'+Z['sql']['replace'](/:uid/g,'\x27'+(B?.['id']??'NULL')+'\x27'));return{'sql':u,'values':Z[p(0x15e)]};}
@@ -1 +1 @@
1
- const y=Y,getIP=w=>(w['headers']?.['x-real-ip']||w['headers']?.['x-forwarded-for']||w['ip']||w['connection']?.['remoteAddress']||'')['split'](':')[y(0x132)]();function Y(w,y){w=w-0x132;const d=f();let Z=d[w];return Z;}function f(){const d=['pop'];f=function(){return d;};return f();}export default getIP;
1
+ const n=k,getIP=h=>(h['headers']?.['x-real-ip']||h[n(0x1a5)]?.['x-forwarded-for']||h['ip']||h['connection']?.['remoteAddress']||'')[n(0x1a6)](':')[n(0x1a7)]();export default getIP;function k(h,n){h=h-0x1a5;const B=Q();let G=B[h];return G;}function Q(){const B=['headers','split','pop'];Q=function(){return B;};return Q();}
@@ -0,0 +1,2 @@
1
+ ALTER TABLE admin.role_access_scope
2
+ ALTER COLUMN role_id DROP NOT NULL;
@@ -0,0 +1,32 @@
1
+ CREATE TABLE IF NOT EXISTS admin.role_access_scope (
2
+ id text PRIMARY KEY DEFAULT next_id(),
3
+
4
+ role_id text ,
5
+
6
+ user_id text,
7
+
8
+ resource text,
9
+
10
+ scope text NOT NULL,
11
+
12
+ value jsonb,
13
+
14
+ enabled boolean NOT NULL DEFAULT true,
15
+
16
+ created_by text,
17
+ created_at timestamptz NOT NULL DEFAULT now(),
18
+ updated_by text,
19
+ updated_at timestamptz NOT NULL DEFAULT now()
20
+ );
21
+
22
+ CREATE INDEX IF NOT EXISTS role_access_scope_role_idx
23
+ ON admin.role_access_scope(role_id);
24
+
25
+ CREATE INDEX IF NOT EXISTS role_access_scope_user_idx
26
+ ON admin.role_access_scope(user_id);
27
+
28
+ CREATE INDEX IF NOT EXISTS role_access_scope_scope_idx
29
+ ON admin.role_access_scope(scope);
30
+
31
+ CREATE INDEX IF NOT EXISTS role_access_scope_resource_idx
32
+ ON admin.role_access_scope(resource);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fcore",
3
- "version": "0.0.1-beta.25",
3
+ "version": "0.0.1-beta.27",
4
4
  "description": "Reusable backend foundation for OpenGIS Node.js applications",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -90,4 +90,4 @@
90
90
  "vitest": "4.1.11"
91
91
  },
92
92
  "license": "UNLICENSED"
93
- }
93
+ }