@opengis/fcore 0.0.1-beta.12 → 0.0.1-beta.14

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 (96) 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.d.ts +0 -3
  5. package/dist/fastify.d.ts.map +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.js +1 -1
  26. package/dist/modules/resource/schema.js +1 -1
  27. package/dist/modules/resource/services/add-note.js +1 -1
  28. package/dist/modules/resource/services/add-resource-file.js +1 -1
  29. package/dist/modules/resource/services/create-resource-relation.js +1 -1
  30. package/dist/modules/resource/services/create-resource.js +1 -1
  31. package/dist/modules/resource/services/delete-resource-relation.js +1 -1
  32. package/dist/modules/resource/services/delete-resource.js +1 -1
  33. package/dist/modules/resource/services/export-resource.js +1 -1
  34. package/dist/modules/resource/services/get-resource.js +1 -1
  35. package/dist/modules/resource/services/list-resource-relation.js +1 -1
  36. package/dist/modules/resource/services/list-resources.js +1 -1
  37. package/dist/modules/resource/services/search-resource.js +1 -1
  38. package/dist/modules/resource/services/suggest-resource.js +1 -1
  39. package/dist/modules/resource/services/update-resource-relation.js +1 -1
  40. package/dist/modules/resource/services/update-resource.js +1 -1
  41. package/dist/modules/resource/services/upload-resource-file.js +1 -1
  42. package/dist/modules/system/route.js +1 -1
  43. package/dist/modules/system/schema.js +1 -1
  44. package/dist/modules/system/services/check-system.js +1 -1
  45. package/dist/modules/system/services/get-access.js +1 -1
  46. package/dist/modules/system/services/get-api-list.js +1 -1
  47. package/dist/modules/system/services/get-audit-log.js +1 -1
  48. package/dist/modules/system/services/get-dictionary.js +1 -1
  49. package/dist/modules/system/services/get-system-log.js +1 -1
  50. package/dist/modules/system/services/get-system-settings.js +1 -1
  51. package/dist/modules/system/services/list-dictionaries.js +1 -1
  52. package/dist/modules/system/services/set-access.js +1 -1
  53. package/dist/modules/system/services/update-dictionary.js +1 -1
  54. package/dist/modules/system/services/update-system-settings.js +1 -1
  55. package/dist/modules/utils/require-admin.js +1 -1
  56. package/dist/modules/utils/safe-user.js +1 -1
  57. package/dist/modules/utils/unsupported.js +1 -1
  58. package/dist/plugins/audit/audit.js +1 -1
  59. package/dist/plugins/audit/services/write-audit.js +1 -1
  60. package/dist/plugins/auth/get-user-permissions.js +1 -1
  61. package/dist/plugins/auth/index.js +1 -1
  62. package/dist/plugins/auth/verifyUser.js +1 -1
  63. package/dist/plugins/dictionary.js +1 -1
  64. package/dist/plugins/file.js +1 -1
  65. package/dist/plugins/jwt.js +1 -1
  66. package/dist/plugins/logger/index.js +1 -1
  67. package/dist/plugins/logger/transport.js +1 -1
  68. package/dist/plugins/pg.js +1 -1
  69. package/dist/plugins/redis.js +1 -1
  70. package/dist/plugins/resource/resource.js +1 -1
  71. package/dist/plugins/resource/resource.registry.js +1 -1
  72. package/dist/plugins/resource/resource.types.d.ts +6 -0
  73. package/dist/plugins/resource/resource.types.d.ts.map +1 -1
  74. package/dist/plugins/resource/services/add-dictionary-lookup-data.js +1 -1
  75. package/dist/plugins/resource/services/add-file-token.js +1 -1
  76. package/dist/plugins/resource/services/add-table-lookup-data.js +1 -1
  77. package/dist/plugins/resource/services/create-relation.js +1 -1
  78. package/dist/plugins/resource/services/create.js +1 -1
  79. package/dist/plugins/resource/services/delete-relation.js +1 -1
  80. package/dist/plugins/resource/services/delete.js +1 -1
  81. package/dist/plugins/resource/services/find-one.js +1 -1
  82. package/dist/plugins/resource/services/find-relation.js +1 -1
  83. package/dist/plugins/resource/services/find.d.ts.map +1 -1
  84. package/dist/plugins/resource/services/find.js +1 -1
  85. package/dist/plugins/resource/services/update-relation.js +1 -1
  86. package/dist/plugins/resource/services/update.js +1 -1
  87. package/dist/plugins/resource/utils/auto-index.js +1 -1
  88. package/dist/plugins/resource/utils/fields.js +1 -1
  89. package/dist/plugins/resource/utils/filters.js +1 -1
  90. package/dist/plugins/resource/utils/permissions.js +1 -1
  91. package/dist/plugins/resource/utils/sort.js +1 -1
  92. package/dist/plugins/resource/utils/sql.d.ts +1 -1
  93. package/dist/plugins/resource/utils/sql.d.ts.map +1 -1
  94. package/dist/plugins/resource/utils/sql.js +1 -1
  95. package/dist/shared/getIP.js +1 -1
  96. package/package.json +1 -1
