Skip to content

Commit

Permalink
feat: wip port external services and other fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alanshaw committed Jan 16, 2025
1 parent ebe532e commit f668ee4
Show file tree
Hide file tree
Showing 78 changed files with 423 additions and 312 deletions.
26 changes: 13 additions & 13 deletions billing/data/allocations.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import * as Link from 'multiformats/link'
import { DecodeFailure, EncodeFailure, Schema } from './lib.js'

/**
* @typedef {import('../lib/api').Allocation} Allocation
* @typedef {import('../lib/api').AllocationSpaceInsertedAtIndex} AllocationSpaceInsertedAtIndex
* @typedef {import('../types').InferStoreRecord<Allocation>} AllocationStoreRecord
* @typedef {import('../lib/api').AllocationKey} AllocationKey
* @typedef {import('../lib/api').AllocationListKey} AllocationListKey
* @typedef {import('../types').InferStoreRecord<AllocationKey>} AllocationKeyStoreRecord
* @typedef {import('../lib/api.js').Allocation} Allocation
* @typedef {import('../lib/api.js').AllocationSpaceInsertedAtIndex} AllocationSpaceInsertedAtIndex
* @typedef {import('../types.js').InferStoreRecord<Allocation>} AllocationStoreRecord
* @typedef {import('../lib/api.js').AllocationKey} AllocationKey
* @typedef {import('../lib/api.js').AllocationListKey} AllocationListKey
* @typedef {import('../types.js').InferStoreRecord<AllocationKey>} AllocationKeyStoreRecord
* @typedef {{ space: string, insertedAt?: string }} AllocationListStoreRecord
* @typedef {import('../types').StoreRecord} StoreRecord
* @typedef {import('../types.js').StoreRecord} StoreRecord
*/

