@xyo-network/payload-model 3.0.6 → 3.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/Error.d.ts +22 -0
- package/dist/browser/Error.d.ts.map +1 -0
- package/dist/browser/Meta.d.ts +8 -0
- package/dist/browser/Meta.d.ts.map +1 -0
- package/dist/browser/Payload.d.ts +31 -0
- package/dist/browser/Payload.d.ts.map +1 -0
- package/dist/browser/PayloadFindFilter.d.ts +8 -0
- package/dist/browser/PayloadFindFilter.d.ts.map +1 -0
- package/dist/browser/PayloadSet/PayloadSetPayload.d.ts +8 -0
- package/dist/browser/PayloadSet/PayloadSetPayload.d.ts.map +1 -0
- package/dist/browser/PayloadSet/PayloadSetSchema.d.ts +3 -0
- package/dist/browser/PayloadSet/PayloadSetSchema.d.ts.map +1 -0
- package/dist/browser/PayloadSet/index.d.ts +3 -0
- package/dist/browser/PayloadSet/index.d.ts.map +1 -0
- package/dist/browser/PayloadValidationFunction.d.ts +3 -0
- package/dist/browser/PayloadValidationFunction.d.ts.map +1 -0
- package/dist/browser/PayloadValueExpression.d.ts +5 -0
- package/dist/browser/PayloadValueExpression.d.ts.map +1 -0
- package/dist/browser/Query.d.ts +12 -0
- package/dist/browser/Query.d.ts.map +1 -0
- package/dist/browser/Schema.d.ts +14 -0
- package/dist/browser/Schema.d.ts.map +1 -0
- package/dist/browser/Timestamp.d.ts +6 -0
- package/dist/browser/Timestamp.d.ts.map +1 -0
- package/dist/browser/index.d.ts +13 -126
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.mjs +6 -1
- package/dist/browser/index.mjs.map +1 -1
- package/dist/browser/isPayload.d.ts +18 -0
- package/dist/browser/isPayload.d.ts.map +1 -0
- package/dist/browser/isPayloadOfSchemaType.d.ts +7 -0
- package/dist/browser/isPayloadOfSchemaType.d.ts.map +1 -0
- package/dist/browser/isPayloadWithHash.d.ts +5 -0
- package/dist/browser/isPayloadWithHash.d.ts.map +1 -0
- package/dist/neutral/Error.d.ts +22 -0
- package/dist/neutral/Error.d.ts.map +1 -0
- package/dist/neutral/Meta.d.ts +8 -0
- package/dist/neutral/Meta.d.ts.map +1 -0
- package/dist/neutral/Payload.d.ts +31 -0
- package/dist/neutral/Payload.d.ts.map +1 -0
- package/dist/neutral/PayloadFindFilter.d.ts +8 -0
- package/dist/neutral/PayloadFindFilter.d.ts.map +1 -0
- package/dist/neutral/PayloadSet/PayloadSetPayload.d.ts +8 -0
- package/dist/neutral/PayloadSet/PayloadSetPayload.d.ts.map +1 -0
- package/dist/neutral/PayloadSet/PayloadSetSchema.d.ts +3 -0
- package/dist/neutral/PayloadSet/PayloadSetSchema.d.ts.map +1 -0
- package/dist/neutral/PayloadSet/index.d.ts +3 -0
- package/dist/neutral/PayloadSet/index.d.ts.map +1 -0
- package/dist/neutral/PayloadValidationFunction.d.ts +3 -0
- package/dist/neutral/PayloadValidationFunction.d.ts.map +1 -0
- package/dist/neutral/PayloadValueExpression.d.ts +5 -0
- package/dist/neutral/PayloadValueExpression.d.ts.map +1 -0
- package/dist/neutral/Query.d.ts +12 -0
- package/dist/neutral/Query.d.ts.map +1 -0
- package/dist/neutral/Schema.d.ts +14 -0
- package/dist/neutral/Schema.d.ts.map +1 -0
- package/dist/neutral/Timestamp.d.ts +6 -0
- package/dist/neutral/Timestamp.d.ts.map +1 -0
- package/dist/neutral/index.d.ts +13 -126
- package/dist/neutral/index.d.ts.map +1 -0
- package/dist/neutral/index.mjs +6 -1
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/isPayload.d.ts +18 -0
- package/dist/neutral/isPayload.d.ts.map +1 -0
- package/dist/neutral/isPayloadOfSchemaType.d.ts +7 -0
- package/dist/neutral/isPayloadOfSchemaType.d.ts.map +1 -0
- package/dist/neutral/isPayloadWithHash.d.ts +5 -0
- package/dist/neutral/isPayloadWithHash.d.ts.map +1 -0
- package/dist/node/Error.d.ts +22 -0
- package/dist/node/Error.d.ts.map +1 -0
- package/dist/node/Meta.d.ts +8 -0
- package/dist/node/Meta.d.ts.map +1 -0
- package/dist/node/Payload.d.ts +31 -0
- package/dist/node/Payload.d.ts.map +1 -0
- package/dist/node/PayloadFindFilter.d.ts +8 -0
- package/dist/node/PayloadFindFilter.d.ts.map +1 -0
- package/dist/node/PayloadSet/PayloadSetPayload.d.ts +8 -0
- package/dist/node/PayloadSet/PayloadSetPayload.d.ts.map +1 -0
- package/dist/node/PayloadSet/PayloadSetSchema.d.ts +3 -0
- package/dist/node/PayloadSet/PayloadSetSchema.d.ts.map +1 -0
- package/dist/node/PayloadSet/index.d.ts +3 -0
- package/dist/node/PayloadSet/index.d.ts.map +1 -0
- package/dist/node/PayloadValidationFunction.d.ts +3 -0
- package/dist/node/PayloadValidationFunction.d.ts.map +1 -0
- package/dist/node/PayloadValueExpression.d.ts +5 -0
- package/dist/node/PayloadValueExpression.d.ts.map +1 -0
- package/dist/node/Query.d.ts +12 -0
- package/dist/node/Query.d.ts.map +1 -0
- package/dist/node/Schema.d.ts +14 -0
- package/dist/node/Schema.d.ts.map +1 -0
- package/dist/node/Timestamp.d.ts +6 -0
- package/dist/node/Timestamp.d.ts.map +1 -0
- package/dist/node/index.d.ts +13 -126
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.mjs +6 -1
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/isPayload.d.ts +18 -0
- package/dist/node/isPayload.d.ts.map +1 -0
- package/dist/node/isPayloadOfSchemaType.d.ts +7 -0
- package/dist/node/isPayloadOfSchemaType.d.ts.map +1 -0
- package/dist/node/isPayloadWithHash.d.ts +5 -0
- package/dist/node/isPayloadWithHash.d.ts.map +1 -0
- package/package.json +25 -25
- package/src/Meta.ts +4 -2
package/dist/node/index.d.ts
CHANGED
|
@@ -1,126 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
interface SchemaFields extends EmptyObject {
|
|
15
|
-
schema: Schema;
|
|
16
|
-
}
|
|
17
|
-
type WithSchema<T extends EmptyObject | void = void> = T extends EmptyObject ? SchemaFields & T : SchemaFields;
|
|
18
|
-
|
|
19
|
-
interface PayloadMetaFields<TAdditionalMeta extends EmptyObject | void = void> extends EmptyObject {
|
|
20
|
-
$hash: Hash;
|
|
21
|
-
$meta?: TAdditionalMeta extends void ? JsonObject : TAdditionalMeta;
|
|
22
|
-
}
|
|
23
|
-
interface PayloadFields extends EmptyObject {
|
|
24
|
-
schema: Schema;
|
|
25
|
-
}
|
|
26
|
-
type WithPayload<T extends EmptyObject | void = void> = WithSchema<T extends EmptyObject ? PayloadFields & T : PayloadFields>;
|
|
27
|
-
type Payload<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = T extends WithSchema ? S extends Schema ? WithPayload<Omit<T, 'schema'> & {
|
|
28
|
-
schema: S;
|
|
29
|
-
} & PayloadFields> : WithPayload<T> : T extends object ? S extends Schema ? WithPayload<T & {
|
|
30
|
-
schema: S;
|
|
31
|
-
} & PayloadFields> : WithPayload<T & {
|
|
32
|
-
schema: Schema;
|
|
33
|
-
} & PayloadFields> : {
|
|
34
|
-
schema: S extends Schema ? S : Schema;
|
|
35
|
-
} & PayloadFields;
|
|
36
|
-
type OverridablePayload<T extends Payload> = Omit<T, 'schema'> & {
|
|
37
|
-
schema: string;
|
|
38
|
-
};
|
|
39
|
-
type WithSources<T extends EmptyObject> = T & {
|
|
40
|
-
sources?: Hash[];
|
|
41
|
-
};
|
|
42
|
-
type PayloadWithSources<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithSources<Payload<T, S>>;
|
|
43
|
-
type WithAnySchema<T extends Payload> = Omit<T, 'schema'> & {
|
|
44
|
-
schema: string;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
type ModuleErrorSchema = 'network.xyo.error.module';
|
|
48
|
-
declare const ModuleErrorSchema: ModuleErrorSchema;
|
|
49
|
-
type ModuleError = Payload<{
|
|
50
|
-
details?: JsonValue;
|
|
51
|
-
message?: string;
|
|
52
|
-
name?: string;
|
|
53
|
-
query?: Hash;
|
|
54
|
-
schema: ModuleErrorSchema;
|
|
55
|
-
sources?: Hash[];
|
|
56
|
-
}>;
|
|
57
|
-
declare const isModuleError: (x?: unknown | null) => x is SchemaFields & PayloadFields & {
|
|
58
|
-
details?: JsonValue;
|
|
59
|
-
message?: string;
|
|
60
|
-
name?: string;
|
|
61
|
-
query?: Hash;
|
|
62
|
-
schema: ModuleErrorSchema;
|
|
63
|
-
sources?: Hash[];
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
declare const isAnyPayload: (value: unknown) => value is Payload;
|
|
67
|
-
declare const asAnyPayload: {
|
|
68
|
-
<TType extends {
|
|
69
|
-
schema: string;
|
|
70
|
-
} & PayloadFields>(value: _store__xylabs_promise_npm_4_0_2_e41c5d98a1_package.AnyNonPromise, config?: _xylabs_object.TypeCheckConfig): TType | undefined;
|
|
71
|
-
<TType extends {
|
|
72
|
-
schema: string;
|
|
73
|
-
} & PayloadFields>(value: _store__xylabs_promise_npm_4_0_2_e41c5d98a1_package.AnyNonPromise, assert: _xylabs_object.StringOrAlertFunction<{
|
|
74
|
-
schema: string;
|
|
75
|
-
} & PayloadFields>, config?: _xylabs_object.TypeCheckConfig): TType;
|
|
76
|
-
};
|
|
77
|
-
declare const isPayload: <T extends Payload>(schema: string[]) => (value: unknown) => value is T;
|
|
78
|
-
declare const asPayload: <T extends Payload>(schema: string[]) => {
|
|
79
|
-
<TType extends T>(value: _store__xylabs_promise_npm_4_0_2_e41c5d98a1_package.AnyNonPromise, config?: _xylabs_object.TypeCheckConfig): TType | undefined;
|
|
80
|
-
<TType extends T>(value: _store__xylabs_promise_npm_4_0_2_e41c5d98a1_package.AnyNonPromise, assert: _xylabs_object.StringOrAlertFunction<T>, config?: _xylabs_object.TypeCheckConfig): TType;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
type WithMeta<T extends Payload = Payload, M extends JsonObject | void = void> = PayloadMetaFields<M> & T;
|
|
84
|
-
type WithOptionalMeta<T extends Payload = Payload, M extends JsonObject | void = void> = Partial<WithMeta<T, M>> & Omit<WithMeta<T, M>, '$hash'>;
|
|
85
|
-
type PayloadWithMeta<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithMeta<Payload<T, S>>;
|
|
86
|
-
declare const unMeta: <T extends WithMeta<Payload>>(payload?: T) => T | undefined;
|
|
87
|
-
|
|
88
|
-
declare const isPayloadOfSchemaType: <T extends Payload>(schema: string) => (x?: unknown | null) => x is T;
|
|
89
|
-
declare const isPayloadOfSchemaTypeWithMeta: <T extends Payload>(schema: string) => (x?: unknown | null) => x is WithMeta<T>;
|
|
90
|
-
declare const isPayloadOfSchemaTypeWithSources: <T extends Payload>(schema: string) => (x?: unknown | null) => x is WithSources<T>;
|
|
91
|
-
declare const notPayloadOfSchemaType: <T extends Payload>(schema: string) => (x?: unknown | null) => x is T;
|
|
92
|
-
|
|
93
|
-
declare const isWithHash: <T extends Payload>(value: T) => value is WithMeta<T>;
|
|
94
|
-
declare const isPayloadWithHash: <T extends Payload>(value: unknown) => value is WithMeta<T>;
|
|
95
|
-
|
|
96
|
-
interface PayloadFindFilter {
|
|
97
|
-
limit?: number;
|
|
98
|
-
offset?: Hash;
|
|
99
|
-
order?: 'desc' | 'asc';
|
|
100
|
-
schema?: string | string[];
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
type PayloadSetSchema = 'network.xyo.payload.set';
|
|
104
|
-
declare const PayloadSetSchema: PayloadSetSchema;
|
|
105
|
-
|
|
106
|
-
interface PayloadSet {
|
|
107
|
-
optional?: Record<string, number>;
|
|
108
|
-
required?: Record<string, number>;
|
|
109
|
-
}
|
|
110
|
-
type PayloadSetPayload = Payload<PayloadSet, PayloadSetSchema>;
|
|
111
|
-
|
|
112
|
-
type PayloadValidationFunction<T extends Payload = Payload> = (payload: T) => boolean | Promise<boolean>;
|
|
113
|
-
|
|
114
|
-
type PayloadProperty<T extends Payload = Payload> = keyof T;
|
|
115
|
-
type PayloadValue<T extends Payload = Payload, Key extends PayloadProperty<T> = PayloadProperty<T>> = T[Key];
|
|
116
|
-
type PayloadValueExpression<T extends Payload = Payload, Key extends PayloadProperty<T> = PayloadProperty<T>, TValue = PayloadValue<T, Key>> = (payload: T) => TValue;
|
|
117
|
-
|
|
118
|
-
interface QueryFields {
|
|
119
|
-
address?: Address | Address[];
|
|
120
|
-
budget?: number;
|
|
121
|
-
maxFrequency?: 'once' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year';
|
|
122
|
-
minBid?: number;
|
|
123
|
-
}
|
|
124
|
-
type Query<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = Payload<T extends void ? QueryFields : T & QueryFields, S extends void ? T extends WithSchema ? T['schema'] : T extends void ? string : void : S>;
|
|
125
|
-
|
|
126
|
-
export { type ModuleError, ModuleErrorSchema, type OverridablePayload, type Payload, type PayloadFields, type PayloadFindFilter, type PayloadMetaFields, type PayloadProperty, PayloadSchema, type PayloadSet, type PayloadSetPayload, PayloadSetSchema, type PayloadValidationFunction, type PayloadValue, type PayloadValueExpression, type PayloadWithMeta, type PayloadWithSources, type Query, type QueryFields, type Schema, type SchemaFields, type WithAnySchema, type WithMeta, type WithOptionalMeta, type WithPayload, type WithSchema, type WithSources, asAnyPayload, asPayload, asSchema, isAnyPayload, isModuleError, isPayload, isPayloadOfSchemaType, isPayloadOfSchemaTypeWithMeta, isPayloadOfSchemaTypeWithSources, isPayloadWithHash, isSchema, isWithHash, notPayloadOfSchemaType, unMeta };
|
|
1
|
+
export * from './Error.ts';
|
|
2
|
+
export * from './isPayload.ts';
|
|
3
|
+
export * from './isPayloadOfSchemaType.ts';
|
|
4
|
+
export * from './isPayloadWithHash.ts';
|
|
5
|
+
export * from './Meta.ts';
|
|
6
|
+
export * from './Payload.ts';
|
|
7
|
+
export * from './PayloadFindFilter.ts';
|
|
8
|
+
export * from './PayloadSet/index.ts';
|
|
9
|
+
export * from './PayloadValidationFunction.ts';
|
|
10
|
+
export * from './PayloadValueExpression.ts';
|
|
11
|
+
export * from './Query.ts';
|
|
12
|
+
export * from './Schema.ts';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,4BAA4B,CAAA;AAC1C,cAAc,wBAAwB,CAAA;AACtC,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA;AAC5B,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,6BAA6B,CAAA;AAC3C,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA"}
|
package/dist/node/index.mjs
CHANGED
|
@@ -44,7 +44,12 @@ var isPayloadWithHash = (value) => {
|
|
|
44
44
|
// src/Meta.ts
|
|
45
45
|
var unMeta = (payload) => {
|
|
46
46
|
if (payload) {
|
|
47
|
-
const {
|
|
47
|
+
const {
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
49
|
+
$meta,
|
|
50
|
+
$hash,
|
|
51
|
+
...result
|
|
52
|
+
} = payload;
|
|
48
53
|
return result;
|
|
49
54
|
}
|
|
50
55
|
};
|
package/dist/node/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/isPayloadWithHash.ts","../../src/Meta.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.ts"],"sourcesContent":["import { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport type { Payload } from './Payload.ts'\n\nexport const isAnyPayload = (value: unknown): value is Payload => {\n if (isObject(value)) {\n return typeof value.schema === 'string'\n }\n return false\n}\n\nexport const asAnyPayload = AsObjectFactory.create(isAnyPayload)\n\nexport const isPayload\n = <T extends Payload>(schema: string[]) =>\n (value: unknown): value is T => {\n if (isAnyPayload(value)) {\n return schema.includes(value.schema)\n }\n return false\n }\n\nexport const asPayload = <T extends Payload>(schema: string[]) => AsObjectFactory.create((value: unknown): value is T => isPayload(schema)(value))\n","import { isAnyPayload } from './isPayload.ts'\nimport type { WithMeta } from './Meta.ts'\nimport type { Payload, WithSources } from './Payload.ts'\n\nexport const isPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => isAnyPayload(x) && x?.schema === schema\n}\n\nexport const isPayloadOfSchemaTypeWithMeta = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is WithMeta<T> => isPayloadOfSchemaType<WithMeta<T>>(schema)(x) && x.$hash !== undefined\n}\n\nexport const isPayloadOfSchemaTypeWithSources = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is WithSources<T> =>\n isPayloadOfSchemaType<WithSources<T>>(schema)(x) && x.sources !== undefined && Array.isArray(x.sources)\n}\n\nexport const notPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => !isAnyPayload(x) || x?.schema !== schema\n}\n\n// test types -- keep for future validation, but comment out\n\n/*\ntype TestSchema = 'network.xyo.test'\nconst TestSchema: TestSchema = 'network.xyo.test'\n\ntype Test = Payload<{ field: string }, TestSchema>\n\nconst testPayload: Test = { field: 'test', schema: TestSchema }\nconst testWithMeta: WithMeta<Test> = { $hash: '1234abcd', $meta: { timestamp: Date.now() }, field: 'test', schema: TestSchema }\n\nconst testPayloads: Payload[] = [testPayload]\nconst testMetaPayloads: WithMeta<Payload>[] = [testWithMeta]\n\nconst testType: Test = testWithMeta\n\nconst isTest: Test[] = testPayloads.filter(isPayloadOfSchemaType(TestSchema))\nconst isTestFromMeta: Payload[] = testMetaPayloads.filter(isPayloadOfSchemaType(TestSchema))\nconst isTestFromMetaWithMeta: PayloadWithMeta[] = testMetaPayloads.filter(isPayloadOfSchemaType(TestSchema))\n\nconst isTestFromMetaTyped = testMetaPayloads.filter(isPayloadOfSchemaType<Test>(TestSchema))\n\nconst isTestFromMetaTypedWithMeta: WithMeta<Test>[] = testMetaPayloads.filter(isPayloadOfSchemaType(TestSchema))\n\nconst isTestWithMeta: WithMeta<Test>[] = testPayloads.filter(isPayloadOfSchemaTypeWithMeta(TestSchema))\nconst isTestWithMetaFromMeta: WithMeta<Test>[] = testMetaPayloads.filter(isPayloadOfSchemaTypeWithMeta(TestSchema))\n*/\n","import type { Hash } from '@xylabs/hex'\nimport type { JsonValue } from '@xylabs/object'\n\nimport { isPayloadOfSchemaType } from './isPayloadOfSchemaType.ts'\nimport type { Payload } from './Payload.ts'\n\nexport type ModuleErrorSchema = 'network.xyo.error.module'\nexport const ModuleErrorSchema: ModuleErrorSchema = 'network.xyo.error.module'\n\nexport type ModuleError = Payload<{\n details?: JsonValue\n message?: string\n name?: string\n query?: Hash\n schema: ModuleErrorSchema\n sources?: Hash[]\n}>\n\nexport const isModuleError = isPayloadOfSchemaType<ModuleError>(ModuleErrorSchema)\n","import { isAnyPayload } from './isPayload.ts'\nimport type { WithMeta } from './Meta.ts'\nimport type { Payload } from './Payload.ts'\n\n/**\n * Return true if the value is a payload with the required meta fields\n * @param value The value to check\n * @returns True if the value is a payload with the required meta fields\n */\nexport const isWithHash = <T extends Payload>(value: T): value is WithMeta<T> => {\n return typeof (value as WithMeta<T>)?.$hash === 'string'\n}\n\n/**\n * Return true if the value is a payload with the required meta fields\n * @param value The value to check\n * @returns True if the value is a payload with the required meta fields\n */\nexport const isPayloadWithHash = <T extends Payload>(value: unknown): value is WithMeta<T> => {\n return isAnyPayload(value) && isWithHash(value)\n}\n","import type { EmptyObject, JsonObject } from '@xylabs/object'\n\nimport type { Payload, PayloadMetaFields } from './Payload.ts'\nimport type { Schema, WithSchema } from './Schema.ts'\n\nexport type WithMeta<T extends Payload = Payload, M extends JsonObject | void = void> = PayloadMetaFields<M> & T\nexport type WithOptionalMeta<T extends Payload = Payload, M extends JsonObject | void = void> = Partial<WithMeta<T, M>> &\n Omit<WithMeta<T, M>, '$hash'>\n\nexport type PayloadWithMeta<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithMeta<Payload<T, S>>\n\nexport const unMeta = <T extends WithMeta<Payload>>(payload?: T): T | undefined => {\n if (payload) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n
|
|
1
|
+
{"version":3,"sources":["../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/isPayloadWithHash.ts","../../src/Meta.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.ts"],"sourcesContent":["import { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport type { Payload } from './Payload.ts'\n\nexport const isAnyPayload = (value: unknown): value is Payload => {\n if (isObject(value)) {\n return typeof value.schema === 'string'\n }\n return false\n}\n\nexport const asAnyPayload = AsObjectFactory.create(isAnyPayload)\n\nexport const isPayload\n = <T extends Payload>(schema: string[]) =>\n (value: unknown): value is T => {\n if (isAnyPayload(value)) {\n return schema.includes(value.schema)\n }\n return false\n }\n\nexport const asPayload = <T extends Payload>(schema: string[]) => AsObjectFactory.create((value: unknown): value is T => isPayload(schema)(value))\n","import { isAnyPayload } from './isPayload.ts'\nimport type { WithMeta } from './Meta.ts'\nimport type { Payload, WithSources } from './Payload.ts'\n\nexport const isPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => isAnyPayload(x) && x?.schema === schema\n}\n\nexport const isPayloadOfSchemaTypeWithMeta = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is WithMeta<T> => isPayloadOfSchemaType<WithMeta<T>>(schema)(x) && x.$hash !== undefined\n}\n\nexport const isPayloadOfSchemaTypeWithSources = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is WithSources<T> =>\n isPayloadOfSchemaType<WithSources<T>>(schema)(x) && x.sources !== undefined && Array.isArray(x.sources)\n}\n\nexport const notPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => !isAnyPayload(x) || x?.schema !== schema\n}\n\n// test types -- keep for future validation, but comment out\n\n/*\ntype TestSchema = 'network.xyo.test'\nconst TestSchema: TestSchema = 'network.xyo.test'\n\ntype Test = Payload<{ field: string }, TestSchema>\n\nconst testPayload: Test = { field: 'test', schema: TestSchema }\nconst testWithMeta: WithMeta<Test> = { $hash: '1234abcd', $meta: { timestamp: Date.now() }, field: 'test', schema: TestSchema }\n\nconst testPayloads: Payload[] = [testPayload]\nconst testMetaPayloads: WithMeta<Payload>[] = [testWithMeta]\n\nconst testType: Test = testWithMeta\n\nconst isTest: Test[] = testPayloads.filter(isPayloadOfSchemaType(TestSchema))\nconst isTestFromMeta: Payload[] = testMetaPayloads.filter(isPayloadOfSchemaType(TestSchema))\nconst isTestFromMetaWithMeta: PayloadWithMeta[] = testMetaPayloads.filter(isPayloadOfSchemaType(TestSchema))\n\nconst isTestFromMetaTyped = testMetaPayloads.filter(isPayloadOfSchemaType<Test>(TestSchema))\n\nconst isTestFromMetaTypedWithMeta: WithMeta<Test>[] = testMetaPayloads.filter(isPayloadOfSchemaType(TestSchema))\n\nconst isTestWithMeta: WithMeta<Test>[] = testPayloads.filter(isPayloadOfSchemaTypeWithMeta(TestSchema))\nconst isTestWithMetaFromMeta: WithMeta<Test>[] = testMetaPayloads.filter(isPayloadOfSchemaTypeWithMeta(TestSchema))\n*/\n","import type { Hash } from '@xylabs/hex'\nimport type { JsonValue } from '@xylabs/object'\n\nimport { isPayloadOfSchemaType } from './isPayloadOfSchemaType.ts'\nimport type { Payload } from './Payload.ts'\n\nexport type ModuleErrorSchema = 'network.xyo.error.module'\nexport const ModuleErrorSchema: ModuleErrorSchema = 'network.xyo.error.module'\n\nexport type ModuleError = Payload<{\n details?: JsonValue\n message?: string\n name?: string\n query?: Hash\n schema: ModuleErrorSchema\n sources?: Hash[]\n}>\n\nexport const isModuleError = isPayloadOfSchemaType<ModuleError>(ModuleErrorSchema)\n","import { isAnyPayload } from './isPayload.ts'\nimport type { WithMeta } from './Meta.ts'\nimport type { Payload } from './Payload.ts'\n\n/**\n * Return true if the value is a payload with the required meta fields\n * @param value The value to check\n * @returns True if the value is a payload with the required meta fields\n */\nexport const isWithHash = <T extends Payload>(value: T): value is WithMeta<T> => {\n return typeof (value as WithMeta<T>)?.$hash === 'string'\n}\n\n/**\n * Return true if the value is a payload with the required meta fields\n * @param value The value to check\n * @returns True if the value is a payload with the required meta fields\n */\nexport const isPayloadWithHash = <T extends Payload>(value: unknown): value is WithMeta<T> => {\n return isAnyPayload(value) && isWithHash(value)\n}\n","import type { EmptyObject, JsonObject } from '@xylabs/object'\n\nimport type { Payload, PayloadMetaFields } from './Payload.ts'\nimport type { Schema, WithSchema } from './Schema.ts'\n\nexport type WithMeta<T extends Payload = Payload, M extends JsonObject | void = void> = PayloadMetaFields<M> & T\nexport type WithOptionalMeta<T extends Payload = Payload, M extends JsonObject | void = void> = Partial<WithMeta<T, M>> &\n Omit<WithMeta<T, M>, '$hash'>\n\nexport type PayloadWithMeta<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithMeta<Payload<T, S>>\n\nexport const unMeta = <T extends WithMeta<Payload>>(payload?: T): T | undefined => {\n if (payload) {\n const {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n $meta, $hash, ...result\n } = payload\n return result as T\n }\n}\n","export type PayloadSetSchema = 'network.xyo.payload.set'\nexport const PayloadSetSchema: PayloadSetSchema = 'network.xyo.payload.set'\n","import type { EmptyObject } from '@xylabs/object'\nimport { AsTypeFactory } from '@xylabs/object'\n\n/** Schema type in Javascript is a string */\nexport type Schema = string\n\nexport const PayloadSchema = 'network.xyo.payload' as const\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n return typeof value === 'string'\n}\n\nexport const asSchema = AsTypeFactory.create<Schema>(isSchema)\n\n/** Schema fields for a Payload */\nexport interface SchemaFields extends EmptyObject {\n /** Schema of the object */\n schema: Schema\n}\n\n/** Add the Schema Fields to an object */\nexport type WithSchema<T extends EmptyObject | void = void> = T extends EmptyObject ? SchemaFields & T : SchemaFields\n"],"mappings":";AAAA,SAAS,iBAAiB,gBAAgB;AAInC,IAAM,eAAe,CAAC,UAAqC;AAChE,MAAI,SAAS,KAAK,GAAG;AACnB,WAAO,OAAO,MAAM,WAAW;AAAA,EACjC;AACA,SAAO;AACT;AAEO,IAAM,eAAe,gBAAgB,OAAO,YAAY;AAExD,IAAM,YACT,CAAoB,WACpB,CAAC,UAA+B;AAC9B,MAAI,aAAa,KAAK,GAAG;AACvB,WAAO,OAAO,SAAS,MAAM,MAAM;AAAA,EACrC;AACA,SAAO;AACT;AAEG,IAAM,YAAY,CAAoB,WAAqB,gBAAgB,OAAO,CAAC,UAA+B,UAAU,MAAM,EAAE,KAAK,CAAC;;;AClB1I,IAAM,wBAAwB,CAAoB,WAAmB;AAC1E,SAAO,CAAC,MAA+B,aAAa,CAAC,KAAK,GAAG,WAAW;AAC1E;AAEO,IAAM,gCAAgC,CAAoB,WAAmB;AAClF,SAAO,CAAC,MAAyC,sBAAmC,MAAM,EAAE,CAAC,KAAK,EAAE,UAAU;AAChH;AAEO,IAAM,mCAAmC,CAAoB,WAAmB;AACrF,SAAO,CAAC,MACN,sBAAsC,MAAM,EAAE,CAAC,KAAK,EAAE,YAAY,UAAa,MAAM,QAAQ,EAAE,OAAO;AAC1G;AAEO,IAAM,yBAAyB,CAAoB,WAAmB;AAC3E,SAAO,CAAC,MAA+B,CAAC,aAAa,CAAC,KAAK,GAAG,WAAW;AAC3E;;;ACZO,IAAM,oBAAuC;AAW7C,IAAM,gBAAgB,sBAAmC,iBAAiB;;;ACT1E,IAAM,aAAa,CAAoB,UAAmC;AAC/E,SAAO,OAAQ,OAAuB,UAAU;AAClD;AAOO,IAAM,oBAAoB,CAAoB,UAAyC;AAC5F,SAAO,aAAa,KAAK,KAAK,WAAW,KAAK;AAChD;;;ACTO,IAAM,SAAS,CAA8B,YAA+B;AACjF,MAAI,SAAS;AACX,UAAM;AAAA;AAAA,MAEJ;AAAA,MAAO;AAAA,MAAO,GAAG;AAAA,IACnB,IAAI;AACJ,WAAO;AAAA,EACT;AACF;;;AClBO,IAAM,mBAAqC;;;ACAlD,SAAS,qBAAqB;AAKvB,IAAM,gBAAgB;AAGtB,IAAM,WAAW,CAAC,UAAoC;AAC3D,SAAO,OAAO,UAAU;AAC1B;AAEO,IAAM,WAAW,cAAc,OAAe,QAAQ;","names":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Payload } from './Payload.ts';
|
|
2
|
+
export declare const isAnyPayload: (value: unknown) => value is Payload;
|
|
3
|
+
export declare const asAnyPayload: {
|
|
4
|
+
<TType extends {
|
|
5
|
+
schema: string;
|
|
6
|
+
} & import("./Payload.ts").PayloadFields>(value: import(".store/@xylabs-promise-npm-4.0.3-1670033284/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
|
|
7
|
+
<TType extends {
|
|
8
|
+
schema: string;
|
|
9
|
+
} & import("./Payload.ts").PayloadFields>(value: import(".store/@xylabs-promise-npm-4.0.3-1670033284/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<{
|
|
10
|
+
schema: string;
|
|
11
|
+
} & import("./Payload.ts").PayloadFields>, config?: import("@xylabs/object").TypeCheckConfig): TType;
|
|
12
|
+
};
|
|
13
|
+
export declare const isPayload: <T extends Payload>(schema: string[]) => (value: unknown) => value is T;
|
|
14
|
+
export declare const asPayload: <T extends Payload>(schema: string[]) => {
|
|
15
|
+
<TType extends T>(value: import(".store/@xylabs-promise-npm-4.0.3-1670033284/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
|
|
16
|
+
<TType extends T>(value: import(".store/@xylabs-promise-npm-4.0.3-1670033284/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<T>, config?: import("@xylabs/object").TypeCheckConfig): TType;
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=isPayload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isPayload.d.ts","sourceRoot":"","sources":["../../src/isPayload.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAE3C,eAAO,MAAM,YAAY,UAAW,OAAO,KAAG,KAAK,IAAI,OAKtD,CAAA;AAED,eAAO,MAAM,YAAY;;;;;;;;;CAAuC,CAAA;AAEhE,eAAO,MAAM,SAAS,GACjB,CAAC,SAAS,OAAO,UAAU,MAAM,EAAE,aAC5B,OAAO,KAAG,KAAK,IAAI,CAK1B,CAAA;AAEL,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,OAAO,UAAU,MAAM,EAAE;;;CAAqF,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { WithMeta } from './Meta.ts';
|
|
2
|
+
import type { Payload, WithSources } from './Payload.ts';
|
|
3
|
+
export declare const isPayloadOfSchemaType: <T extends Payload>(schema: string) => (x?: unknown | null) => x is T;
|
|
4
|
+
export declare const isPayloadOfSchemaTypeWithMeta: <T extends Payload>(schema: string) => (x?: unknown | null) => x is WithMeta<T>;
|
|
5
|
+
export declare const isPayloadOfSchemaTypeWithSources: <T extends Payload>(schema: string) => (x?: unknown | null) => x is WithSources<T>;
|
|
6
|
+
export declare const notPayloadOfSchemaType: <T extends Payload>(schema: string) => (x?: unknown | null) => x is T;
|
|
7
|
+
//# sourceMappingURL=isPayloadOfSchemaType.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isPayloadOfSchemaType.d.ts","sourceRoot":"","sources":["../../src/isPayloadOfSchemaType.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAExD,eAAO,MAAM,qBAAqB,GAAI,CAAC,SAAS,OAAO,UAAU,MAAM,UACzD,OAAO,GAAG,IAAI,KAAG,CAAC,IAAI,CACnC,CAAA;AAED,eAAO,MAAM,6BAA6B,GAAI,CAAC,SAAS,OAAO,UAAU,MAAM,UACjE,OAAO,GAAG,IAAI,KAAG,CAAC,IAAI,QAAQ,CAAC,CAAC,CAC7C,CAAA;AAED,eAAO,MAAM,gCAAgC,GAAI,CAAC,SAAS,OAAO,UAAU,MAAM,UACpE,OAAO,GAAG,IAAI,KAAG,CAAC,IAAI,WAAW,CAAC,CAAC,CAEhD,CAAA;AAED,eAAO,MAAM,sBAAsB,GAAI,CAAC,SAAS,OAAO,UAAU,MAAM,UAC1D,OAAO,GAAG,IAAI,KAAG,CAAC,IAAI,CACnC,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { WithMeta } from './Meta.ts';
|
|
2
|
+
import type { Payload } from './Payload.ts';
|
|
3
|
+
export declare const isWithHash: <T extends Payload>(value: T) => value is WithMeta<T>;
|
|
4
|
+
export declare const isPayloadWithHash: <T extends Payload>(value: unknown) => value is WithMeta<T>;
|
|
5
|
+
//# sourceMappingURL=isPayloadWithHash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isPayloadWithHash.d.ts","sourceRoot":"","sources":["../../src/isPayloadWithHash.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAO3C,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,OAAO,SAAS,CAAC,KAAG,KAAK,IAAI,QAAQ,CAAC,CAAC,CAE3E,CAAA;AAOD,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,OAAO,SAAS,OAAO,KAAG,KAAK,IAAI,QAAQ,CAAC,CAAC,CAExF,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/payload-model",
|
|
3
|
-
"
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
"url": "https://xyo.network"
|
|
7
|
-
},
|
|
3
|
+
"version": "3.0.8",
|
|
4
|
+
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
5
|
+
"homepage": "https://xyo.network",
|
|
8
6
|
"bugs": {
|
|
9
|
-
"
|
|
10
|
-
"
|
|
7
|
+
"url": "git+https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues",
|
|
8
|
+
"email": "support@xyo.network"
|
|
11
9
|
},
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
|
|
15
13
|
},
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
"
|
|
14
|
+
"license": "LGPL-3.0-only",
|
|
15
|
+
"author": {
|
|
16
|
+
"name": "XYO Development Team",
|
|
17
|
+
"email": "support@xyo.network",
|
|
18
|
+
"url": "https://xyo.network"
|
|
20
19
|
},
|
|
21
|
-
"
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"type": "module",
|
|
22
22
|
"exports": {
|
|
23
23
|
".": {
|
|
24
24
|
"browser": {
|
|
@@ -38,16 +38,16 @@
|
|
|
38
38
|
},
|
|
39
39
|
"module": "dist/neutral/index.mjs",
|
|
40
40
|
"types": "types.node.d.ts",
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"access": "public"
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@xylabs/hex": "^4.0.3",
|
|
43
|
+
"@xylabs/object": "^4.0.3"
|
|
45
44
|
},
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@xylabs/ts-scripts-yarn3": "^4.0.7",
|
|
47
|
+
"@xylabs/tsconfig": "^4.0.7",
|
|
48
|
+
"typescript": "^5.5.4"
|
|
49
49
|
},
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
}
|
|
53
53
|
}
|
package/src/Meta.ts
CHANGED
|
@@ -11,8 +11,10 @@ export type PayloadWithMeta<T extends void | EmptyObject | WithSchema = void, S
|
|
|
11
11
|
|
|
12
12
|
export const unMeta = <T extends WithMeta<Payload>>(payload?: T): T | undefined => {
|
|
13
13
|
if (payload) {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const {
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
16
|
+
$meta, $hash, ...result
|
|
17
|
+
} = payload
|
|
16
18
|
return result as T
|
|
17
19
|
}
|
|
18
20
|
}
|