Skip to content

Commit 6ac1fe3

Browse files
feat: adapt
1 parent 64bd138 commit 6ac1fe3

File tree

7 files changed

+106
-12
lines changed

7 files changed

+106
-12
lines changed

src/frontend/src/lib/api/actors/actor.deprecated.api.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import type { _SERVICE as OrbiterActor008 } from '$declarations/deprecated/orbit
88
import { idlFactory as idlFactorOrbiter008 } from '$declarations/deprecated/orbiter-0-0-8.factory.did';
99
import type { _SERVICE as SatelliteActor0021 } from '$declarations/deprecated/satellite-0-0-21.did';
1010
import { idlFactory as idlFactorSatellite0021 } from '$declarations/deprecated/satellite-0-0-21.factory.did';
11+
import type { _SERVICE as SatelliteActor0022 } from '$declarations/deprecated/satellite-0-0-22.did';
12+
import { idlFactory as idlFactorSatellite0022 } from '$declarations/deprecated/satellite-0-0-22.factory.did';
1113
import type { _SERVICE as SatelliteActor008 } from '$declarations/deprecated/satellite-0-0-8.did';
1214
import { idlFactory as idlFactorSatellite008 } from '$declarations/deprecated/satellite-0-0-8.factory.did';
1315
import type { _SERVICE as SatelliteActor009 } from '$declarations/deprecated/satellite-0-0-9.did';
@@ -22,6 +24,7 @@ const missionControl0013Actor = new ActorApi<MissionControlActor0013>();
2224
const satellite008Actor = new ActorApi<SatelliteActor008>();
2325
const satellite009Actor = new ActorApi<SatelliteActor009>();
2426
const satellite0021Actor = new ActorApi<SatelliteActor0021>();
27+
const satellite0022Actor = new ActorApi<SatelliteActor0022>();
2528
const orbiter007Actor = new ActorApi<OrbiterActor007>();
2629
const orbiter008Actor = new ActorApi<OrbiterActor008>();
2730

@@ -88,6 +91,7 @@ export const getSatelliteActor009 = ({
8891
idlFactory: idlFactorSatellite009,
8992
identity
9093
});
94+
9195
/**
9296
* @deprecated TODO: to be remove - backwards compatibility
9397
*/
@@ -104,6 +108,22 @@ export const getSatelliteActor0021 = ({
104108
identity
105109
});
106110

111+
/**
112+
* @deprecated TODO: to be remove - backwards compatibility
113+
*/
114+
export const getSatelliteActor0022 = ({
115+
satelliteId,
116+
identity
117+
}: {
118+
satelliteId: Principal;
119+
identity: OptionIdentity;
120+
}): Promise<SatelliteActor0022> =>
121+
satellite0022Actor.getActor({
122+
canisterId: satelliteId,
123+
idlFactory: idlFactorSatellite0022,
124+
identity
125+
});
126+
107127
/**
108128
* @deprecated TODO: to be remove - backwards compatibility
109129
*/