@@ -1 +1 @@
1
- import{UnsupportedError}from'../../../errors.js';function A(x,q){x=x-0x166;const C=g();let J=C[x];return J;}import{createRemove}from'./delete.js';function g(){const p=['includes','Generic\x20Resource\x20relation\x20\x22','DELETE\x20FROM\x20admin.notes\x20WHERE\x20note_id\x20=\x20$1\x20AND\x20resource\x20=\x20$2\x20AND\x20resource_id\x20=\x20$3','resource','foreignKey'];g=function(){return p;};return g();}export function createDeleteRelation(x,q){const C=createRemove(x,q);return async function J({name:K,id:Z,relation:Y,relationId:b,user:k},H){const t=A,F=H?.['pg']??x['pg'],y=q['get'](K);if(['notes','files'][t(0x166)](Y)&&!y['capabilities']?.[t(0x166)](Y))throw new UnsupportedError(t(0x167)+Y+'\x22\x20requires\x20a\x20capabilities\x20\x22'+Y+'\x22');if(Y==='notes')return await F['query'](t(0x168),[b,K,String(Z)]),{'success':!![]};if(Y==='files')return await F['query']('DELETE\x20FROM\x20admin.files\x20WHERE\x20file_id\x20=\x20$1\x20AND\x20resource\x20=\x20$2\x20AND\x20resource_id\x20=\x20$3',[b,K,String(Z)]),{'success':!![]};const r=y['relations']?.[Y];if(!r?.[t(0x169)]||!r[t(0x16a)])throw new UnsupportedError('Generic\x20Resource\x20relation\x20\x22'+Y+'\x22\x20requires\x20a\x20project/provider\x20implementation');const B=await C({'name':r['resource'],'id':b,'user':k,'where':{'column':r['foreignKey'],'value':Z}},H);return{'success':B};};}
1
+ import{UnsupportedError}from'../../../errors.js';import{createRemove}from'./delete.js';function y(k,f){k=k-0x8a;const C=F();let p=C[k];return p;}function F(){const T=['notes','\x22\x20requires\x20a\x20capabilities\x20\x22','query','DELETE\x20FROM\x20admin.files\x20WHERE\x20file_id\x20=\x20$1\x20AND\x20resource\x20=\x20$2\x20AND\x20resource_id\x20=\x20$3','resource','Generic\x20Resource\x20relation\x20\x22'];F=function(){return T;};return F();}export function createDeleteRelation(k,f){const C=createRemove(k,f);return async function p({name:a,id:N,relation:W,relationId:n,user:A},H){const z=y,R=H?.['pg']??k['pg'],u=f['get'](a);if([z(0x8a),'files']['includes'](W)&&!u['capabilities']?.['includes'](W))throw new UnsupportedError('Generic\x20Resource\x20relation\x20\x22'+W+z(0x8b)+W+'\x22');if(W==='notes')return await R['query']('DELETE\x20FROM\x20admin.notes\x20WHERE\x20note_id\x20=\x20$1\x20AND\x20resource\x20=\x20$2\x20AND\x20resource_id\x20=\x20$3',[n,a,String(N)]),{'success':!![]};if(W==='files')return await R[z(0x8c)](z(0x8d),[n,a,String(N)]),{'success':!![]};const d=u['relations']?.[W];if(!d?.[z(0x8e)]||!d['foreignKey'])throw new UnsupportedError(z(0x8f)+W+'\x22\x20requires\x20a\x20project/provider\x20implementation');const j=await C({'name':d[z(0x8e)],'id':n,'user':A,'where':{'column':d['foreignKey'],'value':N}},H);return{'success':j};};}
@@ -1 +1 @@
1
- import{assertOperation}from'../utils/permissions.js';import{qt,qi}from'../utils/sql.js';function A(x,q){x=x-0xf0;const C=g();let J=C[x];return J;}function g(){const t=['get','key','length','audit','write','name','rowCount'];g=function(){return t;};return g();}import{clearTableLookupCache}from'./add-table-lookup-data.js';export function createRemove(x,q){return async function C({name:J,id:K,user:Z,where:Y},b){const B=A,k=q[B(0xf0)](J);assertOperation(k,'delete',Z);const H=b?.['pg']??x['pg'],F=[K];let y='WHERE\x20'+qi(k[B(0xf1)])+'\x20=\x20$1';Y&&(F['push'](Y['value']),y+='\x20AND\x20'+qi(Y['column'])+'\x20=\x20$'+F[B(0xf2)]);const r=await H['query']('DELETE\x20FROM\x20'+qt(k['table'])+'\x20'+y,F);if((r['rowCount']??0x0)>0x0)clearTableLookupCache(k['table'],H);if((r['rowCount']??0x0)>0x0)await(b?.[B(0xf3)]??x['audit'])?.[B(0xf4)]({'module':k['module'],'resource':k[B(0xf5)],'resourceId':K,'action':'delete'});return(r[B(0xf6)]??0x0)>0x0;};}
1
+ import{assertOperation}from'../utils/permissions.js';import{qt,qi}from'../utils/sql.js';import{clearTableLookupCache}from'./add-table-lookup-data.js';function F(){const z=['get','delete','\x20=\x20$','length','DELETE\x20FROM\x20','table','module','name'];F=function(){return z;};return F();}function y(k,f){k=k-0xb9;const C=F();let p=C[k];return p;}export function createRemove(k,f){return async function C({name:p,id:a,user:N,where:W},n){const j=y,A=f[j(0xb9)](p);assertOperation(A,j(0xba),N);const H=n?.['pg']??k['pg'],R=[a];let u='WHERE\x20'+qi(A['key'])+'\x20=\x20$1';W&&(R['push'](W['value']),u+='\x20AND\x20'+qi(W['column'])+j(0xbb)+R[j(0xbc)]);const d=await H['query'](j(0xbd)+qt(A['table'])+'\x20'+u,R);if((d['rowCount']??0x0)>0x0)clearTableLookupCache(A[j(0xbe)],H);if((d['rowCount']??0x0)>0x0)await(n?.['audit']??k['audit'])?.['write']({'module':A[j(0xbf)],'resource':A[j(0xc0)],'resourceId':a,'action':'delete'});return(d['rowCount']??0x0)>0x0;};}
@@ -1 +1 @@
1
- import{ValidationError}from'../../../errors.js';import{assertOperation}from'../utils/permissions.js';function g(){const h=['read','key','integer','Invalid\x20id:\x20','join','fields','include','resource','\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20','dictionary','time'];g=function(){return h;};return g();}function A(x,q){x=x-0x10e;const C=g();let J=C[x];return J;}import{qt,qi,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';export function createFindOne(x,q){return async function C({name:J,id:K,query:query={},user:Z}){const G=A,Y=Date['now'](),b=q['get'](J);assertOperation(b,G(0x10e),Z);if(b['fields'][b[G(0x10f)]]?.['type']===G(0x110)&&!Number['isInteger'](Number(K)))throw new ValidationError(G(0x111)+K+'\x20name:'+J);const k=await x['pg']['query']('SELECT\x20'+readableFields(b)[G(0x112)](',\x20')+'\x20FROM\x20'+qt(b['table'])+'\x20WHERE\x20'+qi(b['key'])+'=$1\x20LIMIT\x201',[K]),H=k['rows'][0x0];if(!H)return null;await addDictionaryLookupData([H],b['fields'],x['dictionary']),await addTableLookupData([H],b[G(0x113)],x['pg']),addFileToken([H],b['fields'],x['file']);const F=Array['isArray'](query['include'])?query[G(0x114)]:query['include']?.['split'](',')??[];for(const y of F){const r=b['relations']?.[y];if(!r?.['foreignKey']||!r['resource']&&!r['table'])throw new ValidationError('Unknown\x20relation:\x20'+y);const B=r['resource']?q['get'](r[G(0x115)]):undefined,t=r['table']??B['table'],p=B?.[G(0x10f)]??'id',w=B?readableFields(B)['join'](',\x20'):'*',R='SELECT\x20'+w+'\x20FROM\x20'+qt(t)+'\x20WHERE\x20'+qi(p)+'\x20=\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20SELECT\x20'+qi(r['foreignKey'])+'\x20FROM\x20'+qt(b['table'])+G(0x116)+qi(b[G(0x10f)])+'\x20=\x20$1\x20LIMIT\x201\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20)',s=(await x['pg']['query'](R,[K]))['rows'];B&&(await addDictionaryLookupData(s,B[G(0x113)],x[G(0x117)]),await addTableLookupData(s,B['fields'],x['pg']),addFileToken(s,B[G(0x113)],x['file'])),H[y]=s;}return H[G(0x118)]=Date['now']()-Y,H;};}
1
+ import{ValidationError}from'../../../errors.js';import{assertOperation}from'../utils/permissions.js';function F(){const l=['type','Invalid\x20id:\x20','query','SELECT\x20','=$1\x20LIMIT\x201','dictionary','isArray','include','split','resource','table','key','join','\x20FROM\x20','\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20','rows','fields'];F=function(){return l;};return F();}import{qt,qi,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(k,f){k=k-0x85;const C=F();let p=C[k];return p;}export function createFindOne(k,f){return async function C({name:p,id:a,query:query={},user:N}){const Q=y,W=Date['now'](),n=f['get'](p);assertOperation(n,'read',N);if(n['fields'][n['key']]?.[Q(0x85)]==='integer'&&!Number['isInteger'](Number(a)))throw new ValidationError(Q(0x86)+a+'\x20name:'+p);const A=n['joins']?.['map'](d=>d['sql']+'\x20')['join']('\x20')||'',H=await k['pg'][Q(0x87)](Q(0x88)+readableFields(n)['join'](',\x20')+'\x20FROM\x20'+qt(n['table'])+'\x20t\x20'+A+'\x20WHERE\x20'+qi(n['key'])+Q(0x89),[a]),R=H['rows'][0x0];if(!R)return null;await addDictionaryLookupData([R],n['fields'],k[Q(0x8a)]),await addTableLookupData([R],n['fields'],k['pg']),addFileToken([R],n['fields'],k['file']);const u=Array[Q(0x8b)](query[Q(0x8c)])?query['include']:query['include']?.[Q(0x8d)](',')??[];for(const d of u){const j=n['relations']?.[d];if(!j?.['foreignKey']||!j['resource']&&!j['table'])throw new ValidationError('Unknown\x20relation:\x20'+d);const z=j[Q(0x8e)]?f['get'](j['resource']):undefined,T=j[Q(0x8f)]??z['table'],S=z?.[Q(0x90)]??'id',i=z?readableFields(z)[Q(0x91)](',\x20'):'*',b='SELECT\x20'+i+'\x20FROM\x20'+qt(T)+'\x20WHERE\x20'+qi(S)+'\x20=\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20SELECT\x20'+qi(j['foreignKey'])+Q(0x92)+qt(n['table'])+Q(0x93)+qi(n['key'])+'\x20=\x20$1\x20LIMIT\x201\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20)',P=(await k['pg']['query'](b,[a]))[Q(0x94)];z&&(await addDictionaryLookupData(P,z[Q(0x95)],k[Q(0x8a)]),await addTableLookupData(P,z['fields'],k['pg']),addFileToken(P,z['fields'],k['file'])),R[d]=P;}return R['time']=Date['now']()-W,R;};}
@@ -1 +1 @@
1
- import{UnsupportedError,ValidationError}from'../../../errors.js';function A(x,q){x=x-0x1a7;const C=g();let J=C[x];return J;}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';export function createFindRelation(x,q){return async function C({name:J,id:K,relation:Z,query:query={}}){const a=A,Y=Date['now'](),b=Math['min'](Math[a(0x1a7)](query[a(0x1a8)]??0x14,0x1),0xc8),k=Math[a(0x1a7)](query['offset']??0x0,0x0);if(!Number[a(0x1a9)](b)||!Number['isFinite'](k))throw new ValidationError('Invalid\x20pagination');const H=q['get'](J),F=H['relations']?.[Z];if(['notes',a(0x1aa)][a(0x1ab)](Z)&&!H[a(0x1ac)]?.['includes'](Z))throw new UnsupportedError('Generic\x20Resource\x20relation\x20\x22'+Z+a(0x1ad)+Z+'\x22');if(Z==='notes'){const s=await x['pg']['query']('SELECT\x20*\x20FROM\x20admin.notes\x20WHERE\x20resource\x20=\x20$1\x20AND\x20resource_id\x20=\x20$2\x20ORDER\x20BY\x20created_at\x20DESC',[J,String(K)]);return{'total':s[a(0x1ae)]['length'],'time':Date['now']()-Y,'rows':s['rows']};}if(Z==='files'){const G=await x['pg']['query']('SELECT\x20*\x20FROM\x20admin.files\x20WHERE\x20resource\x20=\x20$1\x20AND\x20resource_id\x20=\x20$2\x20ORDER\x20BY\x20created_at\x20DESC',[J,String(K)]);return addFileToken(G['rows'],{'file_path':{'type':'file'}},x[a(0x1af)]),{'total':G['rows']['length'],'time':Date['now']()-Y,'rows':G['rows']};}const y=!!(F?.[a(0x1b0)]&&F[a(0x1b1)]&&F[a(0x1b2)]);if(!F||!y&&!F['foreignKey']||!F['resource']&&!F['table'])throw new UnsupportedError('Generic\x20Resource\x20relation\x20\x22'+Z+'\x22\x20requires\x20a\x20project/provider\x20implementation');const r=F['resource']?q['get'](F['resource']):undefined,B=F['table']??r['table'],t=r?.['key']??'id',p=F['fields']?.[a(0x1b3)]?F[a(0x1b4)]['map'](h=>y?'t.'+qi(h):qi(h))['join'](',\x20'):y?'t.*':'*';F['foreignKey']&&autoIndex(B,F['foreignKey'],'btree',x['pg']);const w=y?'SELECT\x20'+p+'\x20FROM\x20'+qt(B)+'\x20t\x0a\x20\x20\x20\x20JOIN\x20'+qt(F['junctionTable'])+'\x20j\x20ON\x20j.'+qi(F[a(0x1b2)])+a(0x1b5)+qi(t)+'\x0a\x20\x20\x20\x20WHERE\x20j.'+qi(F['junctionLocalKey'])+a(0x1b6):'SELECT\x20'+p+'\x20FROM\x20'+qt(B)+'\x20WHERE\x20'+qi(F['foreignKey'])+'\x20=\x20$1\x20LIMIT\x20$2\x20OFFSET\x20$3',R=await x['pg'][a(0x1b7)](w,[K,b,k]);return r&&(await addDictionaryLookupData(R['rows'],r['fields'],x[a(0x1b8)]),await addTableLookupData(R['rows'],r['fields'],x['pg']),addFileToken(R['rows'],r['fields'],x['file'])),{'limit':b,'offset':k,'total':R[a(0x1ae)]['length'],'time':Date['now']()-Y,'rows':R['rows']??null};};}function g(){const m=['max','limit','isFinite','files','includes','capabilities','\x22\x20requires\x20a\x20capabilities\x20\x22','rows','file','junctionTable','junctionLocalKey','junctionForeignKey','length','fields','\x20=\x20t.','\x20=\x20$1\x0a\x20\x20\x20\x20LIMIT\x20$2\x20OFFSET\x20$3','query','dictionary'];g=function(){return m;};return g();}
1
+ import{UnsupportedError,ValidationError}from'../../../errors.js';function y(k,f){k=k-0x91;const C=F();let p=C[k];return p;}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';export function createFindRelation(k,f){return async function C({name:p,id:a,relation:N,query:query={}}){const l=y,W=Date['now'](),n=Math['min'](Math['max'](query['limit']??0x14,0x1),0xc8),A=Math[l(0x91)](query['offset']??0x0,0x0);if(!Number['isFinite'](n)||!Number['isFinite'](A))throw new ValidationError('Invalid\x20pagination');const H=f['get'](p),R=H[l(0x92)]?.[N];if(['notes','files']['includes'](N)&&!H['capabilities']?.['includes'](N))throw new UnsupportedError('Generic\x20Resource\x20relation\x20\x22'+N+l(0x93)+N+'\x22');if(N===l(0x94)){const b=await k['pg'][l(0x95)]('SELECT\x20*\x20FROM\x20admin.notes\x20WHERE\x20resource\x20=\x20$1\x20AND\x20resource_id\x20=\x20$2\x20ORDER\x20BY\x20created_at\x20DESC',[p,String(a)]);return{'total':b[l(0x96)]['length'],'time':Date['now']()-W,'rows':b[l(0x96)]};}if(N==='files'){const P=await k['pg'][l(0x95)]('SELECT\x20*\x20FROM\x20admin.files\x20WHERE\x20resource\x20=\x20$1\x20AND\x20resource_id\x20=\x20$2\x20ORDER\x20BY\x20created_at\x20DESC',[p,String(a)]);return addFileToken(P['rows'],{'file_path':{'type':'file'}},k[l(0x97)]),{'total':P[l(0x96)]['length'],'time':Date[l(0x98)]()-W,'rows':P['rows']};}const u=!!(R?.['junctionTable']&&R['junctionLocalKey']&&R[l(0x99)]);if(!R||!u&&!R['foreignKey']||!R['resource']&&!R['table'])throw new UnsupportedError('Generic\x20Resource\x20relation\x20\x22'+N+l(0x9a));const d=R[l(0x9b)]?f['get'](R['resource']):undefined,j=R['table']??d[l(0x9c)],z=d?.['key']??'id',T=R['fields']?.['length']?R['fields'][l(0x9d)](Q=>u?'t.'+qi(Q):qi(Q))['join'](',\x20'):u?l(0x9e):'*';R['foreignKey']&&autoIndex(j,R[l(0x9f)],'btree',k['pg']);const S=u?l(0xa0)+T+'\x20FROM\x20'+qt(j)+l(0xa1)+qt(R['junctionTable'])+'\x20j\x20ON\x20j.'+qi(R[l(0x99)])+'\x20=\x20t.'+qi(z)+'\x0a\x20\x20\x20\x20WHERE\x20j.'+qi(R[l(0xa2)])+'\x20=\x20$1\x0a\x20\x20\x20\x20LIMIT\x20$2\x20OFFSET\x20$3':l(0xa0)+T+'\x20FROM\x20'+qt(j)+l(0xa3)+qi(R[l(0x9f)])+'\x20=\x20$1\x20LIMIT\x20$2\x20OFFSET\x20$3',i=await k['pg'][l(0x95)](S,[a,n,A]);return d&&(await addDictionaryLookupData(i[l(0x96)],d['fields'],k['dictionary']),await addTableLookupData(i['rows'],d['fields'],k['pg']),addFileToken(i['rows'],d['fields'],k['file'])),{'limit':n,'offset':A,'total':i['rows']['length'],'time':Date['now']()-W,'rows':i['rows']??null};};}function F(){const I=['max','relations','\x22\x20requires\x20a\x20capabilities\x20\x22','notes','query','rows','file','now','junctionForeignKey','\x22\x20requires\x20a\x20project/provider\x20implementation','resource','table','map','t.*','foreignKey','SELECT\x20','\x20t\x0a\x20\x20\x20\x20JOIN\x20','junctionLocalKey','\x20WHERE\x20'];F=function(){return I;};return F();}
@@ -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;AAMhE,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,CA+ChC"}
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;AAMhE,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,CAgDhC"}
@@ -1 +1 @@
1
- import{ValidationError}from'../../../errors.js';import{buildFilters}from'../utils/filters.js';import{assertOperation}from'../utils/permissions.js';function A(x,q){x=x-0x1ae;const C=g();let J=C[x];return J;}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';function g(){const R=['get','read','min','max','limit','offset','filter','isFinite','Invalid\x20pagination','length','table','toLowerCase','sql','\x20WHERE\x20','map','lower(','values','SELECT\x20','join','OFFSET\x20$','rows','fields'];g=function(){return R;};return g();}import{addFileToken}from'./add-file-token.js';import{autoIndex}from'../utils/auto-index.js';export function createFind(x,q){return async function C({name:J,query:query={},user:K}){const w=A,Z=Date['now'](),Y=q[w(0x1ae)](J);assertOperation(Y,w(0x1af),K);const b=Math[w(0x1b0)](Math[w(0x1b1)](query[w(0x1b2)]??0x14,0x1),0xc8),k=Math['max'](query[w(0x1b3)]??0x0,0x0),H=buildFilters(Y,query[w(0x1b4)],0x1,x['pg']),F=buildSort(Y,query['sort']);if(!Number['isFinite'](b)||!Number[w(0x1b5)](k))throw new ValidationError(w(0x1b6));const y=Y['searchable']||Object['keys'](Y['fields'])[w(0x1b4)](p=>Y['fields'][p]?.['searchable']);query['search']&&y[w(0x1b7)]&&(y['map'](p=>autoIndex(Y[w(0x1b8)],p,'text',x['pg'])),H['values']['push'](query['search'][w(0x1b9)]()+'%'),H['sql']+=(H[w(0x1ba)]?'\x20AND\x20':w(0x1bb))+('\x20('+y?.[w(0x1bc)](p=>w(0x1bd)+qt(p)+')\x20LIKE\x20$'+H[w(0x1be)][w(0x1b7)])['join']('\x20OR\x20')+')'));const r=w(0x1bf)+readableFields(Y)[w(0x1c0)](',\x20')+'\x20'+('FROM\x20'+qt(Y['table']))+(''+H['sql']+F+'\x20')+('LIMIT\x20$'+(H['values']['length']+0x1)+'\x20')+(w(0x1c1)+(H[w(0x1be)]['length']+0x2)),B=await x['pg']['query'](r,[...H['values'],b,k]),t=B[w(0x1c2)];return await addDictionaryLookupData(t,Y[w(0x1c3)],x['dictionary']),await addTableLookupData(t,Y['fields'],x['pg']),addFileToken(t,Y['fields'],x['file']),{'limit':b,'offset':k,'total':B['rowCount'],'time':Date['now']()-Z,'rows':t};};}
1
+ import{ValidationError}from'../../../errors.js';import{buildFilters}from'../utils/filters.js';function y(k,f){k=k-0xb5;const C=F();let p=C[k];return p;}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';import{autoIndex}from'../utils/auto-index.js';function F(){const b=['now','limit','filter','isFinite','keys','searchable','search','table','push','toLowerCase','sql','values','item','join','OFFSET\x20$','length','rows'];F=function(){return b;};return F();}export function createFind(k,f){return async function C({name:p,query:query={},user:a}){const i=y,N=Date[i(0xb5)](),W=f['get'](p);assertOperation(W,'read',a);const n=Math['min'](Math['max'](query[i(0xb6)]??0x14,0x1),0xc8),A=Math['max'](query['offset']??0x0,0x0),H=buildFilters(W,query[i(0xb7)],0x1,k['pg']),R=buildSort(W,query['sort']);if(!Number[i(0xb8)](n)||!Number[i(0xb8)](A))throw new ValidationError('Invalid\x20pagination');const u=W['searchable']||Object[i(0xb9)](W['fields'])[i(0xb7)](S=>W['fields'][S]?.[i(0xba)]);query[i(0xbb)]&&u['length']&&(u['map'](S=>autoIndex(W[i(0xbc)],S,'text',k['pg'])),H['values'][i(0xbd)](query['search'][i(0xbe)]()+'%'),H['sql']+=(H[i(0xbf)]?'\x20AND\x20':'\x20WHERE\x20')+('\x20('+u?.['map'](S=>'lower('+qt(S)+')\x20LIKE\x20$'+H[i(0xc0)]['length'])['join']('\x20OR\x20')+')'));const d=W['joins']?.['filter'](S=>S['scope']!==i(0xc1))['map'](S=>S['sql']+'\x20')[i(0xc2)]('\x20')||'',j='SELECT\x20'+readableFields(W,'all')['join'](',\x20')+'\x20'+('FROM\x20'+qt(W['table'])+'\x20t\x20')+(d+'\x20'+H['sql']+'\x20'+R+'\x20')+('LIMIT\x20$'+(H['values']['length']+0x1)+'\x20')+(i(0xc3)+(H['values'][i(0xc4)]+0x2)),z=await k['pg']['query'](j,[...H['values'],n,A]),T=z[i(0xc5)];return await addDictionaryLookupData(T,W['fields'],k['dictionary']),await addTableLookupData(T,W['fields'],k['pg']),addFileToken(T,W['fields'],k['file']),{'limit':n,'offset':A,'total':z['rowCount'],'time':Date[i(0xb5)]()-N,'rows':T};};}
@@ -1 +1 @@
1
- function A(x,q){x=x-0x181;const C=g();let J=C[x];return J;}import{UnsupportedError,ValidationError}from'../../../errors.js';import{createUpdate}from'./update.js';export function createUpdateRelation(x,q){const C=createUpdate(x,q);return async function J({name:K,id:Z,relation:Y,relationId:b,data:k,user:H},F){const B=A,y=q['get'](K),r=y[B(0x181)]?.[Y];if(!r?.[B(0x182)]||!r['foreignKey'])throw new UnsupportedError(B(0x183)+Y);if(Object['hasOwn'](k,r['foreignKey'])&&k[r['foreignKey']]!==Z)throw new ValidationError('Cannot\x20change\x20relation:\x20'+r[B(0x184)]);return C({'name':r['resource'],'id':b,'data':k,'user':H,'where':{'column':r['foreignKey'],'value':Z}},F);};}function g(){const t=['relations','resource','Relation\x20update\x20is\x20not\x20configured:\x20','foreignKey'];g=function(){return t;};return g();}
1
+ import{UnsupportedError,ValidationError}from'../../../errors.js';function F(){const z=['foreignKey'];F=function(){return z;};return F();}import{createUpdate}from'./update.js';function y(k,f){k=k-0xa7;const C=F();let p=C[k];return p;}export function createUpdateRelation(k,f){const C=createUpdate(k,f);return async function p({name:a,id:N,relation:W,relationId:n,data:A,user:H},R){const j=y,u=f['get'](a),d=u['relations']?.[W];if(!d?.['resource']||!d['foreignKey'])throw new UnsupportedError('Relation\x20update\x20is\x20not\x20configured:\x20'+W);if(Object['hasOwn'](A,d[j(0xa7)])&&A[d[j(0xa7)]]!==N)throw new ValidationError('Cannot\x20change\x20relation:\x20'+d['foreignKey']);return C({'name':d['resource'],'id':n,'data':A,'user':H,'where':{'column':d['foreignKey'],'value':N}},R);};}
@@ -1 +1 @@
1
- import{NotFoundError,ValidationError}from'../../../errors.js';import{assertOperation}from'../utils/permissions.js';import{qi,qt,readableFields,writableData}from'../utils/sql.js';import{validateInputData}from'../utils/fields.js';import{clearTableLookupCache}from'./add-table-lookup-data.js';function A(x,q){x=x-0x8b;const C=g();let J=C[x];return J;}export function createUpdate(x,q){return async function C({name:J,id:K,data:Z,user:Y,where:b},k){const G=A,H=q['get'](J);assertOperation(H,'update',Y);const F=writableData(H,Z);if(!F['length'])throw new ValidationError('No\x20writable\x20fields');const y=k?.['pg']??x['pg'];validateInputData({'resource':H,'data':Z,'update':!![]});H['fields']['updated_at']&&F['push'](['updated_at',new Date()]);H[G(0x8b)]['updated_by']&&F['push']([G(0x8c),Y?.['id']]);delete Z[G(0x8d)];const r=F[G(0x8e)](([R],s)=>qi(R)+'\x20=\x20$'+(s+0x1)),B=[...F['map'](([,R])=>R),K];let t='WHERE\x20'+qi(H['key'])+'\x20=\x20$'+B[G(0x8f)];b&&(B['push'](b['value']),t+='\x20AND\x20'+qi(b['column'])+'\x20=\x20$'+B['length']);const p=await y['query']('UPDATE\x20'+qt(H[G(0x90)])+'\x20'+('SET\x20'+r[G(0x91)](',\x20')+'\x20')+(t+'\x20')+('RETURNING\x20'+readableFields(H)[G(0x91)](',\x20')),B),w=p[G(0x92)][0x0];if(!w)throw new NotFoundError(J+':'+K);return clearTableLookupCache(H[G(0x90)],y),await(k?.['audit']??x['audit'])?.['write']({'userId':Y?.['id'],'module':H[G(0x93)],'resource':H['name'],'resourceId':K,'action':'update','fields':Object[G(0x94)](Z)}),w;};}function g(){const h=['fields','updated_by','user_type','map','length','table','join','rows','module','keys'];g=function(){return h;};return g();}
1
+ function F(){const Q=['update','updated_at','updated_by','\x20=\x20$','WHERE\x20','value','SET\x20','keys','module'];F=function(){return Q;};return F();}function y(k,f){k=k-0x113;const C=F();let p=C[k];return p;}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';import{clearTableLookupCache}from'./add-table-lookup-data.js';export function createUpdate(k,f){return async function C({name:p,id:a,data:N,user:W,where:n},A){const P=y,H=f['get'](p);assertOperation(H,P(0x113),W);const R=writableData(H,N);if(!R['length'])throw new ValidationError('No\x20writable\x20fields');const u=A?.['pg']??k['pg'];validateInputData({'resource':H,'data':N,'update':!![]});H['fields'][P(0x114)]&&R['push']([P(0x114),new Date()]);H['fields'][P(0x115)]&&R['push']([P(0x115),W?.['id']]);delete N['user_type'];const d=R['map'](([i],b)=>qi(i)+P(0x116)+(b+0x1)),j=[...R['map'](([,i])=>i),a];let z=P(0x117)+qi(H['key'])+P(0x116)+j['length'];n&&(j['push'](n[P(0x118)]),z+='\x20AND\x20'+qi(n['column'])+'\x20=\x20$'+j['length']);const T=await u['query']('UPDATE\x20'+qt(H['table'])+'\x20'+(P(0x119)+d['join'](',\x20')+'\x20')+(z+'\x20')+('RETURNING\x20'+Object[P(0x11a)](N)['map'](qi)['join'](',\x20')),j),S=T['rows'][0x0];if(!S)throw new NotFoundError(p+':'+a);return clearTableLookupCache(H['table'],u),await(A?.['audit']??k['audit'])?.['write']({'userId':W?.['id'],'module':H[P(0x11b)],'resource':H['name'],'resourceId':a,'action':'update','fields':Object['keys'](N)}),S;};}
@@ -1 +1 @@
1
- function A(x,q){x=x-0x1d7;const C=g();let J=C[x];return J;}import{qi,qt}from'./sql.js';const requestedIndexes=new WeakMap();export function autoIndex(x,q,C='btree',J){const k=A,K=requestedIndexes['get'](J)??new Set();requestedIndexes['set'](J,K);const Z=x+':'+q+':'+C;if(K[k(0x1d7)](Z))return;K['add'](Z),void ensureIndex(x,q,C,J)[k(0x1d8)](()=>{K['delete'](Z);});}async function ensureIndex(x,q,C,J){const H=A,K=x['split']('.'),Z=K['length']===0x2?K[0x0]:H(0x1d9),Y=(x+'_'+q+'_'+C+H(0x1da))['replace'](/[^A-Za-z0-9_]/g,'_'),b=await J[H(0x1db)](H(0x1dc),[Z,Y]);if(b['rowCount'])return;if(C===H(0x1dd)){await J[H(0x1db)]('CREATE\x20EXTENSION\x20IF\x20NOT\x20EXISTS\x20pg_trgm'),await J['query']('CREATE\x20INDEX\x20IF\x20NOT\x20EXISTS\x20'+qi(Y+'_l')+'\x20ON\x20'+qt(x)+'\x20USING\x20btree\x20(lower('+qi(q)+H(0x1de)),await J['query']('CREATE\x20INDEX\x20IF\x20NOT\x20EXISTS\x20'+qi(Y)+'\x20ON\x20'+qt(x)+'\x20USING\x20gin\x20(lower('+qi(q)+H(0x1df));return;}await J['query']('CREATE\x20INDEX\x20IF\x20NOT\x20EXISTS\x20'+qi(Y)+H(0x1e0)+qt(x)+'\x20USING\x20'+C+'\x20('+qi(q)+')');}function g(){const F=['has','catch','public','_idx','query','SELECT\x201\x20FROM\x20pg_indexes\x20WHERE\x20schemaname\x20=\x20$1\x20AND\x20indexname\x20=\x20$2','text',')\x20text_pattern_ops)',')\x20gin_trgm_ops)','\x20ON\x20'];g=function(){return F;};return g();}
1
+ import{qi,qt}from'./sql.js';function F(){const R=['add','SELECT\x201\x20FROM\x20pg_indexes\x20WHERE\x20schemaname\x20=\x20$1\x20AND\x20indexname\x20=\x20$2','query','\x20ON\x20',')\x20text_pattern_ops)','CREATE\x20INDEX\x20IF\x20NOT\x20EXISTS\x20','\x20USING\x20'];F=function(){return R;};return F();}function y(k,f){k=k-0x181;const C=F();let p=C[k];return p;}const requestedIndexes=new WeakMap();export function autoIndex(k,f,C='btree',p){const A=y,a=requestedIndexes['get'](p)??new Set();requestedIndexes['set'](p,a);const N=k+':'+f+':'+C;if(a['has'](N))return;a[A(0x181)](N),void ensureIndex(k,f,C,p)['catch'](()=>{a['delete'](N);});}async function ensureIndex(k,f,C,p){const H=y,a=k['split']('.'),N=a['length']===0x2?a[0x0]:'public',W=(k+'_'+f+'_'+C+'_idx')['replace'](/[^A-Za-z0-9_]/g,'_'),n=await p['query'](H(0x182),[N,W]);if(n['rowCount'])return;if(C==='text'){await p[H(0x183)]('CREATE\x20EXTENSION\x20IF\x20NOT\x20EXISTS\x20pg_trgm'),await p['query']('CREATE\x20INDEX\x20IF\x20NOT\x20EXISTS\x20'+qi(W+'_l')+H(0x184)+qt(k)+'\x20USING\x20btree\x20(lower('+qi(f)+H(0x185)),await p['query']('CREATE\x20INDEX\x20IF\x20NOT\x20EXISTS\x20'+qi(W)+'\x20ON\x20'+qt(k)+'\x20USING\x20gin\x20(lower('+qi(f)+')\x20gin_trgm_ops)');return;}await p['query'](H(0x186)+qi(W)+'\x20ON\x20'+qt(k)+H(0x187)+C+'\x20('+qi(f)+')');}
@@ -1 +1 @@
1
- function g(){const Z=['writable','minLength','maxLength','length','maxLength\x20exceeded:\x20','number','maximum','enum','join','pattern'];g=function(){return Z;};return g();}import{ValidationError}from'../../../errors.js';export{readableFields,writableData,fieldColumn}from'./sql.js';function A(x,q){x=x-0x11d;const C=g();let J=C[x];return J;}const validateInputData=({resource:x,data:q,update:update=![]})=>{const K=A;for(const [C,J]of Object['entries'](x['fields'])){if(J['required']&&J['writable']!==![]&&(q[C]===undefined||q[C]===null)&&!update)throw new ValidationError('Required\x20field:\x20'+C);if(J['required']&&J[K(0x11d)]!==![]&&Object['hasOwn'](q,C)&&(q[C]===undefined||q[C]===null)&&update)throw new ValidationError('Required\x20field:\x20'+C);if(J[K(0x11e)]&&typeof q[C]==='string'&&q[C]['length']<J['minLength'])throw new ValidationError('minLength\x20not\x20met:\x20'+C);if(J[K(0x11f)]&&typeof q[C]==='string'&&q[C][K(0x120)]>J[K(0x11f)])throw new ValidationError(K(0x121)+C);if(J['minimum']&&typeof q[C]==='number'&&q[C]<J['minimum'])throw new ValidationError(C+'\x20should\x20be\x20>=\x20'+J['minimum']);if(J['maximum']&&typeof q[C]===K(0x122)&&q[C]>J[K(0x123)])throw new ValidationError(C+'\x20should\x20be\x20<=\x20'+J['maximum']);if(J['enum']&&q[C]&&!J[K(0x124)]['includes'](q[C]))throw new ValidationError(C+'\x20should\x20be\x20one\x20of\x20('+J['enum'][K(0x125)](',\x20')+')');if(J['pattern']&&typeof q[C]==='string'&&!new RegExp(J[K(0x126)])['test'](q[C]))throw new ValidationError(C+'\x20should\x20match\x20regular\x20expression\x20('+J['pattern']+')');}};export{validateInputData};
1
+ import{ValidationError}from'../../../errors.js';export{readableFields,writableData,fieldColumn}from'./sql.js';const validateInputData=({resource:k,data:f,update:update=![]})=>{const a=y;for(const [C,p]of Object['entries'](k[a(0xd7)])){if(p['required']&&p[a(0xd8)]!==![]&&(f[C]===undefined||f[C]===null)&&!update)throw new ValidationError('Required\x20field:\x20'+C);if(p['required']&&p['writable']!==![]&&Object['hasOwn'](f,C)&&(f[C]===undefined||f[C]===null)&&update)throw new ValidationError(a(0xd9)+C);if(p[a(0xda)]&&typeof f[C]==='string'&&f[C][a(0xdb)]<p['minLength'])throw new ValidationError('minLength\x20not\x20met:\x20'+C);if(p[a(0xdc)]&&typeof f[C]==='string'&&f[C]['length']>p['maxLength'])throw new ValidationError('maxLength\x20exceeded:\x20'+C);if(p['minimum']&&typeof f[C]==='number'&&f[C]<p['minimum'])throw new ValidationError(C+'\x20should\x20be\x20>=\x20'+p['minimum']);if(p['maximum']&&typeof f[C]==='number'&&f[C]>p[a(0xdd)])throw new ValidationError(C+a(0xde)+p['maximum']);if(p['enum']&&f[C]&&!p[a(0xdf)][a(0xe0)](f[C]))throw new ValidationError(C+'\x20should\x20be\x20one\x20of\x20('+p['enum'][a(0xe1)](',\x20')+')');if(p['pattern']&&typeof f[C]===a(0xe2)&&!new RegExp(p['pattern'])['test'](f[C]))throw new ValidationError(C+'\x20should\x20match\x20regular\x20expression\x20('+p[a(0xe3)]+')');}};function y(k,f){k=k-0xd7;const C=F();let p=C[k];return p;}export{validateInputData};function F(){const N=['fields','writable','Required\x20field:\x20','minLength','length','maxLength','maximum','\x20should\x20be\x20<=\x20','enum','includes','join','string','pattern'];F=function(){return N;};return F();}
@@ -1 +1 @@
1
- const w=A;import{fieldColumn,qi}from'./sql.js';import{ValidationError}from'../../../errors.js';import{autoIndex}from'./auto-index.js';const filterOperators=new Set(['eq','ne','gt','gte','lt','lte','in',w(0xe6),'like',w(0xe7),w(0xe8)]);export function parseFilterQuery(x){const R=w,q={...isRecord(x['filter'])?x['filter']:{}};for(const [C,J]of Object['entries'](x)){const K=/^filter\[([^\]]+)\](?:\[([^\]]+)\])?$/['exec'](C);if(!K)continue;const [,Z,Y]=K;if(!Z)continue;if(!Y){q[Z]=J;continue;}if(!filterOperators['has'](Y))throw new ValidationError('Unsupported\x20filter\x20operator:\x20'+Y);const b=isRecord(q[Z])?q[Z]:{};b[Y]=(Y==='in'||Y==='nin')&&typeof J==='string'?J['split'](','):J,q[Z]=b;}return Object[R(0xe9)](q)['length']?q:undefined;}export function buildFilters(x,q,C=0x1,J){const s=w,K=[],Z=[];for(const [Y,b]of Object['entries'](q??{})){const k=x[s(0xea)][Y];if(!k||k['filter']!==!![]&&k[s(0xeb)]!==!![])throw new ValidationError(s(0xec)+Y);const H=qi(fieldColumn(x,Y)),F=isRecord(b)?b:{'eq':b};for(const [y,r]of Object['entries'](F)){if(!filterOperators[s(0xed)](y))throw new ValidationError('Unsupported\x20filter\x20operator:\x20'+y);if((y===s(0xee)||y==='ilike')&&k[s(0xef)]!==s(0xf0)&&k[s(0xef)]!==s(0xf1))throw new ValidationError('Operator\x20'+y+s(0xf2)+Y);J&&autoIndex(x['table'],fieldColumn(x,Y),indexTypeFor(k[s(0xef)],y),J);if(y==='null'){K['push'](H+'\x20IS\x20'+(isTruthy(r)?'':'NOT\x20')+'NULL');continue;}if(y==='in'||y==='nin'){const p=Array['isArray'](r)?r:[r];if(p['length']===0x0){K[s(0xf3)](y==='in'?'FALSE':'TRUE');continue;}Z['push'](p),K[s(0xf3)](H+'\x20'+(y==='in'?'=\x20ANY':s(0xf4))+'($'+(C+Z['length']-0x1)+')');continue;}const B={'eq':'=','ne':'<>','gt':'>','gte':'>=','lt':'<','lte':'<=','like':'like'},t='$'+(C+Z['length']);if(y==='like'){Z[s(0xf3)](r+'%'),K['push']('lower('+H+s(0xf5)+t+')');continue;}Z[s(0xf3)](r),K['push'](H+'\x20'+B[y]+'\x20'+t);}}return{'sql':K['length']?s(0xf6)+K['join']('\x20AND\x20'):'','values':Z};}function isRecord(x){return typeof x==='object'&&x!==null&&!Array['isArray'](x);}function A(x,q){x=x-0xe6;const C=g();let J=C[x];return J;}function isTruthy(x){return x===!![]||x==='true'||x==='1'||x===0x1;}function indexTypeFor(x,q){const G=w;if(q===G(0xee)||q==='ilike')return G(0xf1);if(x==='geom'||x===G(0xf7))return G(0xf8);return G(0xf9);}function g(){const h=['nin','ilike','null','keys','fields','filterable','Field\x20is\x20not\x20filterable:\x20','has','like','type','string','text','\x20requires\x20a\x20text\x20field:\x20','push','<>\x20ALL',')\x20like\x20lower(','\x20WHERE\x20','geometry','gist','btree'];g=function(){return h;};return g();}
1
+ const S=y;import{fieldColumn,qi}from'./sql.js';function y(k,f){k=k-0x149;const C=F();let p=C[k];return p;}import{ValidationError}from'../../../errors.js';import{autoIndex}from'./auto-index.js';const filterOperators=new Set(['eq','ne','gt','gte','lt',S(0x149),'in','nin','like','ilike',S(0x14a)]);export function parseFilterQuery(k){const i=S,f={...isRecord(k['filter'])?k[i(0x14b)]:{}};for(const [C,p]of Object['entries'](k)){const a=/^filter\[([^\]]+)\](?:\[([^\]]+)\])?$/['exec'](C);if(!a)continue;const [,N,W]=a;if(!N)continue;if(!W){f[N]=p;continue;}if(!filterOperators[i(0x14c)](W))throw new ValidationError('Unsupported\x20filter\x20operator:\x20'+W);const n=isRecord(f[N])?f[N]:{};n[W]=(W==='in'||W==='nin')&&typeof p==='string'?p['split'](','):p,f[N]=n;}return Object['keys'](f)[i(0x14d)]?f:undefined;}function F(){const Q=['lte','null','filter','has','length','entries','like','type','string','Operator\x20','table','NOT\x20','nin','push','=\x20ANY','\x20WHERE\x20','join','ilike','text','geom','btree'];F=function(){return Q;};return F();}export function buildFilters(k,f,C=0x1,p){const b=S,a=[],N=[];for(const [W,n]of Object[b(0x14e)](f??{})){const A=k['fields'][W];if(!A||A['filter']!==!![]&&A['filterable']!==!![])throw new ValidationError('Field\x20is\x20not\x20filterable:\x20'+W);const H=qi(fieldColumn(k,W)),R=isRecord(n)?n:{'eq':n};for(const [u,d]of Object['entries'](R)){if(!filterOperators['has'](u))throw new ValidationError('Unsupported\x20filter\x20operator:\x20'+u);if((u===b(0x14f)||u==='ilike')&&A[b(0x150)]!==b(0x151)&&A['type']!=='text')throw new ValidationError(b(0x152)+u+'\x20requires\x20a\x20text\x20field:\x20'+W);p&&autoIndex(k[b(0x153)],fieldColumn(k,W),indexTypeFor(A['type'],u),p);if(u==='null'){a['push'](H+'\x20IS\x20'+(isTruthy(d)?'':b(0x154))+'NULL');continue;}if(u==='in'||u===b(0x155)){const T=Array['isArray'](d)?d:[d];if(T['length']===0x0){a[b(0x156)](u==='in'?'FALSE':'TRUE');continue;}N['push'](T),a['push'](H+'\x20'+(u==='in'?b(0x157):'<>\x20ALL')+'($'+(C+N['length']-0x1)+')');continue;}const j={'eq':'=','ne':'<>','gt':'>','gte':'>=','lt':'<','lte':'<=','like':'like'},z='$'+(C+N['length']);if(u==='like'){N[b(0x156)](d+'%'),a['push']('lower('+H+')\x20like\x20lower('+z+')');continue;}N['push'](d),a['push'](H+'\x20'+j[u]+'\x20'+z);}}return{'sql':a[b(0x14d)]?b(0x158)+a[b(0x159)]('\x20AND\x20'):'','values':N};}function isRecord(k){return typeof k==='object'&&k!==null&&!Array['isArray'](k);}function isTruthy(k){return k===!![]||k==='true'||k==='1'||k===0x1;}function indexTypeFor(k,f){const P=S;if(f==='like'||f===P(0x15a))return P(0x15b);if(k===P(0x15c)||k==='geometry')return'gist';return P(0x15d);}
@@ -1 +1 @@
1
- import{ForbiddenError}from'../../../errors.js';function A(x,q){x=x-0x184;const C=g();let J=C[x];return J;}function g(){const Y=['config','access','admin','type'];g=function(){return Y;};return g();}import{getContext}from'../../../index.js';export function assertOperation(x,q,C){const Z=A,J=getContext()[Z(0x184)];if(J['debug'])return;if(!x['operations']['includes'](q))throw new ForbiddenError(x['name']+'.'+q+'\x20is\x20disabled');if(x[Z(0x185)]!=='public'&&C===undefined)throw new ForbiddenError('Authentication\x20required');if(x[Z(0x185)]===Z(0x186)&&C?.['type']!==Z(0x186))throw new ForbiddenError('Admin\x20access\x20required');if(C?.[Z(0x187)]!==Z(0x186)){const K=(x['permission']??x['name'])+':'+q;if(!C?.['permissions']?.['includes'](K))throw new ForbiddenError('Missing\x20permission:\x20'+K);}}
1
+ function y(k,f){k=k-0xae;const C=F();let p=C[k];return p;}function F(){const W=['config','operations','name','access','admin','Admin\x20access\x20required'];F=function(){return W;};return F();}import{ForbiddenError}from'../../../errors.js';import{getContext}from'../../../index.js';export function assertOperation(k,f,C){const N=y,p=getContext()[N(0xae)];if(p['debug'])return;if(!k[N(0xaf)]['includes'](f))throw new ForbiddenError(k[N(0xb0)]+'.'+f+'\x20is\x20disabled');if(k[N(0xb1)]!=='public'&&C===undefined)throw new ForbiddenError('Authentication\x20required');if(k['access']==='admin'&&C?.['type']!==N(0xb2))throw new ForbiddenError(N(0xb3));if(C?.['type']!==N(0xb2)){const a=(k['permission']??k['name'])+':'+f;if(!C?.['permissions']?.['includes'](a))throw new ForbiddenError('Missing\x20permission:\x20'+a);}}
@@ -1 +1 @@
1
- function A(x,q){x=x-0x10e;const C=g();let J=C[x];return J;}import{fieldColumn,qi}from'./sql.js';import{ValidationError}from'../../../errors.js';export function buildSort(x,q){const b=A;if(!q?.['length'])return'';typeof q==='string'&&(q=[q]);const C=q['map'](J=>{const K=J['startsWith']('-'),Z=K?J['slice'](0x1):J,Y=x['fields'][Z];if(!Y||Y['sort']!==!![]&&Y['sortable']!==!![])throw new ValidationError('Field\x20is\x20not\x20sortable:\x20'+Z);return qi(fieldColumn(x,Z))+'\x20'+(K?'DESC':'ASC');});return'\x20ORDER\x20BY\x20'+C[b(0x10e)](',\x20');}function g(){const k=['join'];g=function(){return k;};return g();}
1
+ import{fieldColumn,qi}from'./sql.js';function F(){const A=['join'];F=function(){return A;};return F();}function y(k,f){k=k-0x113;const C=F();let p=C[k];return p;}import{ValidationError}from'../../../errors.js';export function buildSort(k,f){const n=y;if(!f?.['length'])return'';typeof f==='string'&&(f=[f]);const C=f['map'](p=>{const a=p['startsWith']('-'),N=a?p['slice'](0x1):p,W=k['fields'][N];if(!W||W['sort']!==!![]&&W['sortable']!==!![])throw new ValidationError('Field\x20is\x20not\x20sortable:\x20'+N);return qi(fieldColumn(k,N))+'\x20'+(a?'DESC':'ASC');});return'\x20ORDER\x20BY\x20'+C[n(0x113)](',\x20');}
@@ -4,7 +4,7 @@ export declare const quoteIdentifier: (value: string) => string;
4
4
  /** Quote a schema-qualified PostgreSQL table name. */
