@xyo-network/payload-builder
Advanced tools
Comparing version
@@ -1,6 +0,5 @@ | ||
import type { AnyObject, DeepOmitStartsWith, EmptyObject } from '@xylabs/object'; | ||
import type { AnyObject, EmptyObject } from '@xylabs/object'; | ||
import type { Promisable } from '@xylabs/promise'; | ||
import type { Payload, Schema, WithOptionalSchema, WithoutClientMeta, WithoutMeta, WithoutPrivateStorageMeta, WithoutSchema, WithoutStorageMeta } from '@xyo-network/payload-model'; | ||
import type { Payload, Schema, WithOnlyClientMeta, WithOptionalSchema, WithoutClientMeta, WithoutMeta, WithoutPrivateStorageMeta, WithoutSchema, WithoutStorageMeta } from '@xyo-network/payload-model'; | ||
import type { PayloadBuilderOptions } from './Options.ts'; | ||
export declare const omitByPrefix: <T extends EmptyObject, P extends string>(payload: T, prefix: P, maxDepth?: number) => DeepOmitStartsWith<T, P>; | ||
export declare const omitSchema: <T extends WithOptionalSchema>(payload: T) => WithoutSchema<T>; | ||
@@ -10,2 +9,3 @@ export declare class PayloadBuilderBase<T extends Payload = Payload<AnyObject>, O extends PayloadBuilderOptions<T> = PayloadBuilderOptions<T>> { | ||
protected _fields?: WithoutMeta<WithoutSchema<T>>; | ||
protected _meta?: WithOnlyClientMeta<T>; | ||
protected _schema: Schema; | ||
@@ -22,6 +22,7 @@ constructor(options: O); | ||
static omitStorageMeta<T extends EmptyObject>(payloads: T[], maxDepth?: number): WithoutStorageMeta<T>[]; | ||
dataHashableFields(): Promise<DeepOmitStartsWith<DeepOmitStartsWith<T, "_">, "$">>; | ||
dataHashableFields(): Promise<import("@xylabs/object").DeepOmitStartsWith<import("@xylabs/object").DeepOmitStartsWith<T, "_">, "$">>; | ||
fields(fields: WithoutMeta<WithoutSchema<T>>): this; | ||
meta(meta: WithOnlyClientMeta<T>): this; | ||
schema(value: Schema): void; | ||
} | ||
//# sourceMappingURL=BuilderBase.d.ts.map |
@@ -1,6 +0,5 @@ | ||
import type { AnyObject, DeepOmitStartsWith, EmptyObject } from '@xylabs/object'; | ||
import type { AnyObject, EmptyObject } from '@xylabs/object'; | ||
import type { Promisable } from '@xylabs/promise'; | ||
import type { Payload, Schema, WithOptionalSchema, WithoutClientMeta, WithoutMeta, WithoutPrivateStorageMeta, WithoutSchema, WithoutStorageMeta } from '@xyo-network/payload-model'; | ||
import type { Payload, Schema, WithOnlyClientMeta, WithOptionalSchema, WithoutClientMeta, WithoutMeta, WithoutPrivateStorageMeta, WithoutSchema, WithoutStorageMeta } from '@xyo-network/payload-model'; | ||
import type { PayloadBuilderOptions } from './Options.ts'; | ||
export declare const omitByPrefix: <T extends EmptyObject, P extends string>(payload: T, prefix: P, maxDepth?: number) => DeepOmitStartsWith<T, P>; | ||
export declare const omitSchema: <T extends WithOptionalSchema>(payload: T) => WithoutSchema<T>; | ||
@@ -10,2 +9,3 @@ export declare class PayloadBuilderBase<T extends Payload = Payload<AnyObject>, O extends PayloadBuilderOptions<T> = PayloadBuilderOptions<T>> { | ||
protected _fields?: WithoutMeta<WithoutSchema<T>>; | ||
protected _meta?: WithOnlyClientMeta<T>; | ||
protected _schema: Schema; | ||
@@ -22,6 +22,7 @@ constructor(options: O); | ||
static omitStorageMeta<T extends EmptyObject>(payloads: T[], maxDepth?: number): WithoutStorageMeta<T>[]; | ||
dataHashableFields(): Promise<DeepOmitStartsWith<DeepOmitStartsWith<T, "_">, "$">>; | ||
dataHashableFields(): Promise<import("@xylabs/object").DeepOmitStartsWith<import("@xylabs/object").DeepOmitStartsWith<T, "_">, "$">>; | ||
fields(fields: WithoutMeta<WithoutSchema<T>>): this; | ||
meta(meta: WithOnlyClientMeta<T>): this; | ||
schema(value: Schema): void; | ||
} | ||
//# sourceMappingURL=BuilderBase.d.ts.map |
@@ -1,6 +0,5 @@ | ||
import type { AnyObject, DeepOmitStartsWith, EmptyObject } from '@xylabs/object'; | ||
import type { AnyObject, EmptyObject } from '@xylabs/object'; | ||
import type { Promisable } from '@xylabs/promise'; | ||
import type { Payload, Schema, WithOptionalSchema, WithoutClientMeta, WithoutMeta, WithoutPrivateStorageMeta, WithoutSchema, WithoutStorageMeta } from '@xyo-network/payload-model'; | ||
import type { Payload, Schema, WithOnlyClientMeta, WithOptionalSchema, WithoutClientMeta, WithoutMeta, WithoutPrivateStorageMeta, WithoutSchema, WithoutStorageMeta } from '@xyo-network/payload-model'; | ||
import type { PayloadBuilderOptions } from './Options.ts'; | ||
export declare const omitByPrefix: <T extends EmptyObject, P extends string>(payload: T, prefix: P, maxDepth?: number) => DeepOmitStartsWith<T, P>; | ||
export declare const omitSchema: <T extends WithOptionalSchema>(payload: T) => WithoutSchema<T>; | ||
@@ -10,2 +9,3 @@ export declare class PayloadBuilderBase<T extends Payload = Payload<AnyObject>, O extends PayloadBuilderOptions<T> = PayloadBuilderOptions<T>> { | ||
protected _fields?: WithoutMeta<WithoutSchema<T>>; | ||
protected _meta?: WithOnlyClientMeta<T>; | ||
protected _schema: Schema; | ||
@@ -22,6 +22,7 @@ constructor(options: O); | ||
static omitStorageMeta<T extends EmptyObject>(payloads: T[], maxDepth?: number): WithoutStorageMeta<T>[]; | ||
dataHashableFields(): Promise<DeepOmitStartsWith<DeepOmitStartsWith<T, "_">, "$">>; | ||
dataHashableFields(): Promise<import("@xylabs/object").DeepOmitStartsWith<import("@xylabs/object").DeepOmitStartsWith<T, "_">, "$">>; | ||
fields(fields: WithoutMeta<WithoutSchema<T>>): this; | ||
meta(meta: WithOnlyClientMeta<T>): this; | ||
schema(value: Schema): void; | ||
} | ||
//# sourceMappingURL=BuilderBase.d.ts.map |
{ | ||
"name": "@xyo-network/payload-builder", | ||
"version": "3.6.0-rc.8", | ||
"version": "3.6.0-rc.9", | ||
"description": "Primary SDK for using XYO Protocol 2.0", | ||
@@ -32,9 +32,9 @@ "homepage": "https://xyo.network", | ||
"dependencies": { | ||
"@xylabs/assert": "^4.4.16", | ||
"@xylabs/hex": "^4.4.16", | ||
"@xylabs/logger": "^4.4.16", | ||
"@xylabs/object": "^4.4.16", | ||
"@xylabs/promise": "^4.4.16", | ||
"@xyo-network/hash": "^3.6.0-rc.8", | ||
"@xyo-network/payload-model": "^3.6.0-rc.8" | ||
"@xylabs/assert": "^4.4.18", | ||
"@xylabs/hex": "^4.4.18", | ||
"@xylabs/logger": "^4.4.18", | ||
"@xylabs/object": "^4.4.18", | ||
"@xylabs/promise": "^4.4.18", | ||
"@xyo-network/hash": "^3.6.0-rc.9", | ||
"@xyo-network/payload-model": "^3.6.0-rc.9" | ||
}, | ||
@@ -44,3 +44,3 @@ "devDependencies": { | ||
"@xylabs/tsconfig": "^4.2.4", | ||
"@xylabs/vitest-extended": "^4.4.16", | ||
"@xylabs/vitest-extended": "^4.4.18", | ||
"typescript": "^5.7.2", | ||
@@ -47,0 +47,0 @@ "vitest": "^2.1.8" |
@@ -182,4 +182,5 @@ import type { Hash } from '@xylabs/hex' | ||
...this._fields, | ||
...this._meta, | ||
} as T | ||
} | ||
} |
import { assertEx } from '@xylabs/assert' | ||
import type { | ||
AnyObject, DeepOmitStartsWith, EmptyObject, | ||
} from '@xylabs/object' | ||
import type { AnyObject, EmptyObject } from '@xylabs/object' | ||
import { | ||
isJsonObject, omitBy, toJson, | ||
isJsonObject, omitByPrefix, pickByPrefix, toJson, | ||
} from '@xylabs/object' | ||
@@ -12,2 +10,3 @@ import type { Promisable } from '@xylabs/promise' | ||
Payload, Schema, | ||
WithOnlyClientMeta, | ||
WithOptionalSchema, | ||
@@ -23,6 +22,2 @@ WithoutClientMeta, | ||
export const omitByPrefix = <T extends EmptyObject, P extends string>(payload: T, prefix: P, maxDepth = 100): DeepOmitStartsWith<T, P> => { | ||
return omitBy(payload, omitByPrefixPredicate(prefix), maxDepth) as unknown as DeepOmitStartsWith<T, P> | ||
} | ||
export const omitSchema = <T extends WithOptionalSchema>(payload: T): WithoutSchema<T> => { | ||
@@ -34,10 +29,6 @@ const result = structuredClone(payload) | ||
const omitByPrefixPredicate = (prefix: string) => (_: unknown, key: string) => { | ||
assertEx(typeof key === 'string', () => `Invalid key type [${key}, ${typeof key}]`) | ||
return key.startsWith(prefix) | ||
} | ||
export class PayloadBuilderBase<T extends Payload = Payload<AnyObject>, | ||
O extends PayloadBuilderOptions<T> = PayloadBuilderOptions<T>> { | ||
protected _fields?: WithoutMeta<WithoutSchema<T>> | ||
protected _meta?: WithOnlyClientMeta<T> | ||
protected _schema: Schema | ||
@@ -112,2 +103,8 @@ | ||
meta(meta: WithOnlyClientMeta<T>) { | ||
// we need to do the cast here since ts seems to not like nested, yet same, generics | ||
this._meta = pickByPrefix(meta, '$') as WithOnlyClientMeta<T> | ||
return this | ||
} | ||
schema(value: Schema) { | ||
@@ -114,0 +111,0 @@ this._schema = value |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
124146
-1.29%1129
-0.09%Updated
Updated
Updated
Updated
Updated