Skip to content

Commit

Permalink
Merge pull request #636 from dfinity/kai/fix-svelte-starter-motoko
Browse files Browse the repository at this point in the history
fix: updates svelte-starter-motoko example
  • Loading branch information
krpeacock authored Dec 19, 2023
2 parents c62de1a + e4fc680 commit 164c677
Show file tree
Hide file tree
Showing 43 changed files with 5,311 additions and 10,001 deletions.

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions svelte/svelte-motoko-starter/deps/init.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"canisters": {
"rdmx6-jaaaa-aaaaa-aaadq-cai": {
"arg_str": "(null)",
"arg_raw": "4449444c0a6e016c069ad9a8dc0402caed93df0403c8d99dab0702dfe1a5de0705f7f5cbfb0702f8d995c60f086e786e046c02007801786e066c04c3f9fca002788beea8c5047881cfaef40a0787eb979d0d7a6d7b6e096c02d5f5c5e909789fedfdc50d78010000"
}
}
}
11 changes: 11 additions & 0 deletions svelte/svelte-motoko-starter/deps/pulled.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"canisters": {
"rdmx6-jaaaa-aaaaa-aaadq-cai": {
"name": "internet-identity",
"wasm_hash": "1ae98d1141204d1aa51a7bf2a01561358b21692dc5c65fc3ab893c41d54763f0",
"init_guide": "Use '(null)' for sensible defaults. See the candid interface for more details.",
"candid_args": "(opt InternetIdentityInit)",
"gzip": true
}
}
}
14 changes: 8 additions & 6 deletions svelte/svelte-motoko-starter/dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
"main": "src/backend/main.mo",
"type": "motoko"
},
"internet-identity": {
"type": "pull",
"id": "rdmx6-jaaaa-aaaaa-aaadq-cai"
},
"frontend": {
"dependencies": [
"backend"
"backend",
"internet-identity"
],
"frontend": {
"entrypoint": "src/frontend/public/index.html"
},
"source": [
"src/frontend/public"
"src/frontend/dist"
],
"type": "assets"
}
Expand All @@ -23,6 +25,6 @@
"packtool": ""
}
},
"dfx": "0.12.0",
"output_env_file": "src/frontend/.env",
"version": 1
}
1 change: 0 additions & 1 deletion svelte/svelte-motoko-starter/internet-identity
Submodule internet-identity deleted from 58a633
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
import type { Principal } from '@dfinity/principal';
export interface _SERVICE { 'whoami' : () => Promise<Principal> }
import type { ActorMethod } from '@dfinity/agent';

export interface _SERVICE { 'whoami' : ActorMethod<[], Principal> }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Version: 1.0.0
actor {

};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Version: 1.0.0
actor {

};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
service : {
whoami: () -> (principal) query;
}
20 changes: 12 additions & 8 deletions svelte/svelte-motoko-starter/src/declarations/backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@ export { idlFactory } from './backend.did.js';
export const canisterId = process.env.BACKEND_CANISTER_ID;

