@opengis/fcore 0.0.1-beta.26 → 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 (139) hide show
  1. package/LICENSE +3 -3
  2. package/README.md +71 -71
  3. package/dist/config.js +1 -1
  4. package/dist/context.js +1 -1
  5. package/dist/errors.js +1 -1
  6. package/dist/fastify.js +1 -1
  7. package/dist/fcore.js +1 -1
  8. package/dist/migrations/cli.js +1 -1
  9. package/dist/migrations/runner.js +1 -1
  10. package/dist/modules/auth/adduser-cli.js +1 -1
  11. package/dist/modules/auth/passwd-cli.js +1 -1
  12. package/dist/modules/auth/permission-cli.js +1 -1
  13. package/dist/modules/auth/route.js +1 -1
  14. package/dist/modules/auth/schema.js +1 -1
  15. package/dist/modules/auth/services/change-password.js +1 -1
  16. package/dist/modules/auth/services/get-current-user.js +1 -1
  17. package/dist/modules/auth/services/registration.js +1 -1
  18. package/dist/modules/auth/services/verify-two-factor.js +1 -1
  19. package/dist/modules/file/mime.js +1 -1
  20. package/dist/modules/file/route.js +1 -1
  21. package/dist/modules/file/schema.js +1 -1
  22. package/dist/modules/file/services/get-file.js +1 -1
  23. package/dist/modules/file/services/resize-file.js +1 -1
  24. package/dist/modules/file/services/upload-file.js +1 -1
  25. package/dist/modules/resource/route.d.ts.map +1 -1
  26. package/dist/modules/resource/route.js +1 -1
  27. package/dist/modules/resource/schema.d.ts +13 -0
  28. package/dist/modules/resource/schema.d.ts.map +1 -1
  29. package/dist/modules/resource/schema.js +1 -1
  30. package/dist/modules/resource/services/add-note.js +1 -1
  31. package/dist/modules/resource/services/add-resource-file.js +1 -1
  32. package/dist/modules/resource/services/create-resource-relation.js +1 -1
  33. package/dist/modules/resource/services/create-resource.js +1 -1
  34. package/dist/modules/resource/services/delete-resource-relation.js +1 -1
  35. package/dist/modules/resource/services/delete-resource.js +1 -1
  36. package/dist/modules/resource/services/export-resource.js +1 -1
  37. package/dist/modules/resource/services/generate-resource-code.d.ts +16 -0
  38. package/dist/modules/resource/services/generate-resource-code.d.ts.map +1 -0
  39. package/dist/modules/resource/services/generate-resource-code.js +1 -0
  40. package/dist/modules/resource/services/get-resource-schema.d.ts +6 -0
  41. package/dist/modules/resource/services/get-resource-schema.d.ts.map +1 -0
  42. package/dist/modules/resource/services/get-resource-schema.js +1 -0
  43. package/dist/modules/resource/services/get-resource.js +1 -1
  44. package/dist/modules/resource/services/list-resource-as-user.d.ts +8 -0
  45. package/dist/modules/resource/services/list-resource-as-user.d.ts.map +1 -0
  46. package/dist/modules/resource/services/list-resource-as-user.js +1 -0
  47. package/dist/modules/resource/services/list-resource-list.d.ts +20 -0
  48. package/dist/modules/resource/services/list-resource-list.d.ts.map +1 -0
  49. package/dist/modules/resource/services/list-resource-list.js +1 -0
  50. package/dist/modules/resource/services/list-resource-relation.js +1 -1
  51. package/dist/modules/resource/services/list-resources.d.ts.map +1 -1
  52. package/dist/modules/resource/services/list-resources.js +1 -1
  53. package/dist/modules/resource/services/search-resource.js +1 -1
  54. package/dist/modules/resource/services/suggest-resource.js +1 -1
  55. package/dist/modules/resource/services/update-resource-relation.js +1 -1
  56. package/dist/modules/resource/services/update-resource.js +1 -1
  57. package/dist/modules/resource/services/upload-resource-file.js +1 -1
  58. package/dist/modules/system/route.d.ts.map +1 -1
  59. package/dist/modules/system/route.js +1 -1
  60. package/dist/modules/system/schema.d.ts +22 -0
  61. package/dist/modules/system/schema.d.ts.map +1 -1
  62. package/dist/modules/system/schema.js +1 -1
  63. package/dist/modules/system/services/check-system.js +1 -1
  64. package/dist/modules/system/services/get-access.js +1 -1
  65. package/dist/modules/system/services/get-api-list.js +1 -1
  66. package/dist/modules/system/services/get-audit-log.js +1 -1
  67. package/dist/modules/system/services/get-dictionary.js +1 -1
  68. package/dist/modules/system/services/get-resource-access.d.ts +23 -0
  69. package/dist/modules/system/services/get-resource-access.d.ts.map +1 -0
  70. package/dist/modules/system/services/get-resource-access.js +1 -0
  71. package/dist/modules/system/services/get-resource-scopes.d.ts +16 -0
  72. package/dist/modules/system/services/get-resource-scopes.d.ts.map +1 -0
  73. package/dist/modules/system/services/get-resource-scopes.js +1 -0
  74. package/dist/modules/system/services/get-system-log.js +1 -1
  75. package/dist/modules/system/services/get-system-settings.js +1 -1
  76. package/dist/modules/system/services/list-dictionaries.js +1 -1
  77. package/dist/modules/system/services/set-access.d.ts +1 -0
  78. package/dist/modules/system/services/set-access.d.ts.map +1 -1
  79. package/dist/modules/system/services/set-access.js +1 -1
  80. package/dist/modules/system/services/set-resource-access.d.ts +18 -0
  81. package/dist/modules/system/services/set-resource-access.d.ts.map +1 -0
  82. package/dist/modules/system/services/set-resource-access.js +1 -0
  83. package/dist/modules/system/services/set-resource-scopes.d.ts +10 -0
  84. package/dist/modules/system/services/set-resource-scopes.d.ts.map +1 -0
  85. package/dist/modules/system/services/set-resource-scopes.js +1 -0
  86. package/dist/modules/system/services/update-dictionary.js +1 -1
  87. package/dist/modules/system/services/update-system-settings.js +1 -1
  88. package/dist/modules/utils/require-admin.js +1 -1
  89. package/dist/modules/utils/safe-user.js +1 -1
  90. package/dist/modules/utils/unsupported.js +1 -1
  91. package/dist/plugins/audit/audit.js +1 -1
  92. package/dist/plugins/audit/services/write-audit.js +1 -1
  93. package/dist/plugins/auth/get-user-permissions.js +1 -1
  94. package/dist/plugins/auth/index.js +1 -1
  95. package/dist/plugins/auth/verifyUser.js +1 -1
  96. package/dist/plugins/dictionary.js +1 -1
  97. package/dist/plugins/file.js +1 -1
  98. package/dist/plugins/jwt.js +1 -1
  99. package/dist/plugins/logger/index.js +1 -1
  100. package/dist/plugins/logger/transport.js +1 -1
  101. package/dist/plugins/pg.js +1 -1
  102. package/dist/plugins/redis.js +1 -1
  103. package/dist/plugins/resource/resource.js +1 -1
  104. package/dist/plugins/resource/resource.registry.js +1 -1
  105. package/dist/plugins/resource/resource.types.d.ts +18 -0
  106. package/dist/plugins/resource/resource.types.d.ts.map +1 -1
  107. package/dist/plugins/resource/services/add-dictionary-lookup-data.js +1 -1
  108. package/dist/plugins/resource/services/add-file-token.js +1 -1
  109. package/dist/plugins/resource/services/add-table-lookup-data.js +1 -1
  110. package/dist/plugins/resource/services/create-relation.js +1 -1
  111. package/dist/plugins/resource/services/create.js +1 -1
  112. package/dist/plugins/resource/services/delete-relation.js +1 -1
  113. package/dist/plugins/resource/services/delete.js +1 -1
  114. package/dist/plugins/resource/services/find-one.d.ts.map +1 -1
  115. package/dist/plugins/resource/services/find-one.js +1 -1
  116. package/dist/plugins/resource/services/find-relation.js +1 -1
  117. package/dist/plugins/resource/services/find.d.ts.map +1 -1
  118. package/dist/plugins/resource/services/find.js +1 -1
  119. package/dist/plugins/resource/services/get-table-columns.js +1 -1
  120. package/dist/plugins/resource/services/update-relation.js +1 -1
  121. package/dist/plugins/resource/services/update.js +1 -1
  122. package/dist/plugins/resource/utils/auto-index.js +1 -1
  123. package/dist/plugins/resource/utils/fields.js +1 -1
  124. package/dist/plugins/resource/utils/filters.js +1 -1
  125. package/dist/plugins/resource/utils/permissions.js +1 -1
  126. package/dist/plugins/resource/utils/scope.d.ts +10 -0
  127. package/dist/plugins/resource/utils/scope.d.ts.map +1 -0
  128. package/dist/plugins/resource/utils/scope.js +1 -0
  129. package/dist/plugins/resource/utils/sort.js +1 -1
  130. package/dist/plugins/resource/utils/sql.js +1 -1
  131. package/dist/plugins/resource/utils/summary.d.ts +5 -1
  132. package/dist/plugins/resource/utils/summary.d.ts.map +1 -1
  133. package/dist/plugins/resource/utils/summary.js +1 -1
  134. package/dist/shared/getIP.js +1 -1
  135. package/migrations/20260903130000_move_notes_files_to_admin.sql +17 -17
  136. package/migrations/20260903140000_settings_nulls_not_distinct.sql +18 -18
  137. package/migrations/20260929120000_allow_user_only_role_scopes.sql +2 -0
  138. package/migrations/20260929_role_scope.sql +32 -0
  139. package/package.json +92 -92
