From 4801be4e39bc26a138237f98b1dc6d83606b59e1 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Sat, 13 May 2023 12:53:50 +0200 Subject: [PATCH] feat: remove deprecated list support Signed-off-by: David Dal Busco --- .../satellite-deprecated-no-scope.did.d.ts | 187 ----------------- ...tellite-deprecated-no-scope.factory.did.js | 194 ------------------ .../src/lib/api/satellites.deprected.api.ts | 93 --------- .../src/lib/components/assets/Assets.svelte | 11 +- .../src/lib/components/docs/Docs.svelte | 11 +- .../src/lib/services/users.services.ts | 9 +- .../src/lib/utils/actor.deprecated.utils.ts | 24 --- src/frontend/src/lib/utils/actor.utils.ts | 2 +- 8 files changed, 9 insertions(+), 522 deletions(-) delete mode 100644 src/declarations/deprecated/satellite-deprecated-no-scope.did.d.ts delete mode 100644 src/declarations/deprecated/satellite-deprecated-no-scope.factory.did.js delete mode 100644 src/frontend/src/lib/api/satellites.deprected.api.ts delete mode 100644 src/frontend/src/lib/utils/actor.deprecated.utils.ts diff --git a/src/declarations/deprecated/satellite-deprecated-no-scope.did.d.ts b/src/declarations/deprecated/satellite-deprecated-no-scope.did.d.ts deleted file mode 100644 index 21b06eae8..000000000 --- a/src/declarations/deprecated/satellite-deprecated-no-scope.did.d.ts +++ /dev/null @@ -1,187 +0,0 @@ -import type { ActorMethod } from '@dfinity/agent'; -import type { Principal } from '@dfinity/principal'; - -export interface AssetEncodingNoContent { - modified: bigint; - sha256: Uint8Array | number[]; - total_length: bigint; -} -export interface AssetKey { - token: [] | [string]; - collection: string; - owner: Principal; - name: string; - full_path: string; -} -export interface AssetNoContent { - key: AssetKey; - updated_at: bigint; - encodings: Array<[string, AssetEncodingNoContent]>; - headers: Array<[string, string]>; - created_at: bigint; -} -export interface Chunk { - content: Uint8Array | number[]; - batch_id: bigint; -} -export interface CommitBatch { - batch_id: bigint; - headers: Array<[string, string]>; - chunk_ids: Array; -} -export interface Config { - storage: StorageConfig; -} -export interface Controller { - updated_at: bigint; - metadata: Array<[string, string]>; - created_at: bigint; - expires_at: [] | [bigint]; -} -export interface CustomDomain { - updated_at: bigint; - created_at: bigint; - bn_id: [] | [string]; -} -export interface DelDoc { - updated_at: [] | [bigint]; -} -export interface DeleteControllersArgs { - controllers: Array; -} -export interface Doc { - updated_at: bigint; - owner: Principal; - data: Uint8Array | number[]; - created_at: bigint; -} -export interface HttpRequest { - url: string; - method: string; - body: Uint8Array | number[]; - headers: Array<[string, string]>; -} -export interface HttpResponse { - body: Uint8Array | number[]; - headers: Array<[string, string]>; - streaming_strategy: [] | [StreamingStrategy]; - status_code: number; -} -export interface InitAssetKey { - token: [] | [string]; - collection: string; - name: string; - encoding_type: [] | [string]; - full_path: string; -} -export interface InitUploadResult { - batch_id: bigint; -} -export interface ListOrder { - field: ListOrderField; - desc: boolean; -} -export type ListOrderField = { UpdatedAt: null } | { Keys: null } | { CreatedAt: null }; -export interface ListPaginate { - start_after: [] | [string]; - limit: [] | [bigint]; -} -export interface ListParams { - order: [] | [ListOrder]; - owner: [] | [Principal]; - matcher: [] | [string]; - paginate: [] | [ListPaginate]; -} -export interface ListResults { - matches_length: bigint; - length: bigint; - items: Array<[string, AssetNoContent]>; -} -export interface ListResults_1 { - matches_length: bigint; - length: bigint; - items: Array<[string, Doc]>; -} -export type Permission = - | { Controllers: null } - | { Private: null } - | { Public: null } - | { Managed: null }; -export interface Rule { - updated_at: bigint; - max_size: [] | [bigint]; - read: Permission; - created_at: bigint; - write: Permission; -} -export type RulesType = { Db: null } | { Storage: null }; -export interface SetController { - metadata: Array<[string, string]>; - expires_at: [] | [bigint]; -} -export interface SetControllersArgs { - controller: SetController; - controllers: Array; -} -export interface SetDoc { - updated_at: [] | [bigint]; - data: Uint8Array | number[]; -} -export interface SetRule { - updated_at: [] | [bigint]; - max_size: [] | [bigint]; - read: Permission; - write: Permission; -} -export interface StorageConfig { - headers: Array<[string, Array<[string, string]>]>; -} -export interface StreamingCallbackHttpResponse { - token: [] | [StreamingCallbackToken]; - body: Uint8Array | number[]; -} -export interface StreamingCallbackToken { - token: [] | [string]; - sha256: [] | [Uint8Array | number[]]; - headers: Array<[string, string]>; - index: bigint; - encoding_type: string; - full_path: string; -} -export type StreamingStrategy = { - Callback: { - token: StreamingCallbackToken; - callback: [Principal, string]; - }; -}; -export interface UploadChunk { - chunk_id: bigint; -} -export interface _SERVICE { - commit_asset_upload: ActorMethod<[CommitBatch], undefined>; - del_asset: ActorMethod<[string, string], undefined>; - del_assets: ActorMethod<[[] | [string]], undefined>; - del_controllers: ActorMethod<[DeleteControllersArgs], Array<[Principal, Controller]>>; - del_custom_domain: ActorMethod<[string], undefined>; - del_doc: ActorMethod<[string, string, DelDoc], undefined>; - get_config: ActorMethod<[], Config>; - get_doc: ActorMethod<[string, string], [] | [Doc]>; - http_request: ActorMethod<[HttpRequest], HttpResponse>; - http_request_streaming_callback: ActorMethod< - [StreamingCallbackToken], - StreamingCallbackHttpResponse - >; - init_asset_upload: ActorMethod<[InitAssetKey], InitUploadResult>; - list_assets: ActorMethod<[[] | [string], ListParams], ListResults>; - list_controllers: ActorMethod<[], Array<[Principal, Controller]>>; - list_custom_domains: ActorMethod<[], Array<[string, CustomDomain]>>; - list_docs: ActorMethod<[string, ListParams], ListResults_1>; - list_rules: ActorMethod<[RulesType], Array<[string, Rule]>>; - set_config: ActorMethod<[Config], undefined>; - set_controllers: ActorMethod<[SetControllersArgs], Array<[Principal, Controller]>>; - set_custom_domain: ActorMethod<[string, [] | [string]], undefined>; - set_doc: ActorMethod<[string, string, SetDoc], Doc>; - set_rule: ActorMethod<[RulesType, string, SetRule], undefined>; - upload_asset_chunk: ActorMethod<[Chunk], UploadChunk>; - version: ActorMethod<[], string>; -} diff --git a/src/declarations/deprecated/satellite-deprecated-no-scope.factory.did.js b/src/declarations/deprecated/satellite-deprecated-no-scope.factory.did.js deleted file mode 100644 index 5bdc961c7..000000000 --- a/src/declarations/deprecated/satellite-deprecated-no-scope.factory.did.js +++ /dev/null @@ -1,194 +0,0 @@ -// @ts-ignore -export const idlFactory = ({ IDL }) => { - const CommitBatch = IDL.Record({ - batch_id: IDL.Nat, - headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)), - chunk_ids: IDL.Vec(IDL.Nat) - }); - const DeleteControllersArgs = IDL.Record({ - controllers: IDL.Vec(IDL.Principal) - }); - const Controller = IDL.Record({ - updated_at: IDL.Nat64, - metadata: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)), - created_at: IDL.Nat64, - expires_at: IDL.Opt(IDL.Nat64) - }); - const DelDoc = IDL.Record({ updated_at: IDL.Opt(IDL.Nat64) }); - const StorageConfig = IDL.Record({ - headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)))) - }); - const Config = IDL.Record({ storage: StorageConfig }); - const Doc = IDL.Record({ - updated_at: IDL.Nat64, - owner: IDL.Principal, - data: IDL.Vec(IDL.Nat8), - created_at: IDL.Nat64 - }); - const HttpRequest = IDL.Record({ - url: IDL.Text, - method: IDL.Text, - body: IDL.Vec(IDL.Nat8), - headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)) - }); - const StreamingCallbackToken = IDL.Record({ - token: IDL.Opt(IDL.Text), - sha256: IDL.Opt(IDL.Vec(IDL.Nat8)), - headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)), - index: IDL.Nat64, - encoding_type: IDL.Text, - full_path: IDL.Text - }); - const StreamingStrategy = IDL.Variant({ - Callback: IDL.Record({ - token: StreamingCallbackToken, - callback: IDL.Func([], [], []) - }) - }); - const HttpResponse = IDL.Record({ - body: IDL.Vec(IDL.Nat8), - headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)), - streaming_strategy: IDL.Opt(StreamingStrategy), - status_code: IDL.Nat16 - }); - const StreamingCallbackHttpResponse = IDL.Record({ - token: IDL.Opt(StreamingCallbackToken), - body: IDL.Vec(IDL.Nat8) - }); - const InitAssetKey = IDL.Record({ - token: IDL.Opt(IDL.Text), - collection: IDL.Text, - name: IDL.Text, - encoding_type: IDL.Opt(IDL.Text), - full_path: IDL.Text - }); - const InitUploadResult = IDL.Record({ batch_id: IDL.Nat }); - const ListOrderField = IDL.Variant({ - UpdatedAt: IDL.Null, - Keys: IDL.Null, - CreatedAt: IDL.Null - }); - const ListOrder = IDL.Record({ field: ListOrderField, desc: IDL.Bool }); - const ListPaginate = IDL.Record({ - start_after: IDL.Opt(IDL.Text), - limit: IDL.Opt(IDL.Nat64) - }); - const ListParams = IDL.Record({ - order: IDL.Opt(ListOrder), - owner: IDL.Opt(IDL.Principal), - matcher: IDL.Opt(IDL.Text), - paginate: IDL.Opt(ListPaginate) - }); - const AssetKey = IDL.Record({ - token: IDL.Opt(IDL.Text), - collection: IDL.Text, - owner: IDL.Principal, - name: IDL.Text, - full_path: IDL.Text - }); - const AssetEncodingNoContent = IDL.Record({ - modified: IDL.Nat64, - sha256: IDL.Vec(IDL.Nat8), - total_length: IDL.Nat - }); - const AssetNoContent = IDL.Record({ - key: AssetKey, - updated_at: IDL.Nat64, - encodings: IDL.Vec(IDL.Tuple(IDL.Text, AssetEncodingNoContent)), - headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)), - created_at: IDL.Nat64 - }); - const ListResults = IDL.Record({ - matches_length: IDL.Nat64, - length: IDL.Nat64, - items: IDL.Vec(IDL.Tuple(IDL.Text, AssetNoContent)) - }); - const CustomDomain = IDL.Record({ - updated_at: IDL.Nat64, - created_at: IDL.Nat64, - bn_id: IDL.Opt(IDL.Text) - }); - const ListResults_1 = IDL.Record({ - matches_length: IDL.Nat64, - length: IDL.Nat64, - items: IDL.Vec(IDL.Tuple(IDL.Text, Doc)) - }); - const RulesType = IDL.Variant({ Db: IDL.Null, Storage: IDL.Null }); - const Permission = IDL.Variant({ - Controllers: IDL.Null, - Private: IDL.Null, - Public: IDL.Null, - Managed: IDL.Null - }); - const Rule = IDL.Record({ - updated_at: IDL.Nat64, - max_size: IDL.Opt(IDL.Nat), - read: Permission, - created_at: IDL.Nat64, - write: Permission - }); - const SetController = IDL.Record({ - metadata: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)), - expires_at: IDL.Opt(IDL.Nat64) - }); - const SetControllersArgs = IDL.Record({ - controller: SetController, - controllers: IDL.Vec(IDL.Principal) - }); - const SetDoc = IDL.Record({ - updated_at: IDL.Opt(IDL.Nat64), - data: IDL.Vec(IDL.Nat8) - }); - const SetRule = IDL.Record({ - updated_at: IDL.Opt(IDL.Nat64), - max_size: IDL.Opt(IDL.Nat), - read: Permission, - write: Permission - }); - const Chunk = IDL.Record({ - content: IDL.Vec(IDL.Nat8), - batch_id: IDL.Nat - }); - const UploadChunk = IDL.Record({ chunk_id: IDL.Nat }); - return IDL.Service({ - commit_asset_upload: IDL.Func([CommitBatch], [], []), - del_asset: IDL.Func([IDL.Text, IDL.Text], [], []), - del_assets: IDL.Func([IDL.Opt(IDL.Text)], [], []), - del_controllers: IDL.Func( - [DeleteControllersArgs], - [IDL.Vec(IDL.Tuple(IDL.Principal, Controller))], - [] - ), - del_custom_domain: IDL.Func([IDL.Text], [], []), - del_doc: IDL.Func([IDL.Text, IDL.Text, DelDoc], [], []), - get_config: IDL.Func([], [Config], []), - get_doc: IDL.Func([IDL.Text, IDL.Text], [IDL.Opt(Doc)], ['query']), - http_request: IDL.Func([HttpRequest], [HttpResponse], ['query']), - http_request_streaming_callback: IDL.Func( - [StreamingCallbackToken], - [StreamingCallbackHttpResponse], - ['query'] - ), - init_asset_upload: IDL.Func([InitAssetKey], [InitUploadResult], []), - list_assets: IDL.Func([IDL.Opt(IDL.Text), ListParams], [ListResults], ['query']), - list_controllers: IDL.Func([], [IDL.Vec(IDL.Tuple(IDL.Principal, Controller))], ['query']), - list_custom_domains: IDL.Func([], [IDL.Vec(IDL.Tuple(IDL.Text, CustomDomain))], ['query']), - list_docs: IDL.Func([IDL.Text, ListParams], [ListResults_1], ['query']), - list_rules: IDL.Func([RulesType], [IDL.Vec(IDL.Tuple(IDL.Text, Rule))], ['query']), - set_config: IDL.Func([Config], [], []), - set_controllers: IDL.Func( - [SetControllersArgs], - [IDL.Vec(IDL.Tuple(IDL.Principal, Controller))], - [] - ), - set_custom_domain: IDL.Func([IDL.Text, IDL.Opt(IDL.Text)], [], []), - set_doc: IDL.Func([IDL.Text, IDL.Text, SetDoc], [Doc], []), - set_rule: IDL.Func([RulesType, IDL.Text, SetRule], [], []), - upload_asset_chunk: IDL.Func([Chunk], [UploadChunk], []), - version: IDL.Func([], [IDL.Text], ['query']) - }); -}; -// @ts-ignore -export const init = ({ IDL }) => { - return []; -}; diff --git a/src/frontend/src/lib/api/satellites.deprected.api.ts b/src/frontend/src/lib/api/satellites.deprected.api.ts deleted file mode 100644 index cd4bff33a..000000000 --- a/src/frontend/src/lib/api/satellites.deprected.api.ts +++ /dev/null @@ -1,93 +0,0 @@ -import type { ListParams as ListParamsApi } from '$declarations/deprecated/satellite-deprecated-no-scope.did'; -import type { - AssetNoContent, - Doc, - ListResults as ListAssets, - ListResults_1 as ListDocs -} from '$declarations/satellite/satellite.did'; -import { PAGINATION } from '$lib/constants/constants'; -import type { ListParams } from '$lib/types/list'; -import { getSatelliteActorDeprecated } from '$lib/utils/actor.deprecated.utils'; -import { toNullable } from '$lib/utils/did.utils'; -import { isNullish } from '$lib/utils/utils'; -import { Principal } from '@dfinity/principal'; - -const toListParams = ({ - startAfter, - order, - filter: { matcher, owner } -}: ListParams): ListParamsApi => ({ - matcher: toNullable(matcher === '' ? null : matcher), - paginate: [ - { - start_after: toNullable(startAfter), - limit: [PAGINATION] - } - ], - order: [ - { - desc: order.desc, - field: - order.field === 'created_at' - ? { CreatedAt: null } - : order.field === 'updated_at' - ? { UpdatedAt: null } - : { Keys: null } - } - ], - owner: toNullable(owner === '' || isNullish(owner) ? null : Principal.fromText(owner)) -}); - -/** - * @deprecated TODO: to be remove - backwards compatibility - */ -export const listDocsDeprecated = async ({ - satelliteId, - collection, - params -}: { - satelliteId: Principal; - collection: string; - params: ListParams; -}): Promise => { - const actor = await getSatelliteActorDeprecated(satelliteId); - const { - items, - length: items_length, - matches_length - } = await actor.list_docs(collection, toListParams(params)); - return { - items: items as [string, Doc][], - items_length, - items_page: [], - matches_length, - matches_pages: [] - }; -}; - -/** - * @deprecated TODO: to be remove - backwards compatibility - */ -export const listAssetsDeprecated = async ({ - satelliteId, - collection, - params -}: { - satelliteId: Principal; - collection: string; - params: ListParams; -}): Promise => { - const actor = await getSatelliteActorDeprecated(satelliteId); - const { - items, - length: items_length, - matches_length - } = await actor.list_assets(toNullable(collection), toListParams(params)); - return { - items: items as [string, AssetNoContent][], - items_length, - items_page: [], - matches_length, - matches_pages: [] - }; -}; diff --git a/src/frontend/src/lib/components/assets/Assets.svelte b/src/frontend/src/lib/components/assets/Assets.svelte index 68c5da2c5..8e0a0efce 100644 --- a/src/frontend/src/lib/components/assets/Assets.svelte +++ b/src/frontend/src/lib/components/assets/Assets.svelte @@ -3,7 +3,7 @@ import { getContext, setContext } from 'svelte'; import { RULES_CONTEXT_KEY } from '$lib/types/rules.context'; import { isNullish, nonNullish } from '$lib/utils/utils'; - import { listAssets, listDocs, satelliteVersion } from '$lib/api/satellites.api'; + import { listAssets } from '$lib/api/satellites.api'; import { toasts } from '$lib/stores/toasts.store'; import type { AssetNoContent } from '$declarations/satellite/satellite.did'; import type { PaginationContext } from '$lib/types/pagination.context'; @@ -16,9 +16,7 @@ import DataList from '$lib/components/data/DataList.svelte'; import { listParamsStore } from '$lib/stores/data.store'; import CollectionEmpty from '$lib/components/collections/CollectionEmpty.svelte'; - import type { ListParams } from '$lib/types/list'; - import { compare } from 'semver'; - import { listAssetsDeprecated } from '$lib/api/satellites.deprected.api'; + import type {ListParams} from "$lib/types/list"; const { store }: RulesContext = getContext(RULES_CONTEXT_KEY); @@ -29,10 +27,7 @@ } try { - const version = await satelliteVersion({ satelliteId: $store.satelliteId }); - const list = compare(version, '0.0.9') >= 0 ? listAssets : listAssetsDeprecated; - - const { items, matches_length } = await list({ + const { items, matches_length } = await listAssets({ collection, satelliteId: $store.satelliteId, params: { diff --git a/src/frontend/src/lib/components/docs/Docs.svelte b/src/frontend/src/lib/components/docs/Docs.svelte index 7ad245cc2..cb2eab8de 100644 --- a/src/frontend/src/lib/components/docs/Docs.svelte +++ b/src/frontend/src/lib/components/docs/Docs.svelte @@ -3,7 +3,7 @@ import { getContext, setContext } from 'svelte'; import { RULES_CONTEXT_KEY } from '$lib/types/rules.context'; import { isNullish, nonNullish } from '$lib/utils/utils'; - import { listDocs, satelliteVersion } from '$lib/api/satellites.api'; + import { listDocs } from '$lib/api/satellites.api'; import { toasts } from '$lib/stores/toasts.store'; import type { Doc as DocType } from '$declarations/satellite/satellite.did'; import { PAGINATION_CONTEXT_KEY, type PaginationContext } from '$lib/types/pagination.context'; @@ -14,9 +14,7 @@ import DataList from '$lib/components/data/DataList.svelte'; import { listParamsStore } from '$lib/stores/data.store'; import CollectionEmpty from '$lib/components/collections/CollectionEmpty.svelte'; - import type { ListParams } from '$lib/types/list'; - import { compare } from 'semver'; - import { listDocsDeprecated } from '$lib/api/satellites.deprected.api'; + import type {ListParams} from "$lib/types/list"; const { store }: RulesContext = getContext(RULES_CONTEXT_KEY); @@ -27,10 +25,7 @@ } try { - const version = await satelliteVersion({ satelliteId: $store.satelliteId }); - const list = compare(version, '0.0.9') >= 0 ? listDocs : listDocsDeprecated; - - const { items, matches_length } = await list({ + const { items, matches_length } = await listDocs({ collection, satelliteId: $store.satelliteId, params: { diff --git a/src/frontend/src/lib/services/users.services.ts b/src/frontend/src/lib/services/users.services.ts index bf0efe527..29ec7e181 100644 --- a/src/frontend/src/lib/services/users.services.ts +++ b/src/frontend/src/lib/services/users.services.ts @@ -1,10 +1,8 @@ -import { listDocs, satelliteVersion } from '$lib/api/satellites.api'; -import { listDocsDeprecated } from '$lib/api/satellites.deprected.api'; +import { listDocs } from '$lib/api/satellites.api'; import type { ListParams } from '$lib/types/list'; import type { User } from '$lib/types/user'; import { fromArray } from '$lib/utils/did.utils'; import type { Principal } from '@dfinity/principal'; -import { compare } from 'semver'; export const listUsers = async ({ startAfter, @@ -13,10 +11,7 @@ export const listUsers = async ({ users: [string, User][]; matches_length: bigint; }> => { - const version = await satelliteVersion({ satelliteId }); - const list = compare(version, '0.0.9') >= 0 ? listDocs : listDocsDeprecated; - - const { items, matches_length } = await list({ + const { items, matches_length } = await listDocs({ collection: '#user', satelliteId, params: { diff --git a/src/frontend/src/lib/utils/actor.deprecated.utils.ts b/src/frontend/src/lib/utils/actor.deprecated.utils.ts deleted file mode 100644 index 64abe789c..000000000 --- a/src/frontend/src/lib/utils/actor.deprecated.utils.ts +++ /dev/null @@ -1,24 +0,0 @@ -import type { _SERVICE as SatelliteActor } from '$declarations/deprecated/satellite-deprecated-no-scope.did'; -import { idlFactory as idlFactorSatellite } from '$declarations/deprecated/satellite-deprecated-no-scope.factory.did'; -import { authStore } from '$lib/stores/auth.store'; -import { createActor } from '$lib/utils/actor.utils'; -import type { Identity } from '@dfinity/agent'; -import type { Principal } from '@dfinity/principal'; -import { get } from 'svelte/store'; - -/** - * @deprecated TODO: to be remove - backwards compatibility - */ -export const getSatelliteActorDeprecated = (canisterId: Principal): Promise => { - const identity: Identity | undefined | null = get(authStore).identity; - - if (!identity) { - throw new Error('No internet identity.'); - } - - return createActor({ - canisterId, - idlFactory: idlFactorSatellite, - identity - }); -}; diff --git a/src/frontend/src/lib/utils/actor.utils.ts b/src/frontend/src/lib/utils/actor.utils.ts index a3e46a6eb..32d749c41 100644 --- a/src/frontend/src/lib/utils/actor.utils.ts +++ b/src/frontend/src/lib/utils/actor.utils.ts @@ -77,7 +77,7 @@ export const getMissionControlActor = async ( }); }; -export const createActor = async >({ +const createActor = async >({ canisterId, idlFactory, identity