/**
*
* @deprecated since dfx 0.11.1
* Do not import from `.dfx`, instead switch to using `dfx generate` to generate your JS interface.
* @param {string | import("@dfinity/principal").Principal} canisterId Canister ID of Agent
* @param {{agentOptions?: import("@dfinity/agent").HttpAgentOptions; actorOptions?: import("@dfinity/agent").ActorConfig}} [options]
* @param {{agentOptions?: import("@dfinity/agent").HttpAgentOptions; actorOptions?: import("@dfinity/agent").ActorConfig} | { agent?: import("@dfinity/agent").Agent; actorOptions?: import("@dfinity/agent").ActorConfig }} [options]
* @return {import("@dfinity/agent").ActorSubclass<import("./backend.did.js")._SERVICE>}
*/
export const createActor = (canisterId, options) => {
const agent = new HttpAgent({ ...options?.agentOptions });
export const createActor = (canisterId, options = {}) => {
console.warn(`Deprecation warning: you are currently importing code from .dfx. Going forward, refactor to use the dfx generate command for JavaScript bindings.
See https://internetcomputer.org/docs/current/developer-docs/updates/release-notes/ for migration instructions`);
const agent = options.agent || new HttpAgent({ ...options.agentOptions });

// Fetch root key for certificate validation during development
if(process.env.NODE_ENV !== "production") {
agent.fetchRootKey().catch(err=>{
if (process.env.DFX_NETWORK !== "ic") {
agent.fetchRootKey().catch(err => {
console.warn("Unable to fetch root key. Check to ensure that your local replica is running");
console.error(err);
});
Expand All @@ -27,12 +31,12 @@ export const canisterId = process.env.BACKEND_CANISTER_ID;
return Actor.createActor(idlFactory, {
agent,
canisterId,
...options?.actorOptions,
...(options ? options.actorOptions : {}),
});
};

/**
* A ready-to-use agent for the backend canister
* @type {import("@dfinity/agent").ActorSubclass<import("./backend.did.js")._SERVICE>}
*/
export const backend = createActor(canisterId);
export const backend = createActor(canisterId);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
()
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
service : {
whoami: () -> (principal) query;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import type { Principal } from '@dfinity/principal';
import type { ActorMethod } from '@dfinity/agent';

export interface _SERVICE { 'whoami' : ActorMethod<[], Principal> }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const idlFactory = ({ IDL }) => {
return IDL.Service({ 'whoami' : IDL.Func([], [IDL.Principal], ['query']) });
};
export const init = ({ IDL }) => { return []; };
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ type Time = int;
type CreateAssetArguments = record {
key: Key;
content_type: text;
max_age: opt nat64;
headers: opt vec HeaderField;
enable_aliasing: opt bool;
allow_raw_access: opt bool;
};

// Add or change content for an asset, by content encoding
Expand Down Expand Up @@ -34,19 +38,41 @@ type BatchOperationKind = variant {
CreateAsset: CreateAssetArguments;
SetAssetContent: SetAssetContentArguments;

SetAssetProperties: SetAssetPropertiesArguments;

UnsetAssetContent: UnsetAssetContentArguments;
DeleteAsset: DeleteAssetArguments;

Clear: ClearArguments;
};

type CommitBatchArguments = record {
batch_id: BatchId;
operations: vec BatchOperationKind
};

type CommitProposedBatchArguments = record {
batch_id: BatchId;
evidence: blob;
};

type ComputeEvidenceArguments = record {
batch_id: BatchId;
max_iterations: opt nat16
};

type DeleteBatchArguments = record {
batch_id: BatchId;
};

type HeaderField = record { text; text; };

type HttpRequest = record {
method: text;
url: text;
headers: vec HeaderField;
body: blob;
certificate_version: opt nat16;
};

type HttpResponse = record {
Expand Down Expand Up @@ -75,7 +101,64 @@ type StreamingStrategy = variant {
};
};

service: {
type SetAssetPropertiesArguments = record {
key: Key;
max_age: opt opt nat64;
headers: opt opt vec HeaderField;
allow_raw_access: opt opt bool;
is_aliased: opt opt bool;
};

type ConfigurationResponse = record {
max_batches: opt nat64;
max_chunks: opt nat64;
max_bytes: opt nat64;
};

type ConfigureArguments = record {
max_batches: opt opt nat64;
max_chunks: opt opt nat64;
max_bytes: opt opt nat64;
};

type Permission = variant {
Commit;
ManagePermissions;
Prepare;
};

type GrantPermission = record {
to_principal: principal;
permission: Permission;
};
type RevokePermission = record {
of_principal: principal;
permission: Permission;
};
type ListPermitted = record { permission: Permission };

type ValidationResult = variant { Ok : text; Err : text };

type AssetCanisterArgs = variant {
Init: InitArgs;
Upgrade: UpgradeArgs;
};

type InitArgs = record {};

type UpgradeArgs = record {
set_permissions: opt SetPermissions;
};

/// Sets the list of principals granted each permission.
type SetPermissions = record {
prepare: vec principal;
commit: vec principal;
manage_permissions: vec principal;
};

service: (asset_canister_args: opt AssetCanisterArgs) -> {
api_version: () -> (nat16) query;

get: (record {
key: Key;
Expand Down Expand Up @@ -108,12 +191,29 @@ service: {
};
}) query;

certified_tree : (record {}) -> (record {
certificate: blob;
tree: blob;
}) query;

create_batch : (record {}) -> (record { batch_id: BatchId });

create_chunk: (record { batch_id: BatchId; content: blob }) -> (record { chunk_id: ChunkId });

// Perform all operations successfully, or reject
commit_batch: (record { batch_id: BatchId; operations: vec BatchOperationKind }) -> ();
commit_batch: (CommitBatchArguments) -> ();

// Save the batch operations for later commit
propose_commit_batch: (CommitBatchArguments) -> ();

// Given a batch already proposed, perform all operations successfully, or reject
commit_proposed_batch: (CommitProposedBatchArguments) -> ();

// Compute a hash over the CommitBatchArguments. Call until it returns Some(evidence).
compute_evidence: (ComputeEvidenceArguments) -> (opt blob);

// Delete a batch that has been created, or proposed for commit, but not yet committed
delete_batch: (DeleteBatchArguments) -> ();

create_asset: (CreateAssetArguments) -> ();
set_asset_content: (SetAssetContentArguments) -> ();
Expand All @@ -137,4 +237,26 @@ service: {
http_request_streaming_callback: (token: StreamingCallbackToken) -> (opt StreamingCallbackHttpResponse) query;

authorize: (principal) -> ();
deauthorize: (principal) -> ();
list_authorized: () -> (vec principal);
grant_permission: (GrantPermission) -> ();
revoke_permission: (RevokePermission) -> ();
list_permitted: (ListPermitted) -> (vec principal);
take_ownership: () -> ();

get_asset_properties : (key: Key) -> (record {
max_age: opt nat64;
headers: opt vec HeaderField;
allow_raw_access: opt bool;
is_aliased: opt bool; } ) query;
set_asset_properties: (SetAssetPropertiesArguments) -> ();

get_configuration: () -> (ConfigurationResponse);
configure: (ConfigureArguments) -> ();

validate_grant_permission: (GrantPermission) -> (ValidationResult);
validate_revoke_permission: (RevokePermission) -> (ValidationResult);
validate_take_ownership: () -> (ValidationResult);
validate_commit_proposed_batch: (CommitProposedBatchArguments) -> (ValidationResult);
validate_configure: (ConfigureArguments) -> (ValidationResult);
}
Binary file not shown.
Loading

0 comments on commit 164c677

Please sign in to comment.