@opengis/fcore 0.0.29 → 0.0.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +3 -3
- package/README.md +71 -71
- package/dist/config.js +1 -1
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -1
- package/dist/errors.js +1 -1
- package/dist/fastify.js +1 -1
- package/dist/fcore.d.ts +2 -0
- package/dist/fcore.d.ts.map +1 -1
- package/dist/fcore.js +1 -1
- package/dist/migrations/cli.js +1 -1
- package/dist/migrations/runner.js +1 -1
- package/dist/modules/auth/adduser-cli.js +1 -1
- package/dist/modules/auth/passwd-cli.js +1 -1
- package/dist/modules/auth/permission-cli.js +1 -1
- package/dist/modules/auth/route.d.ts.map +1 -1
- package/dist/modules/auth/route.js +1 -1
- package/dist/modules/auth/schema.js +1 -1
- package/dist/modules/auth/services/change-password.js +1 -1
- package/dist/modules/auth/services/get-current-user.d.ts +2 -2
- package/dist/modules/auth/services/get-current-user.d.ts.map +1 -1
- package/dist/modules/auth/services/get-current-user.js +1 -1
- package/dist/modules/auth/services/registration.js +1 -1
- package/dist/modules/auth/services/verify-two-factor.js +1 -1
- package/dist/modules/file/mime.js +1 -1
- package/dist/modules/file/route.js +1 -1
- package/dist/modules/file/schema.js +1 -1
- package/dist/modules/file/services/get-file.js +1 -1
- package/dist/modules/file/services/resize-file.js +1 -1
- package/dist/modules/file/services/upload-file.js +1 -1
- package/dist/modules/resource/route.js +1 -1
- package/dist/modules/resource/schema.d.ts +3 -2
- package/dist/modules/resource/schema.d.ts.map +1 -1
- package/dist/modules/resource/schema.js +1 -1
- package/dist/modules/resource/services/add-note.js +1 -1
- package/dist/modules/resource/services/add-resource-file.js +1 -1
- package/dist/modules/resource/services/create-resource-relation.js +1 -1
- package/dist/modules/resource/services/create-resource.js +1 -1
- package/dist/modules/resource/services/delete-resource-relation.js +1 -1
- package/dist/modules/resource/services/delete-resource.js +1 -1
- package/dist/modules/resource/services/export-resource.js +1 -1
- package/dist/modules/resource/services/generate-resource-code.js +1 -1
- package/dist/modules/resource/services/get-resource-schema.js +1 -1
- package/dist/modules/resource/services/get-resource.d.ts +1 -1
- package/dist/modules/resource/services/get-resource.js +1 -1
- package/dist/modules/resource/services/list-resource-as-user.js +1 -1
- package/dist/modules/resource/services/list-resource-list.js +1 -1
- package/dist/modules/resource/services/list-resource-relation.js +1 -1
- package/dist/modules/resource/services/list-resources.js +1 -1
- package/dist/modules/resource/services/search-resource.js +1 -1
- package/dist/modules/resource/services/suggest-resource.d.ts.map +1 -1
- package/dist/modules/resource/services/suggest-resource.js +1 -1
- package/dist/modules/resource/services/update-resource-relation.js +1 -1
- package/dist/modules/resource/services/update-resource.js +1 -1
- package/dist/modules/resource/services/upload-resource-file.js +1 -1
- package/dist/modules/system/route.js +1 -1
- package/dist/modules/system/schema.js +1 -1
- package/dist/modules/system/services/check-system.js +1 -1
- package/dist/modules/system/services/get-access.js +1 -1
- package/dist/modules/system/services/get-api-list.js +1 -1
- package/dist/modules/system/services/get-audit-log.js +1 -1
- package/dist/modules/system/services/get-dictionary.js +1 -1
- package/dist/modules/system/services/get-resource-access.js +1 -1
- package/dist/modules/system/services/get-resource-scopes.js +1 -1
- package/dist/modules/system/services/get-system-log.js +1 -1
- package/dist/modules/system/services/get-system-settings.js +1 -1
- package/dist/modules/system/services/list-dictionaries.js +1 -1
- package/dist/modules/system/services/set-access.js +1 -1
- package/dist/modules/system/services/set-resource-access.js +1 -1
- package/dist/modules/system/services/set-resource-scopes.js +1 -1
- package/dist/modules/system/services/update-dictionary.js +1 -1
- package/dist/modules/system/services/update-system-settings.js +1 -1
- package/dist/modules/utils/require-admin.js +1 -1
- package/dist/modules/utils/safe-user.js +1 -1
- package/dist/modules/utils/unsupported.js +1 -1
- package/dist/plugins/audit/audit.js +1 -1
- package/dist/plugins/audit/services/write-audit.js +1 -1
- package/dist/plugins/auth/get-user-permissions.js +1 -1
- package/dist/plugins/auth/index.d.ts.map +1 -1
- package/dist/plugins/auth/index.js +1 -1
- package/dist/plugins/auth/verifyUser.js +1 -1
- package/dist/plugins/dictionary.js +1 -1
- package/dist/plugins/file.js +1 -1
- package/dist/plugins/hooks.d.ts +14 -0
- package/dist/plugins/hooks.d.ts.map +1 -0
- package/dist/plugins/hooks.js +1 -0
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +1 -1
- package/dist/plugins/jwt.js +1 -1
- package/dist/plugins/logger/index.js +1 -1
- package/dist/plugins/logger/transport.js +1 -1
- package/dist/plugins/pg.js +1 -1
- package/dist/plugins/redis.js +1 -1
- package/dist/plugins/resource/resource.js +1 -1
- package/dist/plugins/resource/resource.registry.js +1 -1
- package/dist/plugins/resource/resource.types.d.ts +1 -0
- package/dist/plugins/resource/resource.types.d.ts.map +1 -1
- package/dist/plugins/resource/services/add-dictionary-lookup-data.js +1 -1
- package/dist/plugins/resource/services/add-file-token.js +1 -1
- package/dist/plugins/resource/services/add-table-lookup-data.js +1 -1
- package/dist/plugins/resource/services/create-relation.js +1 -1
- package/dist/plugins/resource/services/create.js +1 -1
- package/dist/plugins/resource/services/delete-relation.js +1 -1
- package/dist/plugins/resource/services/delete.js +1 -1
- package/dist/plugins/resource/services/find-one.d.ts.map +1 -1
- package/dist/plugins/resource/services/find-one.js +1 -1
- package/dist/plugins/resource/services/find-relation.js +1 -1
- package/dist/plugins/resource/services/find.js +1 -1
- package/dist/plugins/resource/services/get-table-columns.js +1 -1
- package/dist/plugins/resource/services/update-relation.js +1 -1
- package/dist/plugins/resource/services/update.js +1 -1
- package/dist/plugins/resource/utils/auto-index.js +1 -1
- package/dist/plugins/resource/utils/fields.js +1 -1
- package/dist/plugins/resource/utils/filters.js +1 -1
- package/dist/plugins/resource/utils/permissions.js +1 -1
- package/dist/plugins/resource/utils/scope.js +1 -1
- package/dist/plugins/resource/utils/sort.js +1 -1
- package/dist/plugins/resource/utils/sql.js +1 -1
- package/dist/plugins/resource/utils/summary.js +1 -1
- package/dist/shared/getIP.js +1 -1
- package/migrations/20260903130000_move_notes_files_to_admin.sql +17 -17
- package/migrations/20260929120000_allow_user_only_role_scopes.sql +1 -1
- package/package.json +92 -92
|
@@ -1 +1 @@
|
|
|
1
|
-
import{UnsupportedError}from'../../../errors.js';function
|
|
1
|
+
import{UnsupportedError}from'../../../errors.js';function g(i,E){i=i-0x6a;const W=T();let M=W[i];return M;}function T(){const r=['get','includes','Generic\x20Resource\x20relation\x20\x22','\x22\x20requires\x20a\x20capabilities\x20\x22','INSERT\x20INTO\x20admin.notes(resource,resource_id,body)\x20VALUES\x20($1,$2,$3)\x20RETURNING\x20*','rows','files','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*','size','\x22\x20requires\x20a\x20project/provider\x20implementation','resource','Relation\x20update\x20is\x20not\x20configured:\x20'];T=function(){return r;};return T();}import{createCreate}from'./create.js';export function createCreateRelation(i,E){const W=createCreate(i,E);return async function M({name:m,id:P,relation:D,data:x,user:Z},f){const o=g,b=f?.['pg']??i['pg'],K=E[o(0x6a)](m);if(['notes','files']['includes'](D)&&!K['capabilities']?.[o(0x6b)](D))throw new UnsupportedError(o(0x6c)+D+o(0x6d)+D+'\x22');if(D==='notes'){const y=await b['query'](o(0x6e),[m,String(P),x?.['body']]);return y[o(0x6f)][0x0];}if(D===o(0x70)){const s=await b['query'](o(0x71),[m,String(P),x?.['filePath'],x?.[o(0x72)]??null]);return s[o(0x6f)][0x0];}const J=K['relations']?.[D];if(!J?.['foreignKey']||!J['resource']&&!J['table'])throw new UnsupportedError(o(0x6c)+D+o(0x73));if(!x)throw new UnsupportedError('No\x20data\x20provided\x20for\x20relation:\x20'+x);if(!J[o(0x74)])throw new UnsupportedError(o(0x75)+D);x[J['foreignKey']]=P;const Q=await W({'name':J['resource'],'data':x??{},'user':Z});return Q;};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ValidationError}from'../../../errors.js';
|
|
1
|
+
import{ValidationError}from'../../../errors.js';function T(){const G=['push','created_by','table','audit','create'];T=function(){return G;};return T();}function g(i,E){i=i-0xf3;const W=T();let M=W[i];return M;}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(i,E){return async function W({name:M,data:m,user:P},D){const r=g,x=E['get'](M);assertOperation(x,'create',P),validateInputData({'resource':x,'data':m});const Z=writableData(x,m);x['fields']['created_at']&&Z[r(0xf3)](['created_at',new Date()]);x['fields']['created_by']&&Z['push']([r(0xf4),P?.['id']]);if(!Z['length'])throw new ValidationError('No\x20writable\x20fields');const f=Z['map'](([s])=>qi(s)),b=Z['map']((s,o)=>'$'+(o+0x1)),K=Z['map'](([,s])=>s),J=D?.['pg']??i['pg'],Q=await J['query']('INSERT\x20INTO\x20'+qt(x['table'])+'\x20('+f['join'](',\x20')+')\x20'+('VALUES\x20('+b['join'](',\x20')+')\x20')+'RETURNING\x20*',K),y=Q['rows'][0x0];return clearTableLookupCache(x[r(0xf5)],J),await(D?.[r(0xf6)]??i['audit'])?.['write']({'userId':P?.['id'],'module':x['module'],'resource':x['name'],'resourceId':y[x['key']],'action':r(0xf7),'fields':Object['keys'](m)}),y;};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{UnsupportedError}from'../../../errors.js';import{createRemove}from'./delete.js';export function createDeleteRelation(i,E){const W=createRemove(i,E);return async function M({name:m,id:P,relation:D,relationId:x,user:Z},f){const y=g,b=f?.['pg']??i['pg'],K=E[y(0x175)](m);if([y(0x176),'files']['includes'](D)&&!K['capabilities']?.[y(0x177)](D))throw new UnsupportedError('Generic\x20Resource\x20relation\x20\x22'+D+'\x22\x20requires\x20a\x20capabilities\x20\x22'+D+'\x22');if(D==='notes')return await b[y(0x178)](y(0x179),[x,m,String(P)]),{'success':!![]};if(D==='files')return await b[y(0x178)]('DELETE\x20FROM\x20admin.files\x20WHERE\x20file_id\x20=\x20$1\x20AND\x20resource\x20=\x20$2\x20AND\x20resource_id\x20=\x20$3',[x,m,String(P)]),{'success':!![]};const J=K['relations']?.[D];if(!J?.['resource']||!J['foreignKey'])throw new UnsupportedError(y(0x17a)+D+'\x22\x20requires\x20a\x20project/provider\x20implementation');const Q=await W({'name':J['resource'],'id':x,'user':Z,'where':{'column':J[y(0x17b)],'value':P}},f);return{'success':Q};};}function g(i,E){i=i-0x175;const W=T();let M=W[i];return M;}function T(){const s=['get','notes','includes','query','DELETE\x20FROM\x20admin.notes\x20WHERE\x20note_id\x20=\x20$1\x20AND\x20resource\x20=\x20$2\x20AND\x20resource_id\x20=\x20$3','Generic\x20Resource\x20relation\x20\x22','foreignKey'];T=function(){return s;};return T();}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{assertOperation}from'../utils/permissions.js';function
|
|
1
|
+
import{assertOperation}from'../utils/permissions.js';function g(i,E){i=i-0xe1;const W=T();let M=W[i];return M;}import{qt,qi}from'../utils/sql.js';function T(){const y=['WHERE\x20','key','length','\x20AND\x20(','where','DELETE\x20FROM\x20','audit','delete'];T=function(){return y;};return T();}import{clearTableLookupCache}from'./add-table-lookup-data.js';export function createRemove(i,E){return async function W({name:M,id:m,user:P,where:D},x){const Q=g,Z=E['get'](M);assertOperation(Z,'delete',P);const f=x?.['pg']??i['pg'],b=[m];let K=Q(0xe1)+qi(Z[Q(0xe2)])+'\x20=\x20$1';D&&(b['push'](D['value']),K+='\x20AND\x20'+qi(D['column'])+'\x20=\x20$'+b[Q(0xe3)]);Z['where']&&(K+=Q(0xe4)+Z[Q(0xe5)]+')');const J=await f['query'](Q(0xe6)+qt(Z['table'])+'\x20'+K,b);if((J['rowCount']??0x0)>0x0)clearTableLookupCache(Z['table'],f);if((J['rowCount']??0x0)>0x0)await(x?.[Q(0xe7)]??i[Q(0xe7)])?.['write']({'module':Z['module'],'resource':Z['name'],'resourceId':m,'action':Q(0xe8)});return(J['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,
|
|
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,gCAOvB;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,6CA0EF"}
|
|
@@ -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';
|
|
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 T(){const S=['now','read','key','isInteger','Unknown\x20scope:\x20','join','where','SELECT\x20','file','keys','then'];T=function(){return S;};return T();}import{addTableLookupData}from'./add-table-lookup-data.js';function g(i,E){i=i-0x9f;const W=T();let M=W[i];return M;}import{addFileToken}from'./add-file-token.js';import{createFindRelation}from'./find-relation.js';export function createFindOne(i,E){return async function W({name:M,id:m,query:query={},user:P}){const G=g,D=Date[G(0x9f)](),x=E['get'](M);assertOperation(x,G(0xa0),P);if(x['fields'][x[G(0xa1)]]?.['type']==='integer'&&!Number[G(0xa2)](Number(m)))throw new ValidationError('Invalid\x20id:\x20'+m+'\x20name:'+M);if(query['scope']&&x['scopes']?.[query['scope']]===undefined)throw new ValidationError(G(0xa3)+query['scope']);const Z=x['joins']?.['map'](o=>o['sql']+'\x20')[G(0xa4)]('\x20')||'',f=x[G(0xa5)]?'\x20AND\x20('+x[G(0xa5)]+')':'',b=query['scope']||(x['scopes']?.['default']?'default':undefined),K=b?'\x20AND\x20('+(x['scopes']?.[b]||'true')+')':'',J=await i['pg']['query'](G(0xa6)+readableFields(x)[G(0xa4)](',\x20')+'\x20FROM\x20'+qt(x['table'])+'\x20t\x20'+Z+'\x20WHERE\x20'+qi(x['key'])+'=$1'+f+K+'\x20LIMIT\x201',[m]),Q=J['rows'][0x0];if(!Q)return null;await addDictionaryLookupData([Q],x['fields'],i['dictionary']),await addTableLookupData([Q],x['fields'],i['pg']),addFileToken([Q],x['fields'],i[G(0xa7)]);const y=(query['include']==='all'?Object[G(0xa8)](x['relations']||{}):null)||(Array['isArray'](query['include'])?query['include']:query['include']?.['split'](',')??[]),s=createFindRelation(i,E);for(const o of y){Q[o]=await s({'name':M,'id':m,'relation':o,'query':query,'user':P})[G(0xa9)](r=>r['rows']??[])['then'](r=>x['relations']?.[o]?.['type']==='one'?r[0x0]??null:r);}return Q['time']=Date['now']()-D,Q;};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function T(){const U=['offset','isFinite','get','relations','capabilities','includes','\x22\x20requires\x20a\x20capabilities\x20\x22','query','length','now','file','rows','resource','key','table','fields','filter','join','junctionTargetKey','junctionLocalKey','\x20=\x20$1\x20','where\x20','localKey','\x20=\x20$1\x20LIMIT\x201\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20)\x20','where','AND\x20(','joins','SELECT\x20'];T=function(){return U;};return T();}import{UnsupportedError,ValidationError}from'../../../errors.js';import{qi,qt}from'../utils/sql.js';import{addDictionaryLookupData}from'./add-dictionary-lookup-data.js';function g(i,E){i=i-0x127;const W=T();let M=W[i];return M;}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(i,E){return async function W({name:M,id:m,relation:P,query:query={}}){const X=g,D=Date['now'](),x=Math['min'](Math['max'](query['limit']??0x14,0x1),0xc8),Z=Math['max'](query[X(0x127)]??0x0,0x0);if(!Number[X(0x128)](x)||!Number['isFinite'](Z))throw new ValidationError('Invalid\x20pagination');const f=E[X(0x129)](M),b=f[X(0x12a)]?.[P];if(['notes','files']['includes'](P)&&!f[X(0x12b)]?.[X(0x12c)](P))throw new UnsupportedError('Generic\x20Resource\x20relation\x20\x22'+P+X(0x12d)+P+'\x22');if(P==='notes'){const p=await i['pg'][X(0x12e)]('SELECT\x20*\x20FROM\x20admin.notes\x20WHERE\x20resource\x20=\x20$1\x20AND\x20resource_id\x20=\x20$2\x20ORDER\x20BY\x20created_at\x20DESC',[M,String(m)]);return{'total':p['rows'][X(0x12f)],'time':Date[X(0x130)]()-D,'rows':p['rows']};}if(P==='files'){const Y=await i['pg']['query']('SELECT\x20*\x20FROM\x20admin.files\x20WHERE\x20resource\x20=\x20$1\x20AND\x20resource_id\x20=\x20$2\x20ORDER\x20BY\x20created_at\x20DESC',[M,String(m)]);return addFileToken(Y['rows'],{'file_path':{'type':'file'}},i[X(0x131)]),{'total':Y[X(0x132)][X(0x12f)],'time':Date[X(0x130)]()-D,'rows':Y['rows']};}if(!b?.[X(0x133)])throw new UnsupportedError('Generic\x20Resource\x20relation\x20\x22'+P+'\x22\x20requires\x20a\x20project/provider\x20implementation');const K=E['get'](b['resource']),J=K?.[X(0x134)]??'id',Q=K?.[X(0x135)],y=Object['keys'](K?.[X(0x136)]??{})[X(0x137)](d=>K?.['fields'][d]?.['read']&&K?.['fields'][d]?.['scope']!=='item')['map'](qi)['join'](',\x20'),s=b['fields']?.[X(0x138)](',\x20')||y||'*';b['foreignKey']&&autoIndex(Q,b['foreignKey'],'btree',i['pg']);const o=b['junctionTable']?'JOIN\x20'+qt(b['junctionTable'])+'\x20j\x20ON\x20j.'+qi(b['junctionForeignKey'])+'\x20=\x20t.'+(b[X(0x139)]||qi(J))+'\x20WHERE\x20'+qi(b[X(0x13a)])+X(0x13b):X(0x13c)+(b['foreignKey']||qi(J))+'\x20=\x20(SELECT\x20'+qi(b[X(0x13d)]||f['key'])+'\x20FROM\x20'+qt(f['table'])+'\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20'+qi(f[X(0x134)])+X(0x13e)+(b[X(0x13f)]?X(0x140)+b['where']+')':''),r=K[X(0x141)]?.['map'](d=>d['sql']+'\x20')[X(0x138)]('\x20')||'',G=X(0x142)+s+'\x20FROM\x20'+qt(Q)+'\x20t\x20'+r+'\x20'+o+'\x20LIMIT\x20$2\x20OFFSET\x20$3',S=await i['pg']['query'](G,[m,x,Z]);return K&&(await addDictionaryLookupData(S[X(0x132)],K['fields'],i['dictionary']),await addTableLookupData(S['rows'],K['fields'],i['pg']),addFileToken(S['rows'],K[X(0x136)],i['file'])),{'limit':x,'offset':Z,'total':S['rows']['length'],'time':Date['now']()-D,'rows':S[X(0x132)]??null};};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ValidationError}from'../../../errors.js';import{buildFilters,buildIndex}from'../utils/filters.js';import{assertOperation}from'../utils/permissions.js';import{buildSort}from'../utils/sort.js';
|
|
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';function T(){const d=['get','offset','filter','sort','isFinite','keys','fields','search','text','sql','lower(','scope','scopes','default','\x20WHERE\x20','joins','SELECT\x20','all','table','OFFSET\x20$','length','values','then','rows','dictionary','now'];T=function(){return d;};return T();}import{qt,readableFields}from'../utils/sql.js';import{addDictionaryLookupData}from'./add-dictionary-lookup-data.js';import{addTableLookupData}from'./add-table-lookup-data.js';import{addFileToken}from'./add-file-token.js';function g(i,E){i=i-0x183;const W=T();let M=W[i];return M;}import{autoIndex}from'../utils/auto-index.js';import{buildSummary}from'../utils/summary.js';import{buildUserResourceScopeFilter}from'../utils/scope.js';export function createFind(i,E){return async function W({name:M,query:query={},user:m}){const Y=g,P=Date['now'](),D=E[Y(0x183)](M);assertOperation(D,'read',m);const x=Math['min'](Math['max'](query['limit']??0x14,0x1),0xc8),Z=Math['max'](query[Y(0x184)]??0x0,0x0);buildIndex(D,query[Y(0x185)],i['pg']);const f=buildFilters(D,query['filter']);D['where']&&(f['sql']+=(f['sql']?'\x20AND\x20':'\x20WHERE\x20')+('('+D['where']+')'));const b=buildSort(D,query[Y(0x186)]);if(!Number[Y(0x187)](x)||!Number['isFinite'](Z))throw new ValidationError('Invalid\x20pagination');const K=D['searchable']||Object[Y(0x188)](D[Y(0x189)])['filter'](p=>D[Y(0x189)][p]?.['searchable']);query[Y(0x18a)]&&K['length']&&(K['map'](p=>autoIndex(D['table'],p,Y(0x18b),i['pg'])),f['values']['push'](query['search']['toLowerCase']()+'%'),f[Y(0x18c)]+=(f['sql']?'\x20AND\x20':'\x20WHERE\x20')+('\x20('+K?.['map'](p=>Y(0x18d)+qt(p)+')\x20LIKE\x20$'+f['values']['length'])['join']('\x20OR\x20')+')'));if(query[Y(0x18e)]&&D['scopes']?.[query['scope']]===undefined)throw new ValidationError('Unknown\x20scope:\x20'+query['scope']);const J=query['scope']||(D[Y(0x18f)]?.[Y(0x190)]?Y(0x190):undefined);J&&(f['sql']+=(f['sql']?'\x20AND\x20':'\x20WHERE\x20')+('('+(D[Y(0x18f)]?.[J]||'true')+')'));const Q=await buildUserResourceScopeFilter(D,m,i['pg'],f['values']['length']+0x1);Q[Y(0x18c)]&&(f['sql']+=(f['sql']?'\x20AND\x20':Y(0x191))+('('+Q[Y(0x18c)]+')'),f['values']['push'](...Q['values']));const y=D[Y(0x192)]?.[Y(0x185)](p=>p['scope']!=='item')['map'](p=>p['sql']+'\x20')['join']('\x20')||'',s=Y(0x193)+readableFields(D,Y(0x194))['join'](',\x20')+'\x20'+('FROM\x20'+qt(D[Y(0x195)])+'\x20t\x20')+(y+'\x20'+f['sql']['replace'](/:uid/g,'\x27'+(m?.['id']??'NULL')+'\x27')+'\x20'+b+'\x20')+('LIMIT\x20$'+(f['values']['length']+0x1)+'\x20')+(Y(0x196)+(f['values'][Y(0x197)]+0x2)),o=buildSummary(D,query,m,Q),[r,G]=await Promise[Y(0x194)]([i['pg']['query'](s,[...f[Y(0x198)],x,Z]),i['pg']['query'](o['sql'],o['values'])[Y(0x199)](p=>p['rows'][0x0]??{})]),S=r[Y(0x19a)];return await addDictionaryLookupData(S,D['fields'],i[Y(0x19b)]),await addTableLookupData(S,D['fields'],i['pg']),addFileToken(S,D['fields'],i['file']),{'time':Date[Y(0x19c)]()-P,'limit':x,'offset':Z,'count':r['rowCount'],'total':G?.['count']??0x0,'summary':G,'rows':S,...query['include']?.['includes']('fields')?{'fields':D[Y(0x189)]}:{}};};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function T(){const P=['\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'];T=function(){return P;};return T();}function g(i,E){i=i-0x1b2;const W=T();let M=W[i];return M;}export async function getTableColumns(i,E){const m=g;if(!i)throw new Error('not\x20enough\x20params:\x20table');if(!E?.['pg'])return[];const W=await E['pg']['query'](m(0x1b2),[i])['then'](M=>M['rows']||[]);return W;}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{UnsupportedError,ValidationError}from'../../../errors.js';import{createUpdate}from'./update.js';function
|
|
1
|
+
function g(i,E){i=i-0x73;const W=T();let M=W[i];return M;}import{UnsupportedError,ValidationError}from'../../../errors.js';import{createUpdate}from'./update.js';function T(){const y=['relations','foreignKey','resource'];T=function(){return y;};return T();}export function createUpdateRelation(i,E){const W=createUpdate(i,E);return async function M({name:m,id:P,relation:D,relationId:x,data:Z,user:f},b){const Q=g,K=E['get'](m),J=K[Q(0x73)]?.[D];if(!J?.['resource']||!J[Q(0x74)])throw new UnsupportedError('Relation\x20update\x20is\x20not\x20configured:\x20'+D);if(Object['hasOwn'](Z,J['foreignKey'])&&Z[J['foreignKey']]!==P)throw new ValidationError('Cannot\x20change\x20relation:\x20'+J['foreignKey']);return W({'name':J[Q(0x75)],'id':x,'data':Z,'user':f,'where':{'column':J['foreignKey'],'value':P}},b);};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{NotFoundError,ValidationError}from'../../../errors.js';
|
|
1
|
+
import{NotFoundError,ValidationError}from'../../../errors.js';import{assertOperation}from'../utils/permissions.js';function g(i,E){i=i-0x6d;const W=T();let M=W[i];return M;}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(i,E){return async function W({name:M,id:m,data:P,user:D,where:x},Z){const S=g,f=E[S(0x6d)](M);assertOperation(f,'update',D);const b=writableData(f,P);if(!b['length'])throw new ValidationError('No\x20writable\x20fields');const K=Z?.['pg']??i['pg'];validateInputData({'resource':f,'data':P,'update':!![]});f[S(0x6e)]['updated_at']&&b[S(0x6f)](['updated_at',new Date()]);f['fields'][S(0x70)]&&b['push'](['updated_by',D?.['id']]);delete P['user_type'];const J=b[S(0x71)](([r],G)=>qi(r)+'\x20=\x20$'+(G+0x1)),Q=[...b[S(0x71)](([,r])=>r),m];let y='WHERE\x20'+qi(f[S(0x72)])+'\x20=\x20$'+Q['length'];x&&(Q['push'](x[S(0x73)]),y+='\x20AND\x20'+qi(x['column'])+S(0x74)+Q[S(0x75)]);f[S(0x76)]&&(y+='\x20AND\x20('+f['where']+')');const s=await K['query']('UPDATE\x20'+qt(f[S(0x77)])+'\x20'+('SET\x20'+J[S(0x78)](',\x20')+'\x20')+(y+'\x20')+('RETURNING\x20'+Object[S(0x79)](P)[S(0x71)](qi)['join'](',\x20')),Q),o=s['rows'][0x0];if(!o)throw new NotFoundError(M+':'+m);return clearTableLookupCache(f[S(0x77)],K),await(Z?.[S(0x7a)]??i['audit'])?.['write']({'userId':D?.['id'],'module':f['module'],'resource':f['name'],'resourceId':m,'action':S(0x7b),'fields':Object['keys'](P)}),o;};}function T(){const p=['get','fields','push','updated_by','map','key','value','\x20=\x20$','length','where','table','join','keys','audit','update'];T=function(){return p;};return T();}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{qi,qt}from'./sql.js';function g(i,E){i=i-0x108;const W=T();let M=W[i];return M;}const requestedIndexes=new WeakMap();export function autoIndex(i,E,W='btree',M){const Z=g,m=requestedIndexes['get'](M)??new Set();requestedIndexes['set'](M,m);const P=i+':'+E+':'+W;if(m[Z(0x108)](P))return;m['add'](P),void ensureIndex(i,E,W,M)['catch'](()=>{m['delete'](P);});}function T(){const b=['has','length','public','rowCount','CREATE\x20INDEX\x20IF\x20NOT\x20EXISTS\x20','\x20ON\x20','query','\x20USING\x20'];T=function(){return b;};return T();}async function ensureIndex(i,E,W,M){const f=g,m=i['split']('.'),P=m[f(0x109)]===0x2?m[0x0]:f(0x10a),D=(i+'_'+E+'_'+W+'_idx')['replace'](/[^A-Za-z0-9_]/g,'_'),x=await M['query']('SELECT\x201\x20FROM\x20pg_indexes\x20WHERE\x20schemaname\x20=\x20$1\x20AND\x20indexname\x20=\x20$2',[P,D]);if(x[f(0x10b)])return;if(W==='text'){await M['query']('CREATE\x20EXTENSION\x20IF\x20NOT\x20EXISTS\x20pg_trgm'),await M['query'](f(0x10c)+qi(D+'_l')+f(0x10d)+qt(i)+'\x20USING\x20btree\x20(lower('+qi(E)+')\x20text_pattern_ops)'),await M[f(0x10e)](f(0x10c)+qi(D)+'\x20ON\x20'+qt(i)+'\x20USING\x20gin\x20(lower('+qi(E)+')\x20gin_trgm_ops)');return;}await M[f(0x10e)]('CREATE\x20INDEX\x20IF\x20NOT\x20EXISTS\x20'+qi(D)+f(0x10d)+qt(i)+f(0x10f)+W+'\x20('+qi(E)+')');}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{ValidationError}from'../../../errors.js';export{readableFields,writableData,fieldColumn}from'./sql.js';const validateInputData=({resource:i,data:E,update:update=![]})=>{const m=g;for(const [W,M]of Object['entries'](i['fields'])){if(M['required']&&M['writable']!==![]&&(E[W]===undefined||E[W]===null)&&!update)throw new ValidationError('Required\x20field:\x20'+W);if(M['required']&&M['writable']!==![]&&Object[m(0xe1)](E,W)&&(E[W]===undefined||E[W]===null)&&update)throw new ValidationError('Required\x20field:\x20'+W);if(M['minLength']&&typeof E[W]==='string'&&E[W]['length']<M[m(0xe2)])throw new ValidationError('minLength\x20not\x20met:\x20'+W);if(M['maxLength']&&typeof E[W]==='string'&&E[W]['length']>M['maxLength'])throw new ValidationError('maxLength\x20exceeded:\x20'+W);if(M['minimum']&&typeof E[W]==='number'&&E[W]<M[m(0xe3)])throw new ValidationError(W+m(0xe4)+M[m(0xe3)]);if(M['maximum']&&typeof E[W]===m(0xe5)&&E[W]>M['maximum'])throw new ValidationError(W+'\x20should\x20be\x20<=\x20'+M['maximum']);if(M['enum']&&E[W]&&!M[m(0xe6)]['includes'](E[W]))throw new ValidationError(W+m(0xe7)+M['enum']['join'](',\x20')+')');if(M['pattern']&&typeof E[W]==='string'&&!new RegExp(M['pattern'])['test'](E[W]))throw new ValidationError(W+'\x20should\x20match\x20regular\x20expression\x20('+M['pattern']+')');}};export{validateInputData};function g(i,E){i=i-0xe1;const W=T();let M=W[i];return M;}function T(){const P=['hasOwn','minLength','minimum','\x20should\x20be\x20>=\x20','number','enum','\x20should\x20be\x20one\x20of\x20('];T=function(){return P;};return T();}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{fieldColumn,qi}from'./sql.js';import{ValidationError}from'../../../errors.js';import{autoIndex}from'./auto-index.js';
|
|
1
|
+
const s=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','gte','lt','lte','in','nin','like',s(0x16d),s(0x16e)]);export function parseFilterQuery(i){const o=s,E={...isRecord(i['filter'])?i['filter']:{}};for(const [W,M]of Object[o(0x16f)](i)){const m=/^filter\[([^\]]+)\](?:\[([^\]]+)\])?$/[o(0x170)](W);if(!m)continue;const [,P,D]=m;if(!P)continue;if(!D){E[P]=M;continue;}if(!filterOperators[o(0x171)](D))throw new ValidationError('Unsupported\x20filter\x20operator:\x20'+D);const x=isRecord(E[P])?E[P]:{};x[D]=(D==='in'||D===o(0x172))&&typeof M==='string'?M[o(0x173)](','):M,E[P]=x;}return Object['keys'](E)['length']?E:undefined;}function g(i,E){i=i-0x16d;const W=T();let M=W[i];return M;}export function buildIndex(i,E,W){for(const [M,m]of Object['entries'](E??{})){const P=i['fields'][M];if(!P||P['filter']!==!![]&&P['filterable']!==!![])throw new ValidationError('Field\x20is\x20not\x20filterable:\x20'+M);W&&autoIndex(i['table'],fieldColumn(i,M),indexTypeFor(P['type'],'eq'),W);}}export function buildFilters(i,E,W=0x1){const r=s,M=[],m=[];for(const [P,D]of Object['entries'](E??{})){const x=i['fields'][P];if(!x||x['filter']!==!![]&&x[r(0x174)]!==!![])throw new ValidationError('Field\x20is\x20not\x20filterable:\x20'+P);const Z=qi(fieldColumn(i,P)),f=isRecord(D)?D:{'eq':D};for(const [b,K]of Object[r(0x16f)](f)){if(!filterOperators[r(0x171)](b))throw new ValidationError('Unsupported\x20filter\x20operator:\x20'+b);if((b==='like'||b==='ilike')&&x['type']!=='string'&&x[r(0x175)]!=='text')throw new ValidationError('Operator\x20'+b+'\x20requires\x20a\x20text\x20field:\x20'+P);if(b===r(0x16e)){M['push'](Z+'\x20IS\x20'+(isTruthy(K)?'':'NOT\x20')+'NULL');continue;}if(b==='in'||b===r(0x172)){const y=Array[r(0x176)](K)?K:[K];if(y['length']===0x0){M[r(0x177)](b==='in'?r(0x178):'TRUE');continue;}m['push'](y),M[r(0x177)](Z+'\x20'+(b==='in'?'=\x20ANY':'<>\x20ALL')+'($'+(W+m['length']-0x1)+')');continue;}const J={'eq':'=','ne':'<>','gt':'>','gte':'>=','lt':'<','lte':'<=','like':'like'},Q='$'+(W+m['length']);if(b==='like'){m[r(0x177)](K+'%'),M[r(0x177)]('lower('+Z+r(0x179)+Q+')');continue;}m['push'](K),M['push'](Z+'\x20'+J[b]+'\x20'+Q);}}return{'sql':M['length']?r(0x17a)+M['join']('\x20AND\x20'):'','values':m};}function isRecord(i){const G=s;return typeof i===G(0x17b)&&i!==null&&!Array['isArray'](i);}function T(){const p=['ilike','null','entries','exec','has','nin','split','filterable','type','isArray','push','FALSE',')\x20like\x20lower(','\x20WHERE\x20','object','text','geom','geometry','btree'];T=function(){return p;};return T();}function isTruthy(i){return i===!![]||i==='true'||i==='1'||i===0x1;}function indexTypeFor(i,E){const S=s;if(E==='like'||E==='ilike')return S(0x17c);if(i===S(0x17d)||i===S(0x17e))return'gist';return S(0x17f);}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function T(){const D=['config','includes','access','admin','permissions'];T=function(){return D;};return T();}import{ForbiddenError}from'../../../errors.js';function g(i,E){i=i-0x117;const W=T();let M=W[i];return M;}import{getContext}from'../../../index.js';export function assertOperation(i,E,W){const P=g,M=getContext()[P(0x117)];if(M['debug'])return;if(!i['operations'][P(0x118)](E))throw new ForbiddenError(i['name']+'.'+E+'\x20is\x20disabled');if(i['access']!=='public'&&W===undefined)throw new ForbiddenError('Authentication\x20required');if(i[P(0x119)]===P(0x11a)&&W?.['type']!=='admin')throw new ForbiddenError('Admin\x20access\x20required');if(W?.['type']!=='admin'){const m=(i['permission']??i['name'])+':'+E;if(!W?.[P(0x11b)]?.['includes'](m))throw new ForbiddenError('Missing\x20permission:\x20'+m);}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ValidationError}from'../../../errors.js';import{qi}from'./sql.js';const scopeCache=new Map(),CACHE_TTL_MS=0x7530;export function clearResourceScopeCache(
|
|
1
|
+
import{ValidationError}from'../../../errors.js';import{qi}from'./sql.js';const scopeCache=new Map(),CACHE_TTL_MS=0x7530;function T(){const o=['delete','keys','promise','then','set','now','key','user_uid','fields','column','name','push','length'];T=function(){return o;};return T();}export function clearResourceScopeCache(i,E){const K=g;if(i&&E){scopeCache[K(0x12d)](i+':'+E);return;}if(i){for(const W of scopeCache[K(0x12e)]()){if(W['startsWith'](i+':'))scopeCache['delete'](W);}return;}scopeCache['clear']();}async function loadScopeRows(i,E,W){const J=g,M=i+':'+E,m=scopeCache['get'](M);if(m&&m['expiresAt']>Date['now']())return m[J(0x12f)];const P=W['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)',[i,E])[J(0x130)](({rows:D})=>{const Q=J,x=new Map();for(const Z of D){const f=x['get'](Z['scope'])??[];if(Array['isArray'](Z['value']))f['push'](...Z['value']);else{if(Z['value']!==null&&Z['value']!==undefined)f['push'](Z['value']);}x[Q(0x131)](Z['scope'],f);}return x;})['catch'](D=>{scopeCache['delete'](M);throw D;});return scopeCache['set'](M,{'expiresAt':Date[J(0x132)]()+CACHE_TTL_MS,'promise':P}),P;}function g(i,E){i=i-0x12d;const W=T();let M=W[i];return M;}export async function getUserResourceScopes(i,E,W){const M=await loadScopeRows(i,E,W);return Object['fromEntries']([...M]['map'](([m,P])=>[m,m==='me'?i:P]));}function columnForScope(i,E){const y=g;if(E===i['name'])return i[y(0x133)];if(E==='me'){const M=['user_id',y(0x134),'owner_id','created_by']['find'](m=>i['fields'][m]);if(!M)throw new ValidationError('Cannot\x20apply\x20\x22me\x22\x20scope\x20to\x20resource\x20without\x20an\x20owner\x20field:\x20'+i['name']);return i[y(0x135)][M]?.['column']??M;}const W=i['fields'][E];if(!W)return'';return W[y(0x136)]??E;}export async function buildUserResourceScopeFilter(i,E,W,M){const s=g;if(!E||E['type']==='admin')return{'sql':'','values':[]};const m=await loadScopeRows(E['id'],i[s(0x137)],W),P=[],D=[];for(const [x,Z]of m){const f=columnForScope(i,x);if(!f){P[s(0x138)]('(FALSE)');continue;}const b='t.'+qi(f);if(x==='me'){D['push'](E['id']),P['push']('('+b+'\x20=\x20$'+(M+D[s(0x139)]-0x1)+')');continue;}if(Z['length']===0x0){P['push']('(FALSE)');continue;}D['push'](Z),P[s(0x138)]('('+b+'\x20=\x20ANY($'+(M+D['length']-0x1)+'))');}return{'sql':P['join']('\x20AND\x20'),'values':D};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function T(){const f=['map','fields'];T=function(){return f;};return T();}import{fieldColumn,qi}from'./sql.js';function g(i,E){i=i-0xc7;const W=T();let M=W[i];return M;}import{ValidationError}from'../../../errors.js';export function buildSort(i,E){const x=g;if(!E?.['length'])return'';typeof E==='string'&&(E=[E]);const W=E[x(0xc7)](M=>{const Z=x,m=M['startsWith']('-'),P=m?M['slice'](0x1):M,D=i[Z(0xc8)][P];if(!D||D['sortable']!==!![])throw new ValidationError('Field\x20is\x20not\x20sortable:\x20'+P);return qi(fieldColumn(i,P))+'\x20'+(m?'DESC':'ASC');});return'\x20ORDER\x20BY\x20'+W['join'](',\x20');}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{ValidationError}from'../../../errors.js';export const quoteIdentifier=i=>'\x22'+i['replace'](/"/g,'\x22\x22')+'\x22';export const quoteTable=i=>i['split']('.')['map'](quoteIdentifier)['join']('.');function T(){const Z=['entries','filter','scope','map','column','\x20AS\x20','fields','writable','type','push'];T=function(){return Z;};return T();}export function fieldColumn(i,E){if(E===i['key'])return i['key'];const W=i['fields'][E];if(!W)throw new ValidationError('Unknown\x20field:\x20'+E);return W['column']??E;}export function readableFields(i,E){const D=g,W=Object[D(0x1e0)](i['fields'])[D(0x1e1)](([,M])=>M['read']!==![]&&M['readable']!==![]&&(E?(M[D(0x1e2)]??'all')===E:!![]))[D(0x1e3)](([M,m])=>quoteIdentifier(m[D(0x1e4)]??M)+D(0x1e5)+quoteIdentifier(M));return!i[D(0x1e6)][i['key']]&&W['unshift'](quoteIdentifier(i['key'])),W;}function g(i,E){i=i-0x1e0;const W=T();let M=W[i];return M;}export function writableData(i,E){const x=g,W=[];for(const [M,m]of Object['entries'](E)){const P=i['fields'][M];if(!P||P['write']===![]||P[x(0x1e7)]===![])throw new ValidationError('Field\x20is\x20not\x20writable:\x20'+M);if((P['write']??P['writable'])!==!![])continue;if(P[x(0x1e8)]==='date'&&!E[M])continue;W[x(0x1e9)]([P[x(0x1e4)]??M,m]);}return W;}export const qi=quoteIdentifier;export const qt=quoteTable;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{buildFilters}from'./filters.js';function
|
|
1
|
+
const Q=g;import{buildFilters}from'./filters.js';import{qt}from'./sql.js';function T(){const o=['count','summary','sql',')\x20AS\x20\x22','(COUNT(*)\x20FILTER\x20(where\x20','SUM(','field',')\x20FILTER\x20(where\x20','where','avg','AVG(','max','true','\x20AND\x20','keys','fields','push','join','\x20t\x20','replace','NULL'];T=function(){return o;};return T();}function g(i,E){i=i-0x1a0;const W=T();let M=W[i];return M;}const defaultSummary={'count':{'aggregate':Q(0x1a0)}};export function buildSummary(i,E,W,M){const y=Q,m={...defaultSummary,...i[y(0x1a1)]??{}},P=Object['entries'](m)['map'](([K,J])=>{const s=y;if('sql'in J)return'('+J[s(0x1a2)]+s(0x1a3)+K+'\x22';switch(J['aggregate']){case s(0x1a0):return s(0x1a4)+(J['where']??'true')+'))::int\x20AS\x20\x22'+K+'\x22';case'countDistinct':return'(COUNT(DISTINCT\x20t.'+qt(J['field'])+')\x20FILTER\x20(where\x20'+(J['where']??'true')+'))::int\x20AS\x20\x22'+K+'\x22';case'sum':return s(0x1a5)+J[s(0x1a6)]+s(0x1a7)+(J[s(0x1a8)]??'true')+')\x20AS\x20\x22'+K+'\x22';case s(0x1a9):return s(0x1aa)+J['field']+')\x20FILTER\x20(where\x20'+(J['where']??'true')+')\x20AS\x20\x22'+K+'\x22';case'min':return'MIN('+J[s(0x1a6)]+s(0x1a7)+(J[s(0x1a8)]??'true')+')\x20AS\x20\x22'+K+'\x22';case s(0x1ab):return'MAX('+J['field']+')\x20FILTER\x20(where\x20'+(J['where']??s(0x1ac))+')\x20AS\x20\x22'+K+'\x22';}}),D=buildFilters(i,E['filter']);i['where']&&(D['sql']+=(D[y(0x1a2)]?'\x20AND\x20':'\x20WHERE\x20')+('('+i['where']+')'));const x=E['scope']||(i['scopes']?.['default']?'default':undefined);x&&(D['sql']+=(D['sql']?y(0x1ad):'\x20WHERE\x20')+('('+(i['scopes']?.[x]||'true')+')'));const Z=i['searchable']||Object[y(0x1ae)](i[y(0x1af)])['filter'](K=>i['fields'][K]?.['searchable']);E['search']&&Z['length']&&(D['values']['push'](E['search']['toLowerCase']()+'%'),D[y(0x1a2)]+=(D['sql']?'\x20AND\x20':'\x20WHERE\x20')+('\x20('+Z['map'](K=>'lower('+qt(K)+')\x20LIKE\x20$'+D['values']['length'])['join']('\x20OR\x20')+')'));M?.['sql']&&(D['sql']+=(D[y(0x1a2)]?'\x20AND\x20':'\x20WHERE\x20')+('('+M['sql']+')'),D['values'][y(0x1b0)](...M['values']));const f=i['joins']?.['filter'](K=>K['scope']!=='item')['map'](K=>K['sql']+'\x20')['join']('\x20')||'',b='SELECT\x20'+P[y(0x1b1)](',\x20')+'\x20'+('FROM\x20'+qt(i['table'])+y(0x1b2))+(f+'\x20'+D['sql'][y(0x1b3)](/:uid/g,'\x27'+(W?.['id']??y(0x1b4))+'\x27'));return{'sql':b,'values':D['values']};}
|
package/dist/shared/getIP.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const E=g,getIP=i=>(i['headers']?.['x-real-ip']||i['headers']?.['x-forwarded-for']||i['ip']||i[E(0x74)]?.[E(0x75)]||'')['split'](':')[E(0x76)]();function T(){const W=['connection','remoteAddress','pop'];T=function(){return W;};return T();}function g(i,E){i=i-0x74;const W=T();let M=W[i];return M;}export default getIP;
|
|
@@ -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,2 +1,2 @@
|
|
|
1
|
-
ALTER TABLE admin.role_access_scope
|
|
1
|
+
ALTER TABLE admin.role_access_scope
|
|
2
2
|
ALTER COLUMN role_id DROP NOT NULL;
|