Skip to content

Commit f8bdcf8

Browse files
committed
dev: [+] DataAccessModule > AppService > select()
This commit adds the DataAccessModule, which is where replacement "flatter" implementations for what is currently implemented via EntityStorage/OM will be developed. This commit also adds AppService, which is where the `crud-q` implementor for apps will be implemented. This commit adds the `select()` implementation for AppService. Currently it is missing many behaviors for parity with the current ES/OM implementation including: - coercion of boolean values - nested objects and their properties - `icon_size` parameter support
1 parent 3c1a4cd commit f8bdcf8

File tree

7 files changed

+466
-0
lines changed

7 files changed

+466
-0
lines changed

src/backend/exports.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { AppsModule } from './src/modules/apps/AppsModule.js';
2727
import { BroadcastModule } from './src/modules/broadcast/BroadcastModule.js';
2828
import { CaptchaModule } from './src/modules/captcha/CaptchaModule.js';
2929
import { Core2Module } from './src/modules/core/Core2Module.js';
30+
import { DataAccessModule } from './src/modules/data-access/DataAccessModule.js';
3031
import { DevelopmentModule } from './src/modules/development/DevelopmentModule.js';
3132
import { DNSModule } from './src/modules/dns/DNSModule.js';
3233
import { DomainModule } from './src/modules/domain/DomainModule.js';
@@ -85,6 +86,7 @@ export default {
8586
KVStoreModule,
8687
DNSModule,
8788
DomainModule,
89+
DataAccessModule,
8890

8991
// Development modules
9092
PerfMonModule,

src/backend/src/data/hardcoded-permissions.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ const hardcoded_user_group_permissions = {
112112
'service:puter-notifications:ii:crud-q': policy_perm('temp.es'),
113113
'service:puter-apps:ii:crud-q': policy_perm('temp.es'),
114114
'service:puter-subdomains:ii:crud-q': policy_perm('temp.es'),
115+
'service:apps:ii:crud-q': policy_perm('temp.es'),
115116
'service:es\\Cnotification:ii:crud-q': policy_perm('user.es'),
116117
'service:es\\Capp:ii:crud-q': policy_perm('user.es'),
117118
'service:es\\Csubdomain:ii:crud-q': policy_perm('user.es'),
@@ -123,6 +124,7 @@ const hardcoded_user_group_permissions = {
123124
'service:es\\Cnotification:ii:crud-q': policy_perm('user.es'),
124125
'service:es\\Capp:ii:crud-q': policy_perm('user.es'),
125126
'service:es\\Csubdomain:ii:crud-q': policy_perm('user.es'),
127+
'service:apps:ii:crud-q': policy_perm('user.es'),
126128
},
127129
},
128130
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default class AppRepository {
2+
//
3+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import BaseService from '../../services/BaseService.js';
2+
import { DB_READ } from '../../services/database/consts.js';
3+
import { Context } from '../../util/context.js';
4+
import AppRepository from './AppRepository.js';
5+
6+
/**
7+
* AppService contains an instance using the repository pattern
8+
*/
9+
export default class AppService extends BaseService {
10+
async _init () {
11+
this.repository = new AppRepository();
12+
this.db = this.services.get('database').get(DB_READ, 'apps');
13+
}
14+
15+
static IMPLEMENTS = {
16+
['crud-q']: {
17+
async create ({ object, options }) {
18+
// TODO
19+
},
20+
async update ({ object, id, options }) {
21+
// TODO
22+
},
23+
async upsert ({ object, id, options }) {
24+
// TODO
25+
},
26+
async read ({ uid, id, params = {} }) {
27+
// TODO
28+
},
29+
async select (options) {
30+
return this.#select(options);
31+
},
32+
async delete ({ uid, id }) {
33+
// TODO
34+
},
35+
},
36+
};
37+
38+
async #select ({ predicate, ...rest }) {
39+
const db = this.db;
40+
41+
if ( ! Array.isArray(predicate) ) throw new Error('predicate must be an array');
42+
43+
const userCanEditOnly = Array.prototype.includes.call(predicate, 'user-can-edit');
44+
45+
const stmt = `SELECT * FROM apps ${userCanEditOnly ? 'WHERE owner_user_id=?' : ''} LIMIT 5000`;
46+
const values = userCanEditOnly ? [Context.get('user').id] : [];
47+
const rows = await db.read(stmt, values);
48+
49+
const client_safe_apps = [];
50+
for ( const row of rows ) {
51+
const app = {};
52+
53+
// FROM ROW
54+
app.approved_for_incentive_program = row.approved_for_incentive_program;
55+
app.approved_for_listing = row.approved_for_listing;
56+
app.approved_for_opening_items = row.approved_for_opening_items;
57+
app.background = row.background;
58+
app.created_at = row.created_at;
59+
app.created_from_origin = row.created_from_origin;
60+
app.description = row.description;
61+
app.godmode = row.godmode;
62+
app.icon = row.icon;
63+
app.index_url = row.index_url;
64+
app.maximize_on_start = row.maximize_on_start;
65+
app.metadata = row.metadata;
66+
app.name = row.name;
67+
app.protected = row.protected;
68+
app.stats = row.stats;
69+
app.title = row.title;
70+
app.uid = row.uid;
71+
72+
// REQURIES OTHER DATA
73+
// app.app_owner;
74+
// app.filetype_associations = row.filetype_associations;
75+
// app.owner = row.owner;
76+
77+
// REFINED BY OTHER DATA
78+
// app.icon;
79+
80+
client_safe_apps.push(app);
81+
}
82+
83+
return client_safe_apps;
84+
}
85+
}

0 commit comments

Comments
 (0)