Skip to content

Commit

Permalink
Added base to links
Browse files Browse the repository at this point in the history
  • Loading branch information
guillemcordoba committed Jul 16, 2024
1 parent fa374ac commit 0c2b63f
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
{{#if (eq collection_type.type "ByAuthor")}}
async get_{{snake_case collection_name}}(author: AgentPubKey): Promise<Array<Link>> {
const records: Record[] = Array.from(this.{{camel_case (plural referenceable.name)}}.values()).map(r => r.revisions[r.revisions.length - 1]).filter(r => r.signed_action.hashed.content.author.toString() === author.toString());
return Promise.all(records.map(async record => ({
return Promise.all(records.map(async record => ({
base: author,
target: {{#if (eq referenceable.hash_type "EntryHash")}}(record.signed_action.hashed.content as NewEntryAction).entry_hash{{else}}record.signed_action.hashed.hash{{/if}},
author: record.signed_action.hashed.content.author,
timestamp: record.signed_action.hashed.content.timestamp,
Expand All @@ -19,7 +20,9 @@
{{else}}
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 => ({
const base = await fakeEntryHash();
return Promise.all(records.map(async record => ({
base,
target: {{#if (eq referenceable.hash_type "EntryHash")}}(record.signed_action.hashed.content as NewEntryAction).entry_hash{{else}}record.signed_action.hashed.hash{{/if}},
author: record.signed_action.hashed.content.author,
timestamp: record.signed_action.hashed.content.timestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { {{pascal_case entry_type.name}} } from './types.js';
{{#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}}, {
base: {{camel_case ../entry_type.name}}.{{field_name}},
target: record.signed_action.hashed.hash,
author: this.myPubKey,
timestamp: Date.now() * 1000,
Expand All @@ -41,6 +42,7 @@ import { {{pascal_case entry_type.name}} } from './types.js';
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}}, {
base: {{camel_case ../entry_type.name}}.{{field_name}},
target: record.signed_action.hashed.hash,
author: this.myPubKey,
timestamp: Date.now() * 1000,
Expand All @@ -54,7 +56,8 @@ import { {{pascal_case entry_type.name}} } from './types.js';
{{#if (eq cardinality "vector")}}
await Promise.all({{camel_case ../entry_type.name}}.{{field_name}}.map(async {{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}}, {
this.{{camel_case (plural ../entry_type.name)}}For{{pascal_case linked_from.name}}.set({{field_name}}, [...existing{{pascal_case field_name}}, {
base: {{field_name}},
target: record.signed_action.hashed.hash,
author: this.myPubKey,
timestamp: Date.now() * 1000,
Expand Down Expand Up @@ -133,6 +136,7 @@ import { {{pascal_case entry_type.name}} } from './types.js';
{{#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}}, {
base: {{camel_case ../entry_type.name}}.{{field_name}},
target: record.signed_action.hashed.hash,
author: record.signed_action.hashed.content.author,
timestamp: record.signed_action.hashed.content.timestamp,
Expand All @@ -146,6 +150,7 @@ import { {{pascal_case entry_type.name}} } from './types.js';
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}}, {
base: {{camel_case ../entry_type.name}}.{{field_name}},
target: record.signed_action.hashed.hash,
author: record.signed_action.hashed.content.author,
timestamp: record.signed_action.hashed.content.timestamp,
Expand All @@ -160,6 +165,7 @@ import { {{pascal_case entry_type.name}} } from './types.js';
await Promise.all({{camel_case ../entry_type.name}}.{{field_name}}.map(async {{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}}, {
base: {{field_name}},
target: record.signed_action.hashed.hash,
author: record.signed_action.hashed.content.author,
timestamp: record.signed_action.hashed.content.timestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

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, {
this.{{camel_case from_referenceable.name}}To{{pascal_case to_referenceable.name}}.set(input.{{snake_case from_referenceable.singular_arg}}, [...existing, {
base: input.{{snake_case from_referenceable.singular_arg}},
target: input.{{snake_case to_referenceable.singular_arg}},
author: this.myPubKey,
timestamp: Date.now() * 1000,
Expand All @@ -25,7 +26,8 @@
}]);
{{#if bidirectional}}
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, {
this.{{camel_case to_referenceable.name}}To{{pascal_case from_referenceable.name}}.set(input.{{snake_case to_referenceable.singular_arg}}, [...existingReverse, {
base: input.{{snake_case to_referenceable.singular_arg}},
target: input.{{snake_case from_referenceable.singular_arg}},
author: this.myPubKey,
timestamp: Date.now() * 1000,
Expand Down
6 changes: 3 additions & 3 deletions templates/app/web-app/tests/package.json.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
},
"dependencies": {
"@msgpack/msgpack": "^2.8.0",
"@holochain/client": "^0.17.0",
"@holochain/client": "^0.17.1",
"@holochain/tryorama": "{{tryorama_version}}",
"@holochain-open-dev/signals": "^0.300.3",
"@holochain-open-dev/utils": "^0.300.0",
"@holochain-open-dev/signals": "^0.300.6",
"@holochain-open-dev/utils": "^0.300.2",
"typescript": "^5.4.5",
"vitest": "^1.4.0"
},
Expand Down
8 changes: 4 additions & 4 deletions templates/app/web-app/ui/package.json.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
"localize:build": "lit-localize build"
},
"dependencies": {
"@holochain/client": "^0.17.0",
"@holochain-open-dev/elements": "^0.300.0",
"@holochain-open-dev/signals": "^0.300.3",
"@holochain-open-dev/utils": "^0.300.0",
"@holochain/client": "^0.17.1",
"@holochain-open-dev/elements": "^0.300.1",
"@holochain-open-dev/signals": "^0.300.6",
"@holochain-open-dev/utils": "^0.300.2",
"@lit/context": "^1.0.0",
"@lit/localize": "^0.12.0",
"@mdi/js": "^7.2.0",
Expand Down
8 changes: 6 additions & 2 deletions templates/zome/collection/ui/src/mocks.ts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
{{#if (eq collection_type.type "ByAuthor")}}
async get_{{snake_case collection_name}}(author: AgentPubKey): Promise<Array<Link>> {
const records: Record[] = Array.from(this.{{camel_case (plural referenceable.name)}}.values()).map(r => r.revisions[r.revisions.length - 1]).filter(r => r.signed_action.hashed.content.author.toString() === author.toString());
return Promise.all(records.map(async record => ({
const base = await fakeEntryHash();
return Promise.all(records.map(async record => ({
base,
target: {{#if (eq referenceable.hash_type "EntryHash")}}(record.signed_action.hashed.content as NewEntryAction).entry_hash{{else}}record.signed_action.hashed.hash{{/if}},
author: record.signed_action.hashed.content.author,
timestamp: record.signed_action.hashed.content.timestamp,
Expand All @@ -19,7 +21,9 @@
{{else}}
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 => ({
const base = await fakeEntryHash();
return Promise.all(records.map(async record => ({
base,
target: {{#if (eq referenceable.hash_type "EntryHash")}}(record.signed_action.hashed.content as NewEntryAction).entry_hash{{else}}record.signed_action.hashed.hash{{/if}},
author: record.signed_action.hashed.content.author,
timestamp: record.signed_action.hashed.content.timestamp,
Expand Down
10 changes: 8 additions & 2 deletions templates/zome/entry-type/ui/src/mocks.ts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { {{pascal_case entry_type.name}} } from './types.js';
{{#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}}, {
base: {{camel_case ../entry_type.name}}.{{field_name}},
target: record.signed_action.hashed.hash,
author: this.myPubKey,
timestamp: Date.now() * 1000,
Expand All @@ -40,7 +41,8 @@ import { {{pascal_case entry_type.name}} } from './types.js';
{{#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}}, {
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}}, {
base: {{camel_case ../entry_type.name}}.{{field_name}},
target: record.signed_action.hashed.hash,
author: this.myPubKey,
timestamp: Date.now() * 1000,
Expand All @@ -54,7 +56,8 @@ import { {{pascal_case entry_type.name}} } from './types.js';
{{#if (eq cardinality "vector")}}
await Promise.all({{camel_case ../entry_type.name}}.{{field_name}}.map(async {{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}}, {
this.{{camel_case (plural ../entry_type.name)}}For{{pascal_case linked_from.name}}.set({{field_name}}, [...existing{{pascal_case field_name}}, {
base: {{field_name}},
target: record.signed_action.hashed.hash,
author: this.myPubKey,
timestamp: Date.now() * 1000,
Expand Down Expand Up @@ -133,6 +136,7 @@ import { {{pascal_case entry_type.name}} } from './types.js';
{{#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}}, {
base: {{camel_case ../entry_type.name}}.{{field_name}},
target: record.signed_action.hashed.hash,
author: record.signed_action.hashed.content.author,
timestamp: record.signed_action.hashed.content.timestamp,
Expand All @@ -146,6 +150,7 @@ import { {{pascal_case entry_type.name}} } from './types.js';
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}}, {
base: {{camel_case ../entry_type.name}}.{{field_name}},
target: record.signed_action.hashed.hash,
author: record.signed_action.hashed.content.author,
timestamp: record.signed_action.hashed.content.timestamp,
Expand All @@ -160,6 +165,7 @@ import { {{pascal_case entry_type.name}} } from './types.js';
await Promise.all({{camel_case ../entry_type.name}}.{{field_name}}.map(async {{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}}, {
base: {{field_name}},
target: record.signed_action.hashed.hash,
author: record.signed_action.hashed.content.author,
timestamp: record.signed_action.hashed.content.timestamp,
Expand Down
6 changes: 4 additions & 2 deletions templates/zome/link-type/ui/src/mocks.ts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

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, {
this.{{camel_case from_referenceable.name}}To{{pascal_case to_referenceable.name}}.set(input.{{snake_case from_referenceable.singular_arg}}, [...existing, {
base: input.{{snake_case from_referenceable.singular_arg}},
target: input.{{snake_case to_referenceable.singular_arg}},
author: this.myPubKey,
timestamp: Date.now() * 1000,
Expand All @@ -25,7 +26,8 @@
}]);
{{#if bidirectional}}
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, {
this.{{camel_case to_referenceable.name}}To{{pascal_case from_referenceable.name}}.set(input.{{snake_case to_referenceable.singular_arg}}, [...existingReverse, {
base: input.{{snake_case to_referenceable.singular_arg}},
target: input.{{snake_case from_referenceable.singular_arg}},
author: this.myPubKey,
timestamp: Date.now() * 1000,
Expand Down
2 changes: 1 addition & 1 deletion templates/zome/web-app/docs/package.json.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"devDependencies": {
"@api-viewer/demo": "1.0.0-pre.10",
"@api-viewer/docs": "1.0.0-pre.10",
"@holochain/client": "^0.17.0",
"@holochain/client": "^0.17.1",
"@holochain-open-dev/profiles": "github:holochain-open-dev/profiles#nixify&path:ui",
"@holochain-open-dev/{{kebab_case app_name}}": "workspace:*",
"@shoelace-style/shoelace": "^2.11.0",
Expand Down
6 changes: 3 additions & 3 deletions templates/zome/web-app/tests/package.json.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
},
"dependencies": {
"@msgpack/msgpack": "^2.8.0",
"@holochain/client": "^0.17.0",
"@holochain/client": "^0.17.1",
"@holochain/tryorama": "{{tryorama_version}}",
"@holochain-open-dev/signals": "^0.300.3",
"@holochain-open-dev/utils": "^0.300.0",
"@holochain-open-dev/signals": "^0.300.6",
"@holochain-open-dev/utils": "^0.300.2",
"typescript": "^5.4.5",
"vitest": "^1.4.0"
},
Expand Down
8 changes: 4 additions & 4 deletions templates/zome/web-app/ui/package.json.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
"./locales/*": "./locales/*"
},
"dependencies": {
"@holochain/client": "^0.17.0",
"@holochain-open-dev/elements": "^0.300.0",
"@holochain/client": "^0.17.1",
"@holochain-open-dev/elements": "^0.300.1",
"@holochain-open-dev/profiles": "github:holochain-open-dev/profiles#nixify&path:ui",
"@holochain-open-dev/signals": "^0.300.3",
"@holochain-open-dev/utils": "^0.300.0",
"@holochain-open-dev/signals": "^0.300.6",
"@holochain-open-dev/utils": "^0.300.2",
"@lit/context": "^1.0.0",
"@lit/localize": "^0.12.0",
"@mdi/js": "^7.2.0",
Expand Down

0 comments on commit 0c2b63f

Please sign in to comment.