@@ -1 +1 @@
1
- export function addFileToken(w,h,S){const o=G;if(!S||w['length']===0x0)return w;const X=Object[o(0x116)](h)['filter'](([,Y])=>Y['type']===o(0x117))[o(0x118)](([Y])=>Y);for(const Y of w){for(const v of X){const D=Y[v];typeof D==='string'&&D['length']>0x0&&(Y[v]=S['create'](D));}}return w;}function G(w,h){w=w-0x116;const S=z();let X=S[w];return X;}function z(){const q=['entries','file','map'];z=function(){return q;};return z();}
1
+ function Q(){const b=['string','length','create'];Q=function(){return b;};return Q();}function k(h,n){h=h-0x188;const B=Q();let G=B[h];return G;}export function addFileToken(h,n,B){const e=k;if(!B||h['length']===0x0)return h;const G=Object['entries'](n)['filter'](([,f])=>f['type']==='file')['map'](([f])=>f);for(const f of h){for(const j of G){const Z=f[j];typeof Z===e(0x188)&&Z[e(0x189)]>0x0&&(f[j]=B[e(0x18a)](Z));}}return h;}
@@ -1 +1 @@
1
- function G(w,h){w=w-0x1a5;const S=z();let X=S[w];return X;}import{qi,qt}from'../utils/sql.js';const tableLookupCache=new WeakMap();export function clearTableLookupCache(w,h){const Q=G,S=tableLookupCache['get'](h);if(!S)return;for(const X of S['keys']()){X[Q(0x1a5)](w+':')&&S[Q(0x1a6)](X);}}export async function addTableLookupData(w,h,S){const P=G;if(!S||w[P(0x1a7)]===0x0)return w;const X=tableLookupCache['get'](S)??new Map();tableLookupCache['set'](S,X);const Y=Object['entries'](h)['flatMap'](([v,D])=>{const x=P,{table:o,value:value='id',text:text=x(0x1a8)}=D[x(0x1a9)]??{};return o?[{'field':v,'table':o,'value':value,'text':text}]:[];});for(const v of Y){const D=new Map();for(const Z of w){const K=Z[v['field']];(typeof K===P(0x1aa)||typeof K===P(0x1ab))&&D[P(0x1ac)](String(K),K);}const o=v['table']+':'+v[P(0x1ad)]+':'+v[P(0x1ae)],q=X['get'](o)??new Map();X['set'](o,q);const e=[...D[P(0x1af)]()][P(0x1b0)](([y])=>!q['has'](y))['map'](([,y])=>y);if(e['length']>0x0){const y=await S[P(0x1b1)]('SELECT\x20'+qi(v['value'])+'\x20AS\x20id,\x20'+qi(v[P(0x1ae)])+P(0x1b2)+qt(v['table'])+P(0x1b3)+qi(v['value'])+'\x20=\x20ANY($1)',[e]);for(const V of y[P(0x1b4)]){q['set'](String(V['id']),V);}for(const O of e){!q[P(0x1b5)](String(O))&&q['set'](String(O),null);}}for(const H of w){const R=H[v['field']];H[v['field']+'_data']=R==null?null:q['get'](String(R))??null;}}return w;}function z(){const c=['startsWith','delete','length','name','lookup','string','number','set','value','text','entries','filter','query','\x20AS\x20text\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20','\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20','rows','has'];z=function(){return c;};return z();}
1
+ import{qi,qt}from'../utils/sql.js';function k(h,n){h=h-0x19c;const B=Q();let G=B[h];return G;}const tableLookupCache=new WeakMap();export function clearTableLookupCache(h,n){const m=k,B=tableLookupCache[m(0x19c)](n);if(!B)return;for(const G of B[m(0x19d)]()){G['startsWith'](h+':')&&B['delete'](G);}}function Q(){const U=['get','keys','length','set','flatMap','field','table','text','filter','SELECT\x20','\x20AS\x20id,\x20','\x20=\x20ANY($1)','_data'];Q=function(){return U;};return Q();}export async function addTableLookupData(h,n,B){const A=k;if(!B||h[A(0x19e)]===0x0)return h;const G=tableLookupCache[A(0x19c)](B)??new Map();tableLookupCache[A(0x19f)](B,G);const f=Object['entries'](n)[A(0x1a0)](([j,Z])=>{const {table:e,value:value='id',text:text='name'}=Z['lookup']??{};return e?[{'field':j,'table':e,'value':value,'text':text}]:[];});for(const j of f){const Z=new Map();for(const u of h){const X=u[j[A(0x1a1)]];(typeof X==='string'||typeof X==='number')&&Z['set'](String(X),X);}const e=j[A(0x1a2)]+':'+j['value']+':'+j[A(0x1a3)],b=G[A(0x19c)](e)??new Map();G['set'](e,b);const P=[...Z['entries']()][A(0x1a4)](([H])=>!b['has'](H))['map'](([,H])=>H);if(P[A(0x19e)]>0x0){const H=await B['query'](A(0x1a5)+qi(j['value'])+A(0x1a6)+qi(j[A(0x1a3)])+'\x20AS\x20text\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20'+qt(j['table'])+'\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20'+qi(j['value'])+A(0x1a7),[P]);for(const i of H['rows']){b['set'](String(i['id']),i);}for(const p of P){!b['has'](String(p))&&b[A(0x19f)](String(p),null);}}for(const z of h){const t=z[j[A(0x1a1)]];z[j['field']+A(0x1a8)]=t==null?null:b['get'](String(t))??null;}}return h;}
@@ -1 +1 @@
1
- import{UnsupportedError}from'../../../errors.js';function z(){const P=['get','gallery','includes','capabilities','\x22\x20requires\x20a\x20capabilities\x20\x22','INSERT\x20INTO\x20admin.files\x20(resource,\x20resource_id,\x20file_path,\x20size)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20($1,\x20$2,\x20$3,\x20$4)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20RETURNING\x20*','rows','query','image/jpeg','\x22\x20requires\x20a\x20project/provider\x20implementation','No\x20data\x20provided\x20for\x20relation:\x20','resource'];z=function(){return P;};return z();}import{createCreate}from'./create.js';function G(w,h){w=w-0x1cb;const S=z();let X=S[w];return X;}export function createCreateRelation(w,h){const S=createCreate(w,h);return async function X({name:Y,id:v,relation:D,data:o,user:q},e){const Q=G,Z=e?.['pg']??w['pg'],K=h[Q(0x1cb)](Y);if(['notes','files',Q(0x1cc)][Q(0x1cd)](D)&&!K[Q(0x1ce)]?.['includes'](D))throw new UnsupportedError('Generic\x20Resource\x20relation\x20\x22'+D+Q(0x1cf)+D+'\x22');if(D==='notes'){const O=await Z['query']('INSERT\x20INTO\x20admin.notes(resource,resource_id,body)\x20VALUES\x20($1,$2,$3)\x20RETURNING\x20*',[Y,String(v),o?.['body']]);return O['rows'][0x0];}if(D==='files'){const H=await Z['query'](Q(0x1d0),[Y,String(v),o?.['filePath'],o?.['size']??null]);return H[Q(0x1d1)][0x0];}if(D==='gallery'){const R=await Z[Q(0x1d2)]('INSERT\x20INTO\x20admin.gallery\x20(resource,\x20resource_id,\x20file_path,\x20size,\x20mime_type)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20($1,\x20$2,\x20$3,\x20$4)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20RETURNING\x20*',[Y,String(v),o?.['filePath'],o?.['size']??null,o?.['mimeType']??Q(0x1d3)]);return R[Q(0x1d1)][0x0];}const y=K['relations']?.[D];if(!y?.['foreignKey']||!y['resource']&&!y['table'])throw new UnsupportedError('Generic\x20Resource\x20relation\x20\x22'+D+Q(0x1d4));if(!o)throw new UnsupportedError(Q(0x1d5)+o);if(!y['resource'])throw new UnsupportedError('Relation\x20update\x20is\x20not\x20configured:\x20'+D);o[y['foreignKey']]=v;const V=await S({'name':y[Q(0x1d6)],'data':o??{},'user':q});return V;};}
1
+ import{UnsupportedError}from'../../../errors.js';function k(h,n){h=h-0xed;const B=Q();let G=B[h];return G;}function Q(){const A=['get','gallery','Generic\x20Resource\x20relation\x20\x22','\x22\x20requires\x20a\x20capabilities\x20\x22','query','filePath','rows','INSERT\x20INTO\x20admin.gallery\x20(resource,\x20resource_id,\x20file_path,\x20size,\x20mime_type)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20($1,\x20$2,\x20$3,\x20$4)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20RETURNING\x20*','size','resource','Relation\x20update\x20is\x20not\x20configured:\x20'];Q=function(){return A;};return Q();}import{createCreate}from'./create.js';export function createCreateRelation(h,n){const B=createCreate(h,n);return async function G({name:f,id:j,relation:Z,data:e,user:b},P){const m=k,u=P?.['pg']??h['pg'],X=n[m(0xed)](f);if(['notes','files',m(0xee)]['includes'](Z)&&!X['capabilities']?.['includes'](Z))throw new UnsupportedError(m(0xef)+Z+m(0xf0)+Z+'\x22');if(Z==='notes'){const p=await u[m(0xf1)]('INSERT\x20INTO\x20admin.notes(resource,resource_id,body)\x20VALUES\x20($1,$2,$3)\x20RETURNING\x20*',[f,String(j),e?.['body']]);return p['rows'][0x0];}if(Z==='files'){const z=await u['query']('INSERT\x20INTO\x20admin.files\x20(resource,\x20resource_id,\x20file_path,\x20size)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20($1,\x20$2,\x20$3,\x20$4)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20RETURNING\x20*',[f,String(j),e?.[m(0xf2)],e?.['size']??null]);return z[m(0xf3)][0x0];}if(Z==='gallery'){const t=await u['query'](m(0xf4),[f,String(j),e?.['filePath'],e?.[m(0xf5)]??null,e?.['mimeType']??'image/jpeg']);return t['rows'][0x0];}const H=X['relations']?.[Z];if(!H?.['foreignKey']||!H['resource']&&!H['table'])throw new UnsupportedError('Generic\x20Resource\x20relation\x20\x22'+Z+'\x22\x20requires\x20a\x20project/provider\x20implementation');if(!e)throw new UnsupportedError('No\x20data\x20provided\x20for\x20relation:\x20'+e);if(!H[m(0xf6)])throw new UnsupportedError(m(0xf7)+Z);e[H['foreignKey']]=j;const i=await B({'name':H[m(0xf6)],'data':e??{},'user':b});return i;};}
@@ -1 +1 @@
1
- import{ValidationError}from'../../../errors.js';function G(w,h){w=w-0x9d;const S=z();let X=S[w];return X;}import{assertOperation}from'../utils/permissions.js';import{qi,qt,writableData}from'../utils/sql.js';import{validateInputData}from'../utils/fields.js';import{clearTableLookupCache}from'./add-table-lookup-data.js';export function createCreate(w,h){return async function S({name:X,data:Y,user:v},D){const Q=G,o=h[Q(0x9d)](X);assertOperation(o,Q(0x9e),v),validateInputData({'resource':o,'data':Y});const q=writableData(o,Y);o['fields']['created_at']&&q[Q(0x9f)]([Q(0xa0),new Date()]);o['fields']['created_by']&&q[Q(0x9f)](['created_by',v?.['id']]);if(!q['length'])throw new ValidationError('No\x20writable\x20fields');const e=q[Q(0xa1)](([H])=>qi(H)),Z=q['map']((H,R)=>'$'+(R+0x1)),K=q[Q(0xa1)](([,H])=>H),y=D?.['pg']??w['pg'],V=await y['query']('INSERT\x20INTO\x20'+qt(o['table'])+'\x20('+e['join'](',\x20')+')\x20'+('VALUES\x20('+Z[Q(0xa2)](',\x20')+')\x20')+'RETURNING\x20*',K),O=V['rows'][0x0];return clearTableLookupCache(o[Q(0xa3)],y),await(D?.['audit']??w[Q(0xa4)])?.[Q(0xa5)]({'userId':v?.['id'],'module':o['module'],'resource':o['name'],'resourceId':O[o['key']],'action':'create','fields':Object['keys'](Y)}),O;};}function z(){const P=['get','create','push','created_at','map','join','table','audit','write'];z=function(){return P;};return z();}
1
+ import{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 Q(){const A=['get','create','length','No\x20writable\x20fields','query','write','module','key','keys'];Q=function(){return A;};return Q();}function k(h,n){h=h-0x17c;const B=Q();let G=B[h];return G;}import{clearTableLookupCache}from'./add-table-lookup-data.js';export function createCreate(h,n){return async function B({name:G,data:f,user:j},Z){const m=k,e=n[m(0x17c)](G);assertOperation(e,m(0x17d),j),validateInputData({'resource':e,'data':f});const b=writableData(e,f);e['fields']['created_at']&&b['push'](['created_at',new Date()]);e['fields']['created_by']&&b['push'](['created_by',j?.['id']]);if(!b[m(0x17e)])throw new ValidationError(m(0x17f));const P=b['map'](([z])=>qi(z)),u=b['map']((z,t)=>'$'+(t+0x1)),X=b['map'](([,z])=>z),H=Z?.['pg']??h['pg'],i=await H[m(0x180)]('INSERT\x20INTO\x20'+qt(e['table'])+'\x20('+P['join'](',\x20')+')\x20'+('VALUES\x20('+u['join'](',\x20')+')\x20')+'RETURNING\x20*',X),p=i['rows'][0x0];return clearTableLookupCache(e['table'],H),await(Z?.['audit']??h['audit'])?.[m(0x181)]({'userId':j?.['id'],'module':e[m(0x182)],'resource':e['name'],'resourceId':p[e[m(0x183)]],'action':m(0x17d),'fields':Object[m(0x184)](f)}),p;};}
@@ -1 +1 @@
1
- import{UnsupportedError}from'../../../errors.js';import{createRemove}from'./delete.js';function G(w,h){w=w-0xfc;const S=z();let X=S[w];return X;}function z(){const H=['capabilities','query','resource'];z=function(){return H;};return z();}export function createDeleteRelation(w,h){const S=createRemove(w,h);return async function X({name:Y,id:v,relation:D,relationId:o,user:q},e){const O=G,Z=e?.['pg']??w['pg'],K=h['get'](Y);if(['notes','files','gallery']['includes'](D)&&!K[O(0xfc)]?.['includes'](D))throw new UnsupportedError('Generic\x20Resource\x20relation\x20\x22'+D+'\x22\x20requires\x20a\x20capabilities\x20\x22'+D+'\x22');if(D==='notes')return await Z[O(0xfd)]('DELETE\x20FROM\x20admin.notes\x20WHERE\x20note_id\x20=\x20$1\x20AND\x20resource\x20=\x20$2\x20AND\x20resource_id\x20=\x20$3',[o,Y,String(v)]),{'success':!![]};if(D==='files')return await Z['query']('DELETE\x20FROM\x20admin.files\x20WHERE\x20file_id\x20=\x20$1\x20AND\x20resource\x20=\x20$2\x20AND\x20resource_id\x20=\x20$3',[o,Y,String(v)]),{'success':!![]};if(D==='gallery')return await Z['query']('DELETE\x20FROM\x20admin.gallery\x20WHERE\x20id\x20=\x20$1\x20AND\x20resource\x20=\x20$2\x20AND\x20resource_id\x20=\x20$3',[o,Y,String(v)]),{'success':!![]};const y=K['relations']?.[D];if(!y?.[O(0xfe)]||!y['foreignKey'])throw new UnsupportedError('Generic\x20Resource\x20relation\x20\x22'+D+'\x22\x20requires\x20a\x20project/provider\x20implementation');const V=await S({'name':y[O(0xfe)],'id':o,'user':q,'where':{'column':y['foreignKey'],'value':v}},e);return{'success':V};};}
1
+ import{UnsupportedError}from'../../../errors.js';import{createRemove}from'./delete.js';function k(h,n){h=h-0x1a2;const B=Q();let G=B[h];return G;}export function createDeleteRelation(h,n){const B=createRemove(h,n);return async function G({name:f,id:j,relation:Z,relationId:e,user:b},P){const p=k,u=P?.['pg']??h['pg'],X=n['get'](f);if(['notes','files','gallery']['includes'](Z)&&!X['capabilities']?.['includes'](Z))throw new UnsupportedError('Generic\x20Resource\x20relation\x20\x22'+Z+p(0x1a2)+Z+'\x22');if(Z==='notes')return await u[p(0x1a3)](p(0x1a4),[e,f,String(j)]),{'success':!![]};if(Z==='files')return await u['query']('DELETE\x20FROM\x20admin.files\x20WHERE\x20file_id\x20=\x20$1\x20AND\x20resource\x20=\x20$2\x20AND\x20resource_id\x20=\x20$3',[e,f,String(j)]),{'success':!![]};if(Z==='gallery')return await u[p(0x1a3)](p(0x1a5),[e,f,String(j)]),{'success':!![]};const H=X['relations']?.[Z];if(!H?.[p(0x1a6)]||!H['foreignKey'])throw new UnsupportedError(p(0x1a7)+Z+'\x22\x20requires\x20a\x20project/provider\x20implementation');const i=await B({'name':H['resource'],'id':e,'user':b,'where':{'column':H['foreignKey'],'value':j}},P);return{'success':i};};}function Q(){const z=['\x22\x20requires\x20a\x20capabilities\x20\x22','query','DELETE\x20FROM\x20admin.notes\x20WHERE\x20note_id\x20=\x20$1\x20AND\x20resource\x20=\x20$2\x20AND\x20resource_id\x20=\x20$3','DELETE\x20FROM\x20admin.gallery\x20WHERE\x20id\x20=\x20$1\x20AND\x20resource\x20=\x20$2\x20AND\x20resource_id\x20=\x20$3','resource','Generic\x20Resource\x20relation\x20\x22'];Q=function(){return z;};return Q();}
@@ -1 +1 @@
1
- import{assertOperation}from'../utils/permissions.js';import{qt,qi}from'../utils/sql.js';import{clearTableLookupCache}from'./add-table-lookup-data.js';export function createRemove(w,h){return async function S({name:X,id:Y,user:v,where:D},o){const V=G,q=h[V(0x1ac)](X);assertOperation(q,'delete',v);const e=o?.['pg']??w['pg'],Z=[Y];let K=V(0x1ad)+qi(q[V(0x1ae)])+V(0x1af);D&&(Z['push'](D['value']),K+='\x20AND\x20'+qi(D[V(0x1b0)])+'\x20=\x20$'+Z[V(0x1b1)]);q['where']&&(K+='\x20AND\x20('+q['where']+')');const y=await e['query']('DELETE\x20FROM\x20'+qt(q['table'])+'\x20'+K,Z);if((y['rowCount']??0x0)>0x0)clearTableLookupCache(q[V(0x1b2)],e);if((y[V(0x1b3)]??0x0)>0x0)await(o?.['audit']??w['audit'])?.['write']({'module':q[V(0x1b4)],'resource':q[V(0x1b5)],'resourceId':Y,'action':'delete'});return(y['rowCount']??0x0)>0x0;};}function G(w,h){w=w-0x1ac;const S=z();let X=S[w];return X;}function z(){const O=['get','WHERE\x20','key','\x20=\x20$1','column','length','table','rowCount','module','name'];z=function(){return O;};return z();}
1
+ function k(h,n){h=h-0x11c;const B=Q();let G=B[h];return G;}function Q(){const p=['\x20=\x20$1','\x20=\x20$','where','rowCount','audit','name'];Q=function(){return p;};return Q();}import{assertOperation}from'../utils/permissions.js';import{qt,qi}from'../utils/sql.js';import{clearTableLookupCache}from'./add-table-lookup-data.js';export function createRemove(h,n){return async function B({name:G,id:f,user:j,where:Z},e){const i=k,b=n['get'](G);assertOperation(b,'delete',j);const P=e?.['pg']??h['pg'],u=[f];let X='WHERE\x20'+qi(b['key'])+i(0x11c);Z&&(u['push'](Z['value']),X+='\x20AND\x20'+qi(Z['column'])+i(0x11d)+u['length']);b[i(0x11e)]&&(X+='\x20AND\x20('+b['where']+')');const H=await P['query']('DELETE\x20FROM\x20'+qt(b['table'])+'\x20'+X,u);if((H[i(0x11f)]??0x0)>0x0)clearTableLookupCache(b['table'],P);if((H['rowCount']??0x0)>0x0)await(e?.[i(0x120)]??h['audit'])?.['write']({'module':b['module'],'resource':b[i(0x121)],'resourceId':f,'action':'delete'});return(H['rowCount']??0x0)>0x0;};}
@@ -1 +1 @@
1
- {"version":3,"file":"find-one.d.ts","sourceRoot":"","sources":["../../../../src/plugins/resource/services/find-one.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EACV,oBAAoB,EACpB,aAAa,EACb,YAAY,EACb,MAAM,sBAAsB,CAAC;AAK9B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAKhE,wBAAgB,aAAa,CAC3B,IAAI,EAAE,oBAAoB,EAC1B,QAAQ,EAAE,gBAAgB,gCAQvB;IACD,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,IAAI,CAAC,EAAE,YAAY,CAAC;CACrB,6CAgDF"}
1
+ {"version":3,"file":"find-one.d.ts","sourceRoot":"","sources":["../../../../src/plugins/resource/services/find-one.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EACV,oBAAoB,EACpB,aAAa,EACb,YAAY,EACb,MAAM,sBAAsB,CAAC;AAK9B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAKhE,wBAAgB,aAAa,CAC3B,IAAI,EAAE,oBAAoB,EAC1B,QAAQ,EAAE,gBAAgB,gCAQvB;IACD,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,IAAI,CAAC,EAAE,YAAY,CAAC;CACrB,6CAkDF"}
@@ -1 +1 @@
1
- import{ValidationError}from'../../../errors.js';import{assertOperation}from'../utils/permissions.js';import{qt,qi,readableFields}from'../utils/sql.js';import{addDictionaryLookupData}from'./add-dictionary-lookup-data.js';function G(w,h){w=w-0xab;const S=z();let X=S[w];return X;}import{addTableLookupData}from'./add-table-lookup-data.js';import{addFileToken}from'./add-file-token.js';import{createFindRelation}from'./find-relation.js';export function createFindOne(w,h){return async function S({name:X,id:Y,query:query={},user:v}){const R=G,D=Date['now'](),o=h[R(0xab)](X);assertOperation(o,R(0xac),v);if(o['fields'][o[R(0xad)]]?.['type']==='integer'&&!Number['isInteger'](Number(Y)))throw new ValidationError(R(0xae)+Y+'\x20name:'+X);const q=o['joins']?.[R(0xaf)](O=>O['sql']+'\x20')[R(0xb0)]('\x20')||'',e=o['where']?R(0xb1)+o['where']+')':'',Z=await w['pg']['query']('SELECT\x20'+readableFields(o)['join'](',\x20')+'\x20FROM\x20'+qt(o['table'])+'\x20t\x20'+q+'\x20WHERE\x20'+qi(o['key'])+'=$1'+e+'\x20LIMIT\x201',[Y]),K=Z['rows'][0x0];if(!K)return null;await addDictionaryLookupData([K],o['fields'],w['dictionary']),await addTableLookupData([K],o[R(0xb2)],w['pg']),addFileToken([K],o['fields'],w['file']);const y=Array['isArray'](query[R(0xb3)])?query[R(0xb3)]:query[R(0xb3)]?.['split'](',')??[],V=createFindRelation(w,h);for(const O of y){K[O]=await V({'name':X,'id':Y,'relation':O,'query':query,'user':v})['then'](H=>H['rows']??[]);}return K[R(0xb4)]=Date['now']()-D,K;};}function z(){const Q=['get','read','key','Invalid\x20id:\x20','map','join','\x20AND\x20(','fields','include','time'];z=function(){return Q;};return z();}
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 z(){const L=['max','Invalid\x20pagination','get','notes','includes','query','SELECT\x20*\x20FROM\x20admin.notes\x20WHERE\x20resource\x20=\x20$1\x20AND\x20resource_id\x20=\x20$2\x20ORDER\x20BY\x20created_at\x20DESC','rows','now','file','length','Generic\x20Resource\x20relation\x20\x22','keys','map','join','btree','junctionTable','\x20=\x20$1\x20','where\x20','foreignKey','key','AND\x20(','joins','sql','SELECT\x20','\x20FROM\x20','\x20t\x20','\x20LIMIT\x20$2\x20OFFSET\x20$3','dictionary'];z=function(){return L;};return z();}import{qi,qt}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';import{autoIndex}from'../utils/auto-index.js';function G(w,h){w=w-0x9e;const S=z();let X=S[w];return X;}export function createFindRelation(w,h){return async function S({name:X,id:Y,relation:v,query:query={}}){const A=G,D=Date['now'](),o=Math['min'](Math[A(0x9e)](query['limit']??0x14,0x1),0xc8),q=Math[A(0x9e)](query['offset']??0x0,0x0);if(!Number['isFinite'](o)||!Number['isFinite'](q))throw new ValidationError(A(0x9f));const e=h[A(0xa0)](X),Z=e['relations']?.[v];if([A(0xa1),'files']['includes'](v)&&!e['capabilities']?.[A(0xa2)](v))throw new UnsupportedError('Generic\x20Resource\x20relation\x20\x22'+v+'\x22\x20requires\x20a\x20capabilities\x20\x22'+v+'\x22');if(v==='notes'){const c=await w['pg'][A(0xa3)](A(0xa4),[X,String(Y)]);return{'total':c[A(0xa5)]['length'],'time':Date[A(0xa6)]()-D,'rows':c['rows']};}if(v==='files'){const d=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',[X,String(Y)]);return addFileToken(d[A(0xa5)],{'file_path':{'type':A(0xa7)}},w['file']),{'total':d['rows'][A(0xa8)],'time':Date['now']()-D,'rows':d['rows']};}if(!Z?.['resource'])throw new UnsupportedError(A(0xa9)+v+'\x22\x20requires\x20a\x20project/provider\x20implementation');const K=h['get'](Z['resource']),y=K?.['key']??'id',V=K?.['table'],O=Object[A(0xaa)](K?.['fields']??{})['filter'](C=>K?.['fields'][C]?.['read']&&K?.['fields'][C]?.['scope']!=='item')[A(0xab)](qi)[A(0xac)](',\x20'),H=Z['fields']?.['join'](',\x20')||O||'*';Z['foreignKey']&&autoIndex(V,Z['foreignKey'],A(0xad),w['pg']);const R=Z['junctionTable']?'JOIN\x20'+qt(Z[A(0xae)])+'\x20j\x20ON\x20j.'+qi(Z['junctionForeignKey'])+'\x20=\x20t.'+(Z['junctionTargetKey']||qi(y))+'\x20WHERE\x20'+qi(Z['junctionLocalKey'])+A(0xaf):A(0xb0)+(Z[A(0xb1)]||qi(y))+'\x20=\x20(SELECT\x20'+qi(Z['localKey']||e['key'])+'\x20FROM\x20'+qt(e['table'])+'\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20'+qi(e[A(0xb2)])+'\x20=\x20$1\x20LIMIT\x201\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20)\x20'+(Z['where']?A(0xb3)+Z['where']+')':''),Q=K[A(0xb4)]?.['map'](C=>C[A(0xb5)]+'\x20')[A(0xac)]('\x20')||'',P=A(0xb6)+H+A(0xb7)+qt(V)+A(0xb8)+Q+'\x20'+R+A(0xb9),x=await w['pg'][A(0xa3)](P,[Y,o,q]);return K&&(await addDictionaryLookupData(x['rows'],K['fields'],w[A(0xba)]),await addTableLookupData(x[A(0xa5)],K['fields'],w['pg']),addFileToken(x[A(0xa5)],K['fields'],w['file'])),{'limit':o,'offset':q,'total':x[A(0xa5)]['length'],'time':Date['now']()-D,'rows':x['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
- function G(w,h){w=w-0x1b9;const S=z();let X=S[w];return X;}import{ValidationError}from'../../../errors.js';import{buildFilters,buildIndex}from'../utils/filters.js';import{assertOperation}from'../utils/permissions.js';import{buildSort}from'../utils/sort.js';function z(){const d=['read','min','filter','sql','\x20WHERE\x20','where','isFinite','Invalid\x20pagination','keys','fields','searchable','search','map','table','scope','scopes','default','true','all','OFFSET\x20$','length','query','values'];z=function(){return d;};return z();}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';import{autoIndex}from'../utils/auto-index.js';import{buildSummary}from'../utils/summary.js';export function createFind(w,h){return async function S({name:X,query:query={},user:Y}){const c=G,v=Date['now'](),D=h['get'](X);assertOperation(D,c(0x1b9),Y);const o=Math[c(0x1ba)](Math['max'](query['limit']??0x14,0x1),0xc8),q=Math['max'](query['offset']??0x0,0x0);buildIndex(D,query['filter'],w['pg']);const e=buildFilters(D,query[c(0x1bb)]);D['where']&&(e[c(0x1bc)]+=(e['sql']?'\x20AND\x20':c(0x1bd))+('('+D[c(0x1be)]+')'));const Z=buildSort(D,query['sort']);if(!Number[c(0x1bf)](o)||!Number['isFinite'](q))throw new ValidationError(c(0x1c0));const K=D['searchable']||Object[c(0x1c1)](D['fields'])[c(0x1bb)](x=>D[c(0x1c2)][x]?.[c(0x1c3)]);query[c(0x1c4)]&&K['length']&&(K[c(0x1c5)](x=>autoIndex(D[c(0x1c6)],x,'text',w['pg'])),e['values']['push'](query['search']['toLowerCase']()+'%'),e[c(0x1bc)]+=(e[c(0x1bc)]?'\x20AND\x20':c(0x1bd))+('\x20('+K?.['map'](x=>'lower('+qt(x)+')\x20LIKE\x20$'+e['values']['length'])['join']('\x20OR\x20')+')'));if(query['scope']&&D['scopes']?.[query['scope']]===undefined)throw new ValidationError('Unknown\x20scope:\x20'+query[c(0x1c7)]);const y=query['scope']||(D[c(0x1c8)]?.['default']?c(0x1c9):undefined);y&&(e[c(0x1bc)]+=(e['sql']?'\x20AND\x20':c(0x1bd))+('('+(D['scopes']?.[y]||c(0x1ca))+')'));const V=D['joins']?.['filter'](x=>x[c(0x1c7)]!=='item')['map'](x=>x['sql']+'\x20')['join']('\x20')||'',O='SELECT\x20'+readableFields(D,c(0x1cb))['join'](',\x20')+'\x20'+('FROM\x20'+qt(D[c(0x1c6)])+'\x20t\x20')+(V+'\x20'+e[c(0x1bc)]['replace'](/:uid/g,'\x27'+(Y?.['id']??'NULL')+'\x27')+'\x20'+Z+'\x20')+('LIMIT\x20$'+(e['values']['length']+0x1)+'\x20')+(c(0x1cc)+(e['values'][c(0x1cd)]+0x2)),H=buildSummary(D,query,Y),[R,Q]=await Promise[c(0x1cb)]([w['pg'][c(0x1ce)](O,[...e[c(0x1cf)],o,q]),w['pg']['query'](H,e[c(0x1cf)])['then'](x=>x['rows'][0x0]??{})]),P=R['rows'];return await addDictionaryLookupData(P,D['fields'],w['dictionary']),await addTableLookupData(P,D[c(0x1c2)],w['pg']),addFileToken(P,D['fields'],w['file']),{'time':Date['now']()-v,'limit':o,'offset':q,'count':R['rowCount'],'total':Q?.['count']??0x0,'summary':Q,'rows':P};};}
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
- export async function getTableColumns(w,h){const Y=G;if(!w)throw new Error(Y(0x148));if(!h?.['pg'])return[];const S=await h['pg']['query'](Y(0x149),[w])['then'](X=>X['rows']||[]);return S;}function G(w,h){w=w-0x148;const S=z();let X=S[w];return X;}function z(){const v=['not\x20enough\x20params:\x20table','\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'];z=function(){return v;};return z();}
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 z(){const O=['relations','resource','foreignKey','Cannot\x20change\x20relation:\x20'];z=function(){return O;};return z();}import{UnsupportedError,ValidationError}from'../../../errors.js';import{createUpdate}from'./update.js';function G(w,h){w=w-0x17a;const S=z();let X=S[w];return X;}export function createUpdateRelation(w,h){const S=createUpdate(w,h);return async function X({name:Y,id:v,relation:D,relationId:o,data:q,user:e},Z){const V=G,K=h['get'](Y),y=K[V(0x17a)]?.[D];if(!y?.[V(0x17b)]||!y['foreignKey'])throw new UnsupportedError('Relation\x20update\x20is\x20not\x20configured:\x20'+D);if(Object['hasOwn'](q,y['foreignKey'])&&q[y[V(0x17c)]]!==v)throw new ValidationError(V(0x17d)+y['foreignKey']);return S({'name':y['resource'],'id':o,'data':q,'user':e,'where':{'column':y[V(0x17c)],'value':v}},Z);};}
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';function z(){const c=['get','fields','updated_by','user_type','length','value','\x20AND\x20(','keys','rows','audit','write'];z=function(){return c;};return z();}import{qi,qt,writableData}from'../utils/sql.js';import{validateInputData}from'../utils/fields.js';function G(w,h){w=w-0x196;const S=z();let X=S[w];return X;}import{clearTableLookupCache}from'./add-table-lookup-data.js';export function createUpdate(w,h){return async function S({name:X,id:Y,data:v,user:D,where:o},q){const x=G,e=h[x(0x196)](X);assertOperation(e,'update',D);const Z=writableData(e,v);if(!Z['length'])throw new ValidationError('No\x20writable\x20fields');const K=q?.['pg']??w['pg'];validateInputData({'resource':e,'data':v,'update':!![]});e['fields']['updated_at']&&Z['push'](['updated_at',new Date()]);e[x(0x197)][x(0x198)]&&Z['push'](['updated_by',D?.['id']]);delete v[x(0x199)];const y=Z['map'](([Q],P)=>qi(Q)+'\x20=\x20$'+(P+0x1)),V=[...Z['map'](([,Q])=>Q),Y];let O='WHERE\x20'+qi(e['key'])+'\x20=\x20$'+V[x(0x19a)];o&&(V['push'](o[x(0x19b)]),O+='\x20AND\x20'+qi(o['column'])+'\x20=\x20$'+V['length']);e['where']&&(O+=x(0x19c)+e['where']+')');const H=await K['query']('UPDATE\x20'+qt(e['table'])+'\x20'+('SET\x20'+y['join'](',\x20')+'\x20')+(O+'\x20')+('RETURNING\x20'+Object[x(0x19d)](v)['map'](qi)['join'](',\x20')),V),R=H[x(0x19e)][0x0];if(!R)throw new NotFoundError(X+':'+Y);return clearTableLookupCache(e['table'],K),await(q?.['audit']??w[x(0x19f)])?.[x(0x1a0)]({'userId':D?.['id'],'module':e['module'],'resource':e['name'],'resourceId':Y,'action':'update','fields':Object['keys'](v)}),R;};}
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';const requestedIndexes=new WeakMap();function G(w,h){w=w-0x1cc;const S=z();let X=S[w];return X;}function z(){const Z=['set','has','catch','length','_idx','query','SELECT\x201\x20FROM\x20pg_indexes\x20WHERE\x20schemaname\x20=\x20$1\x20AND\x20indexname\x20=\x20$2','CREATE\x20INDEX\x20IF\x20NOT\x20EXISTS\x20','\x20ON\x20','\x20USING\x20'];z=function(){return Z;};return z();}export function autoIndex(w,h,S='btree',X){const q=G,Y=requestedIndexes['get'](X)??new Set();requestedIndexes[q(0x1cc)](X,Y);const v=w+':'+h+':'+S;if(Y[q(0x1cd)](v))return;Y['add'](v),void ensureIndex(w,h,S,X)[q(0x1ce)](()=>{Y['delete'](v);});}async function ensureIndex(w,h,S,X){const e=G,Y=w['split']('.'),v=Y[e(0x1cf)]===0x2?Y[0x0]:'public',D=(w+'_'+h+'_'+S+e(0x1d0))['replace'](/[^A-Za-z0-9_]/g,'_'),o=await X[e(0x1d1)](e(0x1d2),[v,D]);if(o['rowCount'])return;if(S==='text'){await X[e(0x1d1)]('CREATE\x20EXTENSION\x20IF\x20NOT\x20EXISTS\x20pg_trgm'),await X[e(0x1d1)]('CREATE\x20INDEX\x20IF\x20NOT\x20EXISTS\x20'+qi(D+'_l')+'\x20ON\x20'+qt(w)+'\x20USING\x20btree\x20(lower('+qi(h)+')\x20text_pattern_ops)'),await X['query']('CREATE\x20INDEX\x20IF\x20NOT\x20EXISTS\x20'+qi(D)+'\x20ON\x20'+qt(w)+'\x20USING\x20gin\x20(lower('+qi(h)+')\x20gin_trgm_ops)');return;}await X['query'](e(0x1d3)+qi(D)+e(0x1d4)+qt(w)+e(0x1d5)+S+'\x20('+qi(h)+')');}
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 G(w,h){w=w-0x18d;const S=z();let X=S[w];return X;}export{readableFields,writableData,fieldColumn}from'./sql.js';const validateInputData=({resource:w,data:h,update:update=![]})=>{const Y=G;for(const [S,X]of Object['entries'](w['fields'])){if(X[Y(0x18d)]&&X[Y(0x18e)]!==![]&&(h[S]===undefined||h[S]===null)&&!update)throw new ValidationError('Required\x20field:\x20'+S);if(X['required']&&X['writable']!==![]&&Object[Y(0x18f)](h,S)&&(h[S]===undefined||h[S]===null)&&update)throw new ValidationError('Required\x20field:\x20'+S);if(X[Y(0x190)]&&typeof h[S]==='string'&&h[S]['length']<X['minLength'])throw new ValidationError('minLength\x20not\x20met:\x20'+S);if(X[Y(0x191)]&&typeof h[S]==='string'&&h[S][Y(0x192)]>X['maxLength'])throw new ValidationError(Y(0x193)+S);if(X[Y(0x194)]&&typeof h[S]==='number'&&h[S]<X['minimum'])throw new ValidationError(S+'\x20should\x20be\x20>=\x20'+X[Y(0x194)]);if(X['maximum']&&typeof h[S]===Y(0x195)&&h[S]>X['maximum'])throw new ValidationError(S+'\x20should\x20be\x20<=\x20'+X[Y(0x196)]);if(X[Y(0x197)]&&h[S]&&!X[Y(0x197)]['includes'](h[S]))throw new ValidationError(S+Y(0x198)+X['enum'][Y(0x199)](',\x20')+')');if(X['pattern']&&typeof h[S]==='string'&&!new RegExp(X[Y(0x19a)])['test'](h[S]))throw new ValidationError(S+'\x20should\x20match\x20regular\x20expression\x20('+X['pattern']+')');}};function z(){const v=['required','writable','hasOwn','minLength','maxLength','length','maxLength\x20exceeded:\x20','minimum','number','maximum','enum','\x20should\x20be\x20one\x20of\x20(','join','pattern'];z=function(){return v;};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 H=G;import{fieldColumn,qi}from'./sql.js';import{ValidationError}from'../../../errors.js';import{autoIndex}from'./auto-index.js';const filterOperators=new Set(['eq','ne','gt',H(0x15a),'lt','lte','in','nin',H(0x15b),'ilike',H(0x15c)]);export function parseFilterQuery(w){const R=H,h={...isRecord(w[R(0x15d)])?w['filter']:{}};for(const [S,X]of Object['entries'](w)){const Y=/^filter\[([^\]]+)\](?:\[([^\]]+)\])?$/['exec'](S);if(!Y)continue;const [,v,D]=Y;if(!v)continue;if(!D){h[v]=X;continue;}if(!filterOperators['has'](D))throw new ValidationError('Unsupported\x20filter\x20operator:\x20'+D);const o=isRecord(h[v])?h[v]:{};o[D]=(D==='in'||D===R(0x15e))&&typeof X==='string'?X['split'](','):X,h[v]=o;}return Object['keys'](h)['length']?h:undefined;}export function buildIndex(w,h,S){const Q=H;for(const [X,Y]of Object['entries'](h??{})){const v=w['fields'][X];if(!v||v['filter']!==!![]&&v[Q(0x15f)]!==!![])throw new ValidationError('Field\x20is\x20not\x20filterable:\x20'+X);S&&autoIndex(w['table'],fieldColumn(w,X),indexTypeFor(v['type'],'eq'),S);}}function z(){const d=['gte','like','null','filter','nin','filterable','entries','has','\x20IS\x20','NOT\x20','NULL','push','\x20WHERE\x20','\x20AND\x20','object','ilike','geometry'];z=function(){return d;};return z();}function G(w,h){w=w-0x15a;const S=z();let X=S[w];return X;}export function buildFilters(w,h,S=0x1){const P=H,X=[],Y=[];for(const [v,D]of Object[P(0x160)](h??{})){const o=w['fields'][v];if(!o||o['filter']!==!![]&&o['filterable']!==!![])throw new ValidationError('Field\x20is\x20not\x20filterable:\x20'+v);const q=qi(fieldColumn(w,v)),e=isRecord(D)?D:{'eq':D};for(const [Z,K]of Object['entries'](e)){if(!filterOperators[P(0x161)](Z))throw new ValidationError('Unsupported\x20filter\x20operator:\x20'+Z);if((Z===P(0x15b)||Z==='ilike')&&o['type']!=='string'&&o['type']!=='text')throw new ValidationError('Operator\x20'+Z+'\x20requires\x20a\x20text\x20field:\x20'+v);if(Z===P(0x15c)){X['push'](q+P(0x162)+(isTruthy(K)?'':P(0x163))+P(0x164));continue;}if(Z==='in'||Z==='nin'){const O=Array['isArray'](K)?K:[K];if(O['length']===0x0){X['push'](Z==='in'?'FALSE':'TRUE');continue;}Y[P(0x165)](O),X['push'](q+'\x20'+(Z==='in'?'=\x20ANY':'<>\x20ALL')+'($'+(S+Y['length']-0x1)+')');continue;}const y={'eq':'=','ne':'<>','gt':'>','gte':'>=','lt':'<','lte':'<=','like':'like'},V='$'+(S+Y['length']);if(Z==='like'){Y['push'](K+'%'),X[P(0x165)]('lower('+q+')\x20like\x20lower('+V+')');continue;}Y[P(0x165)](K),X['push'](q+'\x20'+y[Z]+'\x20'+V);}}return{'sql':X['length']?P(0x166)+X['join'](P(0x167)):'','values':Y};}function isRecord(w){const x=H;return typeof w===x(0x168)&&w!==null&&!Array['isArray'](w);}function isTruthy(w){return w===!![]||w==='true'||w==='1'||w===0x1;}function indexTypeFor(w,h){const c=H;if(h===c(0x15b)||h===c(0x169))return'text';if(w==='geom'||w===c(0x16a))return'gist';return'btree';}
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 z(){const D=['access','permissions','includes'];z=function(){return D;};return z();}import{ForbiddenError}from'../../../errors.js';import{getContext}from'../../../index.js';function G(w,h){w=w-0x187;const S=z();let X=S[w];return X;}export function assertOperation(w,h,S){const v=G,X=getContext()['config'];if(X['debug'])return;if(!w['operations']['includes'](h))throw new ForbiddenError(w['name']+'.'+h+'\x20is\x20disabled');if(w[v(0x187)]!=='public'&&S===undefined)throw new ForbiddenError('Authentication\x20required');if(w[v(0x187)]==='admin'&&S?.['type']!=='admin')throw new ForbiddenError('Admin\x20access\x20required');if(S?.['type']!=='admin'){const Y=(w['permission']??w['name'])+':'+h;if(!S?.[v(0x188)]?.[v(0x189)](Y))throw new ForbiddenError('Missing\x20permission:\x20'+Y);}}
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';function G(w,h){w=w-0xe0;const S=z();let X=S[w];return X;}import{ValidationError}from'../../../errors.js';function z(){const q=['fields'];z=function(){return q;};return z();}export function buildSort(w,h){if(!h?.['length'])return'';typeof h==='string'&&(h=[h]);const S=h['map'](X=>{const o=G,Y=X['startsWith']('-'),v=Y?X['slice'](0x1):X,D=w[o(0xe0)][v];if(!D||D['sortable']!==!![])throw new ValidationError('Field\x20is\x20not\x20sortable:\x20'+v);return qi(fieldColumn(w,v))+'\x20'+(Y?'DESC':'ASC');});return'\x20ORDER\x20BY\x20'+S['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 D=G;import{ValidationError}from'../../../errors.js';export const quoteIdentifier=w=>'\x22'+w['replace'](/"/g,'\x22\x22')+'\x22';export const quoteTable=w=>w[D(0x1c6)]('.')['map'](quoteIdentifier)[D(0x1c7)]('.');export function fieldColumn(w,h){const o=D;if(h===w[o(0x1c8)])return w[o(0x1c8)];const S=w[o(0x1c9)][h];if(!S)throw new ValidationError('Unknown\x20field:\x20'+h);return S['column']??h;}export function readableFields(w,h){const q=D,S=Object[q(0x1ca)](w[q(0x1c9)])[q(0x1cb)](([,X])=>X[q(0x1cc)]!==![]&&X['readable']!==![]&&(h?(X[q(0x1cd)]??q(0x1ce))===h:!![]))[q(0x1cf)](([X,Y])=>quoteIdentifier(Y[q(0x1d0)]??X)+'\x20AS\x20'+quoteIdentifier(X));return!w['fields'][w[q(0x1c8)]]&&S[q(0x1d1)](quoteIdentifier(w[q(0x1c8)])),S;}export function writableData(w,h){const e=D,S=[];for(const [X,Y]of Object['entries'](h)){const v=w['fields'][X];if(!v||v['write']===![]||v['writable']===![])throw new ValidationError('Field\x20is\x20not\x20writable:\x20'+X);if((v[e(0x1d2)]??v['writable'])!==!![])continue;if(v['type']==='date'&&!h[X])continue;S[e(0x1d3)]([v['column']??X,Y]);}return S;}export const qi=quoteIdentifier;function z(){const Z=['split','join','key','fields','entries','filter','read','scope','all','map','column','unshift','write','push'];z=function(){return Z;};return z();}function G(w,h){w=w-0x1c6;const S=z();let X=S[w];return X;}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
- function G(w,h){w=w-0x1c3;const S=z();let X=S[w];return X;}const K=G;import{buildFilters}from'./filters.js';import{qt}from'./sql.js';const defaultSummary={'count':{'aggregate':K(0x1c3)}};function z(){const O=['count','summary','sql','aggregate','true','))::int\x20AS\x20\x22','field',')\x20FILTER\x20(where\x20','where',')\x20AS\x20\x22','min','MIN(','max','MAX(','filter','\x20AND\x20','scope','item','join','SELECT\x20','\x20t\x20'];z=function(){return O;};return z();}export function buildSummary(w,h,S){const y=K,X={...defaultSummary,...w[y(0x1c4)]??{}},Y=Object['entries'](X)['map'](([e,Z])=>{const V=y;if(V(0x1c5)in Z)return'('+Z['sql']+')\x20AS\x20\x22'+e+'\x22';switch(Z[V(0x1c6)]){case'count':return'(COUNT(*)\x20FILTER\x20(where\x20'+(Z['where']??V(0x1c7))+V(0x1c8)+e+'\x22';case'countDistinct':return'(COUNT(DISTINCT\x20t.'+qt(Z[V(0x1c9)])+')\x20FILTER\x20(where\x20'+(Z['where']??V(0x1c7))+'))::int\x20AS\x20\x22'+e+'\x22';case'sum':return'SUM('+Z['field']+')\x20FILTER\x20(where\x20'+(Z['where']??'true')+')\x20AS\x20\x22'+e+'\x22';case'avg':return'AVG('+Z['field']+V(0x1ca)+(Z[V(0x1cb)]??'true')+V(0x1cc)+e+'\x22';case V(0x1cd):return V(0x1ce)+Z[V(0x1c9)]+')\x20FILTER\x20(where\x20'+(Z['where']??'true')+')\x20AS\x20\x22'+e+'\x22';case V(0x1cf):return V(0x1d0)+Z[V(0x1c9)]+')\x20FILTER\x20(where\x20'+(Z['where']??'true')+V(0x1cc)+e+'\x22';}}),v=buildFilters(w,h[y(0x1d1)]);w['where']&&(v[y(0x1c5)]+=(v['sql']?y(0x1d2):'\x20WHERE\x20')+('('+w[y(0x1cb)]+')'));const D=h['scope']||(w['scopes']?.['default']?'default':undefined);D&&(v['sql']+=(v['sql']?y(0x1d2):'\x20WHERE\x20')+('('+(w['scopes']?.[D]||'true')+')'));const o=w['joins']?.['filter'](e=>e[y(0x1d3)]!==y(0x1d4))['map'](e=>e['sql']+'\x20')[y(0x1d5)]('\x20')||'',q=y(0x1d6)+Y[y(0x1d5)](',\x20')+'\x20'+('FROM\x20'+qt(w['table'])+y(0x1d7))+(o+'\x20'+v['sql']['replace'](/:uid/g,'\x27'+(S?.['id']??'NULL')+'\x27'));return q;}
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
- function G(w,h){w=w-0x125;const S=z();let X=S[w];return X;}function z(){const S=['headers','x-forwarded-for','connection'];z=function(){return S;};return z();}const h=G,getIP=w=>(w[h(0x125)]?.['x-real-ip']||w['headers']?.[h(0x126)]||w['ip']||w[h(0x127)]?.['remoteAddress']||'')['split'](':')['pop']();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();}
@@ -1,18 +1,18 @@
1
- CREATE SCHEMA IF NOT EXISTS admin;
2
-
3
- DO $$
4
- BEGIN
5
- IF to_regclass('crm.notes') IS NOT NULL
6
- AND to_regclass('admin.notes') IS NULL THEN
7
- ALTER TABLE crm.notes SET SCHEMA admin;
8
- END IF;
9
-
10
- IF to_regclass('crm.files') IS NOT NULL
11
- AND to_regclass('admin.files') IS NULL THEN
12
- ALTER TABLE crm.files SET SCHEMA admin;
13
- END IF;
14
- END
15
- $$;
16
-
17
- ALTER INDEX IF EXISTS crm_notes_resource_idx RENAME TO admin_notes_resource_idx;
1
+ CREATE SCHEMA IF NOT EXISTS admin;
2
+
3
+ DO $$
4
+ BEGIN
5
+ IF to_regclass('crm.notes') IS NOT NULL
6
+ AND to_regclass('admin.notes') IS NULL THEN
7
+ ALTER TABLE crm.notes SET SCHEMA admin;
8
+ END IF;
9
+
10
+ IF to_regclass('crm.files') IS NOT NULL
11
+ AND to_regclass('admin.files') IS NULL THEN
12
+ ALTER TABLE crm.files SET SCHEMA admin;
13
+ END IF;
14
+ END
15
+ $$;
16
+
17
+ ALTER INDEX IF EXISTS crm_notes_resource_idx RENAME TO admin_notes_resource_idx;
18
18
  ALTER INDEX IF EXISTS crm_notes_uid_idx RENAME TO admin_notes_uid_idx;
@@ -1,19 +1,19 @@
1
- CREATE SCHEMA IF NOT EXISTS admin;
2
-
3
- CREATE TABLE IF NOT EXISTS admin.settings (
4
- id text PRIMARY KEY DEFAULT next_id(),
5
- resource text NOT NULL DEFAULT 'system',
6
- resource_id text,
7
- key text NOT NULL,
8
- value jsonb,
9
- updated_by text,
10
- updated_at timestamptz NOT NULL DEFAULT now(),
11
- created_by text,
12
- created_at timestamptz NOT NULL DEFAULT now()
13
- );
14
-
15
- DROP INDEX IF EXISTS settings_resource_key_uidx;
16
-
17
- CREATE UNIQUE INDEX settings_resource_key_uidx
18
- ON admin.settings (resource, resource_id, key)
1
+ CREATE SCHEMA IF NOT EXISTS admin;
2
+
3
+ CREATE TABLE IF NOT EXISTS admin.settings (
4
+ id text PRIMARY KEY DEFAULT next_id(),
5
+ resource text NOT NULL DEFAULT 'system',
6
+ resource_id text,
7
+ key text NOT NULL,
8
+ value jsonb,
9
+ updated_by text,
10
+ updated_at timestamptz NOT NULL DEFAULT now(),
11
+ created_by text,
12
+ created_at timestamptz NOT NULL DEFAULT now()
13
+ );
14
+
15
+ DROP INDEX IF EXISTS settings_resource_key_uidx;
16
+
17
+ CREATE UNIQUE INDEX settings_resource_key_uidx
18
+ ON admin.settings (resource, resource_id, key)
19
19
  NULLS NOT DISTINCT;
@@ -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);