5
5
  export declare const quoteTable: (value: string) => string;
6
6
  export declare function fieldColumn(resource: ResourceContract, name: string): string;
7
- export declare function readableFields(resource: ResourceContract): string[];
7
+ export declare function readableFields(resource: ResourceContract, scope?: string): string[];
8
8
  export declare function writableData(resource: ResourceContract, data: Record<string, unknown>): Array<[
9
9
  string,
10
10
  unknown
@@ -1 +1 @@
1
- {"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../../../../src/plugins/resource/utils/sql.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,6CAA6C;AAC7C,eAAO,MAAM,eAAe,UAAW,MAAM,KAAG,MAA0C,CAAC;AAC3F,sDAAsD;AACtD,eAAO,MAAM,UAAU,UAAW,MAAM,KAAG,MAAyD,CAAC;AACrG,wBAAgB,WAAW,CAAC,QAAQ,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAS5E;AACD,wBAAgB,cAAc,CAAC,QAAQ,EAAE,gBAAgB,GAAG,MAAM,EAAE,CAQnE;AACD,wBAAgB,YAAY,CAAC,QAAQ,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC;IAC3F,MAAM;IACN,OAAO;CACV,CAAC,CAaD;AAED,eAAO,MAAM,EAAE,wBAAkB,CAAC;AAClC,eAAO,MAAM,EAAE,mBAAa,CAAC"}
1
+ {"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../../../../src/plugins/resource/utils/sql.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,6CAA6C;AAC7C,eAAO,MAAM,eAAe,UAAW,MAAM,KAAG,MAA0C,CAAC;AAC3F,sDAAsD;AACtD,eAAO,MAAM,UAAU,UAAW,MAAM,KAAG,MAAyD,CAAC;AACrG,wBAAgB,WAAW,CAAC,QAAQ,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAS5E;AACD,wBAAgB,cAAc,CAAC,QAAQ,EAAE,gBAAgB,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAQnF;AACD,wBAAgB,YAAY,CAAC,QAAQ,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC;IAC3F,MAAM;IACN,OAAO;CACV,CAAC,CAmBD;AAED,eAAO,MAAM,EAAE,wBAAkB,CAAC;AAClC,eAAO,MAAM,EAAE,mBAAa,CAAC"}
@@ -1 +1 @@
1
- const Y=A;import{ValidationError}from'../../../errors.js';export const quoteIdentifier=x=>'\x22'+x[Y(0x7f)](/"/g,'\x22\x22')+'\x22';export const quoteTable=x=>x[Y(0x80)]('.')['map'](quoteIdentifier)['join']('.');export function fieldColumn(x,q){const b=Y;if(q===x['key'])return x['key'];const C=x[b(0x81)][q];if(!C)throw new ValidationError('Unknown\x20field:\x20'+q);return C['column']??q;}export function readableFields(x){const k=Y,q=Object['entries'](x['fields'])['filter'](([,C])=>C['read']!==![]&&C['readable']!==![])['map'](([C,J])=>quoteIdentifier(J['column']??C)+k(0x82)+quoteIdentifier(C));return!x['fields'][x['key']]&&q['unshift'](quoteIdentifier(x[k(0x83)])),q;}function g(){const F=['replace','split','fields','\x20AS\x20','key','write','Field\x20is\x20not\x20writable:\x20','push','column'];g=function(){return F;};return g();}export function writableData(x,q){const H=Y,C=[];for(const [J,K]of Object['entries'](q)){const Z=x['fields'][J];if(!Z||Z[H(0x84)]===![]||Z['writable']===![])throw new ValidationError(H(0x85)+J);C[H(0x86)]([Z[H(0x87)]??J,K]);}return C;}function A(x,q){x=x-0x7f;const C=g();let J=C[x];return J;}export const qi=quoteIdentifier;export const qt=quoteTable;
1
+ import{ValidationError}from'../../../errors.js';function F(){const H=['key','fields','entries','read','all','map','column','unshift','writable','type','push'];F=function(){return H;};return F();}export const quoteIdentifier=k=>'\x22'+k['replace'](/"/g,'\x22\x22')+'\x22';function y(k,f){k=k-0x1d9;const C=F();let p=C[k];return p;}export const quoteTable=k=>k['split']('.')['map'](quoteIdentifier)['join']('.');export function fieldColumn(k,f){const W=y;if(f===k[W(0x1d9)])return k['key'];const C=k[W(0x1da)][f];if(!C)throw new ValidationError('Unknown\x20field:\x20'+f);return C['column']??f;}export function readableFields(k,f){const n=y,C=Object[n(0x1db)](k[n(0x1da)])['filter'](([,p])=>p[n(0x1dc)]!==![]&&p['readable']!==![]&&(f?(p['scope']??n(0x1dd))===f:!![]))[n(0x1de)](([p,a])=>quoteIdentifier(a[n(0x1df)]??p)+'\x20AS\x20'+quoteIdentifier(p));return!k['fields'][k[n(0x1d9)]]&&C[n(0x1e0)](quoteIdentifier(k[n(0x1d9)])),C;}export function writableData(k,f){const A=y,C=[];for(const [p,a]of Object['entries'](f)){const N=k[A(0x1da)][p];if(!N||N['write']===![]||N[A(0x1e1)]===![])throw new ValidationError('Field\x20is\x20not\x20writable:\x20'+p);if((N['write']??N['writable'])!==!![])continue;if(N[A(0x1e2)]==='date'&&!f[p])continue;C[A(0x1e3)]([N['column']??p,a]);}return C;}export const qi=quoteIdentifier;export const qt=quoteTable;
@@ -1 +1 @@
1
- function A(x,q){x=x-0x196;const C=g();let J=C[x];return J;}function g(){const C=['connection'];g=function(){return C;};return g();}const q=A,getIP=x=>(x['headers']?.['x-real-ip']||x['headers']?.['x-forwarded-for']||x['ip']||x[q(0x196)]?.['remoteAddress']||'')['split'](':')['pop']();export default getIP;
1
+ function y(k,f){k=k-0x1d5;const C=F();let p=C[k];return p;}function F(){const C=['x-real-ip','connection','pop'];F=function(){return C;};return F();}const f=y,getIP=k=>(k['headers']?.[f(0x1d5)]||k['headers']?.['x-forwarded-for']||k['ip']||k[f(0x1d6)]?.['remoteAddress']||'')['split'](':')[f(0x1d7)]();export default getIP;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fcore",
3
- "version": "0.0.1-beta.12",
3
+ "version": "0.0.1-beta.14",
4
4
  "description": "Reusable backend foundation for OpenGIS Node.js applications",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",