src/frontend/src/lib/api/satellites.api.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import type {
66
Doc,
77
ListResults as ListAssets,
88
ListResults_1 as ListDocs,
9+
ListRulesParams,
10+
ListRulesResults,
911
Rule,
1012
SetDoc,
1113
SetRule
@@ -83,14 +85,16 @@ export const listAssets = async ({
8385
export const listRules = async ({
8486
satelliteId,
8587
type,
88+
filter,
8689
identity
8790
}: {
8891
satelliteId: Principal;
8992
type: CollectionType;
93+
filter: ListRulesParams;
9094
identity: OptionIdentity;
91-
}): Promise<[string, Rule][]> => {
92-
const actor = await getSatelliteActor({ satelliteId, identity });
93-
return actor.list_rules(type);
95+
}): Promise<ListRulesResults> => {
96+
const { list_rules } = await getSatelliteActor({ satelliteId, identity });
97+
return list_rules(type, filter);
9498
};
9599

96100
export const getRule = async ({

src/frontend/src/lib/api/satellites.deprecated.api.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
} from '$declarations/satellite/satellite.did';
1010
import {
1111
getSatelliteActor0021,
12+
getSatelliteActor0022,
1213
getSatelliteActor008,
1314
getSatelliteActor009
1415
} from '$lib/api/actors/actor.deprecated.api';
@@ -178,3 +179,19 @@ export const satelliteBuildVersion = async ({
178179
const { build_version } = await getSatelliteActor0021({ satelliteId, identity });
179180
return build_version();
180181
};
182+
183+
/**
184+
* @deprecated TODO: to be remove - backwards compatibility
185+
*/
186+
export const listRules0022 = async ({
187+
satelliteId,
188+
type,
189+
identity
190+
}: {
191+
satelliteId: Principal;
192+
type: CollectionType;
193+
identity: OptionIdentity;
194+
}): Promise<[string, Rule][]> => {
195+
const actor = await getSatelliteActor0022({ satelliteId, identity });
196+
return actor.list_rules(type);
197+
};

src/frontend/src/lib/constants/rules.constants.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import type { CollectionType, Memory, Permission } from '$declarations/satellite/satellite.did';
1+
import type {
2+
CollectionType,
3+
ListRulesParams,
4+
Memory,
5+
Permission
6+
} from '$declarations/satellite/satellite.did';
7+
import { toNullable } from '@dfinity/utils';
28

39
export const DbCollectionType: CollectionType = { Db: null };
410
export const StorageCollectionType: CollectionType = { Storage: null };
@@ -14,3 +20,7 @@ export const MemoryHeap: Memory = { Heap: null };
1420
export const MemoryStable: Memory = { Stable: null };
1521

1622
export type MemoryText = 'Heap' | 'Stable';
23+
24+
export const filterSystemRules: ListRulesParams = {
25+
matcher: toNullable()
26+
};

src/frontend/src/lib/constants/version.constants.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ const VERSIONS = {
1313
v0_0_16: '0.0.16',
1414
v0_0_17: '0.0.17',
1515
v0_0_20: '0.0.20',
16-
v0_0_21: '0.0.21'
16+
v0_0_21: '0.0.21',
17+
v0_1_0: '0.1.0'
1718
},
1819
ORBITER: {
1920
v0_0_4: '0.0.4',
@@ -37,7 +38,8 @@ export const {
3738
v0_0_16: SATELLITE_v0_0_16,
3839
v0_0_17: SATELLITE_v0_0_17,
3940
v0_0_20: SATELLITE_v0_0_20,
40-
v0_0_21: SATELLITE_v0_0_21
41+
v0_0_21: SATELLITE_v0_0_21,
42+
v0_1_0: SATELLITE_v0_1_0
4143
},
4244
ORBITER: { v0_0_4: ORBITER_v0_0_4, v0_0_5: ORBITER_v0_0_5, v0_0_8: ORBITER_v0_0_8 }
4345
} = VERSIONS;

src/frontend/src/lib/services/rules.loader.services.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { CollectionType } from '$declarations/satellite/satellite.did';
22
import { listRules } from '$lib/api/satellites.api';
3-
import { listRulesDeprecated } from '$lib/api/satellites.deprecated.api';
3+
import { listRules0022, listRulesDeprecated } from '$lib/api/satellites.deprecated.api';
4+
import { filterSystemRules } from '$lib/constants/rules.constants';
45
import { toasts } from '$lib/stores/toasts.store';
56
import type { OptionIdentity } from '$lib/types/itentity';
67
import type { RulesData } from '$lib/types/rules.context';
@@ -19,10 +20,24 @@ export const reloadContextRules = async ({
1920
identity: OptionIdentity;
2021
}) => {
2122
try {
22-
const rules = await listRules({ satelliteId, type, identity });
23+
// TODO: support system filter
24+
const { items: rules } = await listRules({
25+
satelliteId,
26+
type,
27+
filter: filterSystemRules,
28+
identity
29+
});
2330
store.set({ satelliteId, rules, rule: undefined });
2431
} catch (err: unknown) {
2532
// TODO: remove backward compatibility stuffs
33+
try {
34+
const rules = await listRules0022({ satelliteId, identity, type });
35+
store.set({ satelliteId, rules, rule: undefined });
36+
return;
37+
} catch (_: unknown) {
38+
// Ignore error of the workaround
39+
}
40+
2641
try {
2742
const rules = await listRulesDeprecated({ satelliteId, identity, type });
2843
store.set({ satelliteId, rules, rule: undefined });

src/frontend/src/lib/services/user/user.services.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
import type { CollectionType } from '$declarations/satellite/satellite.did';
1+
import type { CollectionType, Rule } from '$declarations/satellite/satellite.did';
22
import { getDoc, listRules, setDoc } from '$lib/api/satellites.api';
3-
import { DbCollectionType, StorageCollectionType } from '$lib/constants/rules.constants';
3+
import { listRules0022 } from '$lib/api/satellites.deprecated.api';
4+
import {
5+
DbCollectionType,
6+
filterSystemRules,
7+
StorageCollectionType
8+
} from '$lib/constants/rules.constants';
9+
import { SATELLITE_v0_1_0 } from '$lib/constants/version.constants';
10+
import { isSatelliteFeatureSupported } from '$lib/services/feature.services';
411
import { busy } from '$lib/stores/busy.store';
512
import { i18n } from '$lib/stores/i18n.store';
613
import { toasts } from '$lib/stores/toasts.store';
@@ -77,9 +84,28 @@ const loadUserUsages = async ({
7784
}: { identity: Identity } & Omit<OpenUserDetailParams, 'identity'>): Promise<
7885
UserUsageCollection[]
7986
> => {
87+
const newestListRules = isSatelliteFeatureSupported({
88+
satelliteId,
89+
requiredMinVersion: SATELLITE_v0_1_0
90+
});
91+
92+
const modernListRules = async (collectionType: CollectionType): Promise<[string, Rule][]> => {
93+
const { items } = await listRules({
94+
satelliteId,
95+
type: collectionType,
96+
filter: filterSystemRules,
97+
identity
98+
});
99+
return items;
100+
};
101+
80102
const [dbRules, storageRules] = await Promise.all([
81-
listRules({ satelliteId, type: DbCollectionType, identity }),
82-
listRules({ satelliteId, type: StorageCollectionType, identity })
103+
newestListRules
104+
? modernListRules(DbCollectionType)
105+
: listRules0022({ satelliteId, type: DbCollectionType, identity }),
106+
newestListRules
107+
? modernListRules(StorageCollectionType)
108+
: listRules0022({ satelliteId, type: DbCollectionType, identity })
83109
]);
84110

85111
const loadUsage = async ({

0 commit comments

Comments
 (0)