const schema = Schema.struct({
Expand All @@ -20,13 +20,13 @@ const schema = Schema.struct({
size: Schema.bigint().greaterThanEqualTo(0n),
})

/** @type {import('../lib/api').Validator<Allocation>} */
/** @type {import('../lib/api.js').Validator<Allocation>} */
export const validate = (input) => schema.read(input)

/** @type {import('../lib/api').Encoder<AllocationKey, AllocationKeyStoreRecord>} */
/** @type {import('../lib/api.js').Encoder<AllocationKey, AllocationKeyStoreRecord>} */
export const encodeKey = (input) => ({ ok: { multihash: input.multihash } })

/** @type {import('../lib/api').Encoder<Allocation, AllocationStoreRecord>} */
/** @type {import('../lib/api.js').Encoder<Allocation, AllocationStoreRecord>} */
export const encode = (input) => {
try {
return {
Expand All @@ -47,7 +47,7 @@ export const encode = (input) => {
}
}

/** @type {import('../lib/api').Decoder<StoreRecord, Allocation>} */
/** @type {import('../lib/api.js').Decoder<StoreRecord, Allocation>} */
export const decode = (input) => {
try {
return {
Expand All @@ -69,7 +69,7 @@ export const decode = (input) => {
}

export const lister = {
/** @type {import('../lib/api').Encoder<AllocationListKey, AllocationListStoreRecord>} */
/** @type {import('../lib/api.js').Encoder<AllocationListKey, AllocationListStoreRecord>} */
encodeKey: (input) => {
/** @type AllocationListStoreRecord */
const conditions = { space: input.space.toString() }
Expand All @@ -82,7 +82,7 @@ export const lister = {
},
}
},
/** @type {import('../lib/api').Decoder<StoreRecord, AllocationSpaceInsertedAtIndex>} */
/** @type {import('../lib/api.js').Decoder<StoreRecord, AllocationSpaceInsertedAtIndex>} */
decode: (input) => {
try {
return {
Expand Down
26 changes: 13 additions & 13 deletions billing/data/consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import * as Link from 'multiformats/link'
import { DecodeFailure, EncodeFailure, Schema } from './lib.js'

/**
* @typedef {import('../lib/api').Consumer} Consumer
* @typedef {import('../types').InferStoreRecord<Consumer>} ConsumerStoreRecord
* @typedef {import('../types').StoreRecord} StoreRecord
* @typedef {import('../lib/api').ConsumerKey} ConsumerKey
* @typedef {import('../types').InferStoreRecord<ConsumerKey>} ConsumerKeyStoreRecord
* @typedef {import('../lib/api').ConsumerListKey} ConsumerListKey
* @typedef {import('../types').InferStoreRecord<ConsumerListKey>} ConsumerListKeyStoreRecord
* @typedef {import('../lib/api.js').Consumer} Consumer
* @typedef {import('../types.js').InferStoreRecord<Consumer>} ConsumerStoreRecord
* @typedef {import('../types.js').StoreRecord} StoreRecord
* @typedef {import('../lib/api.js').ConsumerKey} ConsumerKey
* @typedef {import('../types.js').InferStoreRecord<ConsumerKey>} ConsumerKeyStoreRecord
* @typedef {import('../lib/api.js').ConsumerListKey} ConsumerListKey
* @typedef {import('../types.js').InferStoreRecord<ConsumerListKey>} ConsumerListKeyStoreRecord
* @typedef {Pick<Consumer, 'consumer'|'provider'|'subscription'|'customer'>} ConsumerList
*/

Expand All @@ -22,10 +22,10 @@ const schema = Schema.struct({
updatedAt: Schema.date().optional()
})

/** @type {import('../lib/api').Validator<Consumer>} */
/** @type {import('../lib/api.js').Validator<Consumer>} */
export const validate = input => schema.read(input)

/** @type {import('../lib/api').Encoder<Consumer, ConsumerStoreRecord>} */
/** @type {import('../lib/api.js').Encoder<Consumer, ConsumerStoreRecord>} */
export const encode = input => {
try {
return {
Expand All @@ -46,7 +46,7 @@ export const encode = input => {
}
}

/** @type {import('../lib/api').Decoder<StoreRecord, Consumer>} */
/** @type {import('../lib/api.js').Decoder<StoreRecord, Consumer>} */
export const decode = input => {
try {
return {
Expand All @@ -67,7 +67,7 @@ export const decode = input => {
}
}

/** @type {import('../lib/api').Encoder<ConsumerKey, ConsumerKeyStoreRecord>} */
/** @type {import('../lib/api.js').Encoder<ConsumerKey, ConsumerKeyStoreRecord>} */
export const encodeKey = input => ({
ok: {
subscription: input.subscription,
Expand All @@ -77,9 +77,9 @@ export const encodeKey = input => ({

/** Encoders/decoders for listings. */
export const lister = {
/** @type {import('../lib/api').Encoder<ConsumerListKey, ConsumerListKeyStoreRecord>} */
/** @type {import('../lib/api.js').Encoder<ConsumerListKey, ConsumerListKeyStoreRecord>} */
encodeKey: input => ({ ok: { consumer: input.consumer } }),
/** @type {import('../lib/api').Decoder<StoreRecord, ConsumerList>} */
/** @type {import('../lib/api.js').Decoder<StoreRecord, ConsumerList>} */
decode: input => {
try {
return {
Expand Down
8 changes: 4 additions & 4 deletions billing/data/customer-billing-instruction.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as dagJSON from '@ipld/dag-json'
import { EncodeFailure, DecodeFailure, Schema } from './lib.js'

/**
* @typedef {import('../lib/api').CustomerBillingInstruction} CustomerBillingInstruction
* @typedef {import('../lib/api.js').CustomerBillingInstruction} CustomerBillingInstruction
*/

export const schema = Schema.struct({
Expand All @@ -13,10 +13,10 @@ export const schema = Schema.struct({
to: Schema.date()
})

/** @type {import('../lib/api').Validator<CustomerBillingInstruction>} */
/** @type {import('../lib/api.js').Validator<CustomerBillingInstruction>} */
export const validate = input => schema.read(input)

/** @type {import('../lib/api').Encoder<CustomerBillingInstruction, string>} */
/** @type {import('../lib/api.js').Encoder<CustomerBillingInstruction, string>} */
export const encode = message => {
try {
const data = {
Expand All @@ -32,7 +32,7 @@ export const encode = message => {
}
}

/** @type {import('../lib/api').Decoder<string, CustomerBillingInstruction>} */
/** @type {import('../lib/api.js').Decoder<string, CustomerBillingInstruction>} */
export const decode = str => {
try {
const data = dagJSON.parse(str)
Expand Down
18 changes: 9 additions & 9 deletions billing/data/customer.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { EncodeFailure, DecodeFailure, Schema } from './lib.js'

/**
* @typedef {import('../lib/api').Customer} Customer
* @typedef {import('../types').InferStoreRecord<Customer>} CustomerStoreRecord
* @typedef {import('../types').StoreRecord} StoreRecord
* @typedef {import('../lib/api').CustomerKey} CustomerKey
* @typedef {import('../types').InferStoreRecord<CustomerKey>} CustomerKeyStoreRecord
* @typedef {import('../lib/api.js').Customer} Customer
* @typedef {import('../types.js').InferStoreRecord<Customer>} CustomerStoreRecord
* @typedef {import('../types.js').StoreRecord} StoreRecord
* @typedef {import('../lib/api.js').CustomerKey} CustomerKey
* @typedef {import('../types.js').InferStoreRecord<CustomerKey>} CustomerKeyStoreRecord
*/

const schema = Schema.struct({
Expand All @@ -16,10 +16,10 @@ const schema = Schema.struct({
updatedAt: Schema.date().optional()
})

/** @type {import('../lib/api').Validator<Customer>} */
/** @type {import('../lib/api.js').Validator<Customer>} */
export const validate = input => schema.read(input)

/** @type {import('../lib/api').Encoder<Customer, CustomerStoreRecord>} */
/** @type {import('../lib/api.js').Encoder<Customer, CustomerStoreRecord>} */
export const encode = input => {
try {
return {
Expand All @@ -38,10 +38,10 @@ export const encode = input => {
}
}

/** @type {import('../lib/api').Encoder<CustomerKey, CustomerKeyStoreRecord>} */
/** @type {import('../lib/api.js').Encoder<CustomerKey, CustomerKeyStoreRecord>} */
export const encodeKey = input => ({ ok: { customer: input.customer } })

/** @type {import('../lib/api').Decoder<StoreRecord, Customer>} */
/** @type {import('../lib/api.js').Decoder<StoreRecord, Customer>} */
export const decode = input => {
try {
return {
Expand Down
18 changes: 9 additions & 9 deletions billing/data/egress.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Link } from '@ucanto/server'
import { DecodeFailure, EncodeFailure, Schema } from './lib.js'

/**
* @typedef { import('../lib/api').EgressTrafficData } EgressTrafficData
* @typedef { import('../types').InferStoreRecord<EgressTrafficData> & { pk: string, sk: string } } EgressTrafficStoreRecord
* @typedef { import('../lib/api.js').EgressTrafficData } EgressTrafficData
* @typedef { import('../types.js').InferStoreRecord<EgressTrafficData> & { pk: string, sk: string } } EgressTrafficStoreRecord
* @typedef {{ pk: string, sk: string }} EgressTrafficKeyStoreRecord
*/

Expand All @@ -16,10 +16,10 @@ export const egressSchema = Schema.struct({
cause: Schema.link(),
})

/** @type {import('../lib/api').Validator<EgressTrafficData>} */
/** @type {import('../lib/api.js').Validator<EgressTrafficData>} */
export const validate = input => egressSchema.read(input)

/** @type {import('../lib/api').Encoder<EgressTrafficData, EgressTrafficStoreRecord>} */
/** @type {import('../lib/api.js').Encoder<EgressTrafficData, EgressTrafficStoreRecord>} */
export const encode = input => {
try {
return {
Expand All @@ -41,7 +41,7 @@ export const encode = input => {
}
}

/** @type {import('../lib/api').Encoder<import('../lib/api').EgressTrafficData, string>} */
/** @type {import('../lib/api.js').Encoder<import('../lib/api.js').EgressTrafficData, string>} */
export const encodeStr = input => {
try {
const data = encode(input)
Expand All @@ -54,7 +54,7 @@ export const encodeStr = input => {
}
}

/** @type {import('../lib/api').Decoder<import('../types.js').StoreRecord, import('../lib/api').EgressTrafficData>} */
/** @type {import('../lib/api.js').Decoder<import('../types.js').StoreRecord, import('../lib/api.js').EgressTrafficData>} */
export const decode = input => {
try {
return {
Expand All @@ -74,7 +74,7 @@ export const decode = input => {
}
}

/** @type {import('../lib/api').Decoder<string, import('../lib/api').EgressTrafficData>} */
/** @type {import('../lib/api.js').Decoder<string, import('../lib/api.js').EgressTrafficData>} */
export const decodeStr = input => {
try {
return decode(JSON.parse(input))
Expand All @@ -86,14 +86,14 @@ export const decodeStr = input => {
}

export const lister = {
/** @type {import('../lib/api').Encoder<import('../lib/api').EgressTrafficEventListKey, EgressTrafficKeyStoreRecord>} */
/** @type {import('../lib/api.js').Encoder<import('../lib/api.js').EgressTrafficEventListKey, EgressTrafficKeyStoreRecord>} */
encodeKey: input => ({
ok: {
pk: `${input.space.toString()}#${input.resource.toString()}`,
sk: `${input.servedAt.toISOString()}#${input.cause.toString()}`,
}
}),
/** @type {import('../lib/api').Decoder<EgressTrafficKeyStoreRecord, import('../lib/api').EgressTrafficEventListKey>} */
/** @type {import('../lib/api.js').Decoder<EgressTrafficKeyStoreRecord, import('../lib/api.js').EgressTrafficEventListKey>} */
decodeKey: input => {
try {
const [space, resource] = input.pk.split('#')
Expand Down
8 changes: 4 additions & 4 deletions billing/data/space-billing-instruction.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as dagJSON from '@ipld/dag-json'
import { EncodeFailure, DecodeFailure, Schema } from './lib.js'

/**
* @typedef {import('../lib/api').SpaceBillingInstruction} SpaceBillingInstruction
* @typedef {import('../lib/api.js').SpaceBillingInstruction} SpaceBillingInstruction
*/

export const schema = Schema.struct({
Expand All @@ -15,10 +15,10 @@ export const schema = Schema.struct({
to: Schema.date()
})

/** @type {import('../lib/api').Validator<SpaceBillingInstruction>} */
/** @type {import('../lib/api.js').Validator<SpaceBillingInstruction>} */
export const validate = input => schema.read(input)

/** @type {import('../lib/api').Encoder<SpaceBillingInstruction, string>} */
/** @type {import('../lib/api.js').Encoder<SpaceBillingInstruction, string>} */
export const encode = message => {
try {
const data = {
Expand All @@ -36,7 +36,7 @@ export const encode = message => {
}
}

/** @type {import('../lib/api').Decoder<string, SpaceBillingInstruction>} */
/** @type {import('../lib/api.js').Decoder<string, SpaceBillingInstruction>} */
export const decode = str => {
try {
const data = dagJSON.parse(str)
Expand Down
16 changes: 8 additions & 8 deletions billing/data/space-diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import * as Link from 'multiformats/link'
import { EncodeFailure, DecodeFailure, Schema } from './lib.js'

/**
* @typedef {import('../lib/api').SpaceDiff} SpaceDiff
* @typedef {import('../types').InferStoreRecord<SpaceDiff> & { pk: string, sk: string }} SpaceDiffStoreRecord
* @typedef {import('../lib/api').SpaceDiffListKey} SpaceDiffListKey
* @typedef {import('../lib/api.js').SpaceDiff} SpaceDiff
* @typedef {import('../types.js').InferStoreRecord<SpaceDiff> & { pk: string, sk: string }} SpaceDiffStoreRecord
* @typedef {import('../lib/api.js').SpaceDiffListKey} SpaceDiffListKey
* @typedef {{ pk: string, sk: string }} SpaceDiffListStoreRecord
* @typedef {import('../types').StoreRecord} StoreRecord
* @typedef {import('../types.js').StoreRecord} StoreRecord
*/

export const schema = Schema.struct({
Expand All @@ -19,10 +19,10 @@ export const schema = Schema.struct({
insertedAt: Schema.date()
})

/** @type {import('../lib/api').Validator<SpaceDiff>} */
/** @type {import('../lib/api.js').Validator<SpaceDiff>} */
export const validate = input => schema.read(input)

/** @type {import('../lib/api').Encoder<SpaceDiff, SpaceDiffStoreRecord>} */
/** @type {import('../lib/api.js').Encoder<SpaceDiff, SpaceDiffStoreRecord>} */
export const encode = input => {
try {
return {
Expand All @@ -47,7 +47,7 @@ export const encode = input => {



/** @type {import('../lib/api').Decoder<StoreRecord, SpaceDiff>} */
/** @type {import('../lib/api.js').Decoder<StoreRecord, SpaceDiff>} */
export const decode = input => {
try {
return {
Expand All @@ -69,7 +69,7 @@ export const decode = input => {
}

export const lister = {
/** @type {import('../lib/api').Encoder<SpaceDiffListKey, SpaceDiffListStoreRecord>} */
/** @type {import('../lib/api.js').Encoder<SpaceDiffListKey, SpaceDiffListStoreRecord>} */
encodeKey: input => ({
ok: {
pk: `${input.provider}#${input.space}`,
Expand Down
18 changes: 9 additions & 9 deletions billing/data/space-snapshot.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { DecodeFailure, EncodeFailure, Schema } from './lib.js'

/**
* @typedef {import('../lib/api').SpaceSnapshot} SpaceSnapshot
* @typedef {import('../types').InferStoreRecord<SpaceSnapshot> & { pk: string }} SpaceSnapshotStoreRecord
* @typedef {import('../lib/api').SpaceSnapshotKey} SpaceSnapshotKey
* @typedef {Omit<import('../types').InferStoreRecord<SpaceSnapshotKey>, 'provider'|'space'> & { pk: string }} SpaceSnapshotKeyStoreRecord
* @typedef {import('../types').StoreRecord} StoreRecord
* @typedef {import('../lib/api.js').SpaceSnapshot} SpaceSnapshot
* @typedef {import('../types.js').InferStoreRecord<SpaceSnapshot> & { pk: string }} SpaceSnapshotStoreRecord
* @typedef {import('../lib/api.js').SpaceSnapshotKey} SpaceSnapshotKey
* @typedef {Omit<import('../types.js').InferStoreRecord<SpaceSnapshotKey>, 'provider'|'space'> & { pk: string }} SpaceSnapshotKeyStoreRecord
* @typedef {import('../types.js').StoreRecord} StoreRecord
*/

export const schema = Schema.struct({
Expand All @@ -16,10 +16,10 @@ export const schema = Schema.struct({
insertedAt: Schema.date()
})

/** @type {import('../lib/api').Validator<SpaceSnapshot>} */
/** @type {import('../lib/api.js').Validator<SpaceSnapshot>} */
export const validate = input => schema.read(input)

/** @type {import('../lib/api').Encoder<SpaceSnapshot, SpaceSnapshotStoreRecord>} */
/** @type {import('../lib/api.js').Encoder<SpaceSnapshot, SpaceSnapshotStoreRecord>} */
export const encode = input => {
try {
return {
Expand All @@ -39,15 +39,15 @@ export const encode = input => {
}
}

/** @type {import('../lib/api').Encoder<SpaceSnapshotKey, SpaceSnapshotKeyStoreRecord>} */
/** @type {import('../lib/api.js').Encoder<SpaceSnapshotKey, SpaceSnapshotKeyStoreRecord>} */
export const encodeKey = input => ({
ok: {
pk: `${input.provider}#${input.space}`,
recordedAt: input.recordedAt.toISOString()
}
})

/** @type {import('../lib/api').Decoder<StoreRecord, SpaceSnapshot>} */
/** @type {import('../lib/api.js').Decoder<StoreRecord, SpaceSnapshot>} */
export const decode = input => {
try {
return {
Expand Down
Loading

0 comments on commit f668ee4

Please sign in to comment.