Skip to content

Commit

Permalink
Reimport template
Browse files Browse the repository at this point in the history
  • Loading branch information
guillemcordoba committed May 7, 2024
1 parent 9f706d0 commit 61f68d8
Show file tree
Hide file tree
Showing 42 changed files with 480 additions and 465 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async fn create_a_{{snake_case referenceable.name}}_and_get_{{snake_case collect
// Alice creates a {{pascal_case referenceable.name}}
let record: Record = create_{{snake_case referenceable.name}}(&conductors[0], &alice_zome, sample.clone()).await;

await_consistency(Duration::from_secs(30), [&alice, &bobbo])
await_consistency(Duration::from_secs(60), [&alice, &bobbo])
.await
.expect("Timed out waiting for consistency");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { runScenario, dhtSync } from '@holochain/tryorama';
import { ActionHash, Record, EntryHash } from '@holochain/client';
import { decode } from '@msgpack/msgpack';
import { EntryRecord } from '@holochain-open-dev/utils';
import { toPromise } from '@holochain-open-dev/stores';
import { toPromise } from '@holochain-open-dev/signals';

import { {{pascal_case referenceable.name}} } from '../../../../ui/src/{{dna_role_name}}/{{snake_case coordinator_zome_manifest.name}}/types.js';
import { sample{{pascal_case referenceable.name}} } from '../../../../ui/src/{{dna_role_name}}/{{snake_case coordinator_zome_manifest.name}}/mocks.js';
Expand All @@ -15,7 +15,7 @@ test('create a {{pascal_case referenceable.name}} and get {{lower_case collectio
const { alice, bob } = await setup(scenario);

// Bob gets {{lower_case collection_name}}
let collectionOutput = await toPromise(bob.store.{{camel_case collection_name}}{{#if (eq collection_type.type "ByAuthor")}}.get(alice.player.agentPubKey){{/if}});
let collectionOutput = await toPromise(bob.store.{{camel_case collection_name}}{{#if (eq collection_type.type "ByAuthor")}}.get(alice.player.agentPubKey){{/if}}$);
assert.equal(collectionOutput.size, 0);

// Alice creates a {{pascal_case referenceable.name}}
Expand All @@ -28,7 +28,7 @@ test('create a {{pascal_case referenceable.name}} and get {{lower_case collectio
);

// Bob gets {{lower_case collection_name}} again
collectionOutput = await toPromise(bob.store.{{camel_case collection_name}}{{#if (eq collection_type.type "ByAuthor")}}.get(alice.player.agentPubKey){{/if}});
collectionOutput = await toPromise(bob.store.{{camel_case collection_name}}{{#if (eq collection_type.type "ByAuthor")}}.get(alice.player.agentPubKey){{/if}}$);
assert.equal(collectionOutput.size, 1);
assert.deepEqual({{camel_case referenceable.name}}.{{#if (eq referenceable.hash_type "ActionHash")}}actionHash{{else}}entryHash{{/if}}, Array.from(collectionOutput.keys())[0]);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { LitElement, html } from 'lit';
import { state, customElement, property } from 'lit/decorators.js';
import { AgentPubKey, EntryHash, ActionHash, Record } from '@holochain/client';
import { subscribe } from '@holochain-open-dev/stores';
import { SignalWatcher } from '@holochain-open-dev/signals';
import { consume } from '@lit/context';
import { localized, msg } from '@lit/localize';
import { hashProperty, sharedStyles, wrapPathInSvg, renderAsyncStatus } from '@holochain-open-dev/elements';
import { hashProperty, sharedStyles, wrapPathInSvg } from '@holochain-open-dev/elements';
import { mdiInformationOutline } from '@mdi/js';

import '@holochain-open-dev/elements/dist/elements/display-error.js';
Expand All @@ -20,10 +20,12 @@ import { {{camel_case coordinator_zome_manifest.name}}StoreContext } from '../co
*/
@localized()
@customElement('{{kebab_case collection_name}}')
export class {{pascal_case collection_name}} extends LitElement {
export class {{pascal_case collection_name}} extends SignalWatcher(LitElement) {
{{#if (eq collection_type.type "ByAuthor")}}

// REQUIRED. The author for which the {{plural (pascal_case referenceable.name)}} should be fetched
/**
* REQUIRED. The author for which the {{plural (pascal_case referenceable.name)}} should be fetched
*/
@property(hashProperty('author'))
author!: AgentPubKey;
{{/if}}
Expand Down Expand Up @@ -63,20 +65,21 @@ export class {{pascal_case collection_name}} extends LitElement {
}

render() {
return html`${subscribe(this.{{camel_case coordinator_zome_manifest.name}}Store.{{camel_case collection_name}}{{#if (eq collection_type.type "ByAuthor")}}.get(this.author){{/if}},
renderAsyncStatus({
complete: map => this.renderList(Array.from(map.keys())),
pending: () => html`<div
style="display: flex; flex-direction: column; align-items: center; justify-content: center; flex: 1;"
>
const map = this.{{camel_case coordinator_zome_manifest.name}}Store.{{camel_case collection_name}}{{#if (eq collection_type.type "ByAuthor")}}.get(this.author){{else}}${{/if}}.get();

switch (map.status) {
case 'pending':
return html`<div style="display: flex; flex-direction: column; align-items: center; justify-content: center; flex: 1;">
<sl-spinner style="font-size: 2rem;"></sl-spinner>
</div>`,
error: e => html`<display-error
</div>`;
case 'error':
return html`<display-error
.headline=${msg("Error fetching the {{lower_case (plural referenceable.name)}}")}
.error=${e}
></display-error>`
})
)}`;
.error=${map.error}
></display-error>`;
case 'completed':
return this.renderList(Array.from(map.value.keys()));
}
}

static styles = [sharedStyles];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}

{{else}}
async get_{{snake_case collection_name}}(_: any): Promise<Array<Link>> {
async get_{{snake_case collection_name}}(): Promise<Array<Link>> {
const records: Record[] = Array.from(this.{{camel_case (plural referenceable.name)}}.values()).map(r => r.revisions[r.revisions.length - 1]);
return Promise.all(records.map(async record => ({
target: {{#if (eq referenceable.hash_type "EntryHash")}}(record.signed_action.hashed.content as NewEntryAction).entry_hash{{else}}record.signed_action.hashed.hash{{/if}},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

{{#if (eq collection_type.type "ByAuthor")}}
{{camel_case collection_name}} = new LazyHoloHashMap((author: AgentPubKey) =>
pipe(
collectionStore(
mapCompleted(
collectionSignal(
this.client,
() => this.client.get{{pascal_case collection_name}}(author),
'{{pascal_case collection_name}}'
Expand All @@ -16,8 +16,8 @@
)
);
{{else}}
{{camel_case collection_name}} = pipe(
collectionStore(
{{camel_case collection_name}}$ = mapCompleted(
collectionSignal(
this.client,
() => this.client.get{{pascal_case collection_name}}(),
'{{pascal_case collection_name}}'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ inputs, rootPath, excludedCrates, ... }:
{ inputs, rootPath, ... }:

{
perSystem =
Expand All @@ -7,7 +7,6 @@
, ...
}: {
packages.{{zome_manifest.name}} = inputs.hc-infra.outputs.lib.rustZome {
inherit excludedCrates;
workspacePath = rootPath;
holochain = inputs'.holochain;
crateCargoToml = ./Cargo.toml;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { {{pascal_case zome_manifest.name}}Client } from './{{dna_role_name}}/{{
import { {{pascal_case zome_manifest.name}}Store } from './{{dna_role_name}}/{{kebab_case zome_manifest.name}}/{{kebab_case zome_manifest.name}}-store.js';

{{#merge previous_file_content}}
{{#match_scope "export class HolochainApp extends LitElement {"}}
{{#match_scope "export class HolochainApp extends SignalWatcher(LitElement) {"}}
@provide({ context: {{camel_case zome_manifest.name}}StoreContext })
@property()
_{{camel_case zome_manifest.name}}Store!: {{pascal_case zome_manifest.name}}Store;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { createContext } from '@lit/context';
import { {{pascal_case zome_manifest.name}}Store } from './{{kebab_case zome_manifest.name}}-store.js';

export const {{camel_case zome_manifest.name}}StoreContext = createContext<{{pascal_case zome_manifest.name}}Store>(
'hc_zome_{{snake_case zome_manifest.name}}/store'
'{{snake_case zome_manifest.name}}/store'
);

Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {
collectionStore,
liveLinksStore,
deletedLinksStore,
allRevisionsOfEntryStore,
latestVersionOfEntryStore,
immutableEntryStore,
deletesForEntryStore,
AsyncReadable,
pipe
} from "@holochain-open-dev/stores";
collectionSignal,
liveLinksSignal,
deletedLinksSignal,
allRevisionsOfEntrySignal,
latestVersionOfEntrySignal,
immutableEntrySignal,
deletesForEntrySignal,
mapCompleted,
AsyncComputed
} from "@holochain-open-dev/signals";
import { slice, HashType, retype, EntryRecord, LazyHoloHashMap } from "@holochain-open-dev/utils";
import { NewEntryAction, Record, ActionHash, EntryHash, AgentPubKey } from '@holochain/client';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,21 @@ pub async fn sample_{{snake_case entry_type.name}}_1(conductor: &SweetConductor,
{{/if}}
{{/if}}
{{else}}
{{field_name}}: zome.cell_id().agent_pubkey().clone(),
{{#if (eq cardinality "vector")}}
{{field_name}}: vec![zome.cell_id().agent_pubkey().clone()],
{{else}}
{{field_name}}: zome.cell_id().agent_pubkey().clone(),
{{/if}}
{{/if}}
{{else}}
{{#if (eq cardinality "vector")}}
{{field_name}}: vec![{{> (concat field_type.type "/sample1")}}],
{{else}}
{{#if (eq cardinality "option")}}
{{field_name}}: Some({{> (concat field_type.type "/sample1")}}),
{{else}}
{{field_name}}: {{> (concat field_type.type "/sample1")}},
{{/if}}
{{/if}}
{{/if}}
{{/each}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async fn create_and_read_{{snake_case entry_type.name}}() {
// Alice creates a {{pascal_case entry_type.name}}
let record: Record = create_{{snake_case entry_type.name}}(&conductors[0], &alice_zome, sample.clone()).await;

await_consistency(Duration::from_secs(30), [&alice, &bobbo])
await_consistency(Duration::from_secs(60), [&alice, &bobbo])
.await
.expect("Timed out waiting for consistency");

Expand Down Expand Up @@ -117,7 +117,7 @@ async fn create_and_update_{{snake_case entry_type.name}}() {
let record: Record = create_{{snake_case entry_type.name}}(&conductors[0], &alice_zome, sample_1.clone()).await;
let original_action_hash = record.signed_action.hashed.hash.clone();

await_consistency(Duration::from_secs(30), [&alice, &bobbo])
await_consistency(Duration::from_secs(60), [&alice, &bobbo])
.await
.expect("Timed out waiting for consistency");

Expand All @@ -138,7 +138,7 @@ async fn create_and_update_{{snake_case entry_type.name}}() {
let entry: {{pascal_case entry_type.name}} = update_record.entry().to_app_option().unwrap().unwrap();
assert_eq!(sample_2, entry);

await_consistency(Duration::from_secs(30), [&alice, &bobbo])
await_consistency(Duration::from_secs(60), [&alice, &bobbo])
.await
.expect("Timed out waiting for consistency");

Expand All @@ -164,7 +164,7 @@ async fn create_and_update_{{snake_case entry_type.name}}() {
let entry: {{pascal_case entry_type.name}} = update_record.entry().to_app_option().unwrap().unwrap();
assert_eq!(sample_1, entry);

await_consistency(Duration::from_secs(30), [&alice, &bobbo])
await_consistency(Duration::from_secs(60), [&alice, &bobbo])
.await
.expect("Timed out waiting for consistency");

Expand Down Expand Up @@ -206,7 +206,7 @@ async fn create_and_delete_{{snake_case entry_type.name}}() {
.call(&alice_zome, "delete_{{snake_case entry_type.name}}", original_action_hash.clone())
.await;

await_consistency(Duration::from_secs(30), [&alice, &bobbo])
await_consistency(Duration::from_secs(60), [&alice, &bobbo])
.await
.expect("Timed out waiting for consistency");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ActionHash, SignedActionHashed, Delete, Record } from '@holochain/clien
import { decode } from '@msgpack/msgpack';
import { EntryRecord } from '@holochain-open-dev/utils';
import { cleanNodeDecoding } from '@holochain-open-dev/utils/dist/clean-node-decoding.js';
import { toPromise } from '@holochain-open-dev/stores';
import { toPromise } from '@holochain-open-dev/signals';

import { {{pascal_case entry_type.name}} } from '../../../../ui/src/{{dna_role_name}}/{{snake_case coordinator_zome_manifest.name}}/types.js';
import { sample{{pascal_case entry_type.name}} } from '../../../../ui/src/{{dna_role_name}}/{{snake_case coordinator_zome_manifest.name}}/mocks.js';
Expand Down Expand Up @@ -38,7 +38,7 @@ test('create and read {{pascal_case entry_type.name}}', async () => {
);

// Bob gets the created {{pascal_case entry_type.name}}
const createReadOutput: EntryRecord<{{pascal_case entry_type.name}}> = await toPromise(bob.store.{{camel_case (plural entry_type.name)}}.get({{camel_case entry_type.name}}{{#if entry_type.reference_entry_hash}}.entryHash{{else}}.actionHash{{/if}}){{#if crud.update}}.original{{else}}.entry{{/if}});
const createReadOutput: EntryRecord<{{pascal_case entry_type.name}}> = await toPromise(bob.store.{{camel_case (plural entry_type.name)}}.get({{camel_case entry_type.name}}{{#if entry_type.reference_entry_hash}}.entryHash{{else}}.actionHash{{/if}}){{#if crud.update}}.original{{else}}.entry{{/if}}$);
assert.deepEqual(sample, cleanNodeDecoding(createReadOutput.entry));
});
});
Expand Down Expand Up @@ -67,7 +67,7 @@ test('create and update {{pascal_case entry_type.name}}', async () => {
);

// Bob gets the updated {{pascal_case entry_type.name}}
const readUpdatedOutput0: EntryRecord<{{pascal_case entry_type.name}}> = await toPromise(bob.store.{{camel_case (plural entry_type.name)}}.get({{camel_case entry_type.name}}.actionHash).latestVersion);
const readUpdatedOutput0: EntryRecord<{{pascal_case entry_type.name}}> = await toPromise(bob.store.{{camel_case (plural entry_type.name)}}.get({{camel_case entry_type.name}}.actionHash).latestVersion$);
assert.deepEqual(contentUpdate, cleanNodeDecoding(readUpdatedOutput0.entry));

// Alice updates the {{pascal_case entry_type.name}} again
Expand All @@ -83,7 +83,7 @@ test('create and update {{pascal_case entry_type.name}}', async () => {
);

// Bob gets the updated {{pascal_case entry_type.name}}
const readUpdatedOutput1: EntryRecord<{{pascal_case entry_type.name}}> = await toPromise(bob.store.{{camel_case (plural entry_type.name)}}.get(originalActionHash).latestVersion);
const readUpdatedOutput1: EntryRecord<{{pascal_case entry_type.name}}> = await toPromise(bob.store.{{camel_case (plural entry_type.name)}}.get(originalActionHash).latestVersion$);
assert.deepEqual(contentUpdate, cleanNodeDecoding(readUpdatedOutput1.entry));
});
});
Expand All @@ -109,7 +109,7 @@ test('create and delete {{pascal_case entry_type.name}}', async () => {
);

// Bob tries to get the deleted {{pascal_case entry_type.name}}
const deletes: Array<SignedActionHashed<Delete>> = await toPromise(bob.store.{{camel_case (plural entry_type.name)}}.get({{camel_case entry_type.name}}.actionHash).deletes);
const deletes: Array<SignedActionHashed<Delete>> = await toPromise(bob.store.{{camel_case (plural entry_type.name)}}.get({{camel_case entry_type.name}}.actionHash).deletes$);
assert.equal(deletes.length, 1);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { repeat } from "lit/directives/repeat.js";
import { state, property, query, customElement } from 'lit/decorators.js';
import { ActionHash, Record, DnaHash, AgentPubKey, EntryHash } from '@holochain/client';
import { EntryRecord } from '@holochain-open-dev/utils';
import { SignalWatcher } from '@holochain-open-dev/signals';
import { hashProperty, notifyError, hashState, sharedStyles, onSubmit, wrapPathInSvg } from '@holochain-open-dev/elements';
import { consume } from '@lit/context';
import { localized, msg } from '@lit/localize';
Expand Down Expand Up @@ -34,19 +35,32 @@ import { {{pascal_case entry_type.name}}{{#each entry_type.fields}}{{#if (eq fie
*/
@localized()
@customElement('create-{{kebab_case entry_type.name}}')
export class Create{{pascal_case entry_type.name}} extends LitElement {
export class Create{{pascal_case entry_type.name}} extends SignalWatcher(LitElement) {
{{#each entry_type.fields}}
{{#if (not widget) }}
{{#if (not (eq cardinality "vector" ) )}}
// REQUIRED. The {{lower_case field_name}} for this {{pascal_case ../entry_type.name}}
{{#if (eq cardinality "single" )}}
/**
* REQUIRED. The {{lower_case field_name}} for this {{pascal_case ../entry_type.name}}
*/
@property({{#if (or (eq field_type.type "AgentPubKey") (or (eq field_type.type "ActionHash") (eq field_type.type "EntryHash" ) ) ) }}hashProperty('{{kebab_case field_name}}'){{/if}})
{{camel_case field_name}}!: {{> (concat field_type.type "/type") }};

{{else}}
// REQUIRED. The {{plural (lower_case field_name)}} for this {{pascal_case ../entry_type.name}}
{{#if (eq cardinality "vector" )}}
/**
* REQUIRED. The {{plural (lower_case field_name)}} for this {{pascal_case ../entry_type.name}}
*/
@property()
{{camel_case field_name}}!: Array<{{> (concat field_type.type "/type") }}>;

{{else}}
/**
* OPTIONAl. The {{lower_case field_name}} for this {{pascal_case ../entry_type.name}}
*/
@property({{#if (or (eq field_type.type "AgentPubKey") (or (eq field_type.type "ActionHash") (eq field_type.type "EntryHash" ) ) ) }}hashProperty('{{kebab_case field_name}}'){{/if}})
{{camel_case field_name}}: {{> (concat field_type.type "/type") }} | undefined;

{{/if}}
{{/if}}
{{/if}}
{{/each}}
Expand Down Expand Up @@ -81,7 +95,7 @@ export class Create{{pascal_case entry_type.name}} extends LitElement {
{{/if}}
{{/each}}

async create{{pascal_case entry_type.name}}(fields: any) {
async create{{pascal_case entry_type.name}}(fields: Partial<{{pascal_case entry_type.name}}>) {
{{#each entry_type.fields}}
{{#if (not widget)}}
{{#if (ne cardinality "option")}}
Expand All @@ -94,12 +108,12 @@ export class Create{{pascal_case entry_type.name}} extends LitElement {
{{#each entry_type.fields}}
{{#if widget}}
{{#if (eq cardinality "vector")}}
{{snake_case field_name}}: (Array.isArray(fields.{{snake_case field_name}}) ? fields.{{snake_case field_name}} : [fields.{{snake_case field_name}}]).map((el: any) => {{> (concat field_type.type "/" widget "/edit/to-value") field_name=field_name variable_to_read="el" }}),
{{snake_case field_name}}: (Array.isArray(fields.{{snake_case field_name}}!) ? fields.{{snake_case field_name}}! : [fields.{{snake_case field_name}}!] as unknown as Array<{{> (concat field_type.type "/type") }}>).map((el) => {{> (concat field_type.type "/" widget "/edit/to-value") field_name=field_name variable_to_read="el" }}),
{{else}}
{{snake_case field_name}}: {{> (concat field_type.type "/" widget "/edit/to-value") field_name=field_name variable_to_read=(concat "fields." (snake_case field_name)) }},
{{snake_case field_name}}: {{> (concat field_type.type "/" widget "/edit/to-value") field_name=field_name variable_to_read=(concat "fields." (snake_case field_name) "!" ) }},
{{/if}}
{{else}}
{{snake_case field_name}}: this.{{camel_case field_name}},
{{snake_case field_name}}: this.{{camel_case field_name}}!,
{{/if}}
{{/each}}
};
Expand All @@ -117,7 +131,7 @@ export class Create{{pascal_case entry_type.name}} extends LitElement {
}));

this.form.reset();
} catch (e: any) {
} catch (e: unknown) {
console.error(e);
notifyError(msg("Error creating the {{lower_case entry_type.name}}"));
}
Expand Down
Loading

0 comments on commit 61f68d8

Please sign in to comment.