-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7cd359a
commit d1e83d6
Showing
28 changed files
with
314 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...ction/ui/src/{{dna_role_name}}/{{kebab_case coordinator_zome_manifest.name}}/mocks.ts.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{{#merge_scope previous_file_content (concat "export class " (pascal_case app_name) "ZomeMock extends ZomeMock implements AppAgentClient {" ) }} | ||
{{previous_scope_content}} | ||
|
||
{{#if (eq collection_type.type "ByAuthor")}} | ||
async get_{{snake_case collection_name}}(author: AgentPubKey): Promise<Array<Record>> { | ||
const actionHashes: {{referenceable.hash_type}}[] = this.{{camel_case referenceable.name}}.authorMap.get(author); | ||
return actionHashes.map(actionHash => this.{{camel_case referenceable.name}}.entryRecord(actionHash)).map(er => er?.record).filter(r => !!r) as Record[]; | ||
} | ||
|
||
{{else}} | ||
async get_{{snake_case collection_name}}(_: any): Promise<Array<Record>> { | ||
return this.{{camel_case referenceable.name}}.entryRecords.map(er => er?.record).filter(r => !!r) as Record[]; | ||
} | ||
{{/if}} | ||
|
||
{{/merge_scope}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...ofiles")) (not (eq (pascal_case zome_manifest.name) "FileStorage")))}}mocks.ts{{¡if}}.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { | ||
AgentPubKeyMap, | ||
decodeEntry, | ||
fakeEntry, | ||
fakeCreateAction, | ||
fakeUpdateEntry, | ||
fakeDeleteEntry, | ||
fakeRecord, | ||
pickBy, | ||
ZomeMock, | ||
RecordBag, | ||
entryState, | ||
HoloHashMap, | ||
HashType, | ||
hash | ||
} from "@holochain-open-dev/utils"; | ||
import { | ||
decodeHashFromBase64, | ||
AgentPubKey, | ||
ActionHash, | ||
EntryHash, | ||
AppAgentClient, | ||
fakeAgentPubKey, | ||
fakeDnaHash, | ||
fakeActionHash, | ||
fakeEntryHash, | ||
Record, | ||
} from "@holochain/client"; | ||
import { {{pascal_case app_name}}Client } from './{{kebab_case app_name}}-client.js' | ||
|
||
export class {{pascal_case app_name}}ZomeMock extends ZomeMock implements AppAgentClient { | ||
constructor( | ||
myPubKey?: AgentPubKey | ||
) { | ||
super("{{snake_case app_name}}_test", "{{snake_case app_name}}", myPubKey); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
...-type/ui/src/{{dna_role_name}}/{{kebab_case coordinator_zome_manifest.name}}/mocks.ts.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
import { {{pascal_case entry_type.name}} } from './types.js'; | ||
|
||
{{#merge_scope previous_file_content (concat "export class " (pascal_case app_name) "ZomeMock extends ZomeMock implements AppAgentClient {" ) }} | ||
{{previous_scope_content}} | ||
/** {{title_case entry_type.name}} */ | ||
{{camel_case entry_type.name}} = new RecordBag<{{pascal_case entry_type.name}}>(); | ||
{{#each entry_type.fields}} | ||
{{#if linked_from}} | ||
{{camel_case (plural ../entry_type.name)}}For{{pascal_case linked_from.name}} = new HoloHashMap<ActionHash, ActionHash[]>(); | ||
{{/if}} | ||
{{/each}} | ||
|
||
async create_{{snake_case entry_type.name}}({{camel_case entry_type.name}}: {{pascal_case entry_type.name}}): Promise<Record> { | ||
const record = fakeRecord(fakeCreateAction(hash({{camel_case entry_type.name}}, HashType.ENTRY)), fakeEntry({{camel_case entry_type.name}})); | ||
|
||
this.{{camel_case entry_type.name}}.add([record]); | ||
|
||
{{#each entry_type.fields}} | ||
{{#if linked_from}} | ||
{{#if (eq cardinality "single")}} | ||
const existing{{pascal_case field_name}} = this.{{camel_case (plural ../entry_type.name)}}For{{pascal_case linked_from.name}}.get({{camel_case ../entry_type.name}}.{{field_name}}) || []; | ||
this.{{camel_case (plural ../entry_type.name)}}For{{pascal_case linked_from.name}}.set({{camel_case ../entry_type.name}}.{{field_name}}, [...existing{{pascal_case field_name}}, record.signed_action.hashed.hash]); | ||
{{/if}} | ||
{{#if (eq cardinality "option")}} | ||
if ({{camel_case ../entry_type.name}}.{{field_name}}) { | ||
const existing{{pascal_case field_name}} = this.{{camel_case (plural ../entry_type.name)}}For{{pascal_case linked_from.name}}.get({{camel_case ../entry_type.name}}.{{field_name}}) || []; | ||
this.{{camel_case (plural ../entry_type.name)}}For{{pascal_case linked_from.name}}.set({{camel_case ../entry_type.name}}.{{field_name}}, [...existing{{pascal_case field_name}}, record.signed_action.hashed.hash]); | ||
} | ||
{{/if}} | ||
{{#if (eq cardinality "vector")}} | ||
for (const {{field_name}} of {{camel_case ../entry_type.name}}.{{field_name}}) { | ||
const existing{{pascal_case field_name}} = this.{{camel_case (plural ../entry_type.name)}}For{{pascal_case linked_from.name}}.get({{field_name}}) || []; | ||
this.{{camel_case (plural ../entry_type.name)}}For{{pascal_case linked_from.name}}.set({{field_name}}, [...existing{{pascal_case field_name}}, record.signed_action.hashed.hash]); | ||
} | ||
{{/if}} | ||
{{/if}} | ||
{{/each}} | ||
|
||
return record; | ||
} | ||
|
||
async get_{{snake_case entry_type.name}}({{camel_case entry_type.name}}Hash: {{#if entry_type.reference_entry_hash}}EntryHash{{else}}ActionHash{{/if}}): Promise<Record | undefined> { | ||
const state = entryState(this.{{camel_case entry_type.name}}, {{camel_case entry_type.name}}Hash); | ||
|
||
if (!state || state.deleted) return undefined; | ||
|
||
return state.lastUpdate?.record; | ||
} | ||
|
||
{{#if crud.delete}} | ||
async delete_{{snake_case entry_type.name}}(original_{{snake_case entry_type.name}}_hash: ActionHash): Promise<ActionHash> { | ||
const record = fakeRecord(fakeDeleteEntry(original_{{snake_case entry_type.name}}_hash)); | ||
|
||
this.{{camel_case entry_type.name}}.add([record]); | ||
|
||
return record.signed_action.hashed.hash; | ||
} | ||
{{/if}} | ||
|
||
{{#if crud.update}} | ||
async update_{{snake_case entry_type.name}}(input: { {{#if link_from_original_to_each_update}}original_{{snake_case entry_type.name}}_hash: ActionHash; {{/if}}previous_{{snake_case entry_type.name}}_hash: ActionHash; updated_{{snake_case entry_type.name}}: {{pascal_case entry_type.name}}; }): Promise<Record> { | ||
const record = fakeRecord(fakeUpdateEntry(input.previous_{{snake_case entry_type.name}}_hash, fakeEntry(input.updated_{{snake_case entry_type.name}})), fakeEntry(input.updated_{{snake_case entry_type.name}})); | ||
|
||
this.{{camel_case entry_type.name}}.add([record]); | ||
|
||
const {{camel_case entry_type.name}} = input.updated_{{snake_case entry_type.name}}; | ||
|
||
{{#each entry_type.fields}} | ||
{{#if linked_from}} | ||
{{#if (eq cardinality "single")}} | ||
const existing{{pascal_case field_name}} = this.{{camel_case (plural ../entry_type.name)}}For{{pascal_case linked_from.name}}.get({{camel_case ../entry_type.name}}.{{field_name}}) || []; | ||
this.{{camel_case (plural ../entry_type.name)}}For{{pascal_case linked_from.name}}.set({{camel_case ../entry_type.name}}.{{field_name}}, [...existing{{pascal_case field_name}}, record.signed_action.hashed.hash]); | ||
{{/if}} | ||
{{#if (eq cardinality "option")}} | ||
if ({{camel_case ../entry_type.name}}.{{field_name}}) { | ||
const existing{{pascal_case field_name}} = this.{{camel_case (plural ../entry_type.name)}}For{{pascal_case linked_from.name}}.get({{camel_case ../entry_type.name}}.{{field_name}}) || []; | ||
this.{{camel_case (plural ../entry_type.name)}}For{{pascal_case linked_from.name}}.set({{camel_case ../entry_type.name}}.{{field_name}}, [...existing{{pascal_case field_name}}, record.signed_action.hashed.hash]); | ||
} | ||
{{/if}} | ||
{{#if (eq cardinality "vector")}} | ||
for (const {{field_name}} of {{camel_case ../entry_type.name}}.{{field_name}}) { | ||
const existing{{pascal_case field_name}} = this.{{camel_case (plural ../entry_type.name)}}For{{pascal_case linked_from.name}}.get({{field_name}}) || []; | ||
this.{{camel_case (plural ../entry_type.name)}}For{{pascal_case linked_from.name}}.set({{field_name}}, [...existing{{pascal_case field_name}}, record.signed_action.hashed.hash]); | ||
} | ||
{{/if}} | ||
{{/if}} | ||
{{/each}} | ||
|
||
return record; | ||
} | ||
{{/if}} | ||
|
||
{{#each entry_type.fields}} | ||
{{#if linked_from}} | ||
async get_{{snake_case (plural ../entry_type.name)}}_for_{{snake_case linked_from.name}}({{camel_case linked_from.singular_arg}}: {{linked_from.hash_type}}): Promise<Array<Record>> { | ||
const actionHashes: ActionHash[] = this.{{camel_case (plural ../entry_type.name)}}For{{pascal_case linked_from.name}}.get({{camel_case linked_from.singular_arg}}) || []; | ||
|
||
return actionHashes.map(actionHash => this.{{camel_case ../entry_type.name}}.entryRecord(actionHash)?.record).filter(r => !!r) as Record[]; | ||
} | ||
|
||
{{/if}} | ||
{{/each}} | ||
|
||
{{/merge_scope}} | ||
|
||
export async function sample{{pascal_case entry_type.name}}(client: {{pascal_case app_name}}Client, partial{{pascal_case entry_type.name}}: Partial<{{pascal_case entry_type.name}}> = {}): Promise<{{ pascal_case entry_type.name }}> { | ||
return { | ||
...{ | ||
{{#each entry_type.fields}} | ||
{{#if linked_from}} | ||
{{#if (ne linked_from.hash_type "AgentPubKey")}} | ||
{{#if (eq cardinality "vector")}} | ||
{{#if (eq (pascal_case linked_from.name) (pascal_case ../entry_type.name))}} | ||
{{field_name}}: [], | ||
{{else}} | ||
{{#if (eq linked_from.hash_type "ActionHash")}} | ||
{{field_name}}: partial{{pascal_case ../entry_type.name}}.{{field_name}} || [(await client.create{{pascal_case linked_from.name}}(await sample{{pascal_case linked_from.name}}(client))).actionHash], | ||
{{else}} | ||
{{field_name}}: partial{{pascal_case ../entry_type.name}}.{{field_name}} || [(await client.create{{pascal_case linked_from.name}}(await sample{{pascal_case linked_from.name}}(client))).entryHash], | ||
{{/if}} | ||
{{/if}} | ||
{{else}} | ||
{{#if (eq (pascal_case linked_from.name) (pascal_case ../entry_type.name))}} | ||
{{field_name}}: null, | ||
{{else}} | ||
{{#if (eq linked_from.hash_type "ActionHash")}} | ||
{{field_name}}: partial{{pascal_case ../entry_type.name}}.{{field_name}} || (await client.create{{pascal_case linked_from.name}}(await sample{{pascal_case linked_from.name}}(client))).actionHash, | ||
{{else}} | ||
{{field_name}}: partial{{pascal_case entry_type.name}}.{{field_name}} || (await client.create{{pascal_case linked_from.name}}(await sample{{pascal_case linked_from.name}}(client))).entryHash, | ||
{{/if}} | ||
{{/if}} | ||
{{/if}} | ||
{{else}} | ||
{{field_name}}: client.client.myPubKey, | ||
{{/if}} | ||
{{else}} | ||
{{#if (eq cardinality "vector")}} | ||
{{field_name}}: [{{> (concat field_type.type "/sample-js") field_type=field_type}}], | ||
{{else}} | ||
{{field_name}}: {{> (concat field_type.type "/sample-js") field_type=field_type}}, | ||
{{/if}} | ||
{{/if}} | ||
{{/each}} | ||
}, | ||
...partial{{pascal_case entry_type.name}} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...-type/ui/src/{{dna_role_name}}/{{kebab_case coordinator_zome_manifest.name}}/mocks.ts.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{{#merge_scope previous_file_content (concat "export class " (pascal_case app_name) "ZomeMock extends ZomeMock implements AppAgentClient {" ) }} | ||
{{previous_scope_content}} | ||
|
||
/** {{title_case (plural to_referenceable.name)}} for {{title_case from_referenceable.name}} */ | ||
{{camel_case from_referenceable.name}}To{{pascal_case to_referenceable.name}} = new HoloHashMap<{{from_referenceable.hash_type}}, {{to_referenceable.hash_type}}[]>(); | ||
{{#if bidireccional}} | ||
{{camel_case to_referenceable.name}}To{{pascal_case from_referenceable.name}} = new HoloHashMap<{{to_referenceable.hash_type}}, {{from_referenceable.hash_type}}[]>(); | ||
{{/if}} | ||
|
||
{{#if (eq to_referenceable.hash_type "AgentPubKey")}} | ||
async get_{{snake_case (plural to_referenceable.name)}}_for_{{snake_case from_referenceable.name}}({{camel_case from_referenceable.singular_arg}}: {{from_referenceable.hash_type}}): Promise<Array<AgentPubKey>> { | ||
return this.{{camel_case from_referenceable.name}}To{{pascal_case to_referenceable.name}}.get({{camel_case from_referenceable.singular_arg}}) || [] | ||
} | ||
{{else}} | ||
async get_{{snake_case (plural to_referenceable.name)}}_for_{{snake_case from_referenceable.name}}({{camel_case from_referenceable.singular_arg}}: {{from_referenceable.hash_type}}): Promise<Array<Record>> { | ||
const actionHashes: {{to_referenceable.hash_type}}[] = this.{{camel_case from_referenceable.name}}To{{pascal_case to_referenceable.name}}.get({{camel_case from_referenceable.singular_arg}}) || []; | ||
return actionHashes.map(actionHash => this.{{camel_case to_referenceable.name}}.entryRecord(actionHash)).map(er => er?.record).filter(r => !!r) as Record[]; | ||
} | ||
{{/if}} | ||
|
||
async add_{{snake_case to_referenceable.name}}_for_{{snake_case from_referenceable.name}}(input: { {{snake_case from_referenceable.singular_arg}}: {{from_referenceable.hash_type}}; {{snake_case to_referenceable.singular_arg}}: {{to_referenceable.hash_type}} }): Promise<void> { | ||
const existing = this.{{camel_case from_referenceable.name}}To{{pascal_case to_referenceable.name}}.get(input.{{snake_case from_referenceable.singular_arg}}) || []; | ||
this.{{camel_case from_referenceable.name}}To{{pascal_case to_referenceable.name}}.set(input.{{snake_case from_referenceable.singular_arg}}, [...existing, input.{{snake_case to_referenceable.singular_arg}}]); | ||
{{#if bidireccional}} | ||
const existingReverse = this.{{camel_case to_referenceable.name}}To{{pascal_case from_referenceable.name}}.get(input.{{snake_case to_referenceable.singular_arg}}) || []; | ||
this.{{camel_case to_referenceable.name}}To{{pascal_case from_referenceable.name}}.set(input.{{snake_case to_referenceable.singular_arg}}, [...existingReverse, input.{{snake_case from_referenceable.singular_arg}}]); | ||
{{/if}} | ||
} | ||
|
||
{{#if bidireccional}} | ||
{{#if (eq from_referenceable.hash_type "AgentPubKey")}} | ||
async get_{{snake_case (plural from_referenceable.name)}}_for_{{snake_case to_referenceable.name}}({{camel_case to_referenceable.singular_arg}}: {{to_referenceable.hash_type}}): Promise<Array<AgentPubKey>> { | ||
return this.{{camel_case to_referenceable.name}}To{{pascal_case from_referenceable.name}}.get({{camel_case to_referenceable.singular_arg}}) || [] | ||
} | ||
{{else}} | ||
async get_{{snake_case (plural from_referenceable.name)}}_for_{{snake_case to_referenceable.name}}({{camel_case to_referenceable.singular_arg}}: {{to_referenceable.hash_type}}): Promise<Array<Record>> { | ||
const actionHashes: {{from_referenceable.hash_type}}[] = this.{{camel_case to_referenceable.name}}To{{pascal_case from_referenceable.name}}.get({{camel_case to_referenceable.singular_arg}}) || []; | ||
return actionHashes.map(actionHash => this.{{camel_case from_referenceable.name}}.entryRecord(actionHash)).map(er => er?.record).filter(r => !!r) as Record[];; | ||
} | ||
{{/if}} | ||
{{/if}} | ||
|
||
{{/merge_scope}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.