@xyo-network/payload-model 2.90.1 → 2.90.3
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/Payload.d.cts +5 -4
- package/dist/browser/Payload.d.cts.map +1 -1
- package/dist/browser/Payload.d.mts +5 -4
- package/dist/browser/Payload.d.mts.map +1 -1
- package/dist/browser/Payload.d.ts +5 -4
- package/dist/browser/Payload.d.ts.map +1 -1
- package/dist/browser/index.cjs +14 -1
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +14 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/isPayloadOfSchemaType.d.cts +4 -0
- package/dist/browser/isPayloadOfSchemaType.d.cts.map +1 -1
- package/dist/browser/isPayloadOfSchemaType.d.mts +4 -0
- package/dist/browser/isPayloadOfSchemaType.d.mts.map +1 -1
- package/dist/browser/isPayloadOfSchemaType.d.ts +4 -0
- package/dist/browser/isPayloadOfSchemaType.d.ts.map +1 -1
- package/dist/node/Payload.d.cts +5 -4
- package/dist/node/Payload.d.cts.map +1 -1
- package/dist/node/Payload.d.mts +5 -4
- package/dist/node/Payload.d.mts.map +1 -1
- package/dist/node/Payload.d.ts +5 -4
- package/dist/node/Payload.d.ts.map +1 -1
- package/dist/node/index.cjs +17 -2
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +14 -1
- package/dist/node/index.js.map +1 -1
- package/dist/node/isPayloadOfSchemaType.d.cts +4 -0
- package/dist/node/isPayloadOfSchemaType.d.cts.map +1 -1
- package/dist/node/isPayloadOfSchemaType.d.mts +4 -0
- package/dist/node/isPayloadOfSchemaType.d.mts.map +1 -1
- package/dist/node/isPayloadOfSchemaType.d.ts +4 -0
- package/dist/node/isPayloadOfSchemaType.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/Payload.ts +10 -6
- package/src/isPayloadOfSchemaType.ts +5 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Hash } from '@xylabs/hex';
|
|
2
|
-
import { EmptyObject, JsonObject
|
|
2
|
+
import { EmptyObject, JsonObject } from '@xylabs/object';
|
|
3
3
|
import { Schema, WithSchema } from './Schema';
|
|
4
4
|
/** Meta fields for a payload - Either both $hash and $meta should exist or neither */
|
|
5
5
|
export interface PayloadMetaFields extends EmptyObject {
|
|
@@ -24,9 +24,10 @@ export type Payload<T extends void | EmptyObject | WithSchema = void, S extends
|
|
|
24
24
|
export type OverridablePayload<T extends Payload> = Omit<T, 'schema'> & {
|
|
25
25
|
schema: string;
|
|
26
26
|
};
|
|
27
|
-
export type DivinedPayload<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = Payload<WithAdditional<{
|
|
28
|
-
sources: Hash[];
|
|
29
|
-
}, T>, S>;
|
|
30
27
|
export type WithMeta<T extends Payload = Payload> = T & PayloadMetaFields;
|
|
28
|
+
export type WithOptionalMeta<T extends Payload = Payload> = Partial<WithMeta<T>> & Omit<WithMeta<T>, '$hash'>;
|
|
31
29
|
export type PayloadWithMeta<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithMeta<Payload<T, S>>;
|
|
30
|
+
export declare const unMeta: <T extends WithMeta<{
|
|
31
|
+
schema: string;
|
|
32
|
+
} & object>>(payload?: T | undefined) => T | undefined;
|
|
32
33
|
//# sourceMappingURL=Payload.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Payload.d.ts","sourceRoot":"","sources":["../../src/Payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"Payload.d.ts","sourceRoot":"","sources":["../../src/Payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAExD,OAAO,EAAE,MAAM,EA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AM,MAAM,QAAQ,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI,CAAC,GAAG,iBAAiB,CAAA;AACzE,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAA;AAE7G,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,IAAI,GAAG,WAAW,GAAG,UAAU,GAAG,IAAI,EAAE,CAAC,SAAS,MAAM,GAAG,IAAI,GAAG,IAAI,IAAI,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AAEvI,eAAO,MAAM,MAAM;;sDAMlB,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Hash } from '@xylabs/hex';
|
|
2
|
-
import { EmptyObject, JsonObject
|
|
2
|
+
import { EmptyObject, JsonObject } from '@xylabs/object';
|
|
3
3
|
import { Schema, WithSchema } from './Schema';
|
|
4
4
|
/** Meta fields for a payload - Either both $hash and $meta should exist or neither */
|
|
5
5
|
export interface PayloadMetaFields extends EmptyObject {
|
|
@@ -24,9 +24,10 @@ export type Payload<T extends void | EmptyObject | WithSchema = void, S extends
|
|
|
24
24
|
export type OverridablePayload<T extends Payload> = Omit<T, 'schema'> & {
|
|
25
25
|
schema: string;
|
|
26
26
|
};
|
|
27
|
-
export type DivinedPayload<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = Payload<WithAdditional<{
|
|
28
|
-
sources: Hash[];
|
|
29
|
-
}, T>, S>;
|
|
30
27
|
export type WithMeta<T extends Payload = Payload> = T & PayloadMetaFields;
|
|
28
|
+
export type WithOptionalMeta<T extends Payload = Payload> = Partial<WithMeta<T>> & Omit<WithMeta<T>, '$hash'>;
|
|
31
29
|
export type PayloadWithMeta<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithMeta<Payload<T, S>>;
|
|
30
|
+
export declare const unMeta: <T extends WithMeta<{
|
|
31
|
+
schema: string;
|
|
32
|
+
} & object>>(payload?: T | undefined) => T | undefined;
|
|
32
33
|
//# sourceMappingURL=Payload.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Payload.d.ts","sourceRoot":"","sources":["../../src/Payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"Payload.d.ts","sourceRoot":"","sources":["../../src/Payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAExD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAE7C,sFAAsF;AACtF,MAAM,WAAW,iBAAkB,SAAQ,WAAW;IACpD,8EAA8E;IAC9E,KAAK,EAAE,IAAI,CAAA;IACX,wEAAwE;IACxE,KAAK,CAAC,EAAE,UAAU,CAAA;CACnB;AAED,sCAAsC;AACtC,MAAM,MAAM,aAAa,GAAG,WAAW,CAAA;AAEvC,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,WAAW,GAAG,IAAI,GAAG,IAAI,IAAI,UAAU,CAAC,CAAC,SAAS,WAAW,GAAG,aAAa,GAAG,CAAC,GAAG,aAAa,CAAC,CAAA;AAEpI,6BAA6B;AAC7B,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,IAAI,GAAG,WAAW,GAAG,UAAU,GAAG,IAAI,EAAE,CAAC,SAAS,MAAM,GAAG,IAAI,GAAG,IAAI,IAAI,CAAC,SAAS,UAAU,GACxH,CAAC,SAAS,MAAM,GAEd,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG;IAA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chema } from './Schema';
|
|
4
4
|
/** Meta fields for a payload - Either both $hash and $meta should exist or neither */
|
|
5
5
|
export interface PayloadMetaFields extends EmptyObject {
|
|
@@ -24,9 +24,10 @@ export type Payload<T extends void | EmptyObject | WithSchema = void, S extends
|
|
|
24
24
|
export type OverridablePayload<T extends Payload> = Omit<T, 'schema'> & {
|
|
25
25
|
schema: string;
|
|
26
26
|
};
|
|
27
|
-
export type DivinedPayload<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = Payload<WithAdditional<{
|
|
28
|
-
sources: Hash[];
|
|
29
|
-
}, T>, S>;
|
|
30
27
|
export type WithMeta<T extends Payload = Payload> = T & PayloadMetaFields;
|
|
28
|
+
export type WithOptionalMeta<T extends Payload = Payload> = Partial<WithMeta<T>> & Omit<WithMeta<T>, '$hash'>;
|
|
31
29
|
export type PayloadWithMeta<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithMeta<Payload<T, S>>;
|
|
30
|
+
export declare const unMeta: <T extends WithMeta<{
|
|
31
|
+
schema: string;
|
|
32
|
+
} & object>>(payload?: T | undefined) => T | undefined;
|
|
32
33
|
//# sourceMappingURL=Payload.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Payload.d.ts","sourceRoot":"","sources":["../../src/Payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"Payload.d.ts","sourceRoot":"","sources":["../../src/Payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAExD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAE7C,sFAAsF;AACtF,MAAM,WAAW,iBAAkB,SAAQ,WAAW;IACpD,8EA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AAM,gBAAgB,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAA;AAE7G,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,IAAI,GAAG,WAAW,GAAG,UAAU,GAAG,IAAI,EAAE,CAAC,SAAS,MAAM,GAAG,IAAI,GAAG,IAAI,IAAI,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AAEvI,eAAO,MAAM,MAAM;;sDAMlB,CAAA"}
|
package/dist/browser/index.cjs
CHANGED
|
@@ -31,10 +31,12 @@ __export(src_exports, {
|
|
|
31
31
|
isModuleError: () => isModuleError,
|
|
32
32
|
isPayload: () => isPayload,
|
|
33
33
|
isPayloadOfSchemaType: () => isPayloadOfSchemaType,
|
|
34
|
+
isPayloadOfSchemaTypeWithMeta: () => isPayloadOfSchemaTypeWithMeta,
|
|
34
35
|
isPayloadWithHash: () => isPayloadWithHash,
|
|
35
36
|
isSchema: () => isSchema,
|
|
36
37
|
isWithHash: () => isWithHash,
|
|
37
|
-
notPayloadOfSchemaType: () => notPayloadOfSchemaType
|
|
38
|
+
notPayloadOfSchemaType: () => notPayloadOfSchemaType,
|
|
39
|
+
unMeta: () => unMeta
|
|
38
40
|
});
|
|
39
41
|
module.exports = __toCommonJS(src_exports);
|
|
40
42
|
|
|
@@ -59,6 +61,9 @@ var asPayload = /* @__PURE__ */ __name((schema) => import_object.AsObjectFactory
|
|
|
59
61
|
var isPayloadOfSchemaType = /* @__PURE__ */ __name((schema) => {
|
|
60
62
|
return (x) => isAnyPayload(x) && x?.schema === schema;
|
|
61
63
|
}, "isPayloadOfSchemaType");
|
|
64
|
+
var isPayloadOfSchemaTypeWithMeta = /* @__PURE__ */ __name((schema) => {
|
|
65
|
+
return (x) => isPayloadOfSchemaType(schema)(x) && x.$hash !== void 0 && x.$meta !== void 0;
|
|
66
|
+
}, "isPayloadOfSchemaTypeWithMeta");
|
|
62
67
|
var notPayloadOfSchemaType = /* @__PURE__ */ __name((schema) => {
|
|
63
68
|
return (x) => !isAnyPayload(x) || x?.schema !== schema;
|
|
64
69
|
}, "notPayloadOfSchemaType");
|
|
@@ -75,6 +80,14 @@ var isPayloadWithHash = /* @__PURE__ */ __name((value) => {
|
|
|
75
80
|
return isAnyPayload(value) && isWithHash(value);
|
|
76
81
|
}, "isPayloadWithHash");
|
|
77
82
|
|
|
83
|
+
// src/Payload.ts
|
|
84
|
+
var unMeta = /* @__PURE__ */ __name((payload) => {
|
|
85
|
+
if (payload) {
|
|
86
|
+
const { $meta, $hash, ...result } = payload;
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
}, "unMeta");
|
|
90
|
+
|
|
78
91
|
// src/PayloadSet/PayloadSetSchema.ts
|
|
79
92
|
var PayloadSetSchema = "network.xyo.payload.set";
|
|
80
93
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/isPayloadWithHash.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.ts"],"sourcesContent":["export * from './Error'\nexport * from './isPayload'\nexport * from './isPayloadOfSchemaType'\nexport * from './isPayloadWithHash'\nexport * from './Payload'\nexport * from './PayloadFindFilter'\nexport * from './PayloadSet'\nexport * from './Query'\nexport * from './Schema'\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport { Payload } from './Payload'\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'\nimport { Payload } from './Payload'\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 notPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => !isAnyPayload(x) || x?.schema !== schema\n}\n","import { isPayloadOfSchemaType } from './isPayloadOfSchemaType'\nimport { Payload } from './Payload'\n\nexport type ModuleErrorSchema = 'network.xyo.error.module'\nexport const ModuleErrorSchema: ModuleErrorSchema = 'network.xyo.error.module'\n\nexport type ModuleError = Payload<{\n message?: string\n name?: string\n query?: string\n schema: ModuleErrorSchema\n sources?: string[]\n}>\n\nexport const isModuleError = isPayloadOfSchemaType<ModuleError>(ModuleErrorSchema)\n","import { isAnyPayload } from './isPayload'\nimport { Payload, WithMeta } from './Payload'\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","export type PayloadSetSchema = 'network.xyo.payload.set'\nexport const PayloadSetSchema: PayloadSetSchema = 'network.xyo.payload.set'\n","import { AsTypeFactory, EmptyObject } from '@xylabs/object'\n\n/** Schema type in Javascript is a string */\nexport type Schema = string\n\nexport const PayloadSchema = 'network.xyo.payload'\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n if (typeof value === 'string') {\n return true\n }\n return false\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
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/isPayloadWithHash.ts","../../src/Payload.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.ts"],"sourcesContent":["export * from './Error'\nexport * from './isPayload'\nexport * from './isPayloadOfSchemaType'\nexport * from './isPayloadWithHash'\nexport * from './Payload'\nexport * from './PayloadFindFilter'\nexport * from './PayloadSet'\nexport * from './Query'\nexport * from './Schema'\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport { Payload } from './Payload'\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'\nimport { Payload, WithMeta } from './Payload'\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 && x.$meta !== undefined\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","import { isPayloadOfSchemaType } from './isPayloadOfSchemaType'\nimport { Payload } from './Payload'\n\nexport type ModuleErrorSchema = 'network.xyo.error.module'\nexport const ModuleErrorSchema: ModuleErrorSchema = 'network.xyo.error.module'\n\nexport type ModuleError = Payload<{\n message?: string\n name?: string\n query?: string\n schema: ModuleErrorSchema\n sources?: string[]\n}>\n\nexport const isModuleError = isPayloadOfSchemaType<ModuleError>(ModuleErrorSchema)\n","import { isAnyPayload } from './isPayload'\nimport { Payload, WithMeta } from './Payload'\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 { Hash } from '@xylabs/hex'\nimport { EmptyObject, JsonObject } from '@xylabs/object'\n\nimport { Schema, WithSchema } from './Schema'\n\n/** Meta fields for a payload - Either both $hash and $meta should exist or neither */\nexport interface PayloadMetaFields extends EmptyObject {\n /** Hash of the body of the payload excluding the items in the $meta object */\n $hash: Hash\n /** Meta data that should be included in the main hash of the payload */\n $meta?: JsonObject\n}\n\n/** Additional fields for a payload */\nexport type PayloadFields = EmptyObject\n\nexport type WithPayload<T extends EmptyObject | void = void> = WithSchema<T extends EmptyObject ? PayloadFields & T : PayloadFields>\n\n/** Base Type for Payloads */\nexport type Payload<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = T extends WithSchema\n ? S extends Schema\n ? /* T (w/Schema) & S provided */\n WithPayload<Omit<T, 'schema'> & { schema: S } & PayloadFields>\n : /* Only T (w/Schema) provided */\n WithPayload<T>\n : T extends object\n ? S extends Schema\n ? /* T (w/o Schema) & S provided */\n WithPayload<T & { schema: S } & PayloadFields>\n : /* Only T (w/o Schema) provided */\n WithPayload<T & { schema: Schema } & PayloadFields>\n : /* Either just S or neither S or T provided */\n {\n schema: S extends Schema ? S : Schema\n } & PayloadFields\n\nexport type OverridablePayload<T extends Payload> = Omit<T, 'schema'> & { schema: string }\n\nexport type WithMeta<T extends Payload = Payload> = T & PayloadMetaFields\nexport type WithOptionalMeta<T extends Payload = Payload> = Partial<WithMeta<T>> & Omit<WithMeta<T>, '$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 const { $meta, $hash, ...result } = 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 { AsTypeFactory, EmptyObject } from '@xylabs/object'\n\n/** Schema type in Javascript is a string */\nexport type Schema = string\n\nexport const PayloadSchema = 'network.xyo.payload'\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n if (typeof value === 'string') {\n return true\n }\n return false\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;;;;;;;;;;;;;;;;;;;;;;ACCA,oBAA0C;AAInC,IAAMA,eAAe,wBAACC,UAAAA;AAC3B,UAAIC,wBAASD,KAAAA,GAAQ;AACnB,WAAO,OAAOA,MAAME,WAAW;EACj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AA;AACvB,MAAI,OAAOA,UAAU,UAAU;AAC7B,WAAO;EACT;AACA,SAAO;AACT,GALwB;AAOjB,IAAMC,WAAWC,6BAAcC,OAAeJ,QAAAA;","names":["isAnyPayload","value","isObject","schema","asAnyPayload","AsObjectFactory","create","isPayload","includes","asPayload","isPayloadOfSchemaType","schema","x","isAnyPayload","isPayloadOfSchemaTypeWithMeta","$hash","undefined","$meta","notPayloadOfSchemaType","ModuleErrorSchema","isModuleError","isPayloadOfSchemaType","isWithHash","value","$hash","isPayloadWithHash","isAnyPayload","unMeta","payload","$meta","$hash","result","PayloadSetSchema","import_object","PayloadSchema","isSchema","value","asSchema","AsTypeFactory","create"]}
|
package/dist/browser/index.js
CHANGED
|
@@ -22,6 +22,9 @@ var asPayload = /* @__PURE__ */ __name((schema) => AsObjectFactory.create((value
|
|
|
22
22
|
var isPayloadOfSchemaType = /* @__PURE__ */ __name((schema) => {
|
|
23
23
|
return (x) => isAnyPayload(x) && x?.schema === schema;
|
|
24
24
|
}, "isPayloadOfSchemaType");
|
|
25
|
+
var isPayloadOfSchemaTypeWithMeta = /* @__PURE__ */ __name((schema) => {
|
|
26
|
+
return (x) => isPayloadOfSchemaType(schema)(x) && x.$hash !== void 0 && x.$meta !== void 0;
|
|
27
|
+
}, "isPayloadOfSchemaTypeWithMeta");
|
|
25
28
|
var notPayloadOfSchemaType = /* @__PURE__ */ __name((schema) => {
|
|
26
29
|
return (x) => !isAnyPayload(x) || x?.schema !== schema;
|
|
27
30
|
}, "notPayloadOfSchemaType");
|
|
@@ -38,6 +41,14 @@ var isPayloadWithHash = /* @__PURE__ */ __name((value) => {
|
|
|
38
41
|
return isAnyPayload(value) && isWithHash(value);
|
|
39
42
|
}, "isPayloadWithHash");
|
|
40
43
|
|
|
44
|
+
// src/Payload.ts
|
|
45
|
+
var unMeta = /* @__PURE__ */ __name((payload) => {
|
|
46
|
+
if (payload) {
|
|
47
|
+
const { $meta, $hash, ...result } = payload;
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
}, "unMeta");
|
|
51
|
+
|
|
41
52
|
// src/PayloadSet/PayloadSetSchema.ts
|
|
42
53
|
var PayloadSetSchema = "network.xyo.payload.set";
|
|
43
54
|
|
|
@@ -62,9 +73,11 @@ export {
|
|
|
62
73
|
isModuleError,
|
|
63
74
|
isPayload,
|
|
64
75
|
isPayloadOfSchemaType,
|
|
76
|
+
isPayloadOfSchemaTypeWithMeta,
|
|
65
77
|
isPayloadWithHash,
|
|
66
78
|
isSchema,
|
|
67
79
|
isWithHash,
|
|
68
|
-
notPayloadOfSchemaType
|
|
80
|
+
notPayloadOfSchemaType,
|
|
81
|
+
unMeta
|
|
69
82
|
};
|
|
70
83
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/isPayloadWithHash.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport { Payload } from './Payload'\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'\nimport { Payload } from './Payload'\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 notPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => !isAnyPayload(x) || x?.schema !== schema\n}\n","import { isPayloadOfSchemaType } from './isPayloadOfSchemaType'\nimport { Payload } from './Payload'\n\nexport type ModuleErrorSchema = 'network.xyo.error.module'\nexport const ModuleErrorSchema: ModuleErrorSchema = 'network.xyo.error.module'\n\nexport type ModuleError = Payload<{\n message?: string\n name?: string\n query?: string\n schema: ModuleErrorSchema\n sources?: string[]\n}>\n\nexport const isModuleError = isPayloadOfSchemaType<ModuleError>(ModuleErrorSchema)\n","import { isAnyPayload } from './isPayload'\nimport { Payload, WithMeta } from './Payload'\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","export type PayloadSetSchema = 'network.xyo.payload.set'\nexport const PayloadSetSchema: PayloadSetSchema = 'network.xyo.payload.set'\n","import { AsTypeFactory, EmptyObject } from '@xylabs/object'\n\n/** Schema type in Javascript is a string */\nexport type Schema = string\n\nexport const PayloadSchema = 'network.xyo.payload'\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n if (typeof value === 'string') {\n return true\n }\n return false\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":";;;;AACA,SAASA,iBAAiBC,gBAAgB;AAInC,IAAMC,eAAe,wBAACC,UAAAA;AAC3B,MAAIC,SAASD,KAAAA,GAAQ;AACnB,WAAO,OAAOA,MAAME,WAAW;EACjC;AACA,SAAO;AACT,GAL4B;AAOrB,IAAMC,eAAeC,gBAAgBC,OAAON,YAAAA;AAE5C,IAAMO,YACX,wBAAoBJ,WACpB,CAACF,UAAAA;AACC,MAAID,aAAaC,KAAAA,GAAQ;AACvB,WAAOE,OAAOK,SAASP,MAAME,MAAM;EACrC;AACA,SAAO;AACT,GANA;AAQK,IAAMM,YAAY,wBAAoBN,WAAqBE,gBAAgBC,OAAO,CAACL,UAA+BM,UAAUJ,MAAAA,EAAQF,KAAAA,CAAAA,GAAlH;;;ACpBlB,IAAMS,wBAAwB,wBAAoBC,WAAAA;AACvD,SAAO,CAACC,MAA+BC,aAAaD,CAAAA,KAAMA,GAAGD,WAAWA;AAC1E,GAFqC;AAI9B,IAAMG,
|
|
1
|
+
{"version":3,"sources":["../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/isPayloadWithHash.ts","../../src/Payload.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport { Payload } from './Payload'\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'\nimport { Payload, WithMeta } from './Payload'\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 && x.$meta !== undefined\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","import { isPayloadOfSchemaType } from './isPayloadOfSchemaType'\nimport { Payload } from './Payload'\n\nexport type ModuleErrorSchema = 'network.xyo.error.module'\nexport const ModuleErrorSchema: ModuleErrorSchema = 'network.xyo.error.module'\n\nexport type ModuleError = Payload<{\n message?: string\n name?: string\n query?: string\n schema: ModuleErrorSchema\n sources?: string[]\n}>\n\nexport const isModuleError = isPayloadOfSchemaType<ModuleError>(ModuleErrorSchema)\n","import { isAnyPayload } from './isPayload'\nimport { Payload, WithMeta } from './Payload'\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 { Hash } from '@xylabs/hex'\nimport { EmptyObject, JsonObject } from '@xylabs/object'\n\nimport { Schema, WithSchema } from './Schema'\n\n/** Meta fields for a payload - Either both $hash and $meta should exist or neither */\nexport interface PayloadMetaFields extends EmptyObject {\n /** Hash of the body of the payload excluding the items in the $meta object */\n $hash: Hash\n /** Meta data that should be included in the main hash of the payload */\n $meta?: JsonObject\n}\n\n/** Additional fields for a payload */\nexport type PayloadFields = EmptyObject\n\nexport type WithPayload<T extends EmptyObject | void = void> = WithSchema<T extends EmptyObject ? PayloadFields & T : PayloadFields>\n\n/** Base Type for Payloads */\nexport type Payload<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = T extends WithSchema\n ? S extends Schema\n ? /* T (w/Schema) & S provided */\n WithPayload<Omit<T, 'schema'> & { schema: S } & PayloadFields>\n : /* Only T (w/Schema) provided */\n WithPayload<T>\n : T extends object\n ? S extends Schema\n ? /* T (w/o Schema) & S provided */\n WithPayload<T & { schema: S } & PayloadFields>\n : /* Only T (w/o Schema) provided */\n WithPayload<T & { schema: Schema } & PayloadFields>\n : /* Either just S or neither S or T provided */\n {\n schema: S extends Schema ? S : Schema\n } & PayloadFields\n\nexport type OverridablePayload<T extends Payload> = Omit<T, 'schema'> & { schema: string }\n\nexport type WithMeta<T extends Payload = Payload> = T & PayloadMetaFields\nexport type WithOptionalMeta<T extends Payload = Payload> = Partial<WithMeta<T>> & Omit<WithMeta<T>, '$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 const { $meta, $hash, ...result } = 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 { AsTypeFactory, EmptyObject } from '@xylabs/object'\n\n/** Schema type in Javascript is a string */\nexport type Schema = string\n\nexport const PayloadSchema = 'network.xyo.payload'\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n if (typeof value === 'string') {\n return true\n }\n return false\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":";;;;AACA,SAASA,iBAAiBC,gBAAgB;AAInC,IAAMC,eAAe,wBAACC,UAAAA;AAC3B,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BAAkC;AAKpC,IAAMC,gBAAgB;AAGtB,IAAMC,WAAW,wBAACC,UAAAA;AACvB,MAAI,OAAOA,UAAU,UAAU;AAC7B,WAAO;EACT;AACA,SAAO;AACT,GALwB;AAOjB,IAAMC,WAAWC,cAAcC,OAAeJ,QAAAA;","names":["AsObjectFactory","isObject","isAnyPayload","value","isObject","schema","asAnyPayload","AsObjectFactory","create","isPayload","includes","asPayload","isPayloadOfSchemaType","schema","x","isAnyPayload","isPayloadOfSchemaTypeWithMeta","$hash","undefined","$meta","notPayloadOfSchemaType","ModuleErrorSchema","isModuleError","isPayloadOfSchemaType","isWithHash","value","$hash","isPayloadWithHash","isAnyPayload","unMeta","payload","$meta","$hash","result","PayloadSetSchema","AsTypeFactory","PayloadSchema","isSchema","value","asSchema","AsTypeFactory","create"]}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { WithMeta } from './Payload';
|
|
1
2
|
export declare const isPayloadOfSchemaType: <T extends {
|
|
2
3
|
schema: string;
|
|
3
4
|
} & object>(schema: string) => (x?: unknown | null) => x is T;
|
|
5
|
+
export declare const isPayloadOfSchemaTypeWithMeta: <T extends {
|
|
6
|
+
schema: string;
|
|
7
|
+
} & object>(schema: string) => (x?: unknown | null) => x is WithMeta<T>;
|
|
4
8
|
export declare const notPayloadOfSchemaType: <T extends {
|
|
5
9
|
schema: string;
|
|
6
10
|
} & object>(schema: string) => (x?: unknown | null) => x is T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isPayloadOfSchemaType.d.ts","sourceRoot":"","sources":["../../src/isPayloadOfSchemaType.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"isPayloadOfSchemaType.d.ts","sourceRoot":"","sources":["../../src/isPayloadOfSchemaType.ts"],"names":[],"mappings":"AACA,OAAO,EAAW,QAAQ,EAAE,MAAM,WAAW,CAAA;AAE7C,eAAO,MAAM,qBAAqB;;oBAA+B,MAAM,UACzD,OAAO,GAAG,IAAI,WAC3B,CAAA;AAED,eAAO,MAAM,6BAA6B;;oBAA+B,MAAM,UACjE,OAAO,GAAG,IAAI,qBAC3B,CAAA;AAED,eAAO,MAAM,sBAAsB;;oBAA+B,MAAM,UAC1D,OAAO,GAAG,IAAI,WAC3B,CAAA"}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { WithMeta } from './Payload';
|
|
1
2
|
export declare const isPayloadOfSchemaType: <T extends {
|
|
2
3
|
schema: string;
|
|
3
4
|
} & object>(schema: string) => (x?: unknown | null) => x is T;
|
|
5
|
+
export declare const isPayloadOfSchemaTypeWithMeta: <T extends {
|
|
6
|
+
schema: string;
|
|
7
|
+
} & object>(schema: string) => (x?: unknown | null) => x is WithMeta<T>;
|
|
4
8
|
export declare const notPayloadOfSchemaType: <T extends {
|
|
5
9
|
schema: string;
|
|
6
10
|
} & object>(schema: string) => (x?: unknown | null) => x is T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isPayloadOfSchemaType.d.ts","sourceRoot":"","sources":["../../src/isPayloadOfSchemaType.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"isPayloadOfSchemaType.d.ts","sourceRoot":"","sources":["../../src/isPayloadOfSchemaType.ts"],"names":[],"mappings":"AACA,OAAO,EAAW,QAAQ,EAAE,MAAM,WAAW,CAAA;AAE7C,eAAO,MAAM,qBAAqB;;oBAA+B,MAAM,UACzD,OAAO,GAAG,IAAI,WAC3B,CAAA;AAED,eAAO,MAAM,6BAA6B;;oBAA+B,MAAM,UACjE,OAAO,GAAG,IAAI,qBAC3B,CAAA;AAED,eAAO,MAAM,sBAAsB;;oBAA+B,MAAM,UAC1D,OAAO,GAAG,IAAI,WAC3B,CAAA"}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { WithMeta } from './Payload';
|
|
1
2
|
export declare const isPayloadOfSchemaType: <T extends {
|
|
2
3
|
schema: string;
|
|
3
4
|
} & object>(schema: string) => (x?: unknown | null) => x is T;
|
|
5
|
+
export declare const isPayloadOfSchemaTypeWithMeta: <T extends {
|
|
6
|
+
schema: string;
|
|
7
|
+
} & object>(schema: string) => (x?: unknown | null) => x is WithMeta<T>;
|
|
4
8
|
export declare const notPayloadOfSchemaType: <T extends {
|
|
5
9
|
schema: string;
|
|
6
10
|
} & object>(schema: string) => (x?: unknown | null) => x is T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isPayloadOfSchemaType.d.ts","sourceRoot":"","sources":["../../src/isPayloadOfSchemaType.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"isPayloadOfSchemaType.d.ts","sourceRoot":"","sources":["../../src/isPayloadOfSchemaType.ts"],"names":[],"mappings":"AACA,OAAO,EAAW,QAAQ,EAAE,MAAM,WAAW,CAAA;AAE7C,eAAO,MAAM,qBAAqB;;oBAA+B,MAAM,UACzD,OAAO,GAAG,IAAI,WAC3B,CAAA;AAED,eAAO,MAAM,6BAA6B;;oBAA+B,MAAM,UACjE,OAAO,GAAG,IAAI,qBAC3B,CAAA;AAED,eAAO,MAAM,sBAAsB;;oBAA+B,MAAM,UAC1D,OAAO,GAAG,IAAI,WAC3B,CAAA"}
|
package/dist/node/Payload.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Hash } from '@xylabs/hex';
|
|
2
|
-
import { EmptyObject, JsonObject
|
|
2
|
+
import { EmptyObject, JsonObject } from '@xylabs/object';
|
|
3
3
|
import { Schema, WithSchema } from './Schema';
|
|
4
4
|
/** Meta fields for a payload - Either both $hash and $meta should exist or neither */
|
|
5
5
|
export interface PayloadMetaFields extends EmptyObject {
|
|
@@ -24,9 +24,10 @@ export type Payload<T extends void | EmptyObject | WithSchema = void, S extends
|
|
|
24
24
|
export type OverridablePayload<T extends Payload> = Omit<T, 'schema'> & {
|
|
25
25
|
schema: string;
|
|
26
26
|
};
|
|
27
|
-
export type DivinedPayload<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = Payload<WithAdditional<{
|
|
28
|
-
sources: Hash[];
|
|
29
|
-
}, T>, S>;
|
|
30
27
|
export type WithMeta<T extends Payload = Payload> = T & PayloadMetaFields;
|
|
28
|
+
export type WithOptionalMeta<T extends Payload = Payload> = Partial<WithMeta<T>> & Omit<WithMeta<T>, '$hash'>;
|
|
31
29
|
export type PayloadWithMeta<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithMeta<Payload<T, S>>;
|
|
30
|
+
export declare const unMeta: <T extends WithMeta<{
|
|
31
|
+
schema: string;
|
|
32
|
+
} & object>>(payload?: T | undefined) => T | undefined;
|
|
32
33
|
//# sourceMappingURL=Payload.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Payload.d.ts","sourceRoot":"","sources":["../../src/Payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"Payload.d.ts","sourceRoot":"","sources":["../../src/Payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAExD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAE7C,sFAAsF;AACtF,MAAM,WAAW,iBAAkB,SAAQ,WAAW;IACpD,8EAA8E;IAC9E,KAAK,EAAE,IAAI,CAAA;IACX,wEAAwE;IACxE,KAAK,CAAC,EAAE,UAAU,CAAA;CACnB;AAED,sCAAsC;AACtC,MAAM,MAAM,aAAa,GAAG,WAAW,CAAA;AAEvC,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,WAAW,GAAG,IAAI,GAAG,IAAI,IAAI,UAAU,CAAC,CAAC,SAAS,WAAW,GAAG,aAAa,GAAG,CAAC,GAAG,aAAa,CAAC,CAAA;AAEpI,6BAA6B;A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AO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AAEvI,eAAO,MAAM,MAAM;;sDAMlB,CAAA"}
|
package/dist/node/Payload.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Hash } from '@xylabs/hex';
|
|
2
|
-
import { EmptyObject, JsonObject
|
|
2
|
+
import { EmptyObject, JsonObject } from '@xylabs/object';
|
|
3
3
|
import { Schema, WithSchema } from './Schema';
|
|
4
4
|
/** Meta fields for a payload - Either both $hash and $meta should exist or neither */
|
|
5
5
|
export interface PayloadMetaFields extends EmptyObject {
|
|
@@ -24,9 +24,10 @@ export type Payload<T extends void | EmptyObject | WithSchema = void, S extends
|
|
|
24
24
|
export type OverridablePayload<T extends Payload> = Omit<T, 'schema'> & {
|
|
25
25
|
schema: string;
|
|
26
26
|
};
|
|
27
|
-
export type DivinedPayload<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = Payload<WithAdditional<{
|
|
28
|
-
sources: Hash[];
|
|
29
|
-
}, T>, S>;
|
|
30
27
|
export type WithMeta<T extends Payload = Payload> = T & PayloadMetaFields;
|
|
28
|
+
export type WithOptionalMeta<T extends Payload = Payload> = Partial<WithMeta<T>> & Omit<WithMeta<T>, '$hash'>;
|
|
31
29
|
export type PayloadWithMeta<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithMeta<Payload<T, S>>;
|
|
30
|
+
export declare const unMeta: <T extends WithMeta<{
|
|
31
|
+
schema: string;
|
|
32
|
+
} & object>>(payload?: T | undefined) => T | undefined;
|
|
32
33
|
//# sourceMappingURL=Payload.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Payload.d.ts","sourceRoot":"","sources":["../../src/Payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"Payload.d.ts","sourceRoot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C,GAAG,aAAa,CAAA;AAEvB,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,OAAO,IAAI,IAAI,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAA;AAE1F,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI,CAAC,GAAG,iBAAiB,CAAA;AACzE,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAA;AAE7G,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,IAAI,GAAG,WAAW,GAAG,UAAU,GAAG,IAAI,EAAE,CAAC,SAAS,MAAM,GAAG,IAAI,GAAG,IAAI,IAAI,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AAEvI,eAAO,MAAM,MAAM;;sDAMlB,CAAA"}
|
package/dist/node/Payload.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Hash } from '@xylabs/hex';
|
|
2
|
-
import { EmptyObject, JsonObject
|
|
2
|
+
import { EmptyObject, JsonObject } from '@xylabs/object';
|
|
3
3
|
import { Schema, WithSchema } from './Schema';
|
|
4
4
|
/** Meta fields for a payload - Either both $hash and $meta should exist or neither */
|
|
5
5
|
export interface PayloadMetaFields extends EmptyObject {
|
|
@@ -24,9 +24,10 @@ export type Payload<T extends void | EmptyObject | WithSchema = void, S extends
|
|
|
24
24
|
export type OverridablePayload<T extends Payload> = Omit<T, 'schema'> & {
|
|
25
25
|
schema: string;
|
|
26
26
|
};
|
|
27
|
-
export type DivinedPayload<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = Payload<WithAdditional<{
|
|
28
|
-
sources: Hash[];
|
|
29
|
-
}, T>, S>;
|
|
30
27
|
export type WithMeta<T extends Payload = Payload> = T & PayloadMetaFields;
|
|
28
|
+
export type WithOptionalMeta<T extends Payload = Payload> = Partial<WithMeta<T>> & Omit<WithMeta<T>, '$hash'>;
|
|
31
29
|
export type PayloadWithMeta<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithMeta<Payload<T, S>>;
|
|
30
|
+
export declare const unMeta: <T extends WithMeta<{
|
|
31
|
+
schema: string;
|
|
32
|
+
} & object>>(payload?: T | undefined) => T | undefined;
|
|
32
33
|
//# sourceMappingURL=Payload.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Payload.d.ts","sourceRoot":"","sources":["../../src/Payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"Payload.d.ts","sourceRoot":"","sources":["../../src/Payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAExD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAE7C,sFAAsF;AACtF,MAAM,WAAW,iBAAkB,SAAQ,WAAW;IACpD,8EAA8E;IAC9E,KAAK,EAAE,IAAI,CAAA;IACX,wEAAwE;IACxE,KAAK,CAAC,EAAE,UAAU,CAAA;CACnB;AAED,sCAAsC;AACtC,MAAM,MAAM,aAAa,GAAG,WAAW,CAAA;AAEvC,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,WAAW,GAAG,IAAI,GAAG,IAAI,IAAI,UAAU,CAAC,CAAC,SAAS,WAAW,GAAG,aAAa,GAAG,CAAC,GAAG,aAAa,CAAC,CAAA;AAEpI,6BAA6B;AAC7B,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,IAA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AAEvI,eAAO,MAAM,MAAM;;sDAMlB,CAAA"}
|
package/dist/node/index.cjs
CHANGED
|
@@ -31,10 +31,12 @@ __export(src_exports, {
|
|
|
31
31
|
isModuleError: () => isModuleError,
|
|
32
32
|
isPayload: () => isPayload,
|
|
33
33
|
isPayloadOfSchemaType: () => isPayloadOfSchemaType,
|
|
34
|
+
isPayloadOfSchemaTypeWithMeta: () => isPayloadOfSchemaTypeWithMeta,
|
|
34
35
|
isPayloadWithHash: () => isPayloadWithHash,
|
|
35
36
|
isSchema: () => isSchema,
|
|
36
37
|
isWithHash: () => isWithHash,
|
|
37
|
-
notPayloadOfSchemaType: () => notPayloadOfSchemaType
|
|
38
|
+
notPayloadOfSchemaType: () => notPayloadOfSchemaType,
|
|
39
|
+
unMeta: () => unMeta
|
|
38
40
|
});
|
|
39
41
|
module.exports = __toCommonJS(src_exports);
|
|
40
42
|
|
|
@@ -59,6 +61,9 @@ var asPayload = /* @__PURE__ */ __name((schema) => import_object.AsObjectFactory
|
|
|
59
61
|
var isPayloadOfSchemaType = /* @__PURE__ */ __name((schema) => {
|
|
60
62
|
return (x) => isAnyPayload(x) && (x == null ? void 0 : x.schema) === schema;
|
|
61
63
|
}, "isPayloadOfSchemaType");
|
|
64
|
+
var isPayloadOfSchemaTypeWithMeta = /* @__PURE__ */ __name((schema) => {
|
|
65
|
+
return (x) => isPayloadOfSchemaType(schema)(x) && x.$hash !== void 0 && x.$meta !== void 0;
|
|
66
|
+
}, "isPayloadOfSchemaTypeWithMeta");
|
|
62
67
|
var notPayloadOfSchemaType = /* @__PURE__ */ __name((schema) => {
|
|
63
68
|
return (x) => !isAnyPayload(x) || (x == null ? void 0 : x.schema) !== schema;
|
|
64
69
|
}, "notPayloadOfSchemaType");
|
|
@@ -75,6 +80,14 @@ var isPayloadWithHash = /* @__PURE__ */ __name((value) => {
|
|
|
75
80
|
return isAnyPayload(value) && isWithHash(value);
|
|
76
81
|
}, "isPayloadWithHash");
|
|
77
82
|
|
|
83
|
+
// src/Payload.ts
|
|
84
|
+
var unMeta = /* @__PURE__ */ __name((payload) => {
|
|
85
|
+
if (payload) {
|
|
86
|
+
const { $meta, $hash, ...result } = payload;
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
}, "unMeta");
|
|
90
|
+
|
|
78
91
|
// src/PayloadSet/PayloadSetSchema.ts
|
|
79
92
|
var PayloadSetSchema = "network.xyo.payload.set";
|
|
80
93
|
|
|
@@ -100,9 +113,11 @@ var asSchema = import_object2.AsTypeFactory.create(isSchema);
|
|
|
100
113
|
isModuleError,
|
|
101
114
|
isPayload,
|
|
102
115
|
isPayloadOfSchemaType,
|
|
116
|
+
isPayloadOfSchemaTypeWithMeta,
|
|
103
117
|
isPayloadWithHash,
|
|
104
118
|
isSchema,
|
|
105
119
|
isWithHash,
|
|
106
|
-
notPayloadOfSchemaType
|
|
120
|
+
notPayloadOfSchemaType,
|
|
121
|
+
unMeta
|
|
107
122
|
});
|
|
108
123
|
//# sourceMappingURL=index.cjs.map
|
package/dist/node/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/isPayloadWithHash.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.ts"],"sourcesContent":["export * from './Error'\nexport * from './isPayload'\nexport * from './isPayloadOfSchemaType'\nexport * from './isPayloadWithHash'\nexport * from './Payload'\nexport * from './PayloadFindFilter'\nexport * from './PayloadSet'\nexport * from './Query'\nexport * from './Schema'\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport { Payload } from './Payload'\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'\nimport { Payload } from './Payload'\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 notPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => !isAnyPayload(x) || x?.schema !== schema\n}\n","import { isPayloadOfSchemaType } from './isPayloadOfSchemaType'\nimport { Payload } from './Payload'\n\nexport type ModuleErrorSchema = 'network.xyo.error.module'\nexport const ModuleErrorSchema: ModuleErrorSchema = 'network.xyo.error.module'\n\nexport type ModuleError = Payload<{\n message?: string\n name?: string\n query?: string\n schema: ModuleErrorSchema\n sources?: string[]\n}>\n\nexport const isModuleError = isPayloadOfSchemaType<ModuleError>(ModuleErrorSchema)\n","import { isAnyPayload } from './isPayload'\nimport { Payload, WithMeta } from './Payload'\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","export type PayloadSetSchema = 'network.xyo.payload.set'\nexport const PayloadSetSchema: PayloadSetSchema = 'network.xyo.payload.set'\n","import { AsTypeFactory, EmptyObject } from '@xylabs/object'\n\n/** Schema type in Javascript is a string */\nexport type Schema = string\n\nexport const PayloadSchema = 'network.xyo.payload'\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n if (typeof value === 'string') {\n return true\n }\n return false\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
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/isPayloadWithHash.ts","../../src/Payload.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.ts"],"sourcesContent":["export * from './Error'\nexport * from './isPayload'\nexport * from './isPayloadOfSchemaType'\nexport * from './isPayloadWithHash'\nexport * from './Payload'\nexport * from './PayloadFindFilter'\nexport * from './PayloadSet'\nexport * from './Query'\nexport * from './Schema'\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport { Payload } from './Payload'\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'\nimport { Payload, WithMeta } from './Payload'\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 && x.$meta !== undefined\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","import { isPayloadOfSchemaType } from './isPayloadOfSchemaType'\nimport { Payload } from './Payload'\n\nexport type ModuleErrorSchema = 'network.xyo.error.module'\nexport const ModuleErrorSchema: ModuleErrorSchema = 'network.xyo.error.module'\n\nexport type ModuleError = Payload<{\n message?: string\n name?: string\n query?: string\n schema: ModuleErrorSchema\n sources?: string[]\n}>\n\nexport const isModuleError = isPayloadOfSchemaType<ModuleError>(ModuleErrorSchema)\n","import { isAnyPayload } from './isPayload'\nimport { Payload, WithMeta } from './Payload'\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 { Hash } from '@xylabs/hex'\nimport { EmptyObject, JsonObject } from '@xylabs/object'\n\nimport { Schema, WithSchema } from './Schema'\n\n/** Meta fields for a payload - Either both $hash and $meta should exist or neither */\nexport interface PayloadMetaFields extends EmptyObject {\n /** Hash of the body of the payload excluding the items in the $meta object */\n $hash: Hash\n /** Meta data that should be included in the main hash of the payload */\n $meta?: JsonObject\n}\n\n/** Additional fields for a payload */\nexport type PayloadFields = EmptyObject\n\nexport type WithPayload<T extends EmptyObject | void = void> = WithSchema<T extends EmptyObject ? PayloadFields & T : PayloadFields>\n\n/** Base Type for Payloads */\nexport type Payload<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = T extends WithSchema\n ? S extends Schema\n ? /* T (w/Schema) & S provided */\n WithPayload<Omit<T, 'schema'> & { schema: S } & PayloadFields>\n : /* Only T (w/Schema) provided */\n WithPayload<T>\n : T extends object\n ? S extends Schema\n ? /* T (w/o Schema) & S provided */\n WithPayload<T & { schema: S } & PayloadFields>\n : /* Only T (w/o Schema) provided */\n WithPayload<T & { schema: Schema } & PayloadFields>\n : /* Either just S or neither S or T provided */\n {\n schema: S extends Schema ? S : Schema\n } & PayloadFields\n\nexport type OverridablePayload<T extends Payload> = Omit<T, 'schema'> & { schema: string }\n\nexport type WithMeta<T extends Payload = Payload> = T & PayloadMetaFields\nexport type WithOptionalMeta<T extends Payload = Payload> = Partial<WithMeta<T>> & Omit<WithMeta<T>, '$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 const { $meta, $hash, ...result } = 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 { AsTypeFactory, EmptyObject } from '@xylabs/object'\n\n/** Schema type in Javascript is a string */\nexport type Schema = string\n\nexport const PayloadSchema = 'network.xyo.payload'\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n if (typeof value === 'string') {\n return true\n }\n return false\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;;;;;;;;;;;;;;;;;;;;;;ACCA,oBAA0C;AAInC,IAAMA,eAAe,wBAACC,UAAAA;AAC3B,UAAIC,wBAASD,KAAAA,GAA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C,gBAAgB;AAGtB,IAAMC,WAAW,wBAACC,UAAAA;AACvB,MAAI,OAAOA,UAAU,UAAU;AAC7B,WAAO;EACT;AACA,SAAO;AACT,GALwB;AAOjB,IAAMC,WAAWC,6BAAcC,OAAeJ,QAAAA;","names":["isAnyPayload","value","isObject","schema","asAnyPayload","AsObjectFactory","create","isPayload","includes","asPayload","isPayloadOfSchemaType","schema","x","isAnyPayload","isPayloadOfSchemaTypeWithMeta","$hash","undefined","$meta","notPayloadOfSchemaType","ModuleErrorSchema","isModuleError","isPayloadOfSchemaType","isWithHash","value","$hash","isPayloadWithHash","isAnyPayload","unMeta","payload","$meta","$hash","result","PayloadSetSchema","import_object","PayloadSchema","isSchema","value","asSchema","AsTypeFactory","create"]}
|
package/dist/node/index.js
CHANGED
|
@@ -22,6 +22,9 @@ var asPayload = /* @__PURE__ */ __name((schema) => AsObjectFactory.create((value
|
|
|
22
22
|
var isPayloadOfSchemaType = /* @__PURE__ */ __name((schema) => {
|
|
23
23
|
return (x) => isAnyPayload(x) && (x == null ? void 0 : x.schema) === schema;
|
|
24
24
|
}, "isPayloadOfSchemaType");
|
|
25
|
+
var isPayloadOfSchemaTypeWithMeta = /* @__PURE__ */ __name((schema) => {
|
|
26
|
+
return (x) => isPayloadOfSchemaType(schema)(x) && x.$hash !== void 0 && x.$meta !== void 0;
|
|
27
|
+
}, "isPayloadOfSchemaTypeWithMeta");
|
|
25
28
|
var notPayloadOfSchemaType = /* @__PURE__ */ __name((schema) => {
|
|
26
29
|
return (x) => !isAnyPayload(x) || (x == null ? void 0 : x.schema) !== schema;
|
|
27
30
|
}, "notPayloadOfSchemaType");
|
|
@@ -38,6 +41,14 @@ var isPayloadWithHash = /* @__PURE__ */ __name((value) => {
|
|
|
38
41
|
return isAnyPayload(value) && isWithHash(value);
|
|
39
42
|
}, "isPayloadWithHash");
|
|
40
43
|
|
|
44
|
+
// src/Payload.ts
|
|
45
|
+
var unMeta = /* @__PURE__ */ __name((payload) => {
|
|
46
|
+
if (payload) {
|
|
47
|
+
const { $meta, $hash, ...result } = payload;
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
}, "unMeta");
|
|
51
|
+
|
|
41
52
|
// src/PayloadSet/PayloadSetSchema.ts
|
|
42
53
|
var PayloadSetSchema = "network.xyo.payload.set";
|
|
43
54
|
|
|
@@ -62,9 +73,11 @@ export {
|
|
|
62
73
|
isModuleError,
|
|
63
74
|
isPayload,
|
|
64
75
|
isPayloadOfSchemaType,
|
|
76
|
+
isPayloadOfSchemaTypeWithMeta,
|
|
65
77
|
isPayloadWithHash,
|
|
66
78
|
isSchema,
|
|
67
79
|
isWithHash,
|
|
68
|
-
notPayloadOfSchemaType
|
|
80
|
+
notPayloadOfSchemaType,
|
|
81
|
+
unMeta
|
|
69
82
|
};
|
|
70
83
|
//# sourceMappingURL=index.js.map
|
package/dist/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/isPayloadWithHash.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport { Payload } from './Payload'\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'\nimport { Payload } from './Payload'\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 notPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => !isAnyPayload(x) || x?.schema !== schema\n}\n","import { isPayloadOfSchemaType } from './isPayloadOfSchemaType'\nimport { Payload } from './Payload'\n\nexport type ModuleErrorSchema = 'network.xyo.error.module'\nexport const ModuleErrorSchema: ModuleErrorSchema = 'network.xyo.error.module'\n\nexport type ModuleError = Payload<{\n message?: string\n name?: string\n query?: string\n schema: ModuleErrorSchema\n sources?: string[]\n}>\n\nexport const isModuleError = isPayloadOfSchemaType<ModuleError>(ModuleErrorSchema)\n","import { isAnyPayload } from './isPayload'\nimport { Payload, WithMeta } from './Payload'\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","export type PayloadSetSchema = 'network.xyo.payload.set'\nexport const PayloadSetSchema: PayloadSetSchema = 'network.xyo.payload.set'\n","import { AsTypeFactory, EmptyObject } from '@xylabs/object'\n\n/** Schema type in Javascript is a string */\nexport type Schema = string\n\nexport const PayloadSchema = 'network.xyo.payload'\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n if (typeof value === 'string') {\n return true\n }\n return false\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":";;;;AACA,SAASA,iBAAiBC,gBAAgB;AAInC,IAAMC,eAAe,wBAACC,UAAAA;AAC3B,MAAIC,SAASD,KAAAA,GAAQ;AACnB,WAAO,OAAOA,MAAME,WAAW;EACjC;AACA,SAAO;AACT,GAL4B;AAOrB,IAAMC,eAAeC,gBAAgBC,OAAON,YAAAA;AAE5C,IAAMO,YACX,wBAAoBJ,WACpB,CAACF,UAAAA;AACC,MAAID,aAAaC,KAAAA,GAAQ;AACvB,WAAOE,OAAOK,SAASP,MAAME,MAAM;EACrC;AACA,SAAO;AACT,GANA;AAQK,IAAMM,YAAY,wBAAoBN,WAAqBE,gBAAgBC,OAAO,CAACL,UAA+BM,UAAUJ,MAAAA,EAAQF,KAAAA,CAAAA,GAAlH;;;ACpBlB,IAAMS,wBAAwB,wBAAoBC,WAAAA;AACvD,SAAO,CAACC,MAA+BC,aAAaD,CAAAA,MAAMA,uBAAGD,YAAWA;AAC1E,GAFqC;AAI9B,IAAMG,
|
|
1
|
+
{"version":3,"sources":["../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/isPayloadWithHash.ts","../../src/Payload.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport { Payload } from './Payload'\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'\nimport { Payload, WithMeta } from './Payload'\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 && x.$meta !== undefined\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","import { isPayloadOfSchemaType } from './isPayloadOfSchemaType'\nimport { Payload } from './Payload'\n\nexport type ModuleErrorSchema = 'network.xyo.error.module'\nexport const ModuleErrorSchema: ModuleErrorSchema = 'network.xyo.error.module'\n\nexport type ModuleError = Payload<{\n message?: string\n name?: string\n query?: string\n schema: ModuleErrorSchema\n sources?: string[]\n}>\n\nexport const isModuleError = isPayloadOfSchemaType<ModuleError>(ModuleErrorSchema)\n","import { isAnyPayload } from './isPayload'\nimport { Payload, WithMeta } from './Payload'\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 { Hash } from '@xylabs/hex'\nimport { EmptyObject, JsonObject } from '@xylabs/object'\n\nimport { Schema, WithSchema } from './Schema'\n\n/** Meta fields for a payload - Either both $hash and $meta should exist or neither */\nexport interface PayloadMetaFields extends EmptyObject {\n /** Hash of the body of the payload excluding the items in the $meta object */\n $hash: Hash\n /** Meta data that should be included in the main hash of the payload */\n $meta?: JsonObject\n}\n\n/** Additional fields for a payload */\nexport type PayloadFields = EmptyObject\n\nexport type WithPayload<T extends EmptyObject | void = void> = WithSchema<T extends EmptyObject ? PayloadFields & T : PayloadFields>\n\n/** Base Type for Payloads */\nexport type Payload<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = T extends WithSchema\n ? S extends Schema\n ? /* T (w/Schema) & S provided */\n WithPayload<Omit<T, 'schema'> & { schema: S } & PayloadFields>\n : /* Only T (w/Schema) provided */\n WithPayload<T>\n : T extends object\n ? S extends Schema\n ? /* T (w/o Schema) & S provided */\n WithPayload<T & { schema: S } & PayloadFields>\n : /* Only T (w/o Schema) provided */\n WithPayload<T & { schema: Schema } & PayloadFields>\n : /* Either just S or neither S or T provided */\n {\n schema: S extends Schema ? S : Schema\n } & PayloadFields\n\nexport type OverridablePayload<T extends Payload> = Omit<T, 'schema'> & { schema: string }\n\nexport type WithMeta<T extends Payload = Payload> = T & PayloadMetaFields\nexport type WithOptionalMeta<T extends Payload = Payload> = Partial<WithMeta<T>> & Omit<WithMeta<T>, '$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 const { $meta, $hash, ...result } = 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 { AsTypeFactory, EmptyObject } from '@xylabs/object'\n\n/** Schema type in Javascript is a string */\nexport type Schema = string\n\nexport const PayloadSchema = 'network.xyo.payload'\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n if (typeof value === 'string') {\n return true\n }\n return false\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 : S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,GAAGC,OAAAA,IAAWH;AACpC,WAAOG;EACT;AACF,GANsB;;;AC1Cf,IAAMC,mBAAqC;;;ACDlD,SAASC,qBAAkC;AAKpC,IAAMC,gBAAgB;AAGtB,IAAMC,WAAW,wBAACC,UAAAA;AACvB,MAAI,OAAOA,UAAU,UAAU;AAC7B,WAAO;EACT;AACA,SAAO;AACT,GALwB;AAOjB,IAAMC,WAAWC,cAAcC,OAAeJ,QAAAA;","names":["AsObjectFactory","isObject","isAnyPayload","value","isObject","schema","asAnyPayload","AsObjectFactory","create","isPayload","includes","asPayload","isPayloadOfSchemaType","schema","x","isAnyPayload","isPayloadOfSchemaTypeWithMeta","$hash","undefined","$meta","notPayloadOfSchemaType","ModuleErrorSchema","isModuleError","isPayloadOfSchemaType","isWithHash","value","$hash","isPayloadWithHash","isAnyPayload","unMeta","payload","$meta","$hash","result","PayloadSetSchema","AsTypeFactory","PayloadSchema","isSchema","value","asSchema","AsTypeFactory","create"]}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { WithMeta } from './Payload';
|
|
1
2
|
export declare const isPayloadOfSchemaType: <T extends {
|
|
2
3
|
schema: string;
|
|
3
4
|
} & object>(schema: string) => (x?: unknown | null) => x is T;
|
|
5
|
+
export declare const isPayloadOfSchemaTypeWithMeta: <T extends {
|
|
6
|
+
schema: string;
|
|
7
|
+
} & object>(schema: string) => (x?: unknown | null) => x is WithMeta<T>;
|
|
4
8
|
export declare const notPayloadOfSchemaType: <T extends {
|
|
5
9
|
schema: string;
|
|
6
10
|
} & object>(schema: string) => (x?: unknown | null) => x is T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isPayloadOfSchemaType.d.ts","sourceRoot":"","sources":["../../src/isPayloadOfSchemaType.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"isPayloadOfSchemaType.d.ts","sourceRoot":"","sources":["../../src/isPayloadOfSchemaType.ts"],"names":[],"mappings":"AACA,OAAO,EAAW,QAAQ,EAAE,MAAM,WAAW,CAAA;AAE7C,eAAO,MAAM,qBAAqB;;oBAA+B,MAAM,UACzD,OAAO,GAAG,IAAI,WAC3B,CAAA;AAED,eAAO,MAAM,6BAA6B;;oBAA+B,MAAM,UACjE,OAAO,GAAG,IAAI,qBAC3B,CAAA;AAED,eAAO,MAAM,sBAAsB;;oBAA+B,MAAM,UAC1D,OAAO,GAAG,IAAI,WAC3B,CAAA"}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { WithMeta } from './Payload';
|
|
1
2
|
export declare const isPayloadOfSchemaType: <T extends {
|
|
2
3
|
schema: string;
|
|
3
4
|
} & object>(schema: string) => (x?: unknown | null) => x is T;
|
|
5
|
+
export declare const isPayloadOfSchemaTypeWithMeta: <T extends {
|
|
6
|
+
schema: string;
|
|
7
|
+
} & object>(schema: string) => (x?: unknown | null) => x is WithMeta<T>;
|
|
4
8
|
export declare const notPayloadOfSchemaType: <T extends {
|
|
5
9
|
schema: string;
|
|
6
10
|
} & object>(schema: string) => (x?: unknown | null) => x is T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isPayloadOfSchemaType.d.ts","sourceRoot":"","sources":["../../src/isPayloadOfSchemaType.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"isPayloadOfSchemaType.d.ts","sourceRoot":"","sources":["../../src/isPayloadOfSchemaType.ts"],"names":[],"mappings":"AACA,OAAO,EAAW,QAAQ,EAAE,MAAM,WAAW,CAAA;AAE7C,eAAO,MAAM,qBAAqB;;oBAA+B,MAAM,UACzD,OAAO,GAAG,IAAI,WAC3B,CAAA;AAED,eAAO,MAAM,6BAA6B;;oBAA+B,MAAM,UACjE,OAAO,GAAG,IAAI,qBAC3B,CAAA;AAED,eAAO,MAAM,sBAAsB;;oBAA+B,MAAM,UAC1D,OAAO,GAAG,IAAI,WAC3B,CAAA"}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { WithMeta } from './Payload';
|
|
1
2
|
export declare const isPayloadOfSchemaType: <T extends {
|
|
2
3
|
schema: string;
|
|
3
4
|
} & object>(schema: string) => (x?: unknown | null) => x is T;
|
|
5
|
+
export declare const isPayloadOfSchemaTypeWithMeta: <T extends {
|
|
6
|
+
schema: string;
|
|
7
|
+
} & object>(schema: string) => (x?: unknown | null) => x is WithMeta<T>;
|
|
4
8
|
export declare const notPayloadOfSchemaType: <T extends {
|
|
5
9
|
schema: string;
|
|
6
10
|
} & object>(schema: string) => (x?: unknown | null) => x is T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isPayloadOfSchemaType.d.ts","sourceRoot":"","sources":["../../src/isPayloadOfSchemaType.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"isPayloadOfSchemaType.d.ts","sourceRoot":"","sources":["../../src/isPayloadOfSchemaType.ts"],"names":[],"mappings":"AACA,OAAO,EAAW,QAAQ,EAAE,MAAM,WAAW,CAAA;AAE7C,eAAO,MAAM,qBAAqB;;oBAA+B,MAAM,UACzD,OAAO,GAAG,IAAI,WAC3B,CAAA;AAED,eAAO,MAAM,6BAA6B;;oBAA+B,MAAM,UACjE,OAAO,GAAG,IAAI,qBAC3B,CAAA;AAED,eAAO,MAAM,sBAAsB;;oBAA+B,MAAM,UAC1D,OAAO,GAAG,IAAI,WAC3B,CAAA"}
|
package/package.json
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@xylabs/hex": "^2.14.
|
|
14
|
-
"@xylabs/object": "^2.89.
|
|
13
|
+
"@xylabs/hex": "^2.14.1",
|
|
14
|
+
"@xylabs/object": "^2.89.1"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@xylabs/ts-scripts-yarn3": "^3.2.42",
|
|
@@ -57,6 +57,6 @@
|
|
|
57
57
|
},
|
|
58
58
|
"sideEffects": false,
|
|
59
59
|
"types": "dist/node/index.d.ts",
|
|
60
|
-
"version": "2.90.
|
|
60
|
+
"version": "2.90.3",
|
|
61
61
|
"type": "module"
|
|
62
62
|
}
|
package/src/Payload.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Hash } from '@xylabs/hex'
|
|
2
|
-
import { EmptyObject, JsonObject
|
|
2
|
+
import { EmptyObject, JsonObject } from '@xylabs/object'
|
|
3
3
|
|
|
4
4
|
import { Schema, WithSchema } from './Schema'
|
|
5
5
|
|
|
@@ -36,11 +36,15 @@ export type Payload<T extends void | EmptyObject | WithSchema = void, S extends
|
|
|
36
36
|
|
|
37
37
|
export type OverridablePayload<T extends Payload> = Omit<T, 'schema'> & { schema: string }
|
|
38
38
|
|
|
39
|
-
export type DivinedPayload<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = Payload<
|
|
40
|
-
WithAdditional<{ sources: Hash[] }, T>,
|
|
41
|
-
S
|
|
42
|
-
>
|
|
43
|
-
|
|
44
39
|
export type WithMeta<T extends Payload = Payload> = T & PayloadMetaFields
|
|
40
|
+
export type WithOptionalMeta<T extends Payload = Payload> = Partial<WithMeta<T>> & Omit<WithMeta<T>, '$hash'>
|
|
45
41
|
|
|
46
42
|
export type PayloadWithMeta<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithMeta<Payload<T, S>>
|
|
43
|
+
|
|
44
|
+
export const unMeta = <T extends WithMeta<Payload>>(payload?: T): T | undefined => {
|
|
45
|
+
if (payload) {
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
47
|
+
const { $meta, $hash, ...result } = payload
|
|
48
|
+
return result as T
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { isAnyPayload } from './isPayload'
|
|
2
|
-
import { Payload } from './Payload'
|
|
2
|
+
import { Payload, WithMeta } from './Payload'
|
|
3
3
|
|
|
4
4
|
export const isPayloadOfSchemaType = <T extends Payload>(schema: string) => {
|
|
5
5
|
return (x?: unknown | null): x is T => isAnyPayload(x) && x?.schema === schema
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
export const isPayloadOfSchemaTypeWithMeta = <T extends Payload>(schema: string) => {
|
|
9
|
+
return (x?: unknown | null): x is WithMeta<T> => isPayloadOfSchemaType<WithMeta<T>>(schema)(x) && x.$hash !== undefined && x.$meta !== undefined
|
|
10
|
+
}
|
|
11
|
+
|
|
8
12
|
export const notPayloadOfSchemaType = <T extends Payload>(schema: string) => {
|
|
9
13
|
return (x?: unknown | null): x is T => !isAnyPayload(x) || x?.schema !== schema
|
|
10
14
|
}
|