Skip to content

Commit

Permalink
refactor: api-delegations
Browse files Browse the repository at this point in the history
  • Loading branch information
marthendalnunes committed Dec 4, 2024
1 parent af7afc0 commit a405722
Show file tree
Hide file tree
Showing 21 changed files with 512 additions and 74 deletions.
3 changes: 2 additions & 1 deletion apps/api-delegations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"postgres": "^3.4.5",
"viem": "^2.21.41",
"zod": "^3.23.8",
"universal-data": "workspace:*"
"universal-data": "workspace:*",
"universal-types": "workspace:*"
},
"devDependencies": {
"@types/pg": "^8.11.10",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { type SQL, eq } from 'drizzle-orm';
import type { GetDelegationsParams } from '../../../validation.js';
import { db } from '../../index.js';
import { type DelegationDb, delegations } from '../../schema.js';
import { delegations } from '../../schema.js';
import { sqlLower } from '../../utils.js';
import type { DelegationWithChainIdMetadata } from 'universal-types';

export type GetDelegationsDbReturnType = DelegationDb[] | undefined;
export type GetDelegationsDbReturnType =
| DelegationWithChainIdMetadata[]
| undefined;

export function getDelegationsDb({
chainId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import type { DelegationWithChainIdMetadataHash } from 'universal-types';
import { db } from '../../index.js';
import {
type InsertCaveatDb,
type InsertDelegationDb,
caveats as caveatsDb,
delegations as delegationsDb,
} from '../../schema.js';

type InsertDelegationDbParams = InsertDelegationDb & {
caveats: Omit<InsertCaveatDb, 'id' | 'delegationHash'>[];
};
type InsertDelegationDbParams = DelegationWithChainIdMetadataHash;

export function insertDelegationDb({
caveats,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "caveats" RENAME COLUMN "enforcerType" TO "type";
1 change: 1 addition & 0 deletions apps/api-delegations/src/db/migrations/0005_lean_rhino.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "delegations" DROP COLUMN IF EXISTS "verifyingContract";
156 changes: 156 additions & 0 deletions apps/api-delegations/src/db/migrations/meta/0004_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
{
"id": "82e90e7e-c11d-4bc1-a2d9-d424468eb207",
"prevId": "66aff067-9977-4af1-b07f-44aa4df06804",
"version": "7",
"dialect": "postgresql",
"tables": {
"public.caveats": {
"name": "caveats",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"type": {
"name": "type",
"type": "varchar(256)",
"primaryKey": false,
"notNull": true
},
"enforcer": {
"name": "enforcer",
"type": "varchar(42)",
"primaryKey": false,
"notNull": true
},
"terms": {
"name": "terms",
"type": "text",
"primaryKey": false,
"notNull": true
},
"args": {
"name": "args",
"type": "text",
"primaryKey": false,
"notNull": true
},
"delegationHash": {
"name": "delegationHash",
"type": "varchar(66)",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {
"caveats_delegationHash_delegations_hash_fk": {
"name": "caveats_delegationHash_delegations_hash_fk",
"tableFrom": "caveats",
"tableTo": "delegations",
"columnsFrom": [
"delegationHash"
],
"columnsTo": [
"hash"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.delegations": {
"name": "delegations",
"schema": "",
"columns": {
"hash": {
"name": "hash",
"type": "varchar(66)",
"primaryKey": true,
"notNull": true
},
"verifyingContract": {
"name": "verifyingContract",
"type": "varchar(42)",
"primaryKey": false,
"notNull": true
},
"type": {
"name": "type",
"type": "varchar(256)",
"primaryKey": false,
"notNull": true
},
"delegator": {
"name": "delegator",
"type": "varchar(42)",
"primaryKey": false,
"notNull": true
},
"chainId": {
"name": "chainId",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"delegate": {
"name": "delegate",
"type": "varchar(42)",
"primaryKey": false,
"notNull": true
},
"authority": {
"name": "authority",
"type": "varchar(66)",
"primaryKey": false,
"notNull": true
},
"salt": {
"name": "salt",
"type": "bigint",
"primaryKey": false,
"notNull": true
},
"signature": {
"name": "signature",
"type": "text",
"primaryKey": false,
"notNull": true
},
"isValid": {
"name": "isValid",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": true
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
}
},
"enums": {},
"schemas": {},
"sequences": {},
"roles": {},
"policies": {},
"views": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}
150 changes: 150 additions & 0 deletions apps/api-delegations/src/db/migrations/meta/0005_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
{
"id": "1f0dc50b-abed-4990-b8a2-435e9ee80874",
"prevId": "82e90e7e-c11d-4bc1-a2d9-d424468eb207",
"version": "7",
"dialect": "postgresql",
"tables": {
"public.caveats": {
"name": "caveats",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"type": {
"name": "type",
"type": "varchar(256)",
"primaryKey": false,
"notNull": true
},
"enforcer": {
"name": "enforcer",
"type": "varchar(42)",
"primaryKey": false,
"notNull": true
},
"terms": {
"name": "terms",
"type": "text",
"primaryKey": false,
"notNull": true
},
"args": {
"name": "args",
"type": "text",
"primaryKey": false,
"notNull": true
},
"delegationHash": {
"name": "delegationHash",
"type": "varchar(66)",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {
"caveats_delegationHash_delegations_hash_fk": {
"name": "caveats_delegationHash_delegations_hash_fk",
"tableFrom": "caveats",
"tableTo": "delegations",
"columnsFrom": [
"delegationHash"
],
"columnsTo": [
"hash"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.delegations": {
"name": "delegations",
"schema": "",
"columns": {
"hash": {
"name": "hash",
"type": "varchar(66)",
"primaryKey": true,
"notNull": true
},
"type": {
"name": "type",
"type": "varchar(256)",
"primaryKey": false,
"notNull": true
},
"delegator": {
"name": "delegator",
"type": "varchar(42)",
"primaryKey": false,
"notNull": true
},
"chainId": {
"name": "chainId",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"delegate": {
"name": "delegate",
"type": "varchar(42)",
"primaryKey": false,
"notNull": true
},
"authority": {
"name": "authority",
"type": "varchar(66)",
"primaryKey": false,
"notNull": true
},
"salt": {
"name": "salt",
"type": "bigint",
"primaryKey": false,
"notNull": true
},
"signature": {
"name": "signature",
"type": "text",
"primaryKey": false,
"notNull": true
},
"isValid": {
"name": "isValid",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": true
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
}
},
"enums": {},
"schemas": {},
"sequences": {},
"roles": {},
"policies": {},
"views": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}
14 changes: 14 additions & 0 deletions apps/api-delegations/src/db/migrations/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@
"when": 1733186099609,
"tag": "0003_young_tiger_shark",
"breakpoints": true
},
{
"idx": 4,
"version": "7",
"when": 1733323209166,
"tag": "0004_warm_gambit",
"breakpoints": true
},
{
"idx": 5,
"version": "7",
"when": 1733323390653,
"tag": "0005_lean_rhino",
"breakpoints": true
}
]
}
Loading

0 comments on commit a405722

Please sign